Skip to main content

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. This example includes optional error handling, output shown below.

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

Example: run with tqdm to get a progressbar

If you install the tqdm extra dependency (pip install parsed-ffmpeg[tqdm]), you can do the following:

input_video = Path(__file__).parent.parent / "tests/assets/input.mp4"
await run_ffmpeg(
    f"ffmpeg -i {input_video} -vf scale=-1:1440 -c:v libx264 output.mp4",
    print_progress_bar=True,
    progress_bar_description=input_video.name,
    overwrite_output=True,
)

It'll give output like this:

input.mp4:  73%|███████▎  | 4466/6084 [00:04<00:00, 1620.10ms/s]

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[[FfmpegStatus], 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,
    print_progress_bar: bool = False,
    progress_bar_description: str | None = None,
) -> 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

parsed_ffmpeg-0.2.1.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

parsed_ffmpeg-0.2.1-py3-none-any.whl (5.7 kB view details)

Uploaded Python 3

File details

Details for the file parsed_ffmpeg-0.2.1.tar.gz.

File metadata

  • Download URL: parsed_ffmpeg-0.2.1.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for parsed_ffmpeg-0.2.1.tar.gz
Algorithm Hash digest
SHA256 731b94cd07fdb2bee3f91df071442b480dfe0bfea6dfa5f690df57b77db2bb71
MD5 9f94f1769a2c3f31369fd54ae7d6dbb7
BLAKE2b-256 2fb5828bb9fa78c20b5dfd3cb4ad1f43dad2f3fd02c342abfbf149de0f6a7a4c

See more details on using hashes here.

File details

Details for the file parsed_ffmpeg-0.2.1-py3-none-any.whl.

File metadata

File hashes

Hashes for parsed_ffmpeg-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d14638fb37000fb4ee93ac74e5a6abbad9c3ee4bb4e679ce8c07a6b671eb6683
MD5 87548cbceec62999c8a1a6b8eba8fe61
BLAKE2b-256 853590cc9d0e184e6be567c30e8707950b213867678657c773064a371ffb5f29

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page