FORUMS: list search recent posts

Closed Captioning problem and guidance

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Corby Logue
Closed Captioning problem and guidance
on Jan 25, 2013 at 9:54:09 pm

Like most people posting for the first time here, I have no experience with javascript and need some help.

However, I found something that is almost exactly what I need. Almost isn't close enough and I'm probably going to have to figure out the changes to make it work. Before I ask for help on that, I gave myself a crash course on javascript (give a fish v. teach to fish, etc.)

So before I go hat in hand with what I don't know, can I get some help on whether I have correctly deciphered what's going on in the following expression (which I pulled from a tutorial I found on youtube about using the voice recognition within CS to automate subtitling/closed captions).

L = thisComp.layer("stack_01.aif");
max = effect("words")("Slider");
n = 0;
if (L.marker.numKeys > 0){
n = L.marker.nearestKey(time).index;
if (L.marker.key(n).time > time){
n--;
}
}
s = "";
if (n > 0){
base = Math.floor((n-1)/max)*max + 1;
for (i = base; i < base + max; i++){
if (i <= L.marker.numKeys){
s += L.marker.key(i).comment + " ";
}
}
}
s


The first three lines are just defining variables and setting their values (I changed 'max' from the original code and hooked it up to a slider called "words")

The first conditional statement checks to see if the total number of markers on layer L is greater than 0. It is, so n is then assigned the value (the index number) of the nearest marker. If the time value of the nth marker is greater than the current time, subtract 1 from n.

At the second loop, n = 0 to start. So we just place s (which is currently nothing, (s = "")) into the comp. Next time back through, we are looking at the value for "max", looping through and placing the comment (which is the subtitle text) in that many markers into the composition.

So if I have my slider set to 20, I am getting 20 words. Which I am. Again, the above code works, I'm just making sure I understand what's happening. So I still have two questions.

1) The first conditional loop, I've seen it in a handful of expressions. While I can decipher it line by line, what's the logic behind it? Is it just saying, find the number of the next marker then subtract 1 from that number?

2) What I ultimately need is subtitle text that fills a box of a certain size (so instead of just 20 words, or whatever I set the slider value to). The problem with the above is sometimes 20 words is 3 lines, sometimes it barely makes it to line 3, sometimes it pushed to 4 lines (I'm using a text box, so it fills to the width of the box, before making a carriage return).

What the client needs wants is to fill three full lines (pretty much, it won't be justified on both margins). What attributes and methods should I be looking at? I combed through the Adobe reference guide but didn't see anything that was obviously helpful.

Logically what I'm thinking is that I'll just run a loop for each line. So if I want three lines, I loop it three times, but each line needs to be a certain length (as in a x-distance) and not a set number of words. Or is there a more elegant way?

Thanks for any help.


Return to posts index

Dan Ebberts
Re: Closed Captioning problem and guidance
on Jan 25, 2013 at 11:12:27 pm

1) The first section is looking for the most recent, previous marker. So if the nearest marker is in the future, subtract one from the index to get the previous one.

2) I don't think this expression is the right solution to your problem. You need a script to do the text fitting for you. There's really no practical way to use an expression to, as in your example, fill three lines of text. It would be an interesting scripting project though.

Dan



Return to posts index

Corby Logue
Re: Closed Captioning problem and guidance
on Jan 26, 2013 at 12:28:24 am

Dan, thanks for the reply. That you seem to reply to every post in this section is really commendable. And I do appreciate the feedback/answers.

Re #2. I'm not sure what you mean in terms of scripting. Is there another way to get scripting to control actions in After Effects? I'm not familiar. Sorry if that's a stupid question.


Return to posts index


Dan Ebberts
Re: Closed Captioning problem and guidance
on Jan 26, 2013 at 1:17:39 am

Yes, scripting is a different beast. You use an expression to control the value/animation of the property hosting the expression.

With scripting, you can actually build things (comps, projects, layers) apply effects, set keyframes, etc. A script generally runs once, on demand, does its thing and leaves, where an expression does its calculation on each frame. For your purposes, with scripting you can easily determine the extents of a text layer, which is not easy with expressions.

Dan



Return to posts index

Corby Logue
Re: Closed Captioning problem and guidance
on Jan 26, 2013 at 1:38:01 am

Thanks, Dan

I found the scripting guide for CS 6 on Adobe's website. Plenty to digest there. Fortunately, the weather here is crappy this weekend, so I should be able to keep myself occupied.


Return to posts index

Jennifer Arani
Re: Closed Captioning problem and guidance
on Mar 15, 2013 at 8:14:19 pm

I am working on the same type of expression above. JUST FYI if anyone else reads this.
Take the Text tool and draw the text area or text box. This will keep the words from going off the screen, because it wraps the text for you.

My issue is stopping the expression from displaying words when no one is speaking. So if my expression is always set to 9 words but I only want 2 of those words to show until I get closer to the next marker.

And then start the script back up.

Jennifer Arani


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2017 CreativeCOW.net All Rights Reserved
[TOP]