0

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

Arvin
  • 954
  • 3
  • 14
  • 33
  • It would be pretty useful to know some things about what you are doing. For example, the language and libraries you're using. – Tobi Nary Jan 12 '16 at 11:04
  • Im using javascript for that. but the language doesnt mater. I just need a logic or algorithm for that – Arvin Jan 12 '16 at 11:23
  • 1
    It does matter. For starters, because most languages have data types for that that you can leverage to get away from calculating time with strings. That's a pretty bad idea to begin with. Additionally, if one knows nothing about the language you're using, your code example is next to completly useless. – Tobi Nary Jan 12 '16 at 11:27
  • Sorry.. I have updated about the project and language in the question – Arvin Jan 12 '16 at 11:29

0 Answers0