Skip to content

VideoStream

A non-owning view of a video stream within a Media. It wraps an AVStream + its codec parameters, owns no native memory, and holds a refcount on its parent Media so the file stays open while the view is alive.

Obtain one from Media::videoStream() or Media::streams(). Pass it to MediaEncoder::addVideo() to map it into an output.

All readonly.

PropertyTypeDescription
$indexintStream index within the container.
$codecstringCodec short name, e.g. "h264".
$durationfloatStream duration in seconds (0.0 if unknown).
$bitrateintStream bit rate in bits/sec.
$widthintFrame width in pixels.
$heightintFrame height in pixels.
$pixelFormatstringPixel format name, e.g. "yuv420p".
$frameRatefloatAverage frame rate in frames/sec.
$v = FFmpeg\Media::open('clip.mp4')->videoStream();
printf("%dx%d %s @ %.3g fps (%s)\n",
$v->width, $v->height, $v->codec, $v->frameRate, $v->pixelFormat);

frameAt(float $seconds): Frame — render a single frame at $seconds, through any filters applied so far, and return it as a Frame. No encoder runs, so it’s the cheap way to preview a graph as you build it.

$v->scale(1280, 720)
->drawText(text: 'DRAFT', x: 40, y: 40)
->frameAt(12.0)
->save('preview.png');

A preview is exact for positional / stateless filters; filters that depend on earlier frames (temporal denoise, some transitions) can only approximate from a cold seek.

mapFrames(Closure(Frame): Frame): VideoStream — run a closure on every decoded Frame as the clip plays, returning each (possibly rewritten) frame to the output. It’s a filter written in PHP — and the path for handing frames to sibling extensions.

$v->mapFrames(function (Frame $frame) {
// inspect or rewrite $frame …
return $frame;
});

save(string $path, VideoCodec $codec = VideoCodec::H264): void — encode just this (possibly filtered) stream to its own file; the container is inferred from the path. The output is video-only — to combine video and audio into one file, compose them with MediaEncoder.

$media->videoStream()->scale(1280, 720)->save('clip.mp4');

Media · AudioStream · Frame · MediaEncoder

An Artisan Build project.

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