pad audio tracks to scene duration
This commit is contained in:
parent
c8991438bb
commit
2a2516bff9
1 changed files with 16 additions and 4 deletions
20
render.py
20
render.py
|
@ -66,6 +66,7 @@ def write_if_new(path, data, mode=''):
|
||||||
|
|
||||||
|
|
||||||
def compose(clips, target=150, base=1024, voice_over=None):
|
def compose(clips, target=150, base=1024, voice_over=None):
|
||||||
|
fps = 24
|
||||||
length = 0
|
length = 0
|
||||||
scene = {
|
scene = {
|
||||||
'front': {
|
'front': {
|
||||||
|
@ -100,6 +101,7 @@ def compose(clips, target=150, base=1024, voice_over=None):
|
||||||
used = []
|
used = []
|
||||||
|
|
||||||
voice_overs = []
|
voice_overs = []
|
||||||
|
sub_offset = 0
|
||||||
if voice_over:
|
if voice_over:
|
||||||
vo_keys = list(sorted(voice_over))
|
vo_keys = list(sorted(voice_over))
|
||||||
if chance(seq, 0.5):
|
if chance(seq, 0.5):
|
||||||
|
@ -118,7 +120,7 @@ def compose(clips, target=150, base=1024, voice_over=None):
|
||||||
if vo_min > target:
|
if vo_min > target:
|
||||||
target = vo_min
|
target = vo_min
|
||||||
elif vo_min < target:
|
elif vo_min < target:
|
||||||
offset = (target - vo_min) / 2
|
offset = int(((target - vo_min) / 2) * fps) / fps
|
||||||
scene['audio-center']['A1'].append({
|
scene['audio-center']['A1'].append({
|
||||||
'blank': True,
|
'blank': True,
|
||||||
'duration': offset
|
'duration': offset
|
||||||
|
@ -298,6 +300,16 @@ def compose(clips, target=150, base=1024, voice_over=None):
|
||||||
})
|
})
|
||||||
used.append(clip)
|
used.append(clip)
|
||||||
print("scene duration %0.3f (target: %0.3f, vo_min: %0.3f)" % (length, target, vo_min))
|
print("scene duration %0.3f (target: %0.3f, vo_min: %0.3f)" % (length, target, vo_min))
|
||||||
|
if sub_offset < length:
|
||||||
|
delta = length - sub_offset
|
||||||
|
scene['audio-center']['A1'].append({
|
||||||
|
'blank': True,
|
||||||
|
'duration': delta
|
||||||
|
})
|
||||||
|
scene['audio-rear']['A1'].append({
|
||||||
|
'blank': True,
|
||||||
|
'duration': delta
|
||||||
|
})
|
||||||
return scene, used
|
return scene, used
|
||||||
|
|
||||||
def get_scene_duration(scene):
|
def get_scene_duration(scene):
|
||||||
|
@ -321,7 +333,7 @@ def get_offset_duration(prefix):
|
||||||
def render(root, scene, prefix=''):
|
def render(root, scene, prefix=''):
|
||||||
fps = 24
|
fps = 24
|
||||||
files = []
|
files = []
|
||||||
scene_duration = int(get_scene_duration(scene) * 24)
|
scene_duration = int(get_scene_duration(scene) * fps)
|
||||||
for timeline, data in scene.items():
|
for timeline, data in scene.items():
|
||||||
if timeline == "subtitles":
|
if timeline == "subtitles":
|
||||||
path = os.path.join(root, prefix + "front.srt")
|
path = os.path.join(root, prefix + "front.srt")
|
||||||
|
@ -338,14 +350,14 @@ def render(root, scene, prefix=''):
|
||||||
#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)
|
track_durations[track] = int(sum([c['duration'] for c in clips]) * fps)
|
||||||
if timeline.startswith('audio-'):
|
if timeline.startswith('audio-'):
|
||||||
track_duration = project.get_duration()
|
track_duration = project.get_duration()
|
||||||
delta = scene_duration - track_duration
|
delta = scene_duration - track_duration
|
||||||
if delta > 0:
|
if delta > 0:
|
||||||
for track in track_durations:
|
for track in track_durations:
|
||||||
if track_durations[track] == track_duration:
|
if track_durations[track] == track_duration:
|
||||||
project.append_clip(track, {'blank': True, "duration": delta/24})
|
project.append_clip(track, {'blank': True, "duration": delta/fps})
|
||||||
break
|
break
|
||||||
path = os.path.join(root, prefix + "%s.kdenlive" % timeline)
|
path = os.path.join(root, prefix + "%s.kdenlive" % timeline)
|
||||||
project_xml = project.to_xml()
|
project_xml = project.to_xml()
|
||||||
|
|
Loading…
Reference in a new issue