🎥 Make videos programmatically with React
variable FPS testbed
Jonny Burgerb19871bc4e7a
diff --git a/packages/example/public/variablefps.webm b/packages/example/public/variablefps.webmnew file mode 100644index 0000000000..2f89ca317fBinary files /dev/null and b/packages/example/public/variablefps.webm differdiff --git a/packages/example/src/OffthreadRemoteVideo/OffthreadRemoteVideo.tsx b/packages/example/src/OffthreadRemoteVideo/OffthreadRemoteVideo.tsxindex a711897187..1e9ff8b22a 100644--- a/packages/example/src/OffthreadRemoteVideo/OffthreadRemoteVideo.tsx+++ b/packages/example/src/OffthreadRemoteVideo/OffthreadRemoteVideo.tsx@@ -17,7 +17,7 @@ export const OffthreadLocalVideo: React.FC = () => {volume={(f) =>interpolate(f, [0, 500], [1, 0], {extrapolateRight: 'clamp'})}- src={staticFile('iphonevideo.mov')}+ src={staticFile('variablefps.webm')}/>);};diff --git a/packages/it-tests/src/rendering/example-videos.ts b/packages/it-tests/src/rendering/example-videos.tsindex 3b7b0a75e2..4945b180c9 100644--- a/packages/it-tests/src/rendering/example-videos.ts+++ b/packages/it-tests/src/rendering/example-videos.ts@@ -15,6 +15,7 @@ export const exampleVideos = {customDar: path.join(examplePackage, "public", "custom-dar.mp4"),screenrecording: path.join(examplePackage, "public", "quick.mov"),nofps: path.join(examplePackage, "public", "nofps.webm"),+ variablefps: path.join(examplePackage, "public", "variablefps.webm"),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/ffmpeg.rs b/packages/renderer/rust/ffmpeg.rsindex 789d3085f3..0e561ec92a 100644--- a/packages/renderer/rust/ffmpeg.rs+++ b/packages/renderer/rust/ffmpeg.rs@@ -48,16 +48,16 @@ pub fn extract_frame(// The requested position in the video.let position = calc_position(time, vid.time_base);- let has_no_fps = vid.fps.denominator() == 0 || vid.fps.numerator() == 0;+ let is_variable_fps = vid.fps.denominator() == 0 || vid.fps.numerator() == 0;let time_of_one_frame_in_seconds =1.0 / (vid.fps.numerator() as f64 / vid.fps.denominator() as f64);// How much the distance between 1 frame is in the videos internal time format.let one_frame_in_time_base = calc_position(time_of_one_frame_in_seconds, vid.time_base);- // If a video has no FPS, take a high threshold, like 1.5fps- let threshold = match has_no_fps {- true => calc_position(1.0, vid.time_base),+ // If a video has no FPS, take a high threshold, like 10fps+ let threshold = match is_variable_fps {+ true => calc_position(1.0 / 10.0, vid.time_base),false => one_frame_in_time_base,};@@ -121,6 +121,7 @@ pub fn extract_frame(vid.time_base,one_frame_in_time_base,threshold,+ is_variable_fps,)?;let from_cache = viddiff --git a/packages/renderer/rust/opened_stream.rs b/packages/renderer/rust/opened_stream.rsindex cb6a85b8bb..05d33a37f1 100644--- a/packages/renderer/rust/opened_stream.rs+++ b/packages/renderer/rust/opened_stream.rs@@ -12,7 +12,7 @@ use std::time::UNIX_EPOCH;use crate::{errors::ErrorWithBacktrace,frame_cache::{get_frame_cache_id, FrameCache, FrameCacheItem},- global_printer::_print_verbose,+ global_printer::{_print_debug, _print_verbose},rotation,scalable_frame::{NotRgbFrame, Rotate, ScalableFrame},};@@ -138,6 +138,7 @@ impl OpenedStream {time_base: Rational,one_frame_in_time_base: i64,threshold: i64,+ is_variable_fps: bool,) -> Result<usize, ErrorWithBacktrace> {let mut freshly_seeked = false;let mut last_seek_position = match self.duration_or_zero {@@ -176,10 +177,14 @@ impl OpenedStream {.get_item_id(position, threshold)?;if matching.is_some() {// Often times there is another package coming with a lower DTS,- // so we receive up to 4 more packets+ // so we receive up to 4 more packets, and 30 if it is a variable FPS videobreak_on_next_keyframe = true;if found_but_forward_seek.is_none() {- found_but_forward_seek = Some(4);+ if is_variable_fps {+ found_but_forward_seek = Some(30);+ } else {+ found_but_forward_seek = Some(4);+ }}}}diff --git a/packages/renderer/src/test/example-videos.ts b/packages/renderer/src/test/example-videos.tsindex 4737368645..a9e12c9897 100644--- a/packages/renderer/src/test/example-videos.ts+++ b/packages/renderer/src/test/example-videos.ts@@ -15,6 +15,7 @@ export const exampleVideos = {customDar: path.join(examplePackage, 'public', 'custom-dar.mp4'),screenrecording: path.join(examplePackage, 'public', 'quick.mov'),nofps: path.join(examplePackage, 'public', 'nofps.webm'),+ variablefps: path.join(examplePackage, 'public', 'variablefps.webm'),webcam: path.join(examplePackage, 'public', 'webcam.webm'),iphonevideo: path.join(examplePackage, 'public', 'iphonevideo.mov'),av1: path.join(examplePackage, 'public', 'av1.webm'),