diff --git a/.gitignore b/.gitignore index 1e11a99..e658837 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /target /.vscode *.png +*.mkv diff --git a/src/main.rs b/src/main.rs index 18a9e94..f4a9d31 100644 --- a/src/main.rs +++ b/src/main.rs @@ -8,6 +8,7 @@ use ffmpeg::media::Type; use ffmpeg::software::scaling::{context::Context, flag::Flags}; use ffmpeg::util::frame::video::Video; use std::path::Path; +use std::time::Instant; mod out; fn main() -> Result<(), Error> { @@ -16,13 +17,14 @@ fn main() -> Result<(), Error> { ffmpeg::init()?; // read the input file - if let Ok(mut ictx) = input(&Path::new("rgb.png")) { + if let Ok(mut ictx) = input(&Path::new("output.mkv")) { let input = ictx .streams() .best(Type::Video) .ok_or(ffmpeg::Error::StreamNotFound)?; let video_stream_index = input.index(); + let fps = input.avg_frame_rate(); let context_decoder = ffmpeg::codec::context::Context::from_parameters(input.parameters())?; // Ctx's video decoder @@ -50,7 +52,7 @@ fn main() -> Result<(), Error> { // test::print_raw(&rgb_frame.data(0)); // test::print_square(&rgb_frame.data(0), rgb_frame.width() as usize); - out::print_square(&rgb_frame, out::LinesFormat::RightLeft); + out::print_square(&rgb_frame, out::LinesFormat::RightLeft, video_stream_index); // test::small_matrix(); } Ok(()) @@ -61,6 +63,9 @@ fn main() -> Result<(), Error> { // Is this for multiple video streams? if stream.index() == video_stream_index { decoder.send_packet(&packet)?; + + let now = Instant::now(); + receive_and_process_decoded_frames(&mut decoder)?; } } diff --git a/src/out.rs b/src/out.rs index 8fdfcb8..35e2017 100644 --- a/src/out.rs +++ b/src/out.rs @@ -14,12 +14,12 @@ pub enum LinesFormat { } /// Must use square images -pub fn print_square(frame: &ffmpeg::frame::Video, lines_format: LinesFormat) { +pub fn print_square(frame: &ffmpeg::frame::Video, lines_format: LinesFormat, video_index: usize) { if frame.format() != Pixel::RGB24 { panic!("Must use Pixel::RGB24"); } if frame.width() != frame.height() { panic!("Must be 1:1 aspect ratio"); } - // Not sure if you can stack multiple frames on top of each other or what, - // but we just want the first one. - let z = 0; + + // This will panic if it's out of bounds. + let z = video_index; let size = frame.width() as usize; // How many bytes per pixel RGBA @@ -71,4 +71,4 @@ fn reverse(raw: & mut [u8]) { .collect::>(); x.iter().enumerate().for_each(|f| raw[f.0] = *f.1); -} \ No newline at end of file +}