Skip to content

Instantly share code, notes, and snippets.

@bzm3r
Last active November 7, 2020 12:23
Show Gist options
  • Save bzm3r/487add1885560ddebba1b7058b0a5140 to your computer and use it in GitHub Desktop.
Save bzm3r/487add1885560ddebba1b7058b0a5140 to your computer and use it in GitHub Desktop.
fn make_movie(width: i32, height: i32, framerate: i32, frames: i32) {
let mut surface =
ImageSurface::create(Format::ARgb32, width, height).expect("Couldn't create surface");
let mut child = Command::new("cmd")
.args(&["/C", &format!(
"ffmpeg -f rawvideo -pix_fmt bgra -s {width}x{height} -i - -pix_fmt yuv420p -r {framerate} -y out.mp4",
width = width,
height = height,
framerate = framerate,
)])
.stdin(Stdio::piped())
.spawn()
.expect("failed to execute process");
{
// limited borrow of stdin
let child_stdin = child.stdin.as_mut().expect("failed to get stdin");
(0..frames).for_each(|f| {
draw(&surface, f);
let d = surface.get_data().expect("Failed to get_data");
child_stdin.write_all(&d).expect("Failed to write to file");
});
}
child.wait().expect("child process wasn't running");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment