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.

from(float $seconds): static · to(float $seconds): static · take(float $seconds): static

Section titled “from(float $seconds): static · to(float $seconds): static · take(float $seconds): static”

Open the file as a slice of itself — a fast input seek applied to the whole input, so video and audio stay in sync. from() sets the start; bound the end with to() (absolute timestamp) or take() (duration — sugar for to(), named take to avoid the $duration property). Immutable: each returns a new windowed Media.

The window resets the timeline — the slice starts at t = 0, $duration reports its own length, and filters, frameAt, and the expression variable t all speak the slice’s time. Frames outside it don’t exist to your code.

$clip = Media::open('lecture.mp4')->from(120.0)->take(60.0); // from 2:00, for one minute
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. Support FFmpeg.