Skip to content

🎥 Make videos programmatically with React

fix everything!

Jonny Burger8e6e37740882
diff --git a/packages/Cargo.lock b/packages/Cargo.lock
index ead19f8923..7cabdee6f2 100644
--- a/packages/Cargo.lock
+++ b/packages/Cargo.lock
@@ -133,7 +133,7 @@ checksum = "7fcaabb2fef8c910e7f4c7ce9f67a1283a1715879a7c230ca9d6d1ae31f16d91"
[[package]]
name = "ffmpeg-next"
version = "6.0.0"
-source = "git+https://github.com/JonnyBurger/rust-ffmpeg?rev=11a21ce6585fbfc4ee3e3b9edd63e44bbd3e8124#11a21ce6585fbfc4ee3e3b9edd63e44bbd3e8124"
+source = "git+https://github.com/JonnyBurger/rust-ffmpeg?rev=089fccdd9d081c7418d6a0e9edb0986a584d32a1#089fccdd9d081c7418d6a0e9edb0986a584d32a1"
dependencies = [
"bitflags",
"ffmpeg-sys-next",
diff --git a/packages/Cargo.toml b/packages/Cargo.toml
index e1779e536c..9f807f001b 100644
--- a/packages/Cargo.toml
+++ b/packages/Cargo.toml
@@ -15,7 +15,7 @@ jpeg-decoder = "0.3"
jpeg-encoder = "0.5.1"
threadpool = "1.8.1"
lazy_static = "1.4"
-ffmpeg-next = {git = "https://github.com/JonnyBurger/rust-ffmpeg", rev ="11a21ce6585fbfc4ee3e3b9edd63e44bbd3e8124"}
+ffmpeg-next = {git = "https://github.com/JonnyBurger/rust-ffmpeg", rev ="089fccdd9d081c7418d6a0e9edb0986a584d32a1"}
[[bin]]
name = "compositor"
diff --git a/packages/renderer/rust/opened_video.rs b/packages/renderer/rust/opened_video.rs
index 4e44cfa4de..debf0a391d 100644
--- a/packages/renderer/rust/opened_video.rs
+++ b/packages/renderer/rust/opened_video.rs
@@ -1,7 +1,7 @@
use std::io::ErrorKind;
use ffmpeg_next::Rational;
-use remotionffmpeg::{format::Pixel, frame::Video, media::Type, Dictionary};
+use remotionffmpeg::{format::Pixel, frame::Video, media::Type, Dictionary, StreamMut};
extern crate ffmpeg_next as remotionffmpeg;
use crate::{
@@ -256,6 +256,10 @@ impl OpenedVideo {
}
fn calculate_display_video_size(dar_x: i32, dar_y: i32, x: u32, y: u32) -> (u32, u32) {
+ if dar_x == 0 || dar_y == 0 {
+ return (x, y);
+ }
+
let dimensions = (x * y) as f64;
let new_width = (dimensions * (dar_x as f64 / dar_y as f64) as f64).sqrt();
let new_height = dimensions / new_width;
@@ -264,6 +268,13 @@ fn calculate_display_video_size(dar_x: i32, dar_y: i32, x: u32, y: u32) -> (u32,
(width, height)
}
+pub fn get_display_aspect_ratio(mut_stream: &StreamMut) -> Rational {
+ unsafe {
+ let asp = mut_stream.get_display_aspect_ratio();
+ return Rational::new(asp.numerator(), asp.denominator());
+ }
+}
+
pub fn open_video(src: &str) -> Result<OpenedVideo, PossibleErrors> {
let mut dictionary = Dictionary::new();
dictionary.set("fflags", "+genpts");
@@ -288,11 +299,7 @@ pub fn open_video(src: &str) -> Result<OpenedVideo, PossibleErrors> {
let original_width = video.width();
let original_height = video.height();
- let mut aspect_ratio: Rational = Rational::new(1, 1);
- unsafe {
- let new = mut_stream.get_display_aspect_ratio();
- aspect_ratio = Rational::new(new.0 .0, new.0 .1);
- }
+ let aspect_ratio = get_display_aspect_ratio(&mut_stream);
let (scaled_width, scaled_height) = calculate_display_video_size(
aspect_ratio.0,