Skip to content

🎥 Make videos programmatically with React

`@remotion/renderer`: Handle videos with `pixel_format = none`

Jonny Burger9f6ddf37a66c
diff --git a/packages/renderer/rust/scalable_frame.rs b/packages/renderer/rust/scalable_frame.rs
index 46327ce389..84f409d978 100644
--- a/packages/renderer/rust/scalable_frame.rs
+++ b/packages/renderer/rust/scalable_frame.rs
@@ -71,15 +71,20 @@ impl ScalableFrame {
let mut planes: Vec<Vec<u8>>;
let format: Pixel;
let linesize: [i32; 8];
- let (mut filter, should_filter) = make_tone_map_filtergraph(frame.filter_graph)?;
- if frame.tone_mapped && should_filter {
+ let filter = make_tone_map_filtergraph(frame.filter_graph)?;
+ if frame.tone_mapped && filter.is_some() {
video = frame::Video::empty();
- filter
+ let mut unwrapped_filter = filter.unwrap();
+ unwrapped_filter
.get("in")
.unwrap()
.source()
.add(&frame.unscaled_frame)?;
- filter.get("out").unwrap().sink().frame(&mut video)?;
+ unwrapped_filter
+ .get("out")
+ .unwrap()
+ .sink()
+ .frame(&mut video)?;
let amount_of_planes = video.planes();
diff --git a/packages/renderer/rust/tone_map.rs b/packages/renderer/rust/tone_map.rs
index a59e1204a4..1ad816b324 100644
--- a/packages/renderer/rust/tone_map.rs
+++ b/packages/renderer/rust/tone_map.rs
@@ -20,12 +20,17 @@ pub struct FilterGraph {
pub aspect_ratio: Rational,
}
-pub fn make_tone_map_filtergraph(graph: FilterGraph) -> Result<(Graph, bool), ffmpeg_next::Error> {
+pub fn make_tone_map_filtergraph(graph: FilterGraph) -> Result<Option<Graph>, ffmpeg_next::Error> {
let mut filter = filter::Graph::new();
let original_width = graph.original_width;
let original_height = graph.original_height;
let pixel_format = graph.format;
+
+ if pixel_format == format::Pixel::None {
+ return Ok(None);
+ }
+
let time_base = graph.time_base;
let aspect_ratio = graph.aspect_ratio;
let video_primaries = graph.video_primaries;
@@ -42,6 +47,7 @@ pub fn make_tone_map_filtergraph(graph: FilterGraph) -> Result<(Graph, bool), ff
aspect_ratio.0,
aspect_ratio.1
);
+
filter.add(&filter::find("buffer").unwrap(), "in", &args)?;
filter.add(&filter::find("buffersink").unwrap(), "out", "")?;
@@ -134,5 +140,9 @@ pub fn make_tone_map_filtergraph(graph: FilterGraph) -> Result<(Graph, bool), ff
filter.validate()?;
- Ok((filter, should_convert))
+ if should_convert {
+ return Ok(Some(filter));
+ } else {
+ return Ok(None);
+ }
}