pub struct MultiTrackComposer { /* private fields */ }Expand description
Composes multiple video layers onto a solid-colour canvas.
Layers are sorted by VideoLayer::z_order before compositing. The
resulting FilterGraph is source-only — call FilterGraph::pull_video
in a loop to extract the output frames. The graph terminates when the
last (highest z_order) layer finishes.
§Examples
use ff_filter::{AnimatedValue, MultiTrackComposer, VideoLayer};
use std::time::Duration;
let mut graph = MultiTrackComposer::new(1920, 1080)
.add_layer(VideoLayer {
source: "clip.mp4".into(),
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),
z_order: 0,
time_offset: Duration::ZERO,
in_point: None,
out_point: None,
in_transition: None,
})
.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 add_layer(self, layer: VideoLayer) -> Self
pub fn add_layer(self, layer: VideoLayer) -> Self
Appends a video layer and returns the updated composer.
If join_with_dissolve was called immediately before this,
the pending transition is consumed and attached to the layer as in_transition.
Sourcepub fn join_with_dissolve(
self,
prev_clip_end_secs: f64,
dissolve_dur_secs: f64,
kind: XfadeTransition,
) -> Self
pub fn join_with_dissolve( self, prev_clip_end_secs: f64, dissolve_dur_secs: f64, kind: XfadeTransition, ) -> Self
Schedules an xfade transition between the preceding layer and the next add_layer call.
prev_clip_end_secs is the duration of the preceding clip’s trimmed output (seconds).
dissolve_dur_secs is the length of the overlap transition.
The transition offset (when it starts within the preceding clip) is computed as
max(0, prev_clip_end_secs − dissolve_dur_secs).
Call this immediately before add_layer to wire the transition:
composer
.add_layer(clip_a)
.join_with_dissolve(4.0, 0.5, XfadeTransition::Fade)
.add_layer(clip_b)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.