Add video stream copy remuxing

This commit is contained in:
ajp_anton
2026-07-22 22:51:00 +00:00
parent 49296d6f45
commit d60ce51b14
7 changed files with 404 additions and 68 deletions
+54
View File
@@ -168,6 +168,60 @@ def render_audio_wav(
)
def remux_video(
*,
ffmpeg: Path,
source: Path,
audio_source: Path | None,
output: Path,
audio_options: AudioEncodeOptions,
source_has_audio: bool,
frame_count: int | None = None,
progress_label: str | None = None,
) -> VideoEncodeResult:
"""Copy the source video stream while optionally copying or encoding audio."""
output.parent.mkdir(parents=True, exist_ok=True)
command = [
str(ffmpeg), "-y", "-hide_banner", "-loglevel", "info", "-nostats",
"-progress", "pipe:2", "-i", str(source), "-map", "0:v:0", "-c:v", "copy",
]
if audio_options.mode == "none" or not source_has_audio:
command.append("-an")
else:
source_index = 0
if audio_source is not None and audio_source.resolve() != source.resolve():
command.extend(["-i", str(audio_source)])
source_index = 1
command.extend(["-map", f"{source_index}:a:0"])
if audio_options.mode == "copy":
command.extend(["-c:a", "copy"])
else:
add_audio_encoder_options(command, audio_options)
command.append(str(output))
process = subprocess.Popen(
command,
stdout=subprocess.DEVNULL,
stderr=subprocess.PIPE,
text=True,
)
encoder_log = read_ffmpeg_progress(
process,
total_frames=frame_count,
label=f"Remuxing {progress_label or output.name}",
)
if process.returncode != 0:
raise RuntimeError(
f"FFmpeg remux failed for {source} with exit {process.returncode}:\n{encoder_log}"
)
return VideoEncodeResult(
script=source,
output=output,
renderer_returncode=0,
ffmpeg_returncode=process.returncode,
encoder_log=encoder_log,
)
def encode_video_only_y4m(
*,
y4m_command: list[str],