Run an ffmpeg command with progress
Project description
ffmpeg-progress-yield
Run an ffmpeg command with its progress yielded.
Contents:
Requirements
- Python 3.8 or higher
- ffmpeg v3.1 or above from http://ffmpeg.org/ installed in your $PATH
Installation
pip3 install ffmpeg-progress-yield
Or download this repository, then run pip install .
.
Usage
As a library
In your Python project, import the helper class 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",
]
ff = FfmpegProgress(cmd)
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",
]
ff = FfmpegProgress(cmd)
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 by calling .quit()
:
ff = FfmpegProgress(cmd)
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. To quit gracefully, use .quit_gracefully()
instead, which sends 'q' to the ffmpeg process, and waits for it to finish.
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).
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.
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
Caveats
Currently, we do not differentiate between stderr
and stdout
. This means progress will be mixed with the ffmpeg log.
You can also check out ffmpeg-progress
for a similar project with a different feature set.
Contributors
Werner Robitza 💻 |
WyattBlue 💻 |
Kirill Konovalov 💻 |
Jason Nader 🐛 |
Launch Lee 💻 |
||
Add your contributions |
License
The MIT License (MIT)
Copyright (c) 2021-2023 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.
Changelog
v0.10.0 (2024-11-18)
- Fix: ensure percentage is always in float.
v0.9.1 (2024-09-16)
- Fix: the logic of the option --progress-only.
v0.9.0 (2024-09-16)
-
Docs: add @LaunchLee as a contributor.
-
Chore: Add an option to print progress only in cli usage.
This option makes the output cleaner when doing batch conversions.
-
Code cleanup, refactoring.
To avoid having to juggle around variables
v0.8.1 (2024-09-09)
- Fix type-checks.
v0.8.0 (2024-09-09)
- Add async support.
v0.7.9 (2024-08-14)
-
Docs: add @ammgws as a contributor.
-
Fix typing error.
-
Chore: remove unused dependency.
-
Fix badge link.
v0.7.8 (2023-06-01)
-
Image handling.
Check if image2 inputs use looping or not, and set duration to infinity if needed
v0.7.6 (2023-05-30)
- Always use duration_override if present.
v0.7.5 (2023-05-30)
-
Fix duration for multiple inputs, fixes #13.
-
Fix 'Test' string in tqdm.
v0.7.4 (2023-05-06)
- Fix: round percentage numbers.
v0.7.3 (2023-05-05)
-
Update readme.
-
Add progress as percent, fixes #12.
v0.7.2 (2023-03-04)
- Do not print input information when probing, addresses #10.
v0.7.1 (2023-02-24)
-
Fix types in CI.
-
Remove unneeded import.
-
Typo.
-
Docs: add @kskadart as a contributor.
-
Fix formatting.
-
Fix types.
-
Feat(ffprobe): FEAT-0001 try to get duration by ffprobe in case if loglevel=error.
-
Fix CI file.
v0.7.0 (2023-01-24)
-
Add duration override to API.
-
Remove manifest.in.
-
Add mypy settings.
v0.6.1 (2022-12-18)
-
Add py.typed.
-
Move API docs to existing section.
v0.6.0 (2022-12-17)
-
Link to API docs.
-
Add API docs.
-
Add export.
-
Bump requirements to python 3.8 or higher.
-
Document methods.
-
Remove unused import.
-
Docs: add @WyattBlue as a contributor.
-
Docs: add @slhck as a contributor.
-
Unhide to_ms.
-
Add type hints + simplify.
-
Add python CI badge.
-
Fix quit tests.
-
Add all-contributors.
-
Add pytest to dev requirements.
-
Add github workflows.
-
Formatting.
-
Fix a few type and formatting errors.
v0.5.0 (2022-12-12)
-
Add stderr callback method.
-
Update README.
-
Add graceful quit method.
-
Add a GIF in the readme.
v0.4.0 (2022-12-11)
- Add a quit method, fixes #4.
v0.3.0 (2022-08-02)
- Update python requirements.
v0.2.0 (2021-11-21)
- Add a usage option.
v0.1.2 (2021-08-14)
- Remove universal_newlines for Windows compat.
v0.1.1 (2021-07-01)
- Remove stats_period option for backwards compatibility, fixes #2.
v0.1.0 (2021-06-30)
-
Format code with black.
-
Yield 0 in progress and improve logic.
-
Set universal_newlines to true and add kwargs support.
-
Increase stats period.
-
Document method.
-
Add typing.
-
Also check for 0 in output.
-
Update gitignore.
-
Drop python 3.5 support.
-
Update badge link.
v0.0.4 (2021-03-10)
- Add python_requires to setup.py.
v0.0.3 (2021-03-06)
- Remove release script.
v0.0.2 (2021-03-06)
-
Fix release script.
-
Remove support for older versions.
-
Format setup.py.
-
Remove requirement for command to start with ffmpeg.
-
Add link to similar project.
-
Add changelog.
-
Rename project.
-
Initial commit.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file ffmpeg-progress-yield-0.10.0.tar.gz
.
File metadata
- Download URL: ffmpeg-progress-yield-0.10.0.tar.gz
- Upload date:
- Size: 49.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2d631074469a86cb3bc3f585353e4edd60f621de300d31bd921bedfe7acd6fc9 |
|
MD5 | 2aae79c1defb2add20f7924012394771 |
|
BLAKE2b-256 | 99c7d3a45d9d399da8031b4ecd86071b9c51f342eba9d32f8591276746795b6e |
File details
Details for the file ffmpeg_progress_yield-0.10.0-py2.py3-none-any.whl
.
File metadata
- Download URL: ffmpeg_progress_yield-0.10.0-py2.py3-none-any.whl
- Upload date:
- Size: 11.4 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c9c171f2b23aacfcda866e3530d5f72617142c047bb9eb3ef8d968fdffb9828e |
|
MD5 | 36e25b0abe846fdb9b1ab29c8726ae5e |
|
BLAKE2b-256 | 36a04ef06a46e92b491f9f462dcac72a9cc4accd6964237105117c9919767db5 |