timecodeFrames method

int timecodeFrames(
  1. int frameCount, {
  2. dynamic ignoreDropFrame = false,
})

timecode frames will be equal to or larger than real frames. Example: in 29.97 fps, after each minute, two frames will be added to the timecode frame count, except after 10 minutes, no frames are added This function adds in the extra timecode frames.

from https://www.davidheidelberger.com/2010/06/10/drop-frame-timecode/

Implementation

int timecodeFrames(int frameCount, {ignoreDropFrame = false}) {
  // always handle frameCount rollover

  // do not accept negative frame numbers
  while (frameCount < 0) {
    frameCount = realFramesPer24Hours + frameCount;
  }
  // greater than 24 hours rolls over to 0
  frameCount = frameCount % realFramesPer24Hours;

  if (isDropFrame && !ignoreDropFrame) {
    var dropFrames = skippedFrameNumbersPerMinute;
    int d = frameCount ~/ realFramesPer10Minutes;
    int m = frameCount % realFramesPer10Minutes;

    if (m > dropFrames) {
      frameCount = frameCount + (dropFrames * 9 * d) + dropFrames * ((m - dropFrames) ~/ timecodeFramesPerMinute);
    } else {
      frameCount = frameCount + dropFrames * 9 * d;
    }
  }

  return frameCount;
}