Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
fix(export): emit silent audio frames when render returns none
Richie McIlroycc0c4673a9ce
diff --git a/crates/export/src/mp4.rs b/crates/export/src/mp4.rsindex 8640a3053..658996672 100644--- a/crates/export/src/mp4.rs+++ b/crates/export/src/mp4.rs@@ -252,12 +252,11 @@ impl Mp4ExportSettings {let (pts, samples) =audio_frame_budget(n, sample_rate, fps_u64, audio_sample_cursor)?;audio_sample_cursor = pts as u64 + samples as u64;- audio+ let mut frame = audio.render_frame(samples, &project_for_audio)- .map(|mut frame| {- frame.set_pts(Some(pts));- frame- })+ .unwrap_or_else(|| silent_audio_frame(samples));+ frame.set_pts(Some(pts));+ Some(frame)});fill_nv12_frame_direct(@@ -472,6 +471,19 @@ fn audio_frame_budget(Some((cursor as i64, (end - cursor) as usize))}+fn silent_audio_frame(samples: usize) -> ffmpeg::frame::Audio {+ let mut frame = ffmpeg::frame::Audio::new(+ AudioRenderer::SAMPLE_FORMAT,+ samples,+ ffmpeg::ChannelLayout::STEREO,+ );+ frame.set_rate(AudioRenderer::SAMPLE_RATE);+ for plane in 0..frame.planes() {+ frame.data_mut(plane).fill(0);+ }+ frame+}+fn fill_nv12_frame_direct(frame: &mut ffmpeg::frame::Video,nv12_data: &[u8],@@ -779,6 +791,22 @@ mod tests {}}+ #[test]+ fn silent_audio_frame_matches_renderer_format() {+ ffmpeg::init().unwrap();++ let samples = 1600usize;+ let frame = silent_audio_frame(samples);++ assert_eq!(frame.samples(), samples);+ assert_eq!(frame.rate(), AudioRenderer::SAMPLE_RATE);+ assert_eq!(frame.format(), AudioRenderer::SAMPLE_FORMAT);+ assert_eq!(frame.channel_layout(), ffmpeg::ChannelLayout::STEREO);+ for plane in 0..frame.planes() {+ assert!(frame.data(plane).iter().all(|byte| *byte == 0));+ }+ }+#[test]fn fill_nv12_frame_preserves_data_layout() {ffmpeg::init().unwrap();