Page 1 of 1

get timecode from layers -or- converting seconds to timecode

Posted: January 25th, 2006, 7:43 am
by byronnash
I'm starting on a script in 6.5 where I need to log out all the starting timecodes of all the layers in a comp. AE only deals in seconds. I know that there is an expression that converts the time to timecode but I can't find that in the scripting guide. I did find this chunk of code that's an expression and wondered if it would work in scripting.

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: January 25th, 2006, 8:48 am
by byronnash
I am using this code below to get useable timecode. I think I am getting some rounding errors or something somewhere because a lot of my timecodes are 1 frame later than they should be. But not all of them which is strange. Can anyone see what I'm missing?

Thanks

Code: Select all

			var curIn = comp_layers[i].inPoint;
			var curFrame = curIn / myComp.frameDuration;

			var h=0;
			var m=0;
			var s=0;
			var f=0;
			
			f+=curFrame;
			
			s+=Math.floor(f*myComp.frameDuration);
			m+=Math.floor(s/60);
			h+=Math.floor(m/60);
			f=f%(1/myComp.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}
			alert(h+";"+m+";"+s+";"+ f);

Posted: January 25th, 2006, 4:33 pm
by w_m0zart
In the topic about a black frame which occurs at the end, I mentioned to subtract 0.005 from the duration. Would that be a solution for you here as well?

Posted: January 26th, 2006, 5:48 am
by byronnash
I tried plugging the -.005 into the variable for the inPoint but that did not work. It's definitely a problem with the drop-frame timecode. When I switch my comp and project to an even 30fps everything works nice. You would think that AE being a video tool, they would have worked out the drop-frame issue a little better. I'll keep working at it, there has got to be a solution.

Posted: January 26th, 2006, 8:04 am
by byronnash
Wow, I found the answer in a much easier fashion that I thought.

With my script I followed these steps:
  • Created a new text layer
    added expression "timeToNTSCTimecode()
    read the valueAtTime of the text at every point I need timecode
    deleted the layer at the end
No math, no fuss, and proper timecode. I may find a snafu one day, but it seems to do the trick right now.