1 Reply Latest reply on Mar 11, 2016 12:02 PM by mamallo

    Convert timecodes to seconds

    anild37066447 Level 1

      Is there a method to convert timecode(hh:mm:ss:ff) to seconds ?

       

      I'm trying to create a marker using markers.CreateMarker() method but for some reasons the supplied value in seconds doesn't match input timecodes.

      For e.g. I have a timecode 00:03:00:00 on a 29.97fps(Non-drop frame). In order to convert it into seconds,

       

      var a = time.split(':');

      var seconds = ((Number(a[0])* 3600) + (Number(a[1]) * 60) + Number(a[2]));

      var milliseconds = (Number(a[3])/ fps);   // fps is 29.97

      var result = seconds + parseFloat(milliseconds,5); 

       

      Result here is 180 seconds. Premiere shows this timecode as :

       

      Non-Drop frame

      In: 00:02:59:24 , which is 5 frames behind.

       

      Drop frames gives me slightly better results

      In: 00:02:59:28, which is 2 frames behind.


      Please suggest.


        • 1. Re: Convert timecodes to seconds
          mamallo Level 1

          Hey there!

           

          I've been struggling with this as well, but in a 1080p60 timeline. I was able to easily make a fix by multiplying my final time by 1.001, but in 29.97 you're going to run into drop frame issues. Check out these articles:

          Frame rate - Wikipedia, the free encyclopedia

          "When NTSC color was introduced in 1953, the older rate of 60 fields per second was reduced by a factor of 1000/1001..."

          SMPTE timecode - Wikipedia, the free encyclopedia

          "In order to make an hour of timecode match an hour on the clock, drop-frame timecode drops frame numbers 0 and 1 of the first second of every minute, except when the number of minutes is divisible by ten"

           

          Knowing that, I played around with some messy conversion. It would be great if there was a native way to do this in Premiere as I'm still a bit lost when it comes to drop frame timecode conversion, but hopefully this will get people pointed in the right direction. I tested this in 23.976, 29.97, and 60. 29.97 Drop Frame has some issues with minutes 20, 21, and 22 being short one frame, but other than that this is working for me and suits my needs.

           

          // time is HH:MM:SS:FF (not detecting ';' vs ':')

          // fps is '23.976', '29.97', '60', etc

          // dropFrame is true/false

          convertTimeCode: function(time, fps, dropFrame){

            time = time.split(':');

            if (time.length != 4) {

              // we could make assumptions and fill in FF or whatever, but for now just return false

              return false;

            } else {

              // combine hours and minutes into minutes

              var minutes = (time[0] * 60) + Number(time[1]);

              // now that we have the total number of minutes, subtract how many minutes are divisible by ten

              var minutesCounted = minutes - Math.floor(minutes/10);

              // combine mintues and seconds to seconds

              var seconds = (minutes * 60) + Number(time[2]);

              var frames = Number(time[3]);

              // fractions of frames? no. round up though.

              frames += Math.ceil(seconds * fps);

              // only run if we're dealing with dropFrame timecode

              if (dropFrame){

                // we don't subtract 2 if we're on frame 0 or 1 of the first minute so let's add one or two frames back in

                if (time[3] < 2 && minutesCounted>0 && time[2] == '00'){

                  // 1 frame if we're on '01' and 2 if we're on '00'

                  frames += (2 - Number(time[3]));

                }

                // from the minutes counted above, we'll subtract 2 frames per minute

                frames = frames - (minutesCounted*2);

              }

              // convert frames back into seconds and multiply by (1001 / 1000)

              return parseFloat(parseFloat(frames / fps) * 1.001);

            }

          },

          // You can create a marker based off of time code by using something like this:

          placeMarker: function(time, fps, dropFrame, name, comment){

              var markerTimeCode = $._PPP_.convertTimeCode(time, fps, dropFrame);

              var markers   = app.project.activeSequence.markers;

              var newMarker     = markers.createMarker(markerTimeCode);

              newMarker.name    = name;

              newMarker.comments  = comment;

              newMarker.setTypeAsComment();

          },

           

          I also threw this into a JSFiddle: Time Code to Seconds - JSFiddle

           

          Hope this helps!