From bdba596d07779408c3fcd6d5477155afb49d6c2b Mon Sep 17 00:00:00 2001 From: Vivian Lim Date: Sun, 29 Nov 2020 02:27:37 -0800 Subject: [PATCH] stop frame properties from changing after starting, ffmpeg doesn't like that --- examples/ffmpeg_recorder.rs | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/examples/ffmpeg_recorder.rs b/examples/ffmpeg_recorder.rs index 212a24a..bf136ac 100644 --- a/examples/ffmpeg_recorder.rs +++ b/examples/ffmpeg_recorder.rs @@ -28,6 +28,7 @@ struct MyEmulator { video_filter: filter::Graph, audio_filter: filter::Graph, sys_path: Option, + frame_properties_locked: bool, } fn video_filter( @@ -147,6 +148,7 @@ impl MyEmulator { video_filter, audio_filter, sys_path: sys_path.as_ref().map(|x| x.as_ref().to_path_buf()), + frame_properties_locked: false, }; let mut pin_emu = Box::pin(emu); @@ -243,6 +245,10 @@ impl retro::wrapper::Handler for MyEmulator { } fn set_pixel_format(&mut self, format: PixelFormat) -> bool { + if self.frame_properties_locked { + return true; + } + self.video_pixel_format = match format { PixelFormat::ARGB1555 => format::Pixel::RGB555, PixelFormat::ARGB8888 => format::Pixel::RGB32, @@ -253,16 +259,26 @@ impl retro::wrapper::Handler for MyEmulator { } fn set_system_av_info(&mut self, system_av_info: SystemAvInfo) -> bool { - self.video_encoder.set_frame_rate(system_av_info.timing.fps.into()); - if system_av_info.timing.sample_rate.round() as i32 > 0 { - self.audio_encoder.set_rate(system_av_info.timing.sample_rate.round() as i32); + if self.frame_properties_locked { + return true; } + + self.video_encoder.set_frame_rate(system_av_info.timing.fps.into()); + /* + if system_av_info.timing.sample_rate.round() as i32 > 0 { + self.audio_encoder.set_rate(system_av_info.timing.sample_rate.round() as i32); + } + */ self.av_info.timing = system_av_info.timing; self.set_geometry(system_av_info.geometry); true } fn set_geometry(&mut self, geometry: GameGeometry) -> bool { + if self.frame_properties_locked { + return true; + } + self.video_encoder.set_width(geometry.base_width); self.video_encoder.set_height(geometry.base_height); self.video_encoder.set_aspect_ratio(geometry.aspect_ratio as f64); @@ -322,6 +338,7 @@ fn main() -> Fallible<()> { let mut emu = MyEmulator::new(opt.core, &opt.system, video_encoder, audio_encoder); emu.load_game(opt.rom); + emu.frame_properties_locked = true; octx.write_header().unwrap(); for _ in 0..60*60 {