pub struct FFMpeg { /* private fields */ }Expand description
Main interface into FFMPEG
This struct holds a child ffmpeg process that you can send frames into. Remember to call FFMpeg::finalize when you’re done.
Dropping this struct basically calls finalize anyway but it ignores errors, so it’s better to call finalize explicitly
Implementations§
Source§impl FFMpeg
impl FFMpeg
Sourcepub fn start(
out_file: impl AsRef<OsStr>,
width: usize,
height: usize,
fps: u32,
) -> Result<FFMpeg>
pub fn start( out_file: impl AsRef<OsStr>, width: usize, height: usize, fps: u32, ) -> Result<FFMpeg>
Start the FFMPEG rendering
Starts the FFMPEG rendering.
Sourcepub fn resolution(&self) -> (usize, usize)
pub fn resolution(&self) -> (usize, usize)
Get the render resolution
Sourcepub fn send_frame(&mut self, pixels: &[Color]) -> Result<()>
pub fn send_frame(&mut self, pixels: &[Color]) -> Result<()>
Send a frame to the FFMPEG process
Send a frame to the FFMPEG process. pixels.len() must be equal to ffmpeg.width() * ffmpeg.height()
Examples found in repository?
examples/bouncing-square.rs (line 37)
23fn main() -> ffmpeg::Result<()> {
24 let mut pixels: [Color; PIXEL_COUNT] = [0; PIXEL_COUNT];
25
26 let mut ffmpeg = ffmpeg::start("out.mp4", WIDTH, HEIGHT, FPS)?;
27
28 let mut x = 0;
29 let mut y = 0;
30 let mut dx = 1;
31 let mut dy = 1;
32 let w = 50;
33 let h = 50;
34 for _ in 0..(60 * FPS) {
35 pixels.fill(0);
36 draw_rect(&mut pixels, WIDTH, x, y, w, h, 0xFF00FF00);
37 ffmpeg.send_frame(&pixels)?;
38
39 let new_x = x + dx;
40 if (0..WIDTH as i32 - w).contains(&new_x) {
41 x = new_x;
42 } else {
43 dx *= -1;
44 }
45
46 let new_y = y + dy;
47 if (0..HEIGHT as i32 - h).contains(&new_y) {
48 y = new_y;
49 } else {
50 dy *= -1;
51 }
52 }
53
54 ffmpeg.finalize()?;
55
56 Ok(())
57}Sourcepub fn finalize(self) -> Result<()>
pub fn finalize(self) -> Result<()>
Finalize the FFMPEG rendering
If this method isn’t called directly or indirectly (such as if std::mem::forget is called on FFMpeg),
the final video may not be complete
Examples found in repository?
examples/bouncing-square.rs (line 54)
23fn main() -> ffmpeg::Result<()> {
24 let mut pixels: [Color; PIXEL_COUNT] = [0; PIXEL_COUNT];
25
26 let mut ffmpeg = ffmpeg::start("out.mp4", WIDTH, HEIGHT, FPS)?;
27
28 let mut x = 0;
29 let mut y = 0;
30 let mut dx = 1;
31 let mut dy = 1;
32 let w = 50;
33 let h = 50;
34 for _ in 0..(60 * FPS) {
35 pixels.fill(0);
36 draw_rect(&mut pixels, WIDTH, x, y, w, h, 0xFF00FF00);
37 ffmpeg.send_frame(&pixels)?;
38
39 let new_x = x + dx;
40 if (0..WIDTH as i32 - w).contains(&new_x) {
41 x = new_x;
42 } else {
43 dx *= -1;
44 }
45
46 let new_y = y + dy;
47 if (0..HEIGHT as i32 - h).contains(&new_y) {
48 y = new_y;
49 } else {
50 dy *= -1;
51 }
52 }
53
54 ffmpeg.finalize()?;
55
56 Ok(())
57}Trait Implementations§
Auto Trait Implementations§
impl Freeze for FFMpeg
impl RefUnwindSafe for FFMpeg
impl Send for FFMpeg
impl Sync for FFMpeg
impl Unpin for FFMpeg
impl UnwindSafe for FFMpeg
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more