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.
Properties
Section titled “Properties”All readonly.
| Property | Type | Description |
|---|---|---|
$index | int | Stream index within the container. |
$codec | string | Codec short name, e.g. "h264". |
$duration | float | Stream duration in seconds (0.0 if unknown). |
$bitrate | int | Stream bit rate in bits/sec. |
$width | int | Frame width in pixels. |
$height | int | Frame height in pixels. |
$pixelFormat | string | Pixel format name, e.g. "yuv420p". |
$frameRate | float | Average frame rate in frames/sec. |
Example
Section titled “Example”$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);Methods
Section titled “Methods”frameAt
Section titled “frameAt”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
Section titled “mapFrames”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');See also
Section titled “See also”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.