Skip to content

🎥 Make videos programmatically with React

fix some videos crashing with tone mapped

Jonny Burgera4bf99541c00
diff --git a/packages/renderer/rust/opened_stream.rs b/packages/renderer/rust/opened_stream.rs
index af9097e965..dd6be1add7 100644
--- a/packages/renderer/rust/opened_stream.rs
+++ b/packages/renderer/rust/opened_stream.rs
@@ -29,6 +29,7 @@ pub struct OpenedStream {
pub scaled_height: u32,
pub video: remotionffmpeg::codec::decoder::Video,
pub filter: remotionffmpeg::filter::Graph,
+ pub should_filter: bool,
pub src: String,
pub original_src: String,
pub input: remotionffmpeg::format::context::Input,
@@ -288,7 +289,8 @@ impl OpenedStream {
match result {
Ok(Some(unfiltered)) => unsafe {
let mut video: Video;
- if tone_mapped {
+ _print_verbose(&format!("received frame {}", tone_mapped))?;
+ if tone_mapped && self.should_filter {
video = frame::Video::empty();
self.filter.get("in").unwrap().source().add(&unfiltered)?;
self.filter.get("out").unwrap().sink().frame(&mut video)?;
@@ -342,11 +344,6 @@ impl OpenedStream {
.add_item(item);
items_in_loop += 1;
- _print_verbose(&format!(
- "received frame {} ({})",
- video.pts().expect("pts"),
- items_in_loop
- ))?;
if items_in_loop % 10 == 0 {
match maximum_frame_cache_size_in_bytes {
@@ -517,7 +514,7 @@ pub fn open_stream(
original_height,
);
- let filter = make_tone_map_filtergraph(
+ let (filter, should_filter) = make_tone_map_filtergraph(
original_width,
original_height,
&format!("{:?}", decoder.format()).to_lowercase(),
@@ -545,6 +542,7 @@ pub fn open_stream(
rotation: rotate,
original_src: original_src.to_string(),
filter,
+ should_filter,
};
Ok((opened_stream, fps, time_base))
diff --git a/packages/renderer/rust/tone_map.rs b/packages/renderer/rust/tone_map.rs
index fe38a2a66a..b707643055 100644
--- a/packages/renderer/rust/tone_map.rs
+++ b/packages/renderer/rust/tone_map.rs
@@ -16,7 +16,7 @@ pub fn make_tone_map_filtergraph(
space: color::Space,
color_range: color::Range,
aspect_ratio: Rational,
-) -> Result<Graph, ffmpeg_next::Error> {
+) -> Result<(Graph, bool), ffmpeg_next::Error> {
let mut filter = filter::Graph::new();
let args = format!(
"width={}:height={}:pix_fmt={}:time_base={}/{}:sar={}/{}",
@@ -65,7 +65,7 @@ pub fn make_tone_map_filtergraph(
_ => "input",
};
- let matrix_is_target = matrix_in == "input" || matrix_in == "709";
+ let matrix_is_target = matrix_in == "input" || matrix_in == "470bg" || matrix_in == "709";
let transfer_is_target = transfer_in == "input" || transfer_in == "709";
let primaries_is_target = primaries == "input" || primaries == "709";
@@ -91,5 +91,5 @@ pub fn make_tone_map_filtergraph(
filter.validate()?;
- Ok(filter)
+ Ok((filter, !is_bt_601))
}
diff --git a/packages/renderer/src/test/extract-frame-rust.test.ts b/packages/renderer/src/test/extract-frame-rust.test.ts
index dd1334559e..83ec50358b 100644
--- a/packages/renderer/src/test/extract-frame-rust.test.ts
+++ b/packages/renderer/src/test/extract-frame-rust.test.ts
@@ -19,7 +19,7 @@ test(
original_src: exampleVideos.bigBuckBunny,
time: 40,
transparent: false,
- tone_mapped: false,
+ tone_mapped: true,
});
expect(data.length).toBe(1280 * 720 * 3 + BMP_HEADER_SIZE);
@@ -28,7 +28,7 @@ test(
original_src: exampleVideos.bigBuckBunny,
time: 40.4,
transparent: false,
- tone_mapped: false,
+ tone_mapped: true,
});
expect(data2.length).toBe(1280 * 720 * 3 + BMP_HEADER_SIZE);
@@ -54,7 +54,7 @@ test(
original_src: exampleVideos.transparentWebm,
time: 1,
transparent: true,
- tone_mapped: false,
+ tone_mapped: true,
});
// Platform specific PNG encoder settings
@@ -95,14 +95,14 @@ test('Should be able to start two compositors', async () => {
original_src: exampleVideos.bigBuckBunny,
time: 40,
transparent: false,
- tone_mapped: false,
+ tone_mapped: true,
});
await compositor2.executeCommand('ExtractFrame', {
src: exampleVideos.bigBuckBunny,
original_src: exampleVideos.bigBuckBunny,
time: 40,
transparent: false,
- tone_mapped: false,
+ tone_mapped: true,
});
});
@@ -118,7 +118,7 @@ test('Should be able to seek backwards', async () => {
original_src: exampleVideos.bigBuckBunny,
time: 40,
transparent: false,
- tone_mapped: false,
+ tone_mapped: true,
});
expect(data.length).toBe(2764854);
const data2 = await compositor.executeCommand('ExtractFrame', {
@@ -126,7 +126,7 @@ test('Should be able to seek backwards', async () => {
original_src: exampleVideos.bigBuckBunny,
time: 35,
transparent: false,
- tone_mapped: false,
+ tone_mapped: true,
});
expect(data2.length).toBe(2764854);
@@ -148,7 +148,7 @@ test(
original_src: exampleVideos.framerWithoutFileExtension,
time: 0.04,
transparent: false,
- tone_mapped: false,
+ tone_mapped: true,
});
expect(data.length).toBe(3499254);
@@ -172,7 +172,7 @@ test(
original_src: exampleVideos.framerWithoutFileExtension,
time: 3.33,
transparent: false,
- tone_mapped: false,
+ tone_mapped: true,
});
const expectedLength = BMP_HEADER_SIZE + 1080 * 1080 * 3;
@@ -205,7 +205,7 @@ test(
original_src: exampleVideos.corrupted,
time: 100,
transparent: false,
- tone_mapped: false,
+ tone_mapped: true,
});
// Pixel fixing
@@ -232,7 +232,7 @@ test('Should be able to extract a frame with abnormal DAR', async () => {
original_src: exampleVideos.customDar,
time: 3.33,
transparent: false,
- tone_mapped: false,
+ tone_mapped: true,
});
const header = data.subarray(0, BMP_HEADER_SIZE);
@@ -266,7 +266,7 @@ test('Should be able to extract the frames in reverse order', async () => {
original_src: exampleVideos.bigBuckBunny,
time: i,
transparent: false,
- tone_mapped: false,
+ tone_mapped: true,
});
const expectedLength = BMP_HEADER_SIZE + 1280 * 720 * 3;
@@ -310,7 +310,7 @@ test('Last frame should be fast', async () => {
original_src: exampleVideos.transparentWebm,
time: 5.0,
transparent: false,
- tone_mapped: false,
+ tone_mapped: true,
});
const time_end = Date.now();
@@ -322,7 +322,7 @@ test('Last frame should be fast', async () => {
original_src: exampleVideos.transparentWebm,
time: 5.0,
transparent: false,
- tone_mapped: false,
+ tone_mapped: true,
});
// Time should be way less now
@@ -336,7 +336,7 @@ test('Last frame should be fast', async () => {
original_src: exampleVideos.transparentWebm,
time: 100,
transparent: false,
- tone_mapped: false,
+ tone_mapped: true,
});
// Time should be way less now
@@ -352,7 +352,7 @@ test('Last frame should be fast', async () => {
original_src: exampleVideos.transparentWebm,
time: 1,
transparent: true,
- tone_mapped: false,
+ tone_mapped: true,
});
const time4_end = Date.now();
@@ -375,7 +375,7 @@ test('Should get from a screen recording', async () => {
original_src: exampleVideos.screenrecording,
time: 0.5,
transparent: false,
- tone_mapped: false,
+ tone_mapped: true,
});
expect(data.length).toBe(15230038);
@@ -396,7 +396,7 @@ test('Should get from video with no fps', async () => {
original_src: exampleVideos.nofps,
time: 0.5,
transparent: false,
- tone_mapped: false,
+ tone_mapped: true,
});
expect(data.length).toBe(3044334);
@@ -417,7 +417,7 @@ test('Should get from broken webcam video', async () => {
original_src: exampleVideos.webcam,
time: 0,
transparent: false,
- tone_mapped: false,
+ tone_mapped: true,
});
expect(data.length).toBe(921654);
@@ -438,7 +438,7 @@ test('Should get from iPhone video', async () => {
original_src: exampleVideos.iphonevideo,
time: 1,
transparent: false,
- tone_mapped: false,
+ tone_mapped: true,
});
expect(data.length).toBe(24883254);
@@ -459,7 +459,7 @@ test('Should get from AV1 video', async () => {
original_src: exampleVideos.av1,
time: 0.5,
transparent: false,
- tone_mapped: false,
+ tone_mapped: true,
});
expect(data.length).toBe(6220854);
@@ -480,7 +480,7 @@ test('Should handle getting a frame from a WebM when it is not transparent', asy
original_src: exampleVideos.variablefps,
time: 0,
transparent: true,
- tone_mapped: false,
+ tone_mapped: true,
});
// Should resort back to BMP because it is faster
@@ -505,7 +505,7 @@ test('Should handle a video with no frames at the beginning', async () => {
original_src: exampleVideos.zerotimestamp,
time: 1.5,
transparent: false,
- tone_mapped: false,
+ tone_mapped: true,
});
// Should resort back to BMP because it is faster
@@ -534,7 +534,7 @@ test('Two different starting times should not result in big seeking', async () =
original_src: exampleVideos.bigBuckBunny,
time,
transparent: false,
- tone_mapped: false,
+ tone_mapped: true,
});
const expectedLength = BMP_HEADER_SIZE + 1280 * 720 * 3;
@@ -638,7 +638,7 @@ test('Should not duplicate frames for iphoneVideo', async () => {
original_src: exampleVideos.iphonevideo,
time: frame30,
transparent: false,
- tone_mapped: false,
+ tone_mapped: true,
});
const secondFrame = await compositor.executeCommand('ExtractFrame', {
@@ -646,7 +646,7 @@ test('Should not duplicate frames for iphoneVideo', async () => {
original_src: exampleVideos.iphonevideo,
time: frame31,
transparent: false,
- tone_mapped: false,
+ tone_mapped: true,
});
const hundredRandomPixels = new Array(100).fill(true).map(() => {