sound
This commit is contained in:
parent
d83a603adf
commit
cca2de20fe
3 changed files with 48 additions and 13 deletions
56
render.py
56
render.py
|
|
@ -153,7 +153,7 @@ def compose(clips, fragment, target=150, base=1024, voice_over=None, options=Non
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
volume_front = '-15'
|
volume_front = '-13'
|
||||||
if clip.get('volume') is not None:
|
if clip.get('volume') is not None:
|
||||||
volume_front = '%0.2f' % (float(volume_front) + clip['volume'])
|
volume_front = '%0.2f' % (float(volume_front) + clip['volume'])
|
||||||
|
|
||||||
|
|
@ -263,9 +263,9 @@ def compose(clips, fragment, target=150, base=1024, voice_over=None, options=Non
|
||||||
print('%07.3f-%07.3f %07.3f' % (sub_offset, sub_offset+vo["duration"], vo["duration"]), vo["src"].split('/')[-1])
|
print('%07.3f-%07.3f %07.3f' % (sub_offset, sub_offset+vo["duration"], vo["duration"]), vo["src"].split('/')[-1])
|
||||||
voice_overs.append(vo)
|
voice_overs.append(vo)
|
||||||
voc = vo.copy()
|
voc = vo.copy()
|
||||||
a, b = '5', '-1'
|
a, b = '6', '-1'
|
||||||
if options.get('stereo_downmix'):
|
if options.get('stereo_downmix'):
|
||||||
a, b = '5', '-1'
|
a, b = '6', '-1'
|
||||||
voc['filter'] = {'volume': a}
|
voc['filter'] = {'volume': a}
|
||||||
scene['audio-center']['A1'].append(voc)
|
scene['audio-center']['A1'].append(voc)
|
||||||
vo_low = vo.copy()
|
vo_low = vo.copy()
|
||||||
|
|
@ -535,9 +535,17 @@ def render_all(options):
|
||||||
timelines = render(prefix, scene, fragment_prefix[len(prefix) + 1:] + '/', options)
|
timelines = render(prefix, scene, fragment_prefix[len(prefix) + 1:] + '/', options)
|
||||||
|
|
||||||
scene_json = json.dumps(scene, indent=2, ensure_ascii=False)
|
scene_json = json.dumps(scene, indent=2, ensure_ascii=False)
|
||||||
write_if_new(os.path.join(fragment_prefix, 'scene.json'), scene_json)
|
scene_json_path = os.path.join(fragment_prefix, 'scene.json')
|
||||||
|
segment_path = os.path.join(fragment_prefix, 'segment.mp4')
|
||||||
|
is_new = write_if_new(scene_json_path, scene_json)
|
||||||
|
if not is_new:
|
||||||
|
if not os.path.exists(segment_path) or os.lstat(scene_json_path).st_mtime > os.lstat(segment_path).st_mtime:
|
||||||
|
is_new = True
|
||||||
|
print("%s needs update" % segment_path)
|
||||||
|
if not is_new:
|
||||||
|
print("%s did not change" % scene_json_path)
|
||||||
|
|
||||||
if not options['no_video'] and not options["single_file"]:
|
if is_new and not options['no_video'] and not options["single_file"]:
|
||||||
for timeline in timelines:
|
for timeline in timelines:
|
||||||
print(timeline)
|
print(timeline)
|
||||||
ext = '.mp4'
|
ext = '.mp4'
|
||||||
|
|
@ -662,7 +670,7 @@ def render_all(options):
|
||||||
if os.path.exists(fn):
|
if os.path.exists(fn):
|
||||||
os.unlink(fn)
|
os.unlink(fn)
|
||||||
|
|
||||||
if options["single_file"]:
|
if is_new and options["single_file"]:
|
||||||
cmds = []
|
cmds = []
|
||||||
base_prefix = Path(base_prefix)
|
base_prefix = Path(base_prefix)
|
||||||
for timeline in (
|
for timeline in (
|
||||||
|
|
@ -828,6 +836,11 @@ def scene_subtitles(scene, options):
|
||||||
return subs
|
return subs
|
||||||
|
|
||||||
|
|
||||||
|
DEFAULTS = {
|
||||||
|
"max-items": 10,
|
||||||
|
"no_video": False
|
||||||
|
}
|
||||||
|
|
||||||
def load_defaults(options):
|
def load_defaults(options):
|
||||||
path = os.path.join(options["prefix"], "options.json")
|
path = os.path.join(options["prefix"], "options.json")
|
||||||
if os.path.exists(path):
|
if os.path.exists(path):
|
||||||
|
|
@ -836,8 +849,19 @@ def load_defaults(options):
|
||||||
for key in defaults:
|
for key in defaults:
|
||||||
if key not in options:
|
if key not in options:
|
||||||
options[key] = defaults[key]
|
options[key] = defaults[key]
|
||||||
|
for key in DEFAULTS:
|
||||||
|
if key not in options:
|
||||||
|
options[key] = DEFAULTS[key]
|
||||||
return options
|
return options
|
||||||
|
|
||||||
|
def reload_options(options):
|
||||||
|
path = os.path.join(options["prefix"], "options.json")
|
||||||
|
if os.path.exists(path):
|
||||||
|
with open(path) as fd:
|
||||||
|
defaults = json.load(fd)
|
||||||
|
for key in defaults:
|
||||||
|
options[key] = defaults[key]
|
||||||
|
return options
|
||||||
|
|
||||||
def update_subtitles(options):
|
def update_subtitles(options):
|
||||||
import item.models
|
import item.models
|
||||||
|
|
@ -890,8 +914,6 @@ def render_infinity(options):
|
||||||
|
|
||||||
defaults = {
|
defaults = {
|
||||||
"offset": 100,
|
"offset": 100,
|
||||||
"max-items": 30,
|
|
||||||
"no_video": False,
|
|
||||||
}
|
}
|
||||||
state_f = os.path.join(prefix, "infinity.json")
|
state_f = os.path.join(prefix, "infinity.json")
|
||||||
if os.path.exists(state_f):
|
if os.path.exists(state_f):
|
||||||
|
|
@ -899,7 +921,16 @@ def render_infinity(options):
|
||||||
state = json.load(fd)
|
state = json.load(fd)
|
||||||
else:
|
else:
|
||||||
state = {}
|
state = {}
|
||||||
for key in ("prefix", "duration", "debug", "single_file", "keep_audio", "stereo_downmix"):
|
|
||||||
|
option_keys = (
|
||||||
|
"prefix",
|
||||||
|
"duration",
|
||||||
|
"debug",
|
||||||
|
"single_file",
|
||||||
|
"keep_audio",
|
||||||
|
"stereo_downmix"
|
||||||
|
)
|
||||||
|
for key in options_keys:
|
||||||
state[key] = options[key]
|
state[key] = options[key]
|
||||||
|
|
||||||
for key in defaults:
|
for key in defaults:
|
||||||
|
|
@ -912,9 +943,9 @@ def render_infinity(options):
|
||||||
f for f in os.listdir(render_prefix)
|
f for f in os.listdir(render_prefix)
|
||||||
if f.isdigit() and os.path.isdir(render_prefix + f) and state["offset"] > int(f) >= 100
|
if f.isdigit() and os.path.isdir(render_prefix + f) and state["offset"] > int(f) >= 100
|
||||||
]
|
]
|
||||||
if len(current) > state["max-items"]:
|
if len(current) > options["max-items"]:
|
||||||
current = ox.sorted_strings(current)
|
current = ox.sorted_strings(current)
|
||||||
remove = current[:-state["max-items"]]
|
remove = current[:-options["max-items"]]
|
||||||
update_m3u(render_prefix, exclude=remove)
|
update_m3u(render_prefix, exclude=remove)
|
||||||
for folder in remove:
|
for folder in remove:
|
||||||
folder = render_prefix + folder
|
folder = render_prefix + folder
|
||||||
|
|
@ -926,6 +957,9 @@ def render_infinity(options):
|
||||||
with open(state_f + "~", "w") as fd:
|
with open(state_f + "~", "w") as fd:
|
||||||
json.dump(state, fd, indent=2)
|
json.dump(state, fd, indent=2)
|
||||||
shutil.move(state_f + "~", state_f)
|
shutil.move(state_f + "~", state_f)
|
||||||
|
options = reload_options(options)
|
||||||
|
for key in options_keys:
|
||||||
|
state[key] = options[key]
|
||||||
|
|
||||||
|
|
||||||
def join_subtitles(base_prefix, options):
|
def join_subtitles(base_prefix, options):
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,7 @@ def render_music():
|
||||||
"src": src,
|
"src": src,
|
||||||
"duration": clip.sort.duration,
|
"duration": clip.sort.duration,
|
||||||
"filter": {
|
"filter": {
|
||||||
'volume': '0',
|
'volume': '2',
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
@ -112,7 +112,7 @@ def render_forest():
|
||||||
"src": src,
|
"src": src,
|
||||||
"duration": clip.sort.duration,
|
"duration": clip.sort.duration,
|
||||||
"filter": {
|
"filter": {
|
||||||
'volume': '2',
|
'volume': '1',
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
||||||
1
utils.py
1
utils.py
|
|
@ -56,6 +56,7 @@ def write_if_new(path, data, mode=''):
|
||||||
if is_new:
|
if is_new:
|
||||||
with open(path, write_mode) as fd:
|
with open(path, write_mode) as fd:
|
||||||
fd.write(data)
|
fd.write(data)
|
||||||
|
return is_new
|
||||||
|
|
||||||
def format_duration(duration, fps, audio=False):
|
def format_duration(duration, fps, audio=False):
|
||||||
if audio:
|
if audio:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue