How to calculate timecode?

I have a question about calculating the delta timecode.
I read the metadata from the movie file containing the generated timecodeHH:MM:SS:FF

( FF= frame, 00->23for example. So this is like 00to framerate-1)

So, I get type data 15:41:08:02, and from another refrence file I get 15:41:07:00
Now I have to calculate timeoffset (like timedelta, but only with frames).
How should I do it?

+5
source share
3 answers
framerate = 24

def timecode_to_frames(timecode):
    return sum(f * int(t) for f,t in zip((3600*framerate, 60*framerate, framerate, 1), timecode.split(':')))

print timecode_to_frames('15:41:08:02') - timecode_to_frames('15:41:07:00')
# returns 26

def frames_to_timecode(frames):
    return '{0:02d}:{1:02d}:{2:02d}:{3:02d}'.format(frames / (3600*framerate),
                                                    frames / (60*framerate) % 60,
                                                    frames / framerate % 60,
                                                    frames % framerate)

print frames_to_timecode(26)
# returns "00:00:01:02"
+4
source

,

def tc_to_frame(hh, mm, ss, ff):
    return ff + (ss + mm*60 + hh*3600) * frame_rate

def frame_to_tc(fn):
    ff = fn % frame_rate
    s = fn // frame_rate
    return (s // 3600, s // 60 % 60, s % 60, ff)

+2

If the timecode is SMPTE timecode , you may need to consider return frames. Temporary frame frame codes reduce the number of frames 0 and 1 of the first second of each minute, unless the number of minutes is divided by 10.

This page contains some historical backgrounds with formulas for converting between time codes and frame numbers.

0
source

All Articles