From dbbaff126c3094ffdc08cd22271ff86a5d33b751 Mon Sep 17 00:00:00 2001 From: tigerenwork Date: Mon, 13 Apr 2026 00:46:07 +0800 Subject: [PATCH] fix: use absolute paths with forward slashes in FFmpeg concat demuxer to support Windows Unicode paths --- cut_head.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/cut_head.py b/cut_head.py index df9fb2e..a8d1e64 100644 --- a/cut_head.py +++ b/cut_head.py @@ -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}")