Media
An input media file opened for reading: container metadata plus typed stream views.
Probing is eager — open() runs avformat_open_input + avformat_find_stream_info,
so metadata and streams are available immediately.
Media owns the input AVFormatContext. The stream views it hands out borrow from it and
hold a refcount on the Media, so the file stays open as long as any view is alive.
Properties
Section titled “Properties”All readonly.
| Property | Type | Description |
|---|---|---|
$duration | float | Container duration in seconds (0.0 if unknown). |
$format | string | Demuxer/container short name, e.g. "mov,mp4,m4a,3gp,3g2,mj2". |
$bitrate | int | Container bit rate in bits/sec. |
Methods
Section titled “Methods”static open(string $path): Media
Section titled “static open(string $path): Media”Open and probe a media file.
- Throws
FileNotFoundExceptionif$pathdoes not exist. - Throws
InvalidFormatExceptionif the file is not probeable media.
streams(): list<VideoStream|AudioStream>
Section titled “streams(): list<VideoStream|AudioStream>”All video and audio streams as typed views, in container order.
videoStream(int $index = 0): ?VideoStream
Section titled “videoStream(int $index = 0): ?VideoStream”The nth video stream (0-based among video streams), or null.
audioStream(int $index = 0): ?AudioStream
Section titled “audioStream(int $index = 0): ?AudioStream”The nth audio stream (0-based among audio streams), or null.
Example
Section titled “Example”use FFmpeg\Media;
$media = Media::open('clip.mkv');printf("%s — %.2fs @ %d bps\n", $media->format, $media->duration, $media->bitrate);
foreach ($media->streams() as $s) { echo $s::class, ' ', $s->codec, "\n";}See also
Section titled “See also”An Artisan Build project.
Built on FFmpeg — an independent binding, not affiliated with or endorsed by the FFmpeg project.
Proudly sponsored by Tighten.