fix: use absolute paths with forward slashes in FFmpeg concat demuxer to support Windows Unicode paths

This commit is contained in:
tigerenwork 2026-04-13 00:46:07 +08:00
parent 8e7c9d374a
commit dbbaff126c
1 changed files with 12 additions and 4 deletions

View File

@ -112,15 +112,23 @@ def smart_cut(input_video, output_video, cut_timestamp):
return
# 3. Concatenate video parts and cleanly mux with the original extracted audio
# Use absolute paths with forward slashes — Windows FFmpeg's concat demuxer
# cannot resolve relative paths when the CWD contains Unicode characters.
abs_part1 = os.path.abspath(part1).replace('\\', '/')
abs_part2 = os.path.abspath(part2).replace('\\', '/')
abs_concat = os.path.abspath(concat_list).replace('\\', '/')
abs_input = os.path.abspath(input_video).replace('\\', '/')
abs_output = os.path.abspath(output_video).replace('\\', '/')
with open(concat_list, 'w', encoding='utf-8') as f:
f.write(f"file '{part1}'\nfile '{part2}'\n")
f.write(f"file '{abs_part1}'\nfile '{abs_part2}'\n")
subprocess.run([
'ffmpeg', '-y', '-v', 'error',
'-f', 'concat', '-safe', '0', '-i', concat_list,
'-ss', str(cut_timestamp), '-i', input_video,
'-f', 'concat', '-safe', '0', '-i', abs_concat,
'-ss', str(cut_timestamp), '-i', abs_input,
'-map', '0:v', '-map', '1:a?',
'-c:v', 'copy', '-c:a', 'copy', output_video
'-c:v', 'copy', '-c:a', 'copy', abs_output
], check=True)
print(f"Success! Saved to {output_video}")