We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi
I'm trying to create a movie-based typeface. I want each letter to create a movie object. for example letter X needs to call X.mov and become an item in and array.
currentLetter = new Movie[str.length()];
for (int i=0; i<str.length(); i++) {
currentLetter[i] = new Movie(this, str.charAt(i)+".mov");
currentLetter[i].jump(random(currentLetter[i].duration()));
}
this returns:
"Could not load movie file .mov"
here is the entire code:
String str = "abab aba";
int wordsNum = 1;
int t = 0;
int[] wordsLength;
float kerning = -130;
float leading = 0;
float charLocation = 0;
float lineLocation = 0;
float fontHeight = 120;
float fontWidth = 160;
float horMargin = 100;
float vertMargin = 100;
Movie[] currentLetter;
import processing.video.*;
void setup() {
size(1200, 900);
frameRate(30);
// finding out how many words are there (important for the wordsLength array)
for (int i = 0; i<str.length(); i++) {
if (str.charAt(i)==' ') {
wordsNum++;
}
}
println("number of words is: ", wordsNum);
int letCount = 0;
wordsLength = new int[wordsNum];
for (int i = 0; i<str.length(); i++) {
if (str.charAt(i)==' ') {
wordsLength[t]=letCount;
letCount=0;
t++;
} else {
letCount++;
}
}
println(wordsLength);
currentLetter = new Movie[str.length()];
for (int i=0; i<str.length(); i++) {
currentLetter[i] = new Movie(this, str.charAt(i)+".mov");
currentLetter[i].jump(random(currentLetter[i].duration()));
}
t=0;
}
void draw() {
background(255);
blendMode(DARKEST);
charLocation = 0;
lineLocation = 0;
t = 0;
for (int let = 0; let < str.length(); let++) {
float letterxLocation = width-horMargin+charLocation-fontWidth;
image(currentLetter[let], letterxLocation, vertMargin+lineLocation, fontWidth, fontHeight);
// Character Location
charLocation = charLocation - fontWidth - kerning;
// checking if it's a new word
if (str.charAt(let)==' ' && t < wordsNum) {
// creatng a new line
if (width-horMargin+charLocation-wordsLength[t]*(fontWidth+kerning) < horMargin) {
charLocation = 0;
lineLocation = lineLocation + fontHeight + leading;
}
t++;
}
}
}
void movieEvent(Movie m) {
m.read();
}
Any ideas? :) Thank you!
Answers
I don't think you want to create multiple movie files playing the same movie. Instead, you could play a movie file (I mean, call your movie.play() function) and then whenever you want to place your movie frame, you just provide the coordinates via image(), exactly as you have done in your previous post:
https://forum.processing.org/two/discussion/25854/movie-files-do-not-show-no-error#latest
Kf
Hi
Thank you for your answer I want the movies to play independently at from different starting points. that's why I'm making separate movie files.
I see it causes a lot of performance issues. Is there possibly a more efficient way?
copied from another thread
Thank you for you answer :) The animations are supposed to be **not **synchronized.
I'm still contemplating the fixed width. I'd be happy to make it not-fixed in the future.
I will try to use sprites asap.
Hope it is helpful! Let us know here how it goes with sprites.
Please do not post near-duplicates: https://forum.processing.org/two/discussion/25876/frame-rate-multiple-videos-and-recording
If you are working on several closely related issues on a single aspect of a single piece of code (like typing multiple videos, and performance), then post updated code as a new message on your existing thread. That way all the information on what you are doing is in one place, and it is easier for us to help you. Duplicates are hard work for most of the forum moderators and volunteers, and it makes them unhappy.
(duplicate thread deleted)
@jeremydouglass, @koogs ok thank you!
FYI I've got a huge improvement in performance once added "P2D" to size value. Still will try the sprites angle.
Great!
While premature optimization is often unwarranted, optimizing for letter differences when they are resource-intensive is an interesting problem.
Note that even with non-synchronized movies, if the clips are short then you can constrain then to a few time alignments -- e.g. 3-second clips whose starts are aligned to 0,1,2 seconds. Now instead of up to 26 (or whatever) lookups, you have a maximum of up to three times that many -- 78 -- but that still isn't as bad as doing an individual sprite lookup for each of 2000 different character-frames. In principle: set a maximum complexity which sets a maximum execution load.
Due to the nature of letter frequency distribution in language, typing in English will mean that over two-thirds of the characters on the screen will be only nine letters -- ETOINSHRD.
https://en.wikipedia.org/wiki/Letter_frequency#Relative_frequencies_of_letters_in_the_English_language
If you want optimize while keeping the visual complexity of the work high, give letters like ETOIN more alignment points as they will be more visible "synchronized" -- but not too many, as they represent the majority of your load.
You can also do this dynamically, by alignment points as new letters are typed. So as you type the letter "e" in a string, each letter e starts aligned with (for example, using any series):
This means that two letters next two each other will never have the same alignment. A 1000 character paragraph will contain on average 120 Es; they will be covered by 11 different sprite images on any given frame.
Or you could use the known frequency of the word ahead of time and assign random 10 options to E, 5 to S, 2 to Z.
Of course, if you want the video font to feel like language, you may actually want tighter alignments -- only 1-2 at most per letter, possibly only one. Then the pile of flickering videos will look like a Zipf's distribution as they change together in different ratios -- that's how a page of natural language looks, with many shapes in different places all the same.
there's also a resize of each video going on. resizing things in draw() is bad.
https://en.wikipedia.org/wiki/Etaoin_shrdlu
good point. resizing videos inside draw on every frame can be really bad -- depending, it could have more negative impact on performance than every other positive optimization you could make all put together.
So I've tried using sprites and seems like it is not behaving better than using movie files. strangely enough, performence using P2D was much worse (attaching the code at the bottom).
a few questions:
(1) if I enter the original height an width of the video to the size value does it still act as if it is resizing it?
(2) Jeremy please tell me if I understand your answer correctly - will using a limited number of "starting points" improve performance?
(3) What if I will change a starting point only for each instance of the letter. let's say we use the word "Massachusetts", the starting points will be 1112211131123 That way, same letter won't have a similar starting point, but new starting points will be limited only to repeating letters. the question here is, should that improve performance?
Thank you for all your help you guys are wonderful :)
don't loadImages in draw() (or anything called from draw()). do it in setup() and reference it.
are you sure? this will load 3617*26=94042 images at the same time
@dehyde===
your code for videos cannot run: in setup() your array for movies contains null movies (called .mov) for each ' ' char: that's why you get the error you posted. That is easy to solve.
in draw() && in your first loop() you use str.length: that is the same error; you have to use your array length (after removing the null movies)
i have tested changing fontWidth && fontHeight to the real videos width && height in order to get rid of resizing: with 5 words and 4 videos(160/140) it works at 28fps
Not tested with 26 movies!
and loading 94042 images n at a time in draw will be SLOW. you need to compromise somewhere.
you forget that we haven't seen your assets, we don't know how big they are or how many frames they contain.
I've removed the currentLetter[i].jump and intrestingly enough the behaviour is the same and letter still seem randomizes.
@koogs
each asset is 120 fps, and contains ~3600 frames on 122*160 pixels. I don't mind long loading time, I was wondering though if the memory can hold that much data without burdening the system.
@akenaton
Currently I have a code that functions rather well (will attach to bottom), 20 fps for around 250 characters.
It's showing a lot of errors though and gets stuck occasionally.
and this:
code: