Skip to content

Fix a hang with multiple outputs, improve duration detection, add on_progress and a run() result (v7.1.0) - #42

Merged
CrypticSignal merged 2 commits into
mainfrom
claude/dreamy-ramanujan-gqb9xy
Nov 12, 2026
Merged

CrypticSignal merged 2 commits into
mainfrom
claude/dreamy-ramanujan-gqb9xy

Conversation

@CrypticSignal

Copy link
Copy Markdown
Owner

Summary

Bug fix: run() could hang forever. If an output other than the last argument already existed (e.g. ffmpeg -i in.mkv -c copy a.mkv -c copy b.mkv with an existing a.mkv), FFmpeg asked "Overwrite? [y/N]" and waited for an answer on its stdin pipe, which nothing writes to. The command now always gets -y or -n (unless it already has one), so FFmpeg never asks. FFmpeg exits with code 0 when -n makes it refuse, so that case is detected (FFmpeg always reports progress when it actually runs) and raises FfmpegCommandError. overwrite=True now applies to every output.

Duration detection, so more commands get a percentage and ETA:

  • Concat demuxer (-f concat -i list.txt): FFprobe can't report a total duration, so the list is read and its files' durations are added up, taking inpoint/outpoint/duration into account.
  • Input options that change how an input is read (-f, -framerate, -pattern_type, -start_number, -safe, -protocol_whitelist) are passed to FFprobe. For example, an image sequence with -framerate 5 was previously probed at 25 fps. FFprobe is not run for capture devices (v4l2, avfoundation, dshow, …) or lavfi.
  • -stream_loop, -loop 1, -shortest and -frames:v/-vframes are now taken into account. The common -loop 1 -i cover.jpg -i song.mp3 -shortest now uses the song's duration instead of 0.04 s.

New API (additive, no breaking changes):

  • on_progress: called with an FfmpegProgress dataclass that has secs, duration_secs, size_mb, percentage, speed, fps, frame and bitrate_kbps. progress_callback is unchanged.
  • run() returns an FfmpegResult with elapsed_secs, processed_secs, duration_secs, output_size_mb and log_file. It used to return None.

Other changes:

  • On Linux, FFmpeg gets SIGTERM (via PR_SET_PDEATHSIG) if the Python process dies, e.g. from SIGKILL. Before, it kept running on its own. macOS and Windows have no simple equivalent, so the README documents it for those.
  • Writing to the null device (/dev/null, NUL) no longer asks whether to overwrite it. test.py no longer needs -y.
  • pytest-timeout (120 s per test) means a hang fails one test instead of taking up the whole 15-minute CI job.

Version bumped to 7.1.0, and the README and CHANGELOG are updated.

Testing

  • pytest: 104 passed locally on Linux with FFmpeg 6.1. ruff check, ruff format --check and mypy (strict) are clean.
  • New regression tests fail or hang without their fixes: the multi-output hang, and FFmpeg outliving a killed Python process.
  • Checked by hand against real files: concat, image sequence with -framerate, -loop 1 + -shortest, -stream_loop 2, -stream_loop -1 -t 4 and -frames:v 5 all get the right expected duration.
  • The Windows and macOS code paths were not run locally; CI covers them.

Generated by Claude Code

FFmpeg asked whether to overwrite the file and waited for an answer on
its standard input pipe, which nothing writes to. Always pass -y or -n
so FFmpeg never prompts, and raise FfmpegCommandError when -n makes
FFmpeg exit with code 0 without processing anything.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XaLfYzZiAcNBbUCUoWkAxF
- Duration detection: read concat demuxer lists, pass input options such
  as -f and -framerate to FFprobe, and account for -stream_loop, -loop,
  -shortest and -frames:v. FFprobe is not run for capture devices.
- Add on_progress, called with an FfmpegProgress that also has the
  speed, fps, frame, bitrate and percentage.
- run() returns an FfmpegResult with the elapsed time and output size.
- On Linux, FFmpeg is sent SIGTERM if the Python process dies.
- Do not ask whether to overwrite the null device.
- Time out hanging tests with pytest-timeout.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XaLfYzZiAcNBbUCUoWkAxF
@CrypticSignal
CrypticSignal force-pushed the claude/dreamy-ramanujan-gqb9xy branch from ff8526b to 333f85f Compare November 12, 2026 12:25
@CrypticSignal
CrypticSignal merged commit 437a14b into main Nov 12, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants