pub struct MultiTrackComposer { /* private fields */ }Expand description
Composes multiple video layers onto a solid-colour canvas.
Layers are composited in the order they are added (first at the bottom). The
resulting FilterGraph is source-only — call FilterGraph::pull_video
in a loop to extract the output frames. The graph terminates when the
last (top) layer finishes.
§Examples
use ff_filter::{AnimatedValue, LayerSource, MultiTrackComposer, VideoLayer};
let mut graph = MultiTrackComposer::new(1920, 1080)
.add_layer(VideoLayer {
source: LayerSource::File("clip.mp4".into()),
proxy: None,
x: AnimatedValue::Static(0.0),
y: AnimatedValue::Static(0.0),
scale_x: AnimatedValue::Static(1.0),
scale_y: AnimatedValue::Static(1.0),
rotation: AnimatedValue::Static(0.0),
opacity: AnimatedValue::Static(1.0),
blend_mode: BlendMode::Normal,
composite_op: CompositeOp::Over,
effects: vec![],
})
.build()?;
while let Some(frame) = graph.pull_video()? {
// encode or display `frame`
}Implementations§
Source§impl MultiTrackComposer
impl MultiTrackComposer
Sourcepub fn new(canvas_width: u32, canvas_height: u32) -> Self
pub fn new(canvas_width: u32, canvas_height: u32) -> Self
Creates a new composer with a black canvas and no layers.
Sourcepub fn background(self, rgb: Rgb) -> Self
pub fn background(self, rgb: Rgb) -> Self
Sets the canvas background colour and returns the updated composer.
Sourcepub fn frame_rate(self, fps: f64) -> Self
pub fn frame_rate(self, fps: f64) -> Self
Sets the output frame rate (frames per second) of the composition.
The background canvas and the per-layer fps conform are generated at
this rate, so it MUST match the rate the caller encodes/muxes at —
otherwise the composited video is stretched or compressed by
this_rate / encode_rate while the audio stays correct, desyncing A/V.
Defaults to 30.0.
Sourcepub fn add_layer(self, layer: VideoLayer) -> Self
pub fn add_layer(self, layer: VideoLayer) -> Self
Appends a video layer and returns the updated composer.
A layer that cross-fades from its predecessor carries a
FilterStep::XFade in its
effects; the compositor wires the transition’s
second input from the preceding layer at build time.
Sourcepub fn build(self) -> Result<FilterGraph, FilterError>
pub fn build(self) -> Result<FilterGraph, FilterError>
Builds a source-only FilterGraph that composites all layers.
§Errors
FilterError::CompositionFailed— canvas width or height is zero, no layers were added, or an underlyingFFmpeggraph-construction call failed.