Skip to main content

MultiTrackComposer

Struct MultiTrackComposer 

Source
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

Source

pub fn new(canvas_width: u32, canvas_height: u32) -> Self

Creates a new composer with a black canvas and no layers.

Source

pub fn background(self, rgb: Rgb) -> Self

Sets the canvas background colour and returns the updated composer.

Source

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.

Source

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.

Source

pub fn build(self) -> Result<FilterGraph, FilterError>

Builds a source-only FilterGraph that composites all layers.

§Errors

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.