In my project I needed to add a timecode(offset) with another timecode(original), to show it in a custom html5 video player.
00:00:17.16 --->(original timecode) +
07:49:42.08 --->(offset timecode)
-----------
07:49:59:24 sincle framerate is 23, this time code is rounded to
07:49:60:01 (7 hrs : 49 mins :60 secs and 1 frame) which is equal to
07:50:00:01 ------>(Resultant timecode)
===========
It is easy and I wrote som code for that in javascript.
function AddTimeCodeWithOffset(Offset, Original, framerate) {
var newTime = Original;
var framerate = parseFloat(framerate);
if (Offset != '00:00:00:00') {
var arOff = Offset.split(':');
var arOrg = Original.split(':');
var hour = parseInt(arOff[0]) + parseInt(arOrg[0]);
var minute = parseInt(arOff[1]) + parseInt(arOrg[1]);
var second = parseInt(arOff[2]) + parseInt(arOrg[2]);
var frame = parseInt(arOff[3]) + parseInt(arOrg[3]);
if (frame >= framerate) {
frame = Math.round(frame - framerate);
second = second + 1;
}
if (second >= 60) {
second = second - 60;
minute = minute + 1;
}
if (minute >= 60) {
minute = minute - 60;
hour = hour + 1;
}
if (frame < 10) { frame = '0' + frame.toString(); }
if (second < 10) { second = '0' + second.toString(); }
if (minute < 10) { minute = '0' + minute.toString(); }
if (hour < 10) { hour = '0' + hour.toString(); }
newTime = hour + ':' + minute + ':' + second + ':' + frame;
}
return newTime;
}
But how to do the reverse process. To get the original time code
from the resultant time code
by subtracting the offset time code