Run ffmpeg commands with nicely parsed output.
Project description
FFmpeg output parser
Overview
Do you already know the ffmpeg command line, and don't want to relearn some syntax of a pythonic ffmpeg wrapper? This is the package for you. Just put in an ffmpeg command and this package structures the output while it's processing.
Usage
The code below converts a video, and prints the percentage completion while it's working.
from parsed_ffmpeg import run_ffmpeg, FfmpegError
async def process_video():
try:
await run_ffmpeg(
f"ffmpeg -i input.mp4 -c:v libx264 output.mp4",
on_status=lambda status: print(f"We're: {status.completion * 100:.1f}% there!"),
overwrite_output=True
)
print("Done!")
except FfmpegError as e:
print(f"ffmpeg failed with error: {e}")
Example script output
We're: 8.2% there!
We're: 45.5% there!
We're: 100.0% there!
Done!
Error example
ffmpeg failed with error:
User command:
ffmpeg -i input.mp4 -c:v libx264 output.mp4
Full command:
ffmpeg -i input.mp4 -c:v libx264 output.mp4 -y -progress pipe:1
Working directory:
C:\Users\rutenl\PycharmProjects\parsed_ffmpeg
[in#0 @ 00000208d2d4e1c0] Error opening input: No such file or directory
Error opening input file input.mp4.
Error opening input files: No such file or directory
Installation
Remember that this package does not come with an ffmpeg binary, you have to have it in path or point to it in your command.
pip install parsed-ffmpeg
API
run_ffmpeg
async def run_ffmpeg(
command: list[str] | str,
on_status: Callable[[StatusUpdate], None] | None = None,
on_stdout: Callable[[str], None] | None = None,
on_stderr: Callable[[str], None] | None = None,
on_error: Callable[[list[str]], None] | None = None,
on_warning: Callable[[str], None] | None = None,
overwrite_output: bool = False,
raise_on_error: bool = True,
) -> None:
...
StatusUpdate
class StatusUpdate:
frame: int | None
fps: float | None
bitrate: str | None
total_size: int | None
out_time_ms: float | None
dup_frames: int | None
drop_frames: int | None
speed: float | None
progress: str | None
duration_ms: int | None
completion: float | None
Changing ffmpeg install location
Just replace the first part of your command (ffmpeg) with the path to ffmpeg. Example:
await run_ffmpeg("C:/apps/ffmpeg.exe -i input.mp4 -c:v libx264 output.mp4 -y")
License
MIT
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 parsed_ffmpeg-0.1.1.tar.gz
.
File metadata
- Download URL: parsed_ffmpeg-0.1.1.tar.gz
- Upload date:
- Size: 3.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 47ae12abdfd30c93ed4252701787831b7e53d4cbad0cbe11719207ffad67995d |
|
MD5 | 1849f92aca8545ee41f398f2207ce591 |
|
BLAKE2b-256 | 2c3adbb29686928a983c7d101a9a276fafbab6965e6a6edefd415ea865ca90c8 |
File details
Details for the file parsed_ffmpeg-0.1.1-py3-none-any.whl
.
File metadata
- Download URL: parsed_ffmpeg-0.1.1-py3-none-any.whl
- Upload date:
- Size: 4.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 52a31c07ed028ae1d563ab5c4d01274d1ccb65ee5004393b328d6dd144cdf2d5 |
|
MD5 | b927db53d3de5cb15e6fbeddfe3ff102 |
|
BLAKE2b-256 | 4046454b7a72fe8deaf396f8cd6ee29b75955f86553f1ffdfed6fe5327fef09e |