diff --git a/docs/module-internals.md b/docs/module-internals.md index 93644d1..284f6fd 100644 --- a/docs/module-internals.md +++ b/docs/module-internals.md @@ -158,6 +158,10 @@ tail when diagnostics are unusually large. Aborts release it even when ffmpeg has already exited. A real subprocess regression writes diagnostics beyond pipe capacity while streaming frames, checks bounded failure reporting, and the Linux full-clip CI job guards the complete path. +The finite source file is opened before the frame pipe, so ffmpeg can initialize +the copied audio stream before producer backpressure is possible. Stream and +metadata mappings are source-indexed accordingly; regressions assert the input +order and both map targets. `probe_video_encode_profile` reads the first source video stream with ffprobe and preserves the supported properties that survive the 8-bit BGR boundary: `yuv420p`/`yuv422p`/`yuv444p` chroma sampling, recognized color tags, encoder diff --git a/src/remove_ai_watermarks/video_encoding.py b/src/remove_ai_watermarks/video_encoding.py index acb4363..fe5f5f4 100644 --- a/src/remove_ai_watermarks/video_encoding.py +++ b/src/remove_ai_watermarks/video_encoding.py @@ -358,21 +358,21 @@ def raw_video_command( "-loglevel", "error", *(["-copyts"] if copy_input_timestamps else []), - *frame_input, "-i", str(source), + *frame_input, "-map", - "0:v:0", + "1:v:0", "-map", - "1:a?", + "0:a?", *_video_codec_args(output.suffix.lower(), crf=crf, profile=profile), *_profile_args(profile), "-c:a", "copy", "-map_metadata", - "-1" if strip_metadata else "1", + "-1" if strip_metadata else "0", "-map_chapters", - "-1" if strip_metadata else "1", + "-1" if strip_metadata else "0", ] if timestamped_input: command.extend(["-fps_mode", "passthrough"]) diff --git a/tests/test_video_invisible.py b/tests/test_video_invisible.py index 735d25b..6df1cd2 100644 --- a/tests/test_video_invisible.py +++ b/tests/test_video_invisible.py @@ -128,6 +128,10 @@ def test_encoder_command_discards_metadata_and_copies_audio( "colorprim=bt709:transfer=bt709:colormatrix=bt709:range=limited" ) assert "pipe:0" in command + assert command.index(str(source)) < command.index("pipe:0") + assert command[command.index("-map") + 1] == "1:v:0" + second_map = command.index("-map", command.index("-map") + 1) + assert command[second_map + 1] == "0:a?" assert "-shortest" not in command