Create a timecode with expressions

Moderators: Disciple, zlovatt

Post Reply
malex
Posts: 20
Joined: May 21st, 2004, 3:03 pm

June 3rd, 2004, 11:10 am

Instead of using any timecode effect, you can very easily do this with expressions :

timeToCurrentFormat();


Apply this expression to a text layer's "source text" parameter.


Steps :
1/Create a text layer (type dummy text)
2/Twirl down to "Source Text"
3/Activate the expression field and paste the expression. It will basically give you the current timecode, so you can't really fake a different timecode (unless you move the layer around in time and precompose)
Guest

June 9th, 2004, 10:36 am

The first argument to timeToCurrentFormat is the time you want to display in seconds. By default this is the current time -- you can display any timecode value this way without precomposing.

For example, timeToCurrentFormat(10)

gives you
0:00:10:00

or apply expr controls to the layer and use this:
timeToCurrentFormat(effect("Slider Control")("Slider")))

to get a slider with arbitrary timecode values
dfl10
Posts: 3
Joined: August 30th, 2005, 3:51 am
Contact:

August 30th, 2005, 5:56 am

Hi all,
i've tried the code above and with adding numbers to it to increase the starting TC... however when i add numbers over two digits log the timecode stops running and just shows that static number.:shock: as the timecode shows 00:00:00:00 (hours:mins:secs:frames) i'd love to be able to change the TC to start at for example 02:00:44:00 and then run from there. any ideas on how to make the expression do this without freezing the number?

any help really appreciated :)

/d
oscarus
Posts: 9
Joined: July 12th, 2004, 4:35 pm
Location: Paris
Contact:

August 30th, 2005, 7:42 am

Apply this expression

Code: Select all

h=5;m=59;s=3;f=7;
f+=timeToFrames();
s+=Math.floor(f*thisComp.frameDuration);
m+=Math.floor(s/60);
h+=Math.floor(m/60);
f=f%(1/thisComp.frameDuration);
s=s%60;
m=m%60;
if(f<10) {f="0"+f}
if(s<10) {s="0"+s}
if(m<10) {m="0"+m}
if(h<10) {h="0"+h}
h+":"+m+":"+s+":"+f
dfl10
Posts: 3
Joined: August 30th, 2005, 3:51 am
Contact:

August 30th, 2005, 8:31 am

brilliant!!! thanks oscarus! i just checked it out and it works beautifully! kinda get the code too, but what does the '%' do?

thanks.d :D
Colin Braley
Posts: 13
Joined: July 14th, 2005, 7:33 pm
Location: VA
Contact:

August 30th, 2005, 8:52 am

It's called the modulus (spelling?) operator. It's pretty much just means "the remainder of the division of the two numbers."
~Colin
dfl10
Posts: 3
Joined: August 30th, 2005, 3:51 am
Contact:

September 2nd, 2005, 12:23 am

thanks guys! i've used the above script in different versions now and it workds great!! a quick other question about running numbers...

anybody have and idea how to script a number to run from a single 0 then automatically on to double digit and three digit as it needs?

/d :)
vidpat
Posts: 86
Joined: October 21st, 2004, 12:36 am
Location: Phoenix, AZ
Contact:

September 2nd, 2005, 1:45 pm

The following expression will count an increasing monotonic sequence:

Code: Select all

var nFrames = 30;
var startValue = 0;
timeToFrames() / nFrames + startValue;
The variables are for your convenience. startValue is the number from which to start counting. nFrames is the number of frames for which each value will be displayed. These, of course, may be tied to sliders if you wish.
sbucci
Posts: 1
Joined: January 14th, 2005, 10:49 am

April 11th, 2006, 11:58 am

I'm trying the script in AE 7 and entered Ocscarus script, which worked great, except I get the frames going into decimal places. I tried the last script in the thread, thinking that eliminated the problem, but maybe I did it wrong.

Do those two scripts go together? If so, does one go before the other?

I want to keep frames from going into decimal places.

Thanks.
Steve Bucci
Media Specialist
philspitler
Posts: 39
Joined: November 2nd, 2005, 10:20 am
Contact:

April 16th, 2006, 11:55 am

I just added a Math.round function to the frames and it seems to have fixed the issue.

Phil



h=0;m=0;s=0;f=0;
f+=timeToFrames();
s+=Math.floor(f*thisComp.frameDuration);
m+=Math.floor(s/60);
h+=Math.floor(m/60);
f=Math.round(f%(1/thisComp.frameDuration));
s=s%60;
m=m%60;
if(f<10) {f="0"+f}
if(s<10) {s="0"+s}
if(m<10) {m="0"+m}
if(h<10) {h="0"+h}
h+":"+m+":"+s+":"+f
Phil Spitler
philspitler
Posts: 39
Joined: November 2nd, 2005, 10:20 am
Contact:

April 16th, 2006, 12:01 pm

The version I just posted seems to have a rounding error.

When I get to 00:00:24:30 ..... it all slips by a frame.

sorry.

Phil
Phil Spitler
fletty
Posts: 1
Joined: May 2nd, 2006, 3:44 pm

May 3rd, 2006, 1:16 am

i needed to create a 72 hour countdown with milliseconds instead of frames.

and so i tried for ages (i've never used expressions before today) to get it to work using the code above. finally got it working

h=71;m=59;s=59;f=99;
f-=timeToFrames(t = time + thisComp.displayStartTime, fps = 3.99 / thisComp.frameDuration, isDuration = false);
s+=Math.floor(f/99);
m+=Math.floor(s/60);
h+=Math.floor(m/60);
f=f%99;
s=s%60;
m=m%60;
if(f<0) {f=100+f}
if(f<10) {f="0"+f}
if(s<10) {s="0"+s}
if(m<10) {m="0"+m}
if(h<10) {h="0"+h}
h+":"+m+":"+s+":"+f

I changed it to f-= and some other stuff too.

can someone please inform me if this is the best way to do this? and/or ways i can improve the code for this task.

cheers :D
drswoboda
Posts: 3
Joined: May 16th, 2006, 10:35 pm

May 31st, 2006, 5:28 pm

I noticed that this cool expression doesn't work with NTSC D1 29.97 video. Anyone out there smart enough to get this to work with Drop Frame and Non-Drop Frame video?

Here is a reference on the math. . .
http://teched.vt.edu/gcc/Html/VirtualTe ... mecode.pdf

This would be very useful.
Thanks,

-David
Jumpcuts
Posts: 1
Joined: January 8th, 2007, 1:53 pm
Location: Boston
Contact:

January 8th, 2007, 8:35 pm

f=Math.round(f%(1.001/thisComp.frameDuration));


If you look at the PDF file you will see why this works. time code is not 60 fields per second but 59.97 fields per second, or 001% slower than 60 fields per second. (In my comp I changed all the 60's to 59.97 as well, but it did not seem to matter for the round up)

Anyway this worked for me, then I put the comp in a new comp and used the "Time reverse Layer" command (Under the Layer menu tree) to make it a cound down instead of a count up.

hope this helps.

SMA

drswoboda wrote:I noticed that this cool expression doesn't work with NTSC D1 29.97 video. Anyone out there smart enough to get this to work with Drop Frame and Non-Drop Frame video?

Here is a reference on the math. . .
http://teched.vt.edu/gcc/Html/VirtualTe ... mecode.pdf

This would be very useful.
Thanks,

-David
pickle
Posts: 1
Joined: April 22nd, 2009, 3:48 am

April 27th, 2009, 4:35 am

oscarus wrote:Apply this expression

Code: Select all

h=5;m=59;s=3;f=7;
f+=timeToFrames();
s+=Math.floor(f*thisComp.frameDuration);
m+=Math.floor(s/60);
h+=Math.floor(m/60);
f=f%(1/thisComp.frameDuration);
s=s%60;
m=m%60;
if(f<10) {f="0"+f}
if(s<10) {s="0"+s}
if(m<10) {m="0"+m}
if(h<10) {h="0"+h}
h+":"+m+":"+s+":"+f

Thanks Oscarus! This has just really helped me out. :)
Post Reply