Source filters
Most streams come from a file. Source filters make one from nothing — a solid color, SMPTE
bars, a test pattern, a sine tone, silence. They have no input to attach to, so they don’t go
through apply(); they’re an entry point of their own, typed by the kind of stream
they produce.
generate()
Section titled “generate()”A source comes from generate(), which takes a 1:1-named source class from the
catalog — a VideoFilter for VideoStream::generate, an AudioFilter for
AudioStream::generate:
use FFmpeg\{VideoStream, AudioStream};use FFmpeg\Filter\{Color, Sine, Smptebars, Anoisesrc};
$black = VideoStream::generate(new Color(color: 'black', size: '1920x1080', duration: 3.0));$tone = AudioStream::generate(new Sine(frequency: 440.0, duration: 2.0));$bars = VideoStream::generate(new Smptebars(size: '1280x720'));$noise = AudioStream::generate(new Anoisesrc(amplitude: 0.1));The types keep the two halves from crossing: a source can’t be apply()’d (it has no input), and
an ordinary filter can’t be generate()’d — both are compile-time errors, backed by a runtime
check that points you at the right method.
The result is an ordinary stream node — filter it, overlay onto it, encode it, exactly like one from a file:
use FFmpeg\Filter\Scale;
$bars = VideoStream::generate(new Smptebars(size: '1280x720', duration: 5.0)) ->apply(new Scale(640, 360));Duration
Section titled “Duration”A source is infinite unless you give it a duration. Inside a graph it’s bounded by whatever
it’s combined with — the companion stream, or shortest on a mix — so you often don’t set one:
// silence as long as the video, to give a silent clip an audio trackuse FFmpeg\Filter\Anullsrc;
$video = Media::open('timelapse.mp4')->videoStream();$track = AudioStream::generate(new Anullsrc(duration: $video->duration));Either way the result is an ordinary stream node — filter it, overlay onto it, encode it, exactly like one from a file. See Examples → Generate a stream from nothing.
Common sources
Section titled “Common sources”| Class | FFmpeg | Produces |
|---|---|---|
Filter\Color | color | A solid, uniformly colored frame |
Filter\Smptebars, Filter\Smptehdbars | smptebars | SMPTE color bars |
Filter\Testsrc, Filter\Testsrc2 | testsrc | A test pattern |
Filter\Mandelbrot | mandelbrot | A Mandelbrot fractal |
Filter\Nullsrc | nullsrc | Blank video |
Filter\Sine | sine | A sine-wave tone |
Filter\Anullsrc | anullsrc | Silence |
Filter\Anoisesrc | anoisesrc | A noise signal |
Filter\Aevalsrc | aevalsrc | Audio from an expression |
An Artisan Build project.
Built on FFmpeg — an independent binding, not affiliated with or endorsed by the FFmpeg project. Support FFmpeg.