fix audio duration
This commit is contained in:
parent
206183f5da
commit
069eec802d
1 changed files with 13 additions and 16 deletions
29
render.py
29
render.py
|
@ -253,33 +253,30 @@ def get_scene_duration(scene):
|
||||||
def render(root, scene, prefix=''):
|
def render(root, scene, prefix=''):
|
||||||
fps = 24
|
fps = 24
|
||||||
files = []
|
files = []
|
||||||
|
scene_duration = int(get_scene_duration(scene) * 24)
|
||||||
for timeline, data in scene.items():
|
for timeline, data in scene.items():
|
||||||
#print(timeline)
|
#print(timeline)
|
||||||
project = KDEnliveProject(root)
|
project = KDEnliveProject(root)
|
||||||
|
|
||||||
tracks = []
|
tracks = []
|
||||||
|
track_durations = {}
|
||||||
for track, clips in data.items():
|
for track, clips in data.items():
|
||||||
#print(track)
|
#print(track)
|
||||||
for clip in clips:
|
for clip in clips:
|
||||||
project.append_clip(track, clip)
|
project.append_clip(track, clip)
|
||||||
|
track_durations[track] = int(sum([c['duration'] for c in clips]) * 24)
|
||||||
|
if timeline.startswith('audio-'):
|
||||||
|
track_duration = project.get_duration()
|
||||||
|
delta = scene_duration - track_duration
|
||||||
|
if delta > 0:
|
||||||
|
for track in track_durations:
|
||||||
|
if track_durations[track] == track_duration:
|
||||||
|
project.append_clip(track, {'blank': True, "duration": delta/24})
|
||||||
|
break
|
||||||
path = os.path.join(root, prefix + "%s.kdenlive" % timeline)
|
path = os.path.join(root, prefix + "%s.kdenlive" % timeline)
|
||||||
with open(path, 'w') as fd:
|
with open(path, 'w') as fd:
|
||||||
fd.write(project.to_xml())
|
fd.write(project.to_xml())
|
||||||
files.append(path)
|
files.append(path)
|
||||||
if timeline == "audio":
|
|
||||||
duration = project.get_duration()
|
|
||||||
for track, clips in data.items():
|
|
||||||
project = KDEnliveProject(root)
|
|
||||||
for clip in clips:
|
|
||||||
project.append_clip(track, clip)
|
|
||||||
track_duration = project.get_duration()
|
|
||||||
delta = duration - track_duration
|
|
||||||
if delta > 0:
|
|
||||||
project.append_clip(track, {'blank': True, "duration": delta/24})
|
|
||||||
path = os.path.join(root, prefix + "%s-%s.kdenlive" % (timeline, track))
|
|
||||||
with open(path, 'w') as fd:
|
|
||||||
fd.write(project.to_xml())
|
|
||||||
files.append(path)
|
|
||||||
return files
|
return files
|
||||||
|
|
||||||
def get_fragments(clips, voice_over, prefix):
|
def get_fragments(clips, voice_over, prefix):
|
||||||
|
@ -451,8 +448,8 @@ def render_all(options):
|
||||||
for cmd in cmds:
|
for cmd in cmds:
|
||||||
#print(" ".join([str(x) for x in cmd]))
|
#print(" ".join([str(x) for x in cmd]))
|
||||||
subprocess.call(cmd)
|
subprocess.call(cmd)
|
||||||
ft = ox.avinfo(fragment_prefix / "front-5.1.mp4")['duration']
|
ft = ox.avinfo(str(fragment_prefix / "front-5.1.mp4"))['duration']
|
||||||
bt = ox.avinfo(fragment_prefix / "back.mp4")['duration']
|
bt = ox.avinfo(str(fragment_prefix / "back.mp4"))['duration']
|
||||||
if ft != bt:
|
if ft != bt:
|
||||||
print(ft, fragment_prefix / "front-5.1.mp4")
|
print(ft, fragment_prefix / "front-5.1.mp4")
|
||||||
print(bt, fragment_prefix / "back.mp4")
|
print(bt, fragment_prefix / "back.mp4")
|
||||||
|
|
Loading…
Reference in a new issue