Repository navigation
Fix stdin/stdout handling, stop FFmpeg gracefully and add new options (v7.0.0) - #41
Merged
Merged
Conversation
… (v7.0.0) Fixes: - FFmpeg no longer reads the Python program's standard input. It gets its own stdin pipe unless its input is standard input. - Ctrl+C sends "q" to FFmpeg so it finishes writing the output file, and falls back to SIGTERM/SIGKILL (or terminate() on Windows) after 5 seconds. - On POSIX, progress is read from a separate pipe, so the output can be written to standard output (e.g. "-f mpegts -"). The progress bar then goes to stderr. Writing to stdout raises FfmpegCommandError on Windows. Robustness: - FFprobe is looked for next to the FFmpeg executable before PATH, and is given 30 seconds to finish. - The constructor only validates. FFprobe and the overwrite prompt run in run(). API: - New quiet, progress_callback and delete_log_on_success parameters. - FfmpegProcessError has returncode and log_file attributes. - Warnings are logged with the better_ffmpeg_progress logger. - tqdm is now an optional extra: better-ffmpeg-progress[tqdm]. Tooling: - Require Python 3.11+, test 3.11-3.14 and add version classifiers. - Add strict mypy and the ruff I, UP and B rules to CI. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XaLfZ47UiCjK2T6R76WJCq
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XaLfZ47UiCjK2T6R76WJCq
On Windows, redirected standard output usually uses cp1252, so printing the check mark crashed after FFmpeg succeeded. Fall back to "OK". Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XaLfZ47UiCjK2T6R76WJCq
Text-mode stderr translates newlines to CRLF on Windows. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XaLfZ47UiCjK2T6R76WJCq
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR fixes two bugs, makes Ctrl+C stop FFmpeg gracefully, adds a few options and tightens CI. It bumps the version to 7.0.0 because some changes are breaking (listed below).
Bug fixes
-i -/pipe:).-progress pipe:1, so output such as-f mpegts -got mixed with the progress lines. On Linux and macOS, progress is now read from a separate pipe (os.pipe()+pass_fds,-progress pipe:<fd>), and the progress bar is shown on stderr in that case. On Windows this raisesFfmpegCommandError, because Windows can't pass extra file descriptors.Graceful Ctrl+C
FFmpeg now gets
qon its stdin, which makes it finish writing the output file before it exits. If it hasn't exited within 5 seconds, the old behaviour takes over: SIGTERM then SIGKILL on POSIX,terminate()on Windows. This means an interrupted MP4 is still playable, on Windows too.Robustness
/opt/ffmpeg/bin/ffprobe) beforePATH.run().API
quiet,progress_callback(secs, duration_or_None, size_mb)anddelete_log_on_success.delete_log_on_successonly deletes regular files, soos.devnullis never deleted.progress_callbackraises an exception, FFmpeg is stopped and the exception is passed on to the caller.FfmpegProcessErrornow hasreturncodeandlog_fileattributes.better_ffmpeg_progresslogger instead of printed.better-ffmpeg-progress[tqdm]). Rich and tqdm are imported only when they're used.Tooling
pyproject.tomllists those versions in its classifiers.I,UPandBrules. The 9 mypy errors found earlier are fixed. Adevextra installs the lint and type-check tools.Breaking changes
use_tqdm=Trueneeds the[tqdm]extra. Without it,FfmpegCommandErroris raised.overwrite=False,-n) and the overwrite prompt now raise or run inrun(), not in the constructor.better_ffmpeg_progresslogger (shown on stderr by default) instead ofprint().Testing
quietdelete_log_on_successmainand pass with this PR.qto FFmpeg and rejecting stdout output, have only been reviewed.Generated by Claude Code