...

View Full Version : Scripts for calculating dropframe video timecode



MaDmiX
02-17-2012, 11:28 PM
Hi All,

I didn't see anything like this on the site and I thought this might be useful for anyone developing for the television industry. There are 2 functions. CnvToFrames takes a text input (formatted as HH:MM:SS:FF) timecode address and converts it to a total count of frames equal to the address. It is for dropframe TC but the code should be easy to modify for NonDrop or PAL or any other framerate. CnvToTime does the reverse. I found this useful for, among other things performing calculations on timecode, and reformatting the results as readable text. e.g.

CnvToFrames(end of segment) - ConvToFrames(start of segment) = segment length

then

CnvToTime(segment length)

Hope this can be of some use.

Regards,

Ken


<html>
<body>

<script type="text/javascript">

function CnvToTime(FrameCount)
{
var FRate = 29.97;
var TotalSecs = parseInt(FrameCount / FRate, 10);
var hours = parseInt(TotalSecs / 3600, 10);
var mins = parseInt((TotalSecs - hours * 3600) / 60, 10);
var secs = TotalSecs - hours * 3600 - mins * 60;
var frames = (FrameCount - TotalSecs * 30);
var dropframes = (hours * 108) + ((mins - parseInt(mins / 10, 10)) * 2);

if ((frames + dropframes) > 30) {secs = secs + 1; frames = "1";}
else if ((frames + dropframes) == 30) {secs = secs + 1; frames = "0";}
else {frames = frames + dropframes;}

//INSERT FOR EACH LOOP HERE TO FORMAT TIMECODE ARRAY

var i;
var timecode = new Array();
timecode[0] = hours;
timecode[1] = mins;
timecode[2] = secs;
timecode[3] = frames

for (i=0;i<timecode.length;i++)
{if(timecode[i] < 10) timecode[i] = "0" + timecode[i];}

return timecode.join(':');
}

function CnvToFrames(timecode)
{
var FRate = 30;
var hours = parseInt(timecode.slice(0,2),10);
var mins = parseInt(timecode.slice(3,5),10);
var secs = parseInt(timecode.slice(6,8),10);
var frames = parseInt(timecode.slice(9,11),10);
var dropframes = (hours * 108) + (mins * 2) - (parseInt(timecode.slice(3,4),10) * 2);

var framecount = (hours * 3600 * FRate) + (mins * 60 * FRate) + (secs * FRate) + frames - dropframes;

return framecount;
}

</script>

</body>
</html>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum