API Reference — Sync¶
The following reference is generated directly from the package's Google-style docstrings via mkdocstrings.
Builder¶
ffmpeg_wrap.input ¶
input(filename: str | PathLike[str], ffmpeg_path: str = 'ffmpeg', **kwargs: Any) -> FFmpeg
Start a new FFmpeg chain with an input file.
This is the recommended entry point for building a fluent chain. It creates
a fresh :class:FFmpeg instance and calls :meth:~FFmpeg.input on it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str | PathLike[str]
|
Input file path or PathLike object. |
required |
ffmpeg_path
|
str
|
Path to the ffmpeg executable. Defaults to |
'ffmpeg'
|
**kwargs
|
Any
|
FFmpeg input options passed through to the input slot
(e.g. |
{}
|
Returns:
| Type | Description |
|---|---|
FFmpeg
|
A new :class: |
FFmpeg
|
chaining. |
Example
from ffmpeg_wrap import input
input("in.mkv", ss=30, t=60).output("clip.mp4").codec("v", "copy").run()
Source code in src/ffmpeg_wrap/_builder.py
758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 | |
ffmpeg_wrap.FFmpeg ¶
FFmpeg(ffmpeg_path: str = 'ffmpeg')
A fluent interface wrapper for ffmpeg.
Build an ffmpeg command incrementally via method chaining and execute it
with :meth:run (sync) or :meth:arun (async). Every builder method
returns self so calls can be chained in a single expression.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ffmpeg_path
|
str
|
Path to the ffmpeg executable. Defaults to |
'ffmpeg'
|
Example
from ffmpeg_wrap import input
out, _ = (
input("in.mkv")
.output("out.mp4")
.codec("v", "libx264")
.codec("a", "aac")
.overwrite_output()
.run(capture_stderr=True, text=True)
)
Initialise the FFmpeg command builder.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ffmpeg_path
|
str
|
Path to the ffmpeg executable. Defaults to
|
'ffmpeg'
|
Example
from ffmpeg_wrap import FFmpeg
ff = FFmpeg(ffmpeg_path="/usr/local/bin/ffmpeg")
ff.input("in.mkv").output("out.mp4").run()
Source code in src/ffmpeg_wrap/_builder.py
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | |
compile ¶
compile() -> list[str]
Build the FFmpeg command as a list of arguments without executing it.
Returns:
| Type | Description |
|---|---|
list[str]
|
The command as a list of strings. |
Example
from ffmpeg_wrap import input
cmd = input("in.mkv").output("out.mp4").codec("v", "copy").compile()
# ['ffmpeg', '-i', '/abs/path/in.mkv', '-c:v', 'copy', 'out.mp4']
print(cmd)
Source code in src/ffmpeg_wrap/_builder.py
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 | |
input ¶
input(filename: str | PathLike[str], **kwargs: Any) -> FFmpeg
Add an input file with optional arguments.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str | PathLike[str]
|
Input file path or PathLike object. |
required |
**kwargs
|
Any
|
FFmpeg input options (e.g., t=10). |
{}
|
Returns:
| Type | Description |
|---|---|
FFmpeg
|
Self for chaining. |
Example
from ffmpeg_wrap import FFmpeg
ff = FFmpeg().input("clip.mkv", ss=30, t=60)
# Emits: -ss 30 -t 60 -i clip.mkv
Source code in src/ffmpeg_wrap/_builder.py
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 | |
output ¶
output(filename: str | PathLike[str], **kwargs: Any) -> FFmpeg
Add an output file with optional arguments.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str | PathLike[str]
|
Output file path or PathLike object. |
required |
**kwargs
|
Any
|
FFmpeg output options (e.g., c="copy", ac=2). |
{}
|
Returns:
| Type | Description |
|---|---|
FFmpeg
|
Self for chaining. |
Example
from ffmpeg_wrap import input
input("in.mkv").output("out.mp4", c="copy", ac=2)
Source code in src/ffmpeg_wrap/_builder.py
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 | |
map ¶
map(*specs: str | Stream) -> FFmpeg
Add one or more -map specifiers to the current output.
Accepts raw specifier strings ("0:v") and Stream objects. For a
Stream, the per-type specifier (e.g. 0:s:0) is used, computed
from probe data rather than the raw absolute index.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*specs
|
str | Stream
|
Map specifiers as strings or |
()
|
Returns:
| Type | Description |
|---|---|
FFmpeg
|
Self for chaining. |
Example
from ffmpeg_wrap import input, probe
result = probe("in.mkv")
video = next(s for s in result.streams if s.is_video)
input("in.mkv").output("out.mkv").map("0:a", video)
Source code in src/ffmpeg_wrap/_builder.py
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | |
map_stream ¶
map_stream(kind: str, ordinal: int, input: int = 0) -> FFmpeg
Add a per-type -map specifier to the current output.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
kind
|
str
|
Stream-type letter (e.g. |
required |
ordinal
|
int
|
Zero-based index within that stream type. |
required |
input
|
int
|
Index of the ffmpeg input to map from. |
0
|
Returns:
| Type | Description |
|---|---|
FFmpeg
|
Self for chaining. |
Example
from ffmpeg_wrap import input
# Map first video and second audio stream from input 0
input("in.mkv").output("out.mkv").map_stream("v", 0).map_stream("a", 1)
Source code in src/ffmpeg_wrap/_builder.py
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 | |
hwaccel ¶
hwaccel(name: str) -> FFmpeg
Request a hardware-acceleration backend on the current input.
Discoverable sugar for input(..., hwaccel=name): emits
-hwaccel {name} before the current input's -i (e.g.
hwaccel("cuda") -> -hwaccel cuda -i in.mkv).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Hardware-acceleration backend (e.g. |
required |
Returns:
| Type | Description |
|---|---|
FFmpeg
|
Self for chaining. |
Example
from ffmpeg_wrap import FFmpeg
ff = FFmpeg().input("in.mkv").hwaccel("cuda").output("out.mp4")
# Emits: -hwaccel cuda -i in.mkv out.mp4
Source code in src/ffmpeg_wrap/_builder.py
225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 | |
codec ¶
codec(kind: str, name: str) -> FFmpeg
Set the codec for a stream type on the current output.
Emits -c:{kind} {name} (e.g. codec("v", "libx265") ->
-c:v libx265).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
kind
|
str
|
Stream-type letter (e.g. |
required |
name
|
str
|
Codec name (e.g. |
required |
Returns:
| Type | Description |
|---|---|
FFmpeg
|
Self for chaining. |
Example
from ffmpeg_wrap import input
input("in.mkv").output("out.mp4").codec("v", "libx264").codec("a", "aac")
Source code in src/ffmpeg_wrap/_builder.py
259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 | |
bitrate ¶
bitrate(kind: str, value: str | int) -> FFmpeg
Set the bitrate for a stream type on the current output.
Emits -b:{kind} {value} (e.g. bitrate("v", "2M") ->
-b:v 2M).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
kind
|
str
|
Stream-type letter (e.g. |
required |
value
|
str | int
|
Bitrate value (e.g. |
required |
Returns:
| Type | Description |
|---|---|
FFmpeg
|
Self for chaining. |
Example
from ffmpeg_wrap import input
input("in.mkv").output("out.mp4").codec("v", "libx264").bitrate("v", "2M")
Source code in src/ffmpeg_wrap/_builder.py
282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 | |
quality ¶
quality(kind: str, value: str | int) -> FFmpeg
Set the quality scale for a stream type on the current output.
Emits -q:{kind} {value} (e.g. quality("a", 2) -> -q:a 2).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
kind
|
str
|
Stream-type letter (e.g. |
required |
value
|
str | int
|
Quality value. |
required |
Returns:
| Type | Description |
|---|---|
FFmpeg
|
Self for chaining. |
Example
from ffmpeg_wrap import input
input("in.mkv").output("out.mp3").codec("a", "libmp3lame").quality("a", 2)
Source code in src/ffmpeg_wrap/_builder.py
305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 | |
audio_filter ¶
audio_filter(chain: str) -> FFmpeg
Set the audio filter chain on the current output.
Emits -filter:a {chain}.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
chain
|
str
|
Filter chain string (e.g. |
required |
Returns:
| Type | Description |
|---|---|
FFmpeg
|
Self for chaining. |
Example
from ffmpeg_wrap import input
input("in.mkv").output("out.mkv").audio_filter("loudnorm")
Source code in src/ffmpeg_wrap/_builder.py
327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 | |
video_filter ¶
video_filter(chain: str) -> FFmpeg
Set the video filter chain on the current output.
Emits -filter:v {chain}.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
chain
|
str
|
Filter chain string (e.g. |
required |
Returns:
| Type | Description |
|---|---|
FFmpeg
|
Self for chaining. |
Example
from ffmpeg_wrap import input
input("in.mkv").output("out.mp4").video_filter("scale=1280:-2")
Source code in src/ffmpeg_wrap/_builder.py
348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 | |
flag ¶
flag(*names: str) -> FFmpeg
Add one or more valueless switches to the current output.
Emits a bare -{name} token per name (e.g. flag("vn", "sn") ->
-vn -sn). This is the intentional way to request a switch; note the
contrast with output(..., vn=None), which omits the flag entirely.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*names
|
str
|
Switch names without the leading dash (e.g. |
()
|
Returns:
| Type | Description |
|---|---|
FFmpeg
|
Self for chaining. |
Example
from ffmpeg_wrap import input
# Extract audio only: suppress video and subtitle streams
input("in.mkv").output("out.aac").flag("vn", "sn")
Source code in src/ffmpeg_wrap/_builder.py
369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 | |
overwrite_output ¶
overwrite_output() -> FFmpeg
Add the -y flag to overwrite output files without prompting.
Returns:
| Type | Description |
|---|---|
FFmpeg
|
Self for chaining. |
Example
from ffmpeg_wrap import input
input("in.mkv").output("out.mp4").overwrite_output().run()
Source code in src/ffmpeg_wrap/_builder.py
394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 | |
global_args ¶
global_args(*args: str) -> FFmpeg
Add raw global arguments emitted before input options.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*args
|
str
|
Global arguments (e.g. |
()
|
Returns:
| Type | Description |
|---|---|
FFmpeg
|
Self for chaining. |
Example
from ffmpeg_wrap import input
input("in.mkv").output("out.mp4").global_args("-nostdin", "-benchmark")
Source code in src/ffmpeg_wrap/_builder.py
410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 | |
hide_banner ¶
hide_banner() -> FFmpeg
Add the -hide_banner global flag.
Thin sugar over :meth:global_args; emitted in the global slot.
Returns:
| Type | Description |
|---|---|
FFmpeg
|
Self for chaining. |
Example
from ffmpeg_wrap import input
input("in.mkv").output("out.mp4").hide_banner().run()
Source code in src/ffmpeg_wrap/_builder.py
429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 | |
loglevel ¶
loglevel(level: str) -> FFmpeg
Set the ffmpeg log level via -loglevel {level}.
Thin sugar over :meth:global_args; emitted in the global slot.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
level
|
str
|
Log level (e.g. |
required |
Returns:
| Type | Description |
|---|---|
FFmpeg
|
Self for chaining. |
Example
from ffmpeg_wrap import input
input("in.mkv").output("out.mp4").loglevel("error").run()
Source code in src/ffmpeg_wrap/_builder.py
447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 | |
filter_complex ¶
filter_complex(graph_str: str) -> FFmpeg
Set a graph-level -filter_complex filtergraph.
Emits -filter_complex <graph_str> in a dedicated slot after global
args and before inputs, so placement no longer depends on parking the
option on an output. Mutually exclusive with
:meth:filter_complex_script at runtime (not enforced here).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph_str
|
str
|
The filtergraph string (e.g.
|
required |
Returns:
| Type | Description |
|---|---|
FFmpeg
|
Self for chaining. |
Example
from ffmpeg_wrap import input
(
input("in.mkv")
.filter_complex("[0:v]split=2[a][b];[a]scale=640:-2[out]")
.output("out.mp4", map="[out]")
)
Source code in src/ffmpeg_wrap/_builder.py
468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 | |
filter_complex_script ¶
filter_complex_script(path: str | PathLike[str]) -> FFmpeg
Read a graph-level filtergraph from a file via -filter_complex_script.
Emits -filter_complex_script <path> in the same dedicated slot as
:meth:filter_complex (after global args, before inputs). Mutually
exclusive with :meth:filter_complex at runtime (not enforced here).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | PathLike[str]
|
Path to a file containing the filtergraph. |
required |
Returns:
| Type | Description |
|---|---|
FFmpeg
|
Self for chaining. |
Example
from ffmpeg_wrap import input
input("in.mkv").filter_complex_script("graph.txt").output("out.mp4").run()
Source code in src/ffmpeg_wrap/_builder.py
497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 | |
run ¶
run(capture_stdout: bool = ..., capture_stderr: bool = ..., *, text: Literal[False] = ...) -> tuple[bytes | None, bytes | None]
run(capture_stdout: bool = ..., capture_stderr: bool = ..., *, text: Literal[True]) -> tuple[str | None, str | None]
run(capture_stdout: bool = False, capture_stderr: bool = False, *, text: bool = False) -> tuple[bytes | None, bytes | None] | tuple[str | None, str | None]
Build and execute the FFmpeg command.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
capture_stdout
|
bool
|
Whether to capture stdout. |
False
|
capture_stderr
|
bool
|
Whether to capture stderr. |
False
|
text
|
bool
|
When True, decode stdout/stderr (and |
False
|
Returns:
| Type | Description |
|---|---|
tuple[bytes | None, bytes | None] | tuple[str | None, str | None]
|
Tuple of (stdout, stderr). Values are |
tuple[bytes | None, bytes | None] | tuple[str | None, str | None]
|
else |
tuple[bytes | None, bytes | None] | tuple[str | None, str | None]
|
None otherwise. |
Raises:
| Type | Description |
|---|---|
FFmpegError
|
If ffmpeg fails. |
Example
import ffmpeg_wrap as ffmpeg
try:
_, stderr = (
ffmpeg.input("in.mkv")
.output("out.mp4")
.overwrite_output()
.run(capture_stderr=True, text=True)
)
except ffmpeg.FFmpegError as e:
print(e.returncode, e.stderr)
Source code in src/ffmpeg_wrap/_builder.py
538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 | |
arun
async
¶
arun(capture_stdout: bool = ..., capture_stderr: bool = ..., *, text: Literal[False] = ...) -> tuple[bytes | None, bytes | None]
arun(capture_stdout: bool = ..., capture_stderr: bool = ..., *, text: Literal[True]) -> tuple[str | None, str | None]
arun(capture_stdout: bool = False, capture_stderr: bool = False, *, text: bool = False) -> tuple[bytes | None, bytes | None] | tuple[str | None, str | None]
Build and execute the FFmpeg command asynchronously.
Async mirror of :meth:run, powered by AnyIO via the optional
[async] extra. The return contract is identical to :meth:run.
Importing this module never imports anyio — the dependency is pulled in
lazily here, so ffmpeg_wrap.aio (and thus anyio) is only loaded when
arun is actually awaited.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
capture_stdout
|
bool
|
Whether to capture stdout. |
False
|
capture_stderr
|
bool
|
Whether to capture stderr. |
False
|
text
|
bool
|
When True, decode stdout/stderr (and |
False
|
Returns:
| Type | Description |
|---|---|
tuple[bytes | None, bytes | None] | tuple[str | None, str | None]
|
Tuple of (stdout, stderr); see :meth: |
Raises:
| Type | Description |
|---|---|
FFmpegError
|
If ffmpeg fails or cannot be executed. |
ImportError
|
If the optional |
Example
import anyio
from ffmpeg_wrap import input
async def main():
_, stderr = await (
input("in.mkv")
.output("out.mp4")
.overwrite_output()
.arun(capture_stderr=True, text=True)
)
anyio.run(main)
Source code in src/ffmpeg_wrap/_builder.py
638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 | |
Probing¶
ffmpeg_wrap.probe ¶
probe(filename: str | PathLike[str], ffprobe_path: str = 'ffprobe') -> ProbeResult
Run ffprobe on the specified file and return typed output.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str | PathLike[str]
|
Path to the file to probe. |
required |
ffprobe_path
|
str
|
Path to the ffprobe executable. |
'ffprobe'
|
Returns:
| Type | Description |
|---|---|
ProbeResult
|
Parsed and typed :class: |
ProbeResult
|
container format information. |
Raises:
| Type | Description |
|---|---|
FFmpegError
|
If ffprobe fails or the output cannot be parsed. |
Example
import ffmpeg_wrap as ffmpeg
result = ffmpeg.probe("video.mkv")
print(result.format.format_name if result.format else None)
for stream in result.streams:
print(stream.index, stream.codec_type, stream.codec_name)
Source code in src/ffmpeg_wrap/_probe.py
649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 | |
ffmpeg_wrap.validate ¶
validate(filename: str | PathLike[str], ffprobe_path: str = 'ffprobe', loglevel: str = 'warning', extra_args: tuple[str, ...] = ()) -> tuple[bool, str]
Run ffprobe in validation mode and report diagnostics.
Does not raise on bad media — a non-zero exit or non-empty stderr is a
normal outcome (returned as ok=False). This makes it safe to use as a
boolean health-check without wrapping in try/except.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str | PathLike[str]
|
Path to the media file (str or PathLike). |
required |
ffprobe_path
|
str
|
Path to the ffprobe executable. |
'ffprobe'
|
loglevel
|
str
|
Value passed to ffprobe's |
'warning'
|
extra_args
|
tuple[str, ...]
|
Additional raw arguments forwarded to ffprobe before the
filename, e.g. |
()
|
Returns:
| Type | Description |
|---|---|
bool
|
|
str
|
code is 0 and |
tuple[bool, str]
|
raw decoded stderr (never |
Raises:
| Type | Description |
|---|---|
FFmpegError
|
Only when the ffprobe executable itself cannot be run
(e.g. not found on |
ValueError
|
If |
Example
import ffmpeg_wrap as ffmpeg
ok, diag = ffmpeg.validate("recording.mkv")
if not ok:
print("Validation failed:", diag)
Source code in src/ffmpeg_wrap/_probe.py
595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 | |
ffmpeg_wrap.ProbeResult ¶
Bases: Struct
Typed result of running :func:probe on a media file.
Top-level container decoded from ffprobe's -print_format json output.
Provides convenient access to all streams and the container format
information in a single structured object.
Attributes:
| Name | Type | Description |
|---|---|---|
streams |
list[Stream]
|
All streams found in the file, in index order. Each entry is
a :class: |
format |
Format | None
|
Container-level format information, or |
Example
from ffmpeg_wrap import probe
result = probe("video.mkv")
print(result.format.format_name if result.format else None)
print([s.codec_name for s in result.streams if s.is_video])
duration_seconds ¶
duration_seconds() -> float | None
Return the container duration as float seconds.
Delegates to self.format; returns None when format is
absent or its duration is missing/non-numeric.
Example
from ffmpeg_wrap import probe
result = probe("video.mkv")
secs = result.duration_seconds()
print(f"Duration: {secs:.1f}s" if secs else "Duration unknown")
Source code in src/ffmpeg_wrap/_probe.py
500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 | |
ffmpeg_wrap.Stream ¶
Bases: Struct
A single stream entry from ffprobe JSON output.
Decoded by msgspec from the ffprobe streams array. All fields
except :attr:index are optional because ffprobe omits irrelevant fields
per stream type (e.g. width/height are absent on audio streams).
Attributes:
| Name | Type | Description |
|---|---|---|
index |
int
|
Absolute stream index within the file (0-based). |
codec_name |
str | None
|
Short codec name as reported by ffprobe (e.g.
|
codec_type |
str | None
|
Stream type string (e.g. |
width |
int | None
|
Video frame width in pixels. |
height |
int | None
|
Video frame height in pixels. |
channels |
int | None
|
Number of audio channels. |
sample_rate |
str | None
|
Audio sample rate as a string (e.g. |
duration |
str | None
|
Stream duration as a decimal-seconds string (e.g.
|
bit_rate |
str | None
|
Stream bit rate as a string (e.g. |
tags |
dict[str, str] | None
|
Key/value metadata tags from the stream header (e.g.
|
disposition |
dict[str, int] | None
|
ffprobe disposition flags as a |
type_index |
int
|
Zero-based ordinal of this stream within its
:attr: |
Example
from ffmpeg_wrap import probe
result = probe("video.mkv")
for stream in result.streams:
print(stream.index, stream.codec_type, stream.codec_name)
is_video
property
¶
is_video: bool
True iff codec_type is "video".
Returns:
| Type | Description |
|---|---|
bool
|
|
Example
from ffmpeg_wrap import probe
result = probe("video.mkv")
videos = [s for s in result.streams if s.is_video]
audios = [s for s in result.streams if s.is_audio]
subs = [s for s in result.streams if s.is_subtitle]
is_audio
property
¶
is_audio: bool
True iff codec_type is "audio".
Returns:
| Type | Description |
|---|---|
bool
|
|
Example
from ffmpeg_wrap import probe
result = probe("video.mkv")
audio_streams = [s for s in result.streams if s.is_audio]
is_subtitle
property
¶
is_subtitle: bool
True iff codec_type is "subtitle".
Returns:
| Type | Description |
|---|---|
bool
|
|
Example
from ffmpeg_wrap import probe
result = probe("video.mkv")
subtitle_streams = [s for s in result.streams if s.is_subtitle]
is_data
property
¶
is_data: bool
True iff codec_type is "data".
Returns:
| Type | Description |
|---|---|
bool
|
|
Example
from ffmpeg_wrap import probe
result = probe("video.mkv")
data_streams = [s for s in result.streams if s.is_data]
is_attachment
property
¶
is_attachment: bool
True iff codec_type is "attachment".
Returns:
| Type | Description |
|---|---|
bool
|
|
Example
from ffmpeg_wrap import probe
result = probe("video.mkv")
attachments = [s for s in result.streams if s.is_attachment]
is_text_subtitle
property
¶
is_text_subtitle: bool
True iff this is a subtitle stream with a known text-based codec.
Best-effort: driven by a documented codec-name set (subrip,
ass, ssa, ...). Unknown subtitle codecs return False.
Returns:
| Type | Description |
|---|---|
bool
|
|
bool
|
|
Example
from ffmpeg_wrap import probe
result = probe("video.mkv")
text_subs = [s for s in result.streams if s.is_text_subtitle]
is_image_subtitle
property
¶
is_image_subtitle: bool
True iff this is a subtitle stream with a known image-based codec.
Best-effort: driven by a documented codec-name set
(hdmv_pgs_subtitle, dvd_subtitle, dvb_subtitle, ...).
Unknown subtitle codecs return False.
Returns:
| Type | Description |
|---|---|
bool
|
|
bool
|
|
Example
from ffmpeg_wrap import probe
result = probe("video.mkv")
image_subs = [s for s in result.streams if s.is_image_subtitle]
map_specifier ¶
map_specifier(input_index: int = 0) -> str
Return the ffmpeg -map specifier for this stream.
Emits the per-type form {input}:{letter}:{ordinal} (e.g. 0:s:0)
derived from codec_type and type_index. When codec_type is
unknown or None, falls back to the unambiguous absolute-index form
{input}:{index}.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_index
|
int
|
Index of the ffmpeg input the stream belongs to. |
0
|
Returns:
| Type | Description |
|---|---|
str
|
The map specifier string. |
Example
from ffmpeg_wrap import probe
result = probe("video.mkv")
sub = next(s for s in result.streams if s.is_subtitle)
print(sub.map_specifier()) # e.g. "0:s:0"
print(sub.map_specifier(1)) # e.g. "1:s:0"
Source code in src/ffmpeg_wrap/_probe.py
230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 | |
duration_seconds ¶
duration_seconds() -> float | None
Return this stream's duration as float seconds.
Returns None when duration is missing or non-numeric
(e.g. "N/A"); the raw duration string is preserved.
Example
from ffmpeg_wrap import probe
result = probe("video.mkv")
for stream in result.streams:
secs = stream.duration_seconds()
if secs is not None:
print(f"stream {stream.index}: {secs:.1f}s")
Source code in src/ffmpeg_wrap/_probe.py
259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 | |
ffmpeg_wrap.Format ¶
Bases: Struct
The format/container section from ffprobe JSON output.
Decoded from the top-level "format" key of ffprobe's JSON output.
All fields are optional because ffprobe may omit them for certain inputs.
Attributes:
| Name | Type | Description |
|---|---|---|
filename |
str | None
|
Resolved path of the probed file as reported by ffprobe. |
nb_streams |
int | None
|
Total number of streams in the container. |
nb_programs |
int | None
|
Number of programs (relevant for MPEG-TS and similar). |
format_name |
str | None
|
Short format/muxer name (e.g. |
format_long_name |
str | None
|
Human-readable format name (e.g.
|
start_time |
str | None
|
Container start time in decimal seconds (e.g.
|
duration |
str | None
|
Container duration in decimal seconds (e.g.
|
size |
str | None
|
File size in bytes as a string (e.g. |
bit_rate |
str | None
|
Overall container bit rate in bits/s as a string. |
probe_score |
int | None
|
ffprobe format-detection confidence score (0-100). |
tags |
dict[str, str] | None
|
Container-level metadata tags (e.g.
|
Example
from ffmpeg_wrap import probe
result = probe("video.mkv")
fmt = result.format
if fmt:
print(fmt.format_name, fmt.duration_seconds())
duration_seconds ¶
duration_seconds() -> float | None
Return the container duration as float seconds.
Returns None when duration is missing or non-numeric
(e.g. "N/A"); the raw duration string is preserved.
Example
from ffmpeg_wrap import probe
result = probe("video.mkv")
if result.format:
secs = result.format.duration_seconds()
print(f"Duration: {secs:.1f}s" if secs else "Unknown duration")
Source code in src/ffmpeg_wrap/_probe.py
455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 | |
ffmpeg_wrap.CodecType ¶
Bases: StrEnum
The known ffprobe codec_type values.
Used for the typed predicates on :class:Stream (is_video etc.).
Note that :attr:Stream.codec_type stays typed str | None rather than
this enum: ffmpeg can report codec_type values outside this set, and
decoding into a strict enum would raise msgspec.ValidationError on such
files. Compare against these members instead of retyping the field.
Attributes:
| Name | Type | Description |
|---|---|---|
VIDEO |
Represents a video stream ( |
|
AUDIO |
Represents an audio stream ( |
|
SUBTITLE |
Represents a subtitle stream ( |
|
DATA |
Represents a data stream ( |
|
ATTACHMENT |
Represents an attachment stream ( |
Example
from ffmpeg_wrap import CodecType, probe
result = probe("video.mkv")
videos = [s for s in result.streams if s.codec_type == CodecType.VIDEO]
Encoder discovery¶
ffmpeg_wrap.encoders ¶
encoders(ffmpeg_path: str = 'ffmpeg') -> frozenset[str]
Return the set of encoder names reported by ffmpeg -encoders.
The result is cached per ffmpeg_path for the lifetime of the process.
Use :func:has_encoder for a single-name membership check.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ffmpeg_path
|
str
|
Path to the ffmpeg executable. |
'ffmpeg'
|
Returns:
| Type | Description |
|---|---|
frozenset[str]
|
A frozenset of encoder names (e.g. |
Raises:
| Type | Description |
|---|---|
FFmpegError
|
If ffmpeg cannot be run or exits non-zero. |
Example
import ffmpeg_wrap as ffmpeg
available = ffmpeg.encoders()
print("libx264" in available) # True if ffmpeg was compiled with it
print(sorted(available)[:5]) # first five encoder names alphabetically
Source code in src/ffmpeg_wrap/_encoders.py
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 | |
ffmpeg_wrap.has_encoder ¶
has_encoder(name: str, ffmpeg_path: str = 'ffmpeg') -> bool
Return whether name is an available ffmpeg encoder.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Encoder name to check (e.g. |
required |
ffmpeg_path
|
str
|
Path to the ffmpeg executable. |
'ffmpeg'
|
Returns:
| Type | Description |
|---|---|
bool
|
|
Raises:
| Type | Description |
|---|---|
FFmpegError
|
If ffmpeg cannot be run or exits non-zero. |
Example
import ffmpeg_wrap as ffmpeg
if ffmpeg.has_encoder("h264_nvenc"):
codec = "h264_nvenc"
else:
codec = "libx264"
ffmpeg.input("in.mkv").output("out.mp4").codec("v", codec).run()
Source code in src/ffmpeg_wrap/_encoders.py
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 | |
Filters¶
ffmpeg_wrap.filter_arg_escape ¶
filter_arg_escape(value: str) -> str
Escape a value for safe embedding in a filtergraph option.
ffmpeg parses a filtergraph at two levels, and a value pasted into a filter
option (such as a subtitles= path) must survive both:
- The filter-option parser, where
:separates options and\/'are escaping/quoting characters. A raw colon (every Windows drive path, and POSIX paths containing one) is otherwise read as an option separator, so ffmpeg mis-parses the tail (e.g.original_size). This level is handled by backslash-escaping\,'and:. - The filtergraph parser, where
'quotes and[],;are special. This level is handled by wrapping the whole value in single quotes; a literal'is emitted via the close/escape/reopen idiom ('\'').
Single-quote wrapping alone is not sufficient: the colon still reaches
the filter-option parser and splits the value, so the backslash escaping is
required as well. The result parses back to the original value.
Typical use is building a subtitles= (or any path-bearing) filter.
Example
from ffmpeg_wrap import filter_arg_escape, input
path = "/media/My Film: Director's Cut/subs.srt"
graph = f"subtitles={filter_arg_escape(path)}"
input("in.mkv").filter_complex(graph).output("out.mp4").run()
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
str
|
The raw string to escape (e.g. a filesystem path). |
required |
Returns:
| Type | Description |
|---|---|
str
|
The escaped, single-quote-wrapped token. |
Source code in src/ffmpeg_wrap/_filters.py
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | |
Errors¶
ffmpeg_wrap.FFmpegError ¶
FFmpegError(message: str, *, stderr: str | None = None, returncode: int | None = None, cmd: list[str] | None = None)
Bases: Exception
Custom exception for FFmpeg errors.
Carries structured introspection from the underlying process failure so
callers can branch on the exit code or inspect stderr without re-parsing
str(e). The message remains args[0] so str(e) is unchanged.
Attributes:
| Name | Type | Description |
|---|---|---|
stderr |
Decoded stderr from the failed process, or |
|
returncode |
Process exit code, or |
|
cmd |
The exact command list that was executed, or |
Example
import ffmpeg_wrap as ffmpeg
try:
ffmpeg.input("missing.mkv").output("out.mp4").run()
except ffmpeg.FFmpegError as e:
print("exit code:", e.returncode)
print("command:", e.cmd)
print("stderr:", e.stderr)
Source code in src/ffmpeg_wrap/_errors.py
33 34 35 36 37 38 39 40 41 42 43 44 | |