Skip to content

Show a progress bar during CLI encodes - #136

Closed
zfleeman wants to merge 1 commit into
mainfrom
zf/cli-progress-bar
Closed

zfleeman wants to merge 1 commit into
mainfrom
zf/cli-progress-bar

Conversation

@zfleeman

Copy link
Copy Markdown
Owner

Closes #135.

What changed

A CLI encode now shows its progress on one line that redraws in place, like the web UI's progress bar:

Performing second pass
[######################--------]  74%  Second pass: 47%
  • The progress math moved out of EncodeJob.status() into a new EncodeProgress class, which the web UI and the CLI both use. EncodeJob now extends it, so the web UI code barely changed.
  • A new ProgressLine class redraws the bar from a background thread. While the encode runs, it stands in for sys.stdout, so ff4d's own prints ("Performing second pass", the retry message) start on a new line instead of running into the bar.
  • The bar is only shown when stdout is a terminal and --verbose is off. Otherwise you get ffmpeg's stats line like before.
  • When a progress bar is watching (on_pass is set), TwoPass.run() passes -nostats to ffmpeg so its stats line doesn't write over the bar. --verbose still keeps it.
  • No new dependency. The bar is plain ASCII with \r, cut to the terminal's width.

Changes the web UI picks up too

  • The web UI's terminal no longer shows ffmpeg's stats line during an encode, since the browser shows the progress.
  • The retry label now puts the pass first: "First pass: 10%. Attempt 2, since the last one was over the target." Before, the attempt note came first and pushed the percent off a narrow terminal.
  • Progress no longer goes backwards when ffmpeg's reported time dips near the end of a pass. Each pass keeps the furthest time it has seen.

Testing

  • uv run pytest --cov: 311 passed, 99.4% coverage.
  • uv run ruff format . && uv run ruff check . pass.
  • Ran real trimmed encodes on macOS with x264 and VP9, including one that went over the target and retried. Each pass's line ends at its final percent, and the retry message prints below it.

@zfleeman zfleeman closed this Oct 28, 2026
@zfleeman
zfleeman deleted the zf/cli-progress-bar branch October 28, 2026 18:34
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.

Show a progress bar during CLI encodes

1 participant