Skip to main content

ffmpeg-progress-yield

All Contributors

PyPI version Python package

Run an ffmpeg command with its progress yielded.

Contents:


Requirements

  • Python 3.9 or higher
  • ffmpeg v3.1 or above from http://ffmpeg.org/ installed in your $PATH

Installation

If you want to use the CLI only, via uv:

uvx ffmpeg-progress-yield

Or install via pipx.

To install the library:

pip3 install --user ffmpeg-progress-yield

Usage

As a library

In your Python project, import the helper class, instantiate a context manager, and run run_command_with_progress.

For more information see the API documentation.

Example:

from ffmpeg_progress_yield import FfmpegProgress

cmd = [
    "ffmpeg", "-i", "test/test.mp4", "-c:v", "libx264", "-vf", "scale=1920x1080", "-preset", "fast", "-f", "null", "/dev/null",
]

with FfmpegProgress(cmd) as ff:
    for progress in ff.run_command_with_progress():
        print(f"{progress}/100")

The command will yield the current progress in percent as a float number.

run_command_with_progress takes a duration_override argument where you can manually override the duration of the command in seconds. This is useful if your input doesn't have an implicit duration (e.g. if you use testsrc).

If you have tqdm installed, you can create a fancy progress bar:

from tqdm import tqdm
from ffmpeg_progress_yield import FfmpegProgress

cmd = [
    "ffmpeg", "-i", "test/test.mp4", "-c:v", "libx264", "-vf", "scale=1920x1080", "-preset", "fast", "-f", "null", "/dev/null",
]

with FfmpegProgress(cmd) as ff:
    with tqdm(total=100, position=1, desc="Test") as pbar:
        for progress in ff.run_command_with_progress():
            pbar.update(progress - pbar.n)

    # get the output
    print(ff.stderr)

You can also quit the command early on by calling .quit():

with FfmpegProgress(cmd) as ff:
    for progress in ff.run_command_with_progress():
        if progress > 50:
            ff.quit()
            break

This will send a hard quit to the ffmpeg process, and may not wait for it to finish. Your encoded file may have truncated data. To quit gracefully, use .quit_gracefully() instead, which sends 'q' to the ffmpeg process, and waits for it to finish (e.g., wait for an encoder to flush its buffers).

This is probably most useful in asynchronous environments, where you can run the command in a separate thread, and quit it from the main thread (e.g. using a Condition Variable).

Process Cleanup and Context Manager Support

The library automatically handles process cleanup to prevent lingering ffmpeg processes. It provides multiple layers of safety:

  1. Automatic cleanup: Processes are automatically cleaned up even if exceptions occur during iteration
  2. Context manager support: Use with statements for guaranteed cleanup
  3. Finalizer fallback: Processes are cleaned up during garbage collection as a last resort

On the command line

Simply prefix your ffmpeg command with ffmpeg-progress-yield:

ffmpeg-progress-yield ffmpeg -i input.mp4 output.mp4

It will show a progress bar, and once the command is done, show the ffmpeg stderr output.

Full usage notes:

usage: ffmpeg-progress-yield [-h] [-d DURATION] [-n] [-p] [-x] [-l LOG_FILE] [--ffprobe-path FFPROBE_PATH] ...

ffmpeg-progress-yield v0.12.0

positional arguments:
  ffmpeg_command        Any ffmpeg command. Do not quote this argument.

options:
  -h, --help            show this help message and exit
  -d, --duration DURATION
                        Duration of the video in seconds (override). (default: None)
  -n, --dry-run         Print ffmpeg command and exit. (default: False)
  -p, --progress-only   Print progress only and do not print stderr at exit. (default: False)
  -x, --exclude-progress
                        Exclude progress lines from ffmpeg log. (default: False)
  -l, --log-file LOG_FILE
                        Send ffmpeg log output to specified file. (default: None)
  --ffprobe-path FFPROBE_PATH
                        Path to ffprobe executable (for duration probing). (default: ffprobe)

Duration override

If you want to manually override the duration to, say, 12.5 seconds (e.g. because your input doesn't have an implicit one):

ffmpeg-progress-yield --duration 12.5 ffmpeg -f lavfi -i testsrc -t 12.5 output.mp4

Exclude progress from the CLI

You can also redirect the output to a log file:

ffmpeg-progress-yield --exclude-progress --log-file log.txt ffmpeg -i input.mp4 output.mp4

This will exclude the progress bar from the output, and redirect it to a log file.

Caveats

Currently, we do not differentiate between stderr and stdout. This means progress will be mixed with the ffmpeg log, unless you use --exclude-progress (or exclude_progress in the Python API).

You can also check out ffmpeg-progress for a similar project with a different feature set.

Contributors

Werner Robitza
Werner Robitza

💻
WyattBlue
WyattBlue

💻
Kirill Konovalov
Kirill Konovalov

💻
Jason Nader
Jason Nader

🐛
Launch Lee
Launch Lee

💻
scufre
scufre

💻
Alexander Sulfrian
Alexander Sulfrian

💻
Add your contributions

License

The MIT License (MIT)

Copyright (c) 2021-2025 Werner Robitza

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Metadata

Release files for ffmpeg-progress-yield 1.1.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ffmpeg-progress-yield 1.1.3
File Size Uploaded
ffmpeg_progress_yield-1.1.3.tar.gz 10.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for ffmpeg-progress-yield 1.1.3
File Interpreter ABI Platform
ffmpeg_progress_yield-1.1.3-py3-none-any.whl Python 3 none any Details

Total release size: 22.7 kB

Release files / ffmpeg_progress_yield-1.1.3.tar.gz

Download URL ffmpeg_progress_yield-1.1.3.tar.gz
Size 10.0 kB
Tags Source
SHA-256 checksum
How to use checksums
79bf782a6d6bf9be64bea1d3b7a0f777f11057705935128a225970db74dedf85
BLAKE2b-256 checksum
How to use checksums
36ebf4836c4c30cef5f26cb0d77fa16938303665f87c1e0f64c2812d00706ecf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.5

Release files / ffmpeg_progress_yield-1.1.3-py3-none-any.whl

Download URL ffmpeg_progress_yield-1.1.3-py3-none-any.whl
Size 12.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4eb4948a72414608c7b05c8061aff85ff47e31e33f629abc22d08d0b03196c62
BLAKE2b-256 checksum
How to use checksums
fdc7c42ce9353ae6b70bd920856a97736ac81e068901fb537126365e6735f1c8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.5

Release history Release notifications | RSS feed

This release

1.1.3 This release

2 release files

1.1.2

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.5

2 release files

1.0.4

2 release files

1.0.3

2 release files

1.0.2

1 release file

1.0.1

1 release file

1.0.0

1 release file

0.12.0

2 release files

0.11.3

2 release files

0.11.2

2 release files

0.11.1

2 release files

0.11.0

2 release files

0.10.0

2 release files

0.9.1

2 release files

0.9.0

2 release files

0.8.1

2 release files

0.8.0

2 release files

0.7.9

2 release files

0.7.8

2 release files

0.7.7

2 release files

0.7.6

2 release files

0.7.5

2 release files

0.7.4

2 release files

0.7.3

2 release files

0.7.2

2 release files

0.7.1

2 release files

0.7.0

2 release files

0.6.1

2 release files

0.6.0

2 release files

0.5.0

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page