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 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,
    })
    .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 add_layer(self, layer: VideoLayer) -> Self

Appends a video layer and returns the updated composer.

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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.