This commit is contained in:
Josh Hawkins 2026-05-03 12:17:25 -05:00
parent 14da821956
commit 513cc18715

View File

@ -53,10 +53,10 @@ logger = logging.getLogger(__name__)
def inject_progress_flags(cmd: list[str]) -> list[str]: def inject_progress_flags(cmd: list[str]) -> list[str]:
"""Insert ``-progress pipe:2 -nostats`` immediately before the output path. """Insert `-progress pipe:2 -nostats` immediately before the output path.
``-progress pipe:2`` writes structured key=value lines to stderr; `-progress pipe:2` writes structured key=value lines to stderr;
``-nostats`` suppresses the noisy default stats output. The output path `-nostats` suppresses the noisy default stats output. The output path
is conventionally the last token in an FFmpeg argv. is conventionally the last token in an FFmpeg argv.
""" """
if not cmd: if not cmd:
@ -73,24 +73,24 @@ def run_ffmpeg_with_progress(
process_started: Optional[Callable[[sp.Popen], None]] = None, process_started: Optional[Callable[[sp.Popen], None]] = None,
use_low_priority: bool = True, use_low_priority: bool = True,
) -> tuple[int, str]: ) -> tuple[int, str]:
"""Run an ffmpeg command, streaming progress via ``-progress pipe:2``. """Run an ffmpeg command, streaming progress via `-progress pipe:2`.
Args: Args:
cmd: ffmpeg argv. Output path must be the last token. cmd: ffmpeg argv. Output path must be the last token.
expected_duration_seconds: Duration of the expected output clip in expected_duration_seconds: Duration of the expected output clip in
seconds. Used to convert ffmpeg's ``out_time_us`` into a percent. seconds. Used to convert ffmpeg's `out_time_us` into a percent.
on_progress: Optional callback invoked with a percent in [0, 100]. on_progress: Optional callback invoked with a percent in [0, 100].
Called once with 0.0 at start, again on each ``out_time_us=`` Called once with 0.0 at start, again on each `out_time_us=`
stderr line, and once with 100.0 on ``progress=end``. stderr line, and once with 100.0 on `progress=end`.
stdin_payload: Optional string written to ffmpeg stdin (used by stdin_payload: Optional string written to ffmpeg stdin (used by
export for concat playlists). export for concat playlists).
process_started: Optional callback invoked with the live ``Popen`` process_started: Optional callback invoked with the live `Popen`
once spawned lets callers store the ref for cancellation. once spawned lets callers store the ref for cancellation.
use_low_priority: When True, prepend ``nice -n PROCESS_PRIORITY_LOW`` use_low_priority: When True, prepend `nice -n PROCESS_PRIORITY_LOW`
so concat doesn't starve detection. so concat doesn't starve detection.
Returns: Returns:
Tuple of ``(returncode, captured_stderr)``. Stdout is left attached Tuple of `(returncode, captured_stderr)`. Stdout is left attached
to the parent process to avoid buffer-full deadlocks. to the parent process to avoid buffer-full deadlocks.
""" """
full_cmd = inject_progress_flags(cmd) full_cmd = inject_progress_flags(cmd)