Fix restore audio
This commit is contained in:
parent
49061f133d
commit
3c059cfb0e
@ -76,17 +76,24 @@ def create_video(target_path : str, fps : float = 30) -> bool:
|
||||
|
||||
|
||||
def restore_audio(target_path : str, output_path : str) -> None:
|
||||
fps = detect_fps(target_path)
|
||||
trim_frame_start = facefusion.globals.trim_frame_start
|
||||
trim_frame_end = facefusion.globals.trim_frame_end
|
||||
temp_output_path = get_temp_output_path(target_path)
|
||||
commands = [ '-hwaccel', 'auto', '-i', temp_output_path, '-i', target_path ]
|
||||
if trim_frame_start is not None and trim_frame_end is not None:
|
||||
commands.extend([ '-filter:v', 'select=between(n,' + str(trim_frame_start) + ',' + str(trim_frame_end) + ')' ])
|
||||
elif trim_frame_start is not None:
|
||||
commands.extend([ '-filter:v', 'select=gt(n,' + str(trim_frame_start) + ')' ])
|
||||
elif trim_frame_end is not None:
|
||||
commands.extend([ '-filter:v', 'select=lt(n,' + str(trim_frame_end) + ')' ])
|
||||
commands.extend([ '-c:a', 'copy', '-map', '0:v:0', '-map', '1:a:0', '-y', output_path ])
|
||||
if trim_frame_start is None and trim_frame_end is None:
|
||||
commands.extend([ '-c:a', 'copy' ])
|
||||
else:
|
||||
if trim_frame_start > 0:
|
||||
start_time = trim_frame_start / fps
|
||||
commands.extend([ '-ss', str(start_time) ])
|
||||
else:
|
||||
commands.extend([ '-ss', '0' ])
|
||||
if trim_frame_end > 0:
|
||||
end_time = trim_frame_end / fps
|
||||
commands.extend([ '-to', str(end_time) ])
|
||||
commands.extend([ '-c:a', 'aac' ])
|
||||
commands.extend([ '-map', '0:v:0', '-map', '1:a:0', '-y', output_path ])
|
||||
done = run_ffmpeg(commands)
|
||||
if not done:
|
||||
move_temp(target_path, output_path)
|
||||
|
Loading…
Reference in New Issue
Block a user