Activity › Forums › Adobe After Effects Expressions › Change string value to time value to frames
-
Change string value to time value to frames
Posted by George Felix on July 6, 2017 at 5:54 pmI have a string that contains a time value – minute : seconds
Sample times below
05:17
60:17
117:25Is there a way to change the string values to frames. I am assuming 29.97 frames per second?
George Felix replied 8 years, 10 months ago 3 Members · 5 Replies -
5 Replies
-
Dan Ebberts
July 6, 2017 at 6:33 pmSomething 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
-
Charlie Laud
July 6, 2017 at 6:45 pmThis 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) -
George Felix
July 6, 2017 at 7:01 pmThank 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
-
George Felix
July 6, 2017 at 7:11 pmI figured it out
str = “+05:17”;
sp = str.slice(0,1);if( sp == “+” ) {
1 } else { 0}
-
George Felix
July 6, 2017 at 7:40 pmI 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);
}
Reply to this Discussion! Login or Sign Up