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(&circle);
26    project.scene.add(&text);
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_paint
33            .to(
34                Paint::Solid(Color::rgb8(0xf2, 0xf2, 0xf2)),
35                Duration::from_secs(2)
36            )
37            .ease(easings::quad_in_out),
38        circle
39            .radius
40            .to(150.0, Duration::from_secs(2))
41            .ease(easings::elastic_out),
42        // Text font size
43        text.font_size
44            .to(50.0, Duration::from_secs(2))
45            .ease(easings::cubic_out),
46    ]);
47
48    // 4. Export (Renders frames and combines them into out.mkv)
49    println!("Starting export to {}...", project.output_path.display());
50    project.export().expect("Failed to export");
51}