🎥 Make videos programmatically with React
cool
Jonny Burger7b3556a47271
diff --git a/packages/renderer/rust/image.rs b/packages/renderer/rust/image.rsindex 814364fa95..c4408c131e 100644--- a/packages/renderer/rust/image.rs+++ b/packages/renderer/rust/image.rs@@ -52,27 +52,41 @@ pub fn save_as_jpeg(Ok(())}+pub enum PixelFormat {+ Bt709,+ Bt2020,+}+pub fn get_png_data(rgba_data: &[u8],width: u32,height: u32,+ format: PixelFormat,) -> Result<Vec<u8>, ErrorWithBacktrace> {let mut png_data = Vec::new();{let mut encoder = png::Encoder::new(&mut png_data, width, height);- encoder.set_color(png::ColorType::Rgba);+ encoder.set_color(png::ColorType::Rgb);encoder.set_depth(png::BitDepth::Eight);encoder.set_source_gamma(png::ScaledFloat::from_scaled(45455)); // 1.0 / 2.2, scaled by 100000encoder.set_source_gamma(png::ScaledFloat::new(1.0 / 2.2)); // 1.0 / 2.2, unscaled, but rounded- let source_chromaticities = png::SourceChromaticities::new(+ let source_chromaticities = match format {// Using unscaled instantiation here// Why those values, explained here https://www.canva.dev/blog/engineering/a-journey-through-colour-space-with-ffmpeg/- (0.31270, 0.32900),- (0.64000, 0.33000),- (0.30000, 0.60000),- (0.15000, 0.06000),- );+ PixelFormat::Bt709 => png::SourceChromaticities::new(+ (0.31270, 0.32900),+ (0.64000, 0.33000),+ (0.30000, 0.60000),+ (0.15000, 0.06000),+ ),+ PixelFormat::Bt2020 => png::SourceChromaticities::new(+ (0.31270, 0.32900),+ (0.708, 0.292),+ (0.17, 0.797),+ (0.131, 0.046),+ ),+ };encoder.set_source_chromaticities(source_chromaticities);let mut writer = encoder.write_header()?;diff --git a/packages/renderer/rust/opened_stream.rs b/packages/renderer/rust/opened_stream.rsindex 3a4a178863..33f789ec46 100644--- a/packages/renderer/rust/opened_stream.rs+++ b/packages/renderer/rust/opened_stream.rs@@ -1,10 +1,6 @@-use std::{- io::{ErrorKind, Write},- time::SystemTime,-};+use std::{io::ErrorKind, time::SystemTime};use ffmpeg_next::Rational;-use image::imageops::rotate90;use remotionffmpeg::{codec::Id,filter,@@ -22,7 +18,7 @@ use crate::{frame_cache_manager::FrameCacheManager,global_printer::_print_verbose,rotation,- scalable_frame::{create_bmp_image_from_frame, rotate_90, NotRgbFrame, Rotate, ScalableFrame},+ scalable_frame::{NotRgbFrame, Rotate, ScalableFrame},};pub struct OpenedStream {@@ -284,9 +280,10 @@ impl OpenedStream {filter.add(&filter::find("buffersink").unwrap(), "out", "")?;filter- .output("in", 0)?- .input("out", 0)?- .parse("zscale=t=linear:npl=100,format=gbrpf32le,zscale=p=bt709,tonemap=tonemap=hable:desat=0,zscale=t=bt709:m=bt709:r=pc,format=bgr24")?;+ .output("in", 0)?+ .input("out", 0)?+ .parse("zscale=t=linear:npl=100,format=gbrpf32le,zscale=p=bt709,tonemap=tonemap=hable:desat=0,zscale=t=bt709:m=bt709:r=pc,format=bgr24")?;+filter.validate()?;_print_verbose(&format!("filter dump {}", filter.dump()))?;diff --git a/packages/renderer/rust/scalable_frame.rs b/packages/renderer/rust/scalable_frame.rsindex 4cafe78b08..57bd61ac59 100644--- a/packages/renderer/rust/scalable_frame.rs+++ b/packages/renderer/rust/scalable_frame.rs@@ -7,7 +7,11 @@ use ffmpeg_next::{software::scaling::{Context, Flags},};-use crate::{errors::ErrorWithBacktrace, global_printer::_print_verbose, image::get_png_data};+use crate::{+ errors::ErrorWithBacktrace,+ global_printer::_print_verbose,+ image::{get_png_data, PixelFormat},+};#[derive(Clone, Copy)]pub enum Rotate {@@ -231,7 +235,7 @@ pub fn scale_and_make_bitmap(|| native_frame.format == Pixel::YUVA444P12LE;if is_transparent_pixel_format {- return get_png_data(&rotated, rotated_width, rotated_height);+ return get_png_data(&rotated, rotated_width, rotated_height, PixelFormat::Bt709);} else {_print_verbose(&format!("Requested transparent image, but the video {} is not transparent (pixel format {:?}). Returning BMP.",