fix subtitle rendering
This commit is contained in:
parent
eb1ea250eb
commit
ad33ce2c41
1 changed files with 18 additions and 20 deletions
38
ffmpeg.py
38
ffmpeg.py
|
@ -11,6 +11,22 @@ def run(cmd):
|
|||
#print(' '.join('"%s"' % c for c in cmd))
|
||||
subprocess.call(cmd)
|
||||
|
||||
def add_subtitles(subtitles, clip, position, duration):
|
||||
if clip.get('subtitles'):
|
||||
if isinstance(clip['subtitles'], list):
|
||||
for sub in clip['subtitles']:
|
||||
subtitles.append({
|
||||
'in': position + sub['in'],
|
||||
'out': position + sub['out'],
|
||||
'value': sub['value']
|
||||
})
|
||||
else:
|
||||
subtitles.append({
|
||||
'in': position,
|
||||
'out': position + duration,
|
||||
'value': clip['subtitles']
|
||||
})
|
||||
|
||||
|
||||
usage = "usage: %(prog)s [options] edit.json"
|
||||
parser = ArgumentParser(usage=usage)
|
||||
|
@ -62,12 +78,7 @@ for clip in edit:
|
|||
src_duration = clip['out']-clip['in']
|
||||
if abs(src_duration-duration) > 1:
|
||||
print(clip.get('annotation', clip['item']), 'expected', src_duration, 'got', duration, out)
|
||||
if clip.get('subtitles'):
|
||||
subtitles.append({
|
||||
'in': position,
|
||||
'out': position+duration,
|
||||
'value': clip['subtitles']
|
||||
})
|
||||
add_subtitles(subtitles, clip, position, duration)
|
||||
position += duration
|
||||
continue
|
||||
src_info = ox.avinfo(clip['path'])
|
||||
|
@ -142,20 +153,7 @@ for clip in edit:
|
|||
src_duration = clip['out']-clip['in']
|
||||
if abs(src_duration-duration) > 1:
|
||||
print(clip.get('annotation', clip['item']), 'expected', src_duration, 'got', duration, out)
|
||||
if clip.get('subtitles'):
|
||||
if isinstance(clip['subtitles'], list):
|
||||
for sub in clip['subtitles']:
|
||||
subtitles.append({
|
||||
'in': position + sub['in'],
|
||||
'out': position + sub['out'],
|
||||
'value': sub['value']
|
||||
})
|
||||
else:
|
||||
subtitles.append({
|
||||
'in': position,
|
||||
'out': position + duration,
|
||||
'value': clip['subtitles']
|
||||
})
|
||||
add_subtitles(subtitles, clip, position, duration)
|
||||
position += duration
|
||||
|
||||
txt = output + '.txt'
|
||||
|
|
Loading…
Reference in a new issue