Page **1** of **2**

### Create a timecode with expressions

Posted: **June 3rd, 2004, 11:10 am**

by **malex**

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)

### timecode

Posted: **June 9th, 2004, 10:36 am**

by **Guest**

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

Posted: **August 30th, 2005, 5:56 am**

by **dfl10**

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.

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

Posted: **August 30th, 2005, 7:42 am**

by **oscarus**

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
```

Posted: **August 30th, 2005, 8:31 am**

by **dfl10**

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

thanks.d

Posted: **August 30th, 2005, 8:52 am**

by **Colin Braley**

It's called the modulus (spelling?) operator. It's pretty much just means "the remainder of the division of the two numbers."

~Colin

Posted: **September 2nd, 2005, 12:23 am**

by **dfl10**

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

Posted: **September 2nd, 2005, 1:45 pm**

by **vidpat**

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.

### AE 7 adjustment to script?

Posted: **April 11th, 2006, 11:58 am**

by **sbucci**

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.

### Try This

Posted: **April 16th, 2006, 11:55 am**

by **philspitler**

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

### Ooops

Posted: **April 16th, 2006, 12:01 pm**

by **philspitler**

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

Posted: **May 3rd, 2006, 1:16 am**

by **fletty**

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

Posted: **May 31st, 2006, 5:28 pm**

by **drswoboda**

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

### Try this small alteration

Posted: **January 8th, 2007, 8:35 pm**

by **Jumpcuts**

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

### Re: Create a timecode with expressions

Posted: **April 27th, 2009, 4:35 am**

by **pickle**

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.