Skip to content

Media

An input media file opened for reading: container metadata plus typed stream views. Probing is eageropen() 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.

All readonly.

PropertyTypeDescription
$durationfloatContainer duration in seconds (0.0 if unknown).
$formatstringDemuxer/container short name, e.g. "mov,mp4,m4a,3gp,3g2,mj2".
$bitrateintContainer bit rate in bits/sec.

Open and probe a media file.

All video and audio streams as typed views, in container order.

The nth video stream (0-based among video streams), or null.

The nth audio stream (0-based among audio streams), or null.

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";
}

VideoStream · AudioStream · MediaEncoder

An Artisan Build project.

Built on FFmpeg — an independent binding, not affiliated with or endorsed by the FFmpeg project.

Proudly sponsored by Tighten.