Skip to main content

export/
export.rs

1use motion_canvas_rs::prelude::*;
2use std::time::Duration;
3
4fn main() {
5    // 1. Initialize for Export
6    let mut project = Project::default()
7        .with_fps(30)
8        .with_ffmpeg(true)
9        .with_title("Export")
10        .with_output_path("output")
11        .close_on_finish();
12
13    // 2. Setup Nodes
14    let circle = Circle::default()
15        .with_position(Vec2::new(400.0, 300.0))
16        .with_radius(50.0)
17        .with_fill(Color::rgb8(0x68, 0xab, 0xdf)); // Blue
18
19    let text = TextNode::default()
20        .with_position(Vec2::new(400.0, 50.0))
21        .with_text("Export Demo")
22        .with_font_size(40.0)
23        .with_fill(Color::rgb8(0xf2, 0xf2, 0xf2)); // White
24
25    project.scene.add(Box::new(circle.clone()));
26    project.scene.add(Box::new(text.clone()));
27
28    // 3. Define Animations (Color and Font Size)
29    project.scene.video_timeline.add(all![
30        // Circle color and size
31        circle
32            .fill_color
33            .to(Color::rgb8(0xf2, 0xf2, 0xf2), Duration::from_secs(2))
34            .ease(easings::quad_in_out),
35        circle
36            .radius
37            .to(150.0, Duration::from_secs(2))
38            .ease(easings::elastic_out),
39        // Text font size
40        text.font_size
41            .to(50.0, Duration::from_secs(2))
42            .ease(easings::cubic_out),
43    ]);
44
45    // 4. Export (Renders frames and combines them into out.mkv)
46    println!("Starting export to {}...", project.output_path.display());
47    project.export().expect("Failed to export");
48}