Skip to content

Instantly share code, notes, and snippets.

@wiiaboo
Created December 31, 2010 04:40
Show Gist options
  • Save wiiaboo/760731 to your computer and use it in GitHub Desktop.
Save wiiaboo/760731 to your computer and use it in GitHub Desktop.
#improve tcconv's algorithm
with open('test/tc1-vfr.txt','r') as v1f:
v1 = v1f.readlines()
del v1[0]
fpsa = float(v1.pop(0).split(' ')[1])
max = 60000
ts = fn1 = fn2 = last = 0
asm = 1000/fpsa
o=[b'# timecode format v2\n']
ap=o.append
en=str.encode
for line in v1:
ovr = line.split(',')
if len(ovr) == 3:
fn1,fn2,fps = ovr
fn1 = int(fn1)
fn2 = int(fn2)
ovf = 1000/float(fps)
while (last < fn1 and last < max):
ap(en('%3.6f\n' % ts))
last,ts=last+1,ts+asm
while (last <= fn2 and last < max):
ap(en('%3.6f\n' % ts))
last,ts=last+1,ts+ovf
while last < max:
ap(en('%3.6f\n' % ts))
last,ts=last+1,ts+asm
with open('newtc.txt','wb') as v2f:
v2f.writelines(o)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment