Typed fluent FFmpeg/ffprobe wrapper with msgspec models
Project description
ffmpeg-wrap
A typed Python wrapper for FFmpeg and ffprobe CLI tools. Build FFmpeg commands with a fluent API and parse ffprobe output into typed data structures.
Requirements
- Python 3.10+
- FFmpeg and ffprobe installed and available on PATH
Installation
With uv:
uv add ffmpeg-wrap
With pip:
pip install ffmpeg-wrap
Usage
import ffmpeg_wrap as ffmpeg
Probe a media file
result = ffmpeg.probe("video.mkv")
for stream in result.streams:
print(stream.codec_name, stream.codec_type)
if result.format:
print(result.format.duration)
print(result.format.format_name)
Build and run an FFmpeg command
ffmpeg.input("input.mkv").output("output.mp4", c="copy").overwrite_output().run()
Multiple inputs and outputs
(
ffmpeg.input("input.mkv", ss=10, t=30)
.output("clip.mp4", vcodec="libx264", acodec="aac")
.overwrite_output()
.run()
)
Global arguments
(
ffmpeg.input("input.mkv")
.output("output.mp4", c="copy")
.global_args("-hide_banner", "-loglevel", "error")
.overwrite_output()
.run()
)
Capture output
stdout, stderr = (
ffmpeg.input("input.mkv")
.output("output.mp4", c="copy")
.overwrite_output()
.run(capture_stdout=True, capture_stderr=True)
)
Error handling
try:
ffmpeg.probe("nonexistent.mkv")
except ffmpeg.FFmpegError as e:
print(f"Probe failed: {e}")
try:
ffmpeg.input("missing.mkv").output("out.mp4").run()
except ffmpeg.FFmpegError as e:
print(f"FFmpeg failed: {e}")
Custom executable paths
result = ffmpeg.probe("video.mkv", ffprobe_path="/usr/local/bin/ffprobe")
ffmpeg.input("input.mkv", ffmpeg_path="/usr/local/bin/ffmpeg").output("output.mp4").run()
API Reference
probe(filename, ffprobe_path="ffprobe")
Run ffprobe on a file and return a typed ProbeResult.
filename-- Path to the media file (str or PathLike).ffprobe_path-- Path to the ffprobe executable. Defaults to"ffprobe".- Returns:
ProbeResultwithstreamsandformatfields. - Raises:
FFmpegErroron subprocess failure or invalid output.
input(filename, ffmpeg_path="ffmpeg", **kwargs)
Create a new FFmpeg builder chain starting with an input file.
filename-- Input file path.ffmpeg_path-- Path to the ffmpeg executable. Defaults to"ffmpeg".**kwargs-- Input options passed as FFmpeg flags (e.g.,ss=10,t=30).- Returns:
FFmpeginstance for method chaining.
FFmpeg
Fluent builder for FFmpeg commands.
input(filename, **kwargs)-- Add an input file with options.output(filename, **kwargs)-- Add an output file with options.overwrite_output()-- Add the-yflag to overwrite existing output files.global_args(*args)-- Add global arguments before inputs.compile()-- Build the command as a list of strings without executing it.run(capture_stdout=False, capture_stderr=False)-- Execute the command. Returns(stdout, stderr). Values arebyteswhen the corresponding capture flag isTrue, orNoneotherwise. RaisesFFmpegErroron failure.
ProbeResult
Typed result from ffprobe.
streams-- List ofStreamobjects.format-- OptionalFormatobject.
Stream
A single stream from ffprobe output. Fields include index, codec_name, codec_type, width, height, channels, sample_rate, duration, bit_rate, tags, disposition.
Format
The format section from ffprobe output. Fields include filename, nb_streams, nb_programs, format_name, format_long_name, start_time, duration, size, bit_rate, probe_score, tags.
FFmpegError
Exception raised when FFmpeg or ffprobe operations fail.
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ffmpeg_wrap-0.1.0.tar.gz.
File metadata
- Download URL: ffmpeg_wrap-0.1.0.tar.gz
- Upload date:
- Size: 24.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.6 {"installer":{"name":"uv","version":"0.11.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8b9b988730c5bc0892191ad966c03b598a8da384e3bc8d2ef4a2a3a61e901d42
|
|
| MD5 |
39e1e77ed36297cecd378b8eca438d0c
|
|
| BLAKE2b-256 |
459279bd848119e01a2dd40eccceb52c15e34c7de167ffd8de3b2a4cf52c98f4
|
File details
Details for the file ffmpeg_wrap-0.1.0-py3-none-any.whl.
File metadata
- Download URL: ffmpeg_wrap-0.1.0-py3-none-any.whl
- Upload date:
- Size: 7.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.6 {"installer":{"name":"uv","version":"0.11.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0f717cca94dc90caf40a04741fc7277b651af01ca611806f004dcaae2c103546
|
|
| MD5 |
a944d0fab283a1b44ffac12a96d7a94e
|
|
| BLAKE2b-256 |
f333b9cb3d37e8de2b8c23c354672746672a6ff01e5fb73a0eafb7e3ba1035f7
|