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