Skip to content

🎥 Make videos programmatically with React

also handle it better on the rust side

Jonny Burger7e00dc00b238
diff --git a/packages/example/public/variablefps-no-duration.webm b/packages/example/public/variablefps-no-duration.webm
new file mode 100644
index 0000000000..017d0d9a8d
Binary files /dev/null and b/packages/example/public/variablefps-no-duration.webm differ
diff --git a/packages/it-tests/src/rendering/get-video-metadata.test.ts b/packages/it-tests/src/rendering/get-video-metadata.test.ts
index 30327926d3..a3559743a8 100644
--- a/packages/it-tests/src/rendering/get-video-metadata.test.ts
+++ b/packages/it-tests/src/rendering/get-video-metadata.test.ts
@@ -100,3 +100,19 @@ test("Should return an error due to using a audio file", async () => {
);
}
});
+
+test("Should not return duration in variable fps video", async () => {
+ const video = path.join(
+ __dirname,
+ "..",
+ "..",
+ "..",
+ "example",
+ "public",
+ "variablefps-no-duration.webm"
+ );
+ expect(existsSync(video)).toEqual(true);
+
+ const hi = await getVideoMetadata(video, { logLevel: "verbose" });
+ console.log(hi);
+});
diff --git a/packages/renderer/rust/ffmpeg.rs b/packages/renderer/rust/ffmpeg.rs
index e484683177..afff26c557 100644
--- a/packages/renderer/rust/ffmpeg.rs
+++ b/packages/renderer/rust/ffmpeg.rs
@@ -7,6 +7,7 @@ use crate::payloads::payloads::{
KnownAudioCodecs, KnownCodecs, KnownColorSpaces, OpenVideoStats, VideoMetadata,
};
use std::fs::File;
+use std::i64;
use std::io::{BufReader, ErrorKind};
extern crate ffmpeg_next as remotionffmpeg;
use remotionffmpeg::{codec, encoder, format, media, Rational};
@@ -301,13 +302,17 @@ pub fn get_video_metadata(file_path: &str) -> Result<VideoMetadata, ErrorWithBac
.map_err(|e| e.to_string())?;
// Get the duration
+ let duration = input.duration();
#[allow(non_snake_case)]
- let durationInSeconds = input.duration() as f64 / remotionffmpeg::ffi::AV_TIME_BASE as f64;
+ let durationInSeconds = match duration {
+ i64::MIN => None,
+ _ => Some(duration as f64 / remotionffmpeg::ffi::AV_TIME_BASE as f64),
+ };
#[allow(non_snake_case)]
let supportsSeeking = match video_codec_name {
KnownCodecs::H264 => {
- if durationInSeconds < 5.0 {
+ if durationInSeconds.is_some() && durationInSeconds.unwrap() < 5.0 {
true
} else {
let f = File::open(file_path).unwrap();
diff --git a/packages/renderer/rust/payloads.rs b/packages/renderer/rust/payloads.rs
index 48ca15a1e1..c68bf4379d 100644
--- a/packages/renderer/rust/payloads.rs
+++ b/packages/renderer/rust/payloads.rs
@@ -221,7 +221,7 @@ pub mod payloads {
pub fps: f32,
pub width: u32,
pub height: u32,
- pub durationInSeconds: f64,
+ pub durationInSeconds: Option<f64>,
pub codec: KnownCodecs,
pub canPlayInVideoTag: bool,
pub supportsSeeking: bool,