本文介绍了如何进行时间码计算?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我对计算时间码增量有疑问.
我从电影文件中读取了包含时间码格式为HH:MM:SS:FF
I got a question regarding calculating time code delta.
I read metadata from a movie file containing a timecode formated HH:MM:SS:FF
(FF
=框架,例如00->23
.因此它类似于00
到framerate-1
)
(FF
= frame, 00->23
for example. So its like 00
to framerate-1
)
所以我得到了像15:41:08:02
这样的一些数据,并且从另一个参考文件中得到了15:41:07:00
现在,我必须计算时间偏移量(如timedelta,但仅包含帧).
我该怎么做呢?
So i get some data like 15:41:08:02
and from another refrence file i get 15:41:07:00
Now I have to calculate the timeoffset (like timedelta but just with frames).
How would i go around doing this?
推荐答案
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"
这篇关于如何进行时间码计算?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!