avoid repetition
This commit is contained in:
parent
dcd2030799
commit
c786f22ed3
1 changed files with 13 additions and 6 deletions
19
render.py
19
render.py
|
@ -66,6 +66,7 @@ def compose(clips, target=150, base=1024, voice_over=None):
|
|||
}
|
||||
all_clips = clips.copy()
|
||||
seq = random(base)
|
||||
used = []
|
||||
|
||||
voice_overs = []
|
||||
if voice_over:
|
||||
|
@ -98,9 +99,9 @@ def compose(clips, target=150, base=1024, voice_over=None):
|
|||
if length:
|
||||
remaining = target - length
|
||||
remaining = remaining * 1.05 # allow for max of 10% over time
|
||||
clips = [c for c in clips if c['duration'] <= remaining]
|
||||
if not clips:
|
||||
break
|
||||
clips_ = [c for c in clips if c['duration'] <= remaining]
|
||||
if clips_:
|
||||
clips = clips_
|
||||
if clip:
|
||||
if chance(seq, 0.5):
|
||||
next_seqid = clip['seqid'] + 1
|
||||
|
@ -110,6 +111,7 @@ def compose(clips, target=150, base=1024, voice_over=None):
|
|||
if not clip:
|
||||
clip = random_choice(seq, clips, True)
|
||||
if not clips:
|
||||
print("not enough clips, need to reset")
|
||||
clips = [c for c in all_clips if c != clip]
|
||||
if not clips:
|
||||
clips = all_clips.copy()
|
||||
|
@ -209,8 +211,9 @@ def compose(clips, target=150, base=1024, voice_over=None):
|
|||
'duration': clip['duration'],
|
||||
'src': foley,
|
||||
})
|
||||
used.append(clip)
|
||||
print("scene duration %0.3f (target: %0.3f, vo_min: %0.3f)" % (length, target, vo_min))
|
||||
return scene
|
||||
return scene, used
|
||||
|
||||
def get_scene_duration(scene):
|
||||
duration = 0
|
||||
|
@ -297,6 +300,7 @@ def render_all(options):
|
|||
position = target_position = 0
|
||||
target = fragment_target = duration / len(fragments)
|
||||
base_prefix = os.path.join(prefix, 'render', str(base))
|
||||
clips_used = []
|
||||
for fragment in fragments:
|
||||
fragment_id = int(fragment['name'].split(' ')[0])
|
||||
name = fragment['name'].replace(' ', '_')
|
||||
|
@ -307,8 +311,11 @@ def render_all(options):
|
|||
continue
|
||||
fragment_prefix = os.path.join(base_prefix, name)
|
||||
os.makedirs(fragment_prefix, exist_ok=True)
|
||||
|
||||
scene = compose(fragment['clips'], target=target, base=base, voice_over=fragment['voice_over'])
|
||||
fragment_clips = fragment['clips']
|
||||
unused_fragment_clips = [c for c in fragment_clips if c not in clips_used]
|
||||
print('fragment clips', len(fragment_clips), 'unused', len(unused_fragment_clips))
|
||||
scene, used = compose(unused_fragment_clips, target=target, base=base, voice_over=fragment['voice_over'])
|
||||
clips_used += used
|
||||
scene_duration = get_scene_duration(scene)
|
||||
print("%s %6.3f -> %6.3f (%6.3f)" % (name, target, scene_duration, fragment_target))
|
||||
position += scene_duration
|
||||
|
|
Loading…
Reference in a new issue