Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating timecode from frames

I have a FPS (frames per second) of 30. I have a total FPS so far, lets say 1020. I want to display this as a formatted timecode, as below.

var fps = 30;
var currentFrame = 1020;

var resultString = ; // HH:MM:SS:FF

Are there any Javascript functions built in for formatting like this?

To be clear, I need the string to be formatted as such: HH:MM:SS:FF

like image 822
waxical Avatar asked Jan 15 '23 15:01

waxical


1 Answers

Are you looking for a built-in JS function?..

var FF = currentFrame % fps;
var seconds = (currentFrame - FF) / fps;
var SS = seconds % 60;
var minutes = (seconds - SS) / 60;
var MM = minutes % 60;
var HH = (minutes - MM) / 60;

There you go.

like image 198
Alexander Pavlov Avatar answered Jan 23 '23 13:01

Alexander Pavlov