ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Change string value to time value to frames

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
George Felix
Change string value to time value to frames
on Jul 6, 2017 at 5:54:15 pm

I have a string that contains a time value – minute : seconds

Sample times below

05:17
60:17
117:25

Is there a way to change the string values to frames. I am assuming 29.97 frames per second?


Return to posts index

Dan Ebberts
Re: Change string value to time value to frames
on Jul 6, 2017 at 6:33:23 pm

Something like this should work:

str = "05:17";
sp = str.split(":");
min = parseInt(sp[0],10);
sec = parseInt(sp[1],10);
timeToFrames(min*60+sec)


Dan



Return to posts index

George Felix
Re: Change string value to time value to frames
on Jul 6, 2017 at 7:01:30 pm

Thank you very much!

You just saved me hours of work. It works excellent.

I am writing a soccer program and the output files of the program will be used to create the after effects graphics.

I have one more question,

The times that I had given you was when a goal was scored. Sometimes a goal will be scored in extra stoppage time, where the string will have a format of

+02:36

The “+” represents that the time is after the 45th minute mark, or the 90th minute mark, or the 105th minute mark or the 120th minute mark where the 02 is in minutes and the 36 is in seconds.

How do I remove the first character to test if it is a “+”. Is there a function that I can just get the first character and test it as a character ? And what is the format of the if else statement?

George


Return to posts index


George Felix
Re: Change string value to time value to frames
on Jul 6, 2017 at 7:11:38 pm

I figured it out

str = "+05:17";
sp = str.slice(0,1);

if( sp == "+" ) {

1 } else { 0}


Return to posts index

Charlie Laud
Re: Change string value to time value to frames
on Jul 6, 2017 at 6:45:14 pm

This will take a string with a minute:second format and convert it to a frame number, depending on your frame rate:

myString = ;
frameRate = 1/thisComp.frameDuration;
timeArray = myString.split(":");
numFrames = (timeArray[0]*60*frameRate) + (timeArray[1]*frameRate)


Return to posts index

George Felix
Re: Change string value to time value to frames
on Jul 6, 2017 at 7:40:05 pm

I have finished this portion of the project. Below is the finished code.

Thank you for your help!!

You have saved me hours of work!!!

George

str = "+00:17";
extraTime = 45;
frameRate = 1/thisComp.frameDuration;
sp = str.slice(0,1);
if(sp == "+") {

strA = str.slice(0);
timeArray = strA.split(":");
numFrames = ((timeArray[0]+extraTime)*60*frameRate) + (timeArray[1]*frameRate);
Math.round(numFrames);

} else {

timeArray = str.split(":");
numFrames = (timeArray[0]*60*frameRate) + (timeArray[1]*frameRate);
Math.round(numFrames);
}


Return to posts index

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