🎥 Make videos programmatically with React
repro case
Jonny Burger28b2e445f769
diff --git a/packages/example/public/zero-timestamp.mp4 b/packages/example/public/zero-timestamp.mp4new file mode 100644index 0000000000..bcd3012158Binary files /dev/null and b/packages/example/public/zero-timestamp.mp4 differdiff --git a/packages/it-tests/src/rendering/example-videos.ts b/packages/it-tests/src/rendering/example-videos.tsindex 4945b180c9..76580b7832 100644--- a/packages/it-tests/src/rendering/example-videos.ts+++ b/packages/it-tests/src/rendering/example-videos.ts@@ -16,6 +16,7 @@ export const exampleVideos = {screenrecording: path.join(examplePackage, "public", "quick.mov"),nofps: path.join(examplePackage, "public", "nofps.webm"),variablefps: path.join(examplePackage, "public", "variablefps.webm"),+ zerotimestamp: path.join(examplePackage, "public", "zero-timestamp.mp4"),webcam: path.join(examplePackage, "public", "webcam.webm"),iphonevideo: path.join(examplePackage, "public", "iphonevideo.mov"),av1: path.join(examplePackage, "public", "av1.webm"),diff --git a/packages/renderer/rust/frame_cache.rs b/packages/renderer/rust/frame_cache.rsindex 6726e9460b..ffc7e501aa 100644--- a/packages/renderer/rust/frame_cache.rs+++ b/packages/renderer/rust/frame_cache.rs@@ -2,7 +2,10 @@ extern crate ffmpeg_next as remotionffmpeg;use std::sync::atomic::{AtomicUsize, Ordering};-use crate::{errors::ErrorWithBacktrace, opened_stream::get_time, scalable_frame::ScalableFrame};+use crate::{+ errors::ErrorWithBacktrace, global_printer::_print_debug, opened_stream::get_time,+ scalable_frame::ScalableFrame,+};pub fn get_frame_cache_id() -> usize {static COUNTER: AtomicUsize = AtomicUsize::new(1);@@ -176,10 +179,36 @@ impl FrameCache {let has_pts_after = self.items.iter().any(|item| item.resolved_pts >= time);- if best_distance > threshold || !has_pts_after {+ // If this happens, then `last_frame` has not worked correctly. Do not match+ if !has_pts_after {return Ok(None);}+ if best_distance > threshold {+ let has_no_items_before = self.items.iter().all(|item| item.resolved_pts > time);+ if has_no_items_before {+ let has_asked_time_before = self+ .items+ .iter()+ .find(|item| item.asked_time <= time)+ .is_some();++ let asked_time_difference =+ (self.items[best_item.unwrap()].asked_time - time).abs();+ if has_asked_time_before {+ _print_debug(&format!(+ "Found timestamp with too much threshold, but will let it pass because no closer frames found {} {}",+ asked_time_difference, threshold+ ))?;+ // Fall through to success case+ } else {+ return Ok(None);+ }+ } else {+ return Ok(None);+ }+ }+match best_item {Some(best_item) => {self.items[best_item].frame.ensure_data()?;diff --git a/packages/renderer/src/test/example-videos.ts b/packages/renderer/src/test/example-videos.tsindex a9e12c9897..278f193aff 100644--- a/packages/renderer/src/test/example-videos.ts+++ b/packages/renderer/src/test/example-videos.ts@@ -16,6 +16,7 @@ export const exampleVideos = {screenrecording: path.join(examplePackage, 'public', 'quick.mov'),nofps: path.join(examplePackage, 'public', 'nofps.webm'),variablefps: path.join(examplePackage, 'public', 'variablefps.webm'),+ zerotimestamp: path.join(examplePackage, 'public', 'zero-timestamp.mp4'),webcam: path.join(examplePackage, 'public', 'webcam.webm'),iphonevideo: path.join(examplePackage, 'public', 'iphonevideo.mov'),av1: path.join(examplePackage, 'public', 'av1.webm'),diff --git a/packages/renderer/src/test/extract-frame-rust.test.ts b/packages/renderer/src/test/extract-frame-rust.test.tsindex 0f8288522b..798c845615 100644--- a/packages/renderer/src/test/extract-frame-rust.test.ts+++ b/packages/renderer/src/test/extract-frame-rust.test.ts@@ -474,6 +474,30 @@ test('Should handle getting a frame from a WebM when it is not transparent', asyawait compositor.waitForDone();});+test('Should handle a video with no frames at the beginning', async () => {+ const compositor = startLongRunningCompositor(+ getIdealMaximumFrameCacheItems(),+ 'info',+ false+ );++ const data = await compositor.executeCommand('ExtractFrame', {+ src: exampleVideos.zerotimestamp,+ original_src: exampleVideos.zerotimestamp,+ time: 1.5,+ transparent: false,+ });++ // Should resort back to BMP because it is faster+ const header = data.slice(0, 8).toString('utf8');+ expect(header).toContain('BM6');++ expect(data.length).toBe(6220854);++ compositor.finishCommands();+ await compositor.waitForDone();+});+test('Two different starting times should not result in big seeking', async () => {const compositor = startLongRunningCompositor(300, 'info', false);