Skip to content

🎥 Make videos programmatically with React

support color mapped

Jonny Burger66dd08642642
diff --git a/packages/core/src/video/offthread-video-source.ts b/packages/core/src/video/offthread-video-source.ts
index f452a05e03..99ffd5772a 100644
--- a/packages/core/src/video/offthread-video-source.ts
+++ b/packages/core/src/video/offthread-video-source.ts
@@ -4,10 +4,12 @@ export const getOffthreadVideoSource = ({
src,
transparent,
currentTime,
+ colorMapped,
}: {
src: string;
transparent: boolean;
currentTime: number;
+ colorMapped: boolean;
}) => {
return `http://localhost:${
window.remotion_proxyPort
@@ -15,5 +17,5 @@ export const getOffthreadVideoSource = ({
getAbsoluteSrc(src),
)}&time=${encodeURIComponent(currentTime)}&transparent=${String(
transparent,
- )}`;
+ )}&colorMapped=${String(colorMapped)}`;
};
diff --git a/packages/core/src/video/props.ts b/packages/core/src/video/props.ts
index 153c0dc2cd..6634ca569b 100644
--- a/packages/core/src/video/props.ts
+++ b/packages/core/src/video/props.ts
@@ -47,6 +47,7 @@ export type OffthreadVideoProps = {
allowAmplificationDuringRender?: boolean;
toneFrequency?: number;
transparent?: boolean;
+ colorMapped?: boolean;
pauseWhenBuffering?: boolean;
/**
* @deprecated For internal use only
diff --git a/packages/renderer/rust/commands/mod.rs b/packages/renderer/rust/commands/mod.rs
index ae4d7866be..3da678b822 100644
--- a/packages/renderer/rust/commands/mod.rs
+++ b/packages/renderer/rust/commands/mod.rs
@@ -18,6 +18,7 @@ pub fn execute_command(
command.original_src,
command.time,
command.transparent,
+ command.color_mapped,
maximum_frame_cache_size_in_bytes,
)?;
Ok(res)
diff --git a/packages/renderer/rust/ffmpeg.rs b/packages/renderer/rust/ffmpeg.rs
index cc04f078bc..de482496a0 100644
--- a/packages/renderer/rust/ffmpeg.rs
+++ b/packages/renderer/rust/ffmpeg.rs
@@ -59,6 +59,7 @@ pub fn extract_frame(
original_src: String,
time: f64,
transparent: bool,
+ color_mapped: bool,
maximum_frame_cache_size_in_bytes: Option<u128>,
) -> Result<Vec<u8>, ErrorWithBacktrace> {
let manager = OpenedVideoManager::get_instance();
@@ -154,6 +155,7 @@ pub fn extract_frame(
one_frame_in_time_base,
threshold,
maximum_frame_cache_size_in_bytes,
+ color_mapped,
)?;
let from_cache = FrameCacheManager::get_instance()
@@ -359,7 +361,7 @@ pub fn get_video_metadata(file_path: &str) -> Result<VideoMetadata, ErrorWithBac
if let Ok(video) = codec.decoder().video() {
#[allow(non_snake_case)]
- let pixelFormat: Option<String> = match video.format() {
+ let pixelFormat: Option<String> = match video.format() {
remotionffmpeg::format::Pixel::YUV420P => Some("yuv420p".to_string()),
remotionffmpeg::format::Pixel::YUYV422 => Some("yuyv422".to_string()),
remotionffmpeg::format::Pixel::RGB24 => Some("rgb24".to_string()),
diff --git a/packages/renderer/rust/opened_stream.rs b/packages/renderer/rust/opened_stream.rs
index 677c7bb836..a1325f7029 100644
--- a/packages/renderer/rust/opened_stream.rs
+++ b/packages/renderer/rust/opened_stream.rs
@@ -160,6 +160,7 @@ impl OpenedStream {
one_frame_in_time_base: i64,
threshold: i64,
maximum_frame_cache_size_in_bytes: Option<u128>,
+ color_mapped: bool,
) -> Result<usize, ErrorWithBacktrace> {
let mut freshly_seeked = false;
let mut last_seek_position = match self.duration_or_zero {
@@ -269,9 +270,14 @@ impl OpenedStream {
match result {
Ok(Some(unfiltered)) => unsafe {
- let mut video = frame::Video::empty();
- self.filter.get("in").unwrap().source().add(&unfiltered)?;
- self.filter.get("out").unwrap().sink().frame(&mut video)?;
+ let mut video: Video;
+ if color_mapped {
+ video = frame::Video::empty();
+ self.filter.get("in").unwrap().source().add(&unfiltered)?;
+ self.filter.get("out").unwrap().sink().frame(&mut video)?;
+ } else {
+ video = unfiltered;
+ }
let linesize = (*video.as_ptr()).linesize;
let frame_cache_id = get_frame_cache_id();
diff --git a/packages/renderer/rust/payloads.rs b/packages/renderer/rust/payloads.rs
index 16650dadd1..e2a851f620 100644
--- a/packages/renderer/rust/payloads.rs
+++ b/packages/renderer/rust/payloads.rs
@@ -65,6 +65,7 @@ pub mod payloads {
pub original_src: String,
pub time: f64,
pub transparent: bool,
+ pub color_mapped: bool,
}
#[derive(Serialize, Deserialize, Debug)]
diff --git a/packages/renderer/src/compositor/payloads.ts b/packages/renderer/src/compositor/payloads.ts
index 737c331342..dc29c1ed80 100644
--- a/packages/renderer/src/compositor/payloads.ts
+++ b/packages/renderer/src/compositor/payloads.ts
@@ -226,6 +226,7 @@ export type CompositorCommand = {
original_src: string;
time: number;
transparent: boolean;
+ color_mapped: boolean;
};
GetSilences: {
src: string;
diff --git a/packages/renderer/src/offthread-video-server.ts b/packages/renderer/src/offthread-video-server.ts
index 4505a2b4ca..15fceab716 100644
--- a/packages/renderer/src/offthread-video-server.ts
+++ b/packages/renderer/src/offthread-video-server.ts
@@ -31,10 +31,17 @@ export const extractUrlAndSourceFromUrl = (url: string) => {
const transparent = params.get('transparent');
+ const colorMapped = params.get('colorMapped');
+
+ if (!colorMapped) {
+ throw new Error('Did not get `transparent` parameter');
+ }
+
return {
src,
time: parseFloat(time),
transparent: transparent === 'true',
+ colorMapped: colorMapped === 'true',
};
};
@@ -93,7 +100,9 @@ export const startOffthreadVideoServer = ({
return;
}
- const {src, time, transparent} = extractUrlAndSourceFromUrl(req.url);
+ const {src, time, transparent, colorMapped} = extractUrlAndSourceFromUrl(
+ req.url,
+ );
response.setHeader('access-control-allow-origin', '*');
if (transparent) {
response.setHeader('content-type', `image/png`);
@@ -137,14 +146,16 @@ export const startOffthreadVideoServer = ({
}
extractStart = Date.now();
- resolve(
- compositor.executeCommand('ExtractFrame', {
+ compositor
+ .executeCommand('ExtractFrame', {
src: to,
original_src: src,
time,
transparent,
- }),
- );
+ color_mapped: colorMapped,
+ })
+ .then(resolve)
+ .catch(reject);
});
})
.then((readable) => {
diff --git a/packages/renderer/src/test/extract-frame-rust.test.ts b/packages/renderer/src/test/extract-frame-rust.test.ts
index dbd0d98e8f..f0d71e7de5 100644
--- a/packages/renderer/src/test/extract-frame-rust.test.ts
+++ b/packages/renderer/src/test/extract-frame-rust.test.ts
@@ -19,6 +19,7 @@ test(
original_src: exampleVideos.bigBuckBunny,
time: 40,
transparent: false,
+ color_mapped: false,
});
expect(data.length).toBe(1280 * 720 * 3 + BMP_HEADER_SIZE);
@@ -27,6 +28,7 @@ test(
original_src: exampleVideos.bigBuckBunny,
time: 40.4,
transparent: false,
+ color_mapped: false,
});
expect(data2.length).toBe(1280 * 720 * 3 + BMP_HEADER_SIZE);
@@ -52,6 +54,7 @@ test(
original_src: exampleVideos.transparentWebm,
time: 1,
transparent: true,
+ color_mapped: false,
});
// Platform specific PNG encoder settings
@@ -92,12 +95,14 @@ test('Should be able to start two compositors', async () => {
original_src: exampleVideos.bigBuckBunny,
time: 40,
transparent: false,
+ color_mapped: false,
});
await compositor2.executeCommand('ExtractFrame', {
src: exampleVideos.bigBuckBunny,
original_src: exampleVideos.bigBuckBunny,
time: 40,
transparent: false,
+ color_mapped: false,
});
});
@@ -113,6 +118,7 @@ test('Should be able to seek backwards', async () => {
original_src: exampleVideos.bigBuckBunny,
time: 40,
transparent: false,
+ color_mapped: false,
});
expect(data.length).toBe(2764854);
const data2 = await compositor.executeCommand('ExtractFrame', {
@@ -120,6 +126,7 @@ test('Should be able to seek backwards', async () => {
original_src: exampleVideos.bigBuckBunny,
time: 35,
transparent: false,
+ color_mapped: false,
});
expect(data2.length).toBe(2764854);
@@ -141,6 +148,7 @@ test(
original_src: exampleVideos.framerWithoutFileExtension,
time: 0.04,
transparent: false,
+ color_mapped: false,
});
expect(data.length).toBe(3499254);
@@ -164,6 +172,7 @@ test(
original_src: exampleVideos.framerWithoutFileExtension,
time: 3.33,
transparent: false,
+ color_mapped: false,
});
const expectedLength = BMP_HEADER_SIZE + 1080 * 1080 * 3;
@@ -196,6 +205,7 @@ test(
original_src: exampleVideos.corrupted,
time: 100,
transparent: false,
+ color_mapped: false,
});
// Pixel fixing
@@ -222,6 +232,7 @@ test('Should be able to extract a frame with abnormal DAR', async () => {
original_src: exampleVideos.customDar,
time: 3.33,
transparent: false,
+ color_mapped: false,
});
const header = data.subarray(0, BMP_HEADER_SIZE);
@@ -255,6 +266,7 @@ test('Should be able to extract the frames in reverse order', async () => {
original_src: exampleVideos.bigBuckBunny,
time: i,
transparent: false,
+ color_mapped: false,
});
const expectedLength = BMP_HEADER_SIZE + 1280 * 720 * 3;
@@ -298,6 +310,7 @@ test('Last frame should be fast', async () => {
original_src: exampleVideos.transparentWebm,
time: 5.0,
transparent: false,
+ color_mapped: false,
});
const time_end = Date.now();
@@ -309,6 +322,7 @@ test('Last frame should be fast', async () => {
original_src: exampleVideos.transparentWebm,
time: 5.0,
transparent: false,
+ color_mapped: false,
});
// Time should be way less now
@@ -322,6 +336,7 @@ test('Last frame should be fast', async () => {
original_src: exampleVideos.transparentWebm,
time: 100,
transparent: false,
+ color_mapped: false,
});
// Time should be way less now
@@ -337,6 +352,7 @@ test('Last frame should be fast', async () => {
original_src: exampleVideos.transparentWebm,
time: 1,
transparent: true,
+ color_mapped: false,
});
const time4_end = Date.now();
@@ -359,6 +375,7 @@ test('Should get from a screen recording', async () => {
original_src: exampleVideos.screenrecording,
time: 0.5,
transparent: false,
+ color_mapped: false,
});
expect(data.length).toBe(15230038);
@@ -379,6 +396,7 @@ test('Should get from video with no fps', async () => {
original_src: exampleVideos.nofps,
time: 0.5,
transparent: false,
+ color_mapped: false,
});
expect(data.length).toBe(3044334);
@@ -399,6 +417,7 @@ test('Should get from broken webcam video', async () => {
original_src: exampleVideos.webcam,
time: 0,
transparent: false,
+ color_mapped: false,
});
expect(data.length).toBe(921654);
@@ -419,6 +438,7 @@ test('Should get from iPhone video', async () => {
original_src: exampleVideos.iphonevideo,
time: 1,
transparent: false,
+ color_mapped: false,
});
expect(data.length).toBe(24883254);
@@ -439,6 +459,7 @@ test('Should get from AV1 video', async () => {
original_src: exampleVideos.av1,
time: 0.5,
transparent: false,
+ color_mapped: false,
});
expect(data.length).toBe(6220854);
@@ -459,6 +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,
+ color_mapped: false,
});
// Should resort back to BMP because it is faster
@@ -483,6 +505,7 @@ test('Should handle a video with no frames at the beginning', async () => {
original_src: exampleVideos.zerotimestamp,
time: 1.5,
transparent: false,
+ color_mapped: false,
});
// Should resort back to BMP because it is faster
@@ -511,6 +534,7 @@ test('Two different starting times should not result in big seeking', async () =
original_src: exampleVideos.bigBuckBunny,
time,
transparent: false,
+ color_mapped: false,
});
const expectedLength = BMP_HEADER_SIZE + 1280 * 720 * 3;
@@ -614,6 +638,7 @@ test('Should not duplicate frames for iphoneVideo', async () => {
original_src: exampleVideos.iphonevideo,
time: frame30,
transparent: false,
+ color_mapped: false,
});
const secondFrame = await compositor.executeCommand('ExtractFrame', {
@@ -621,6 +646,7 @@ test('Should not duplicate frames for iphoneVideo', async () => {
original_src: exampleVideos.iphonevideo,
time: frame31,
transparent: false,
+ color_mapped: false,
});
const hundredRandomPixels = new Array(100).fill(true).map(() => {
diff --git a/packages/renderer/src/test/rust-errors.test.ts b/packages/renderer/src/test/rust-errors.test.ts
index 18319aeee3..468e6b091b 100644
--- a/packages/renderer/src/test/rust-errors.test.ts
+++ b/packages/renderer/src/test/rust-errors.test.ts
@@ -15,6 +15,7 @@ test('Should get Rust errors in a good way', async () => {
original_src: 'invlaid',
time: 1,
transparent: false,
+ color_mapped: false,
});
} catch (err) {
expect((err as Error).message).toContain(
@@ -88,6 +89,7 @@ test(
original_src: 'fsdfds',
time: 1,
transparent: false,
+ color_mapped: false,
});
try {
await callCompositor(JSON.stringify(command), false, 'info');
@@ -109,6 +111,7 @@ test('Invalid payloads will be handled', async () => {
const command = serializeCommand('ExtractFrame', {
src: 'fsdfds',
original_src: 'fsdfds',
+ color_mapped: false,
});
try {
await callCompositor(JSON.stringify(command), false, 'info');
diff --git a/packages/renderer/src/test/rust-memory-usage.test.ts b/packages/renderer/src/test/rust-memory-usage.test.ts
index 95e9e42e8d..a82b113de2 100644
--- a/packages/renderer/src/test/rust-memory-usage.test.ts
+++ b/packages/renderer/src/test/rust-memory-usage.test.ts
@@ -23,6 +23,7 @@ test('Memory usage should be determined ', async () => {
original_src: exampleVideos.bigBuckBunny,
time: 3.333,
transparent: false,
+ color_mapped: false,
});
const stats = await compositor.executeCommand('GetOpenVideoStats', {});
@@ -36,6 +37,7 @@ test('Memory usage should be determined ', async () => {
original_src: exampleVideos.framerWithoutFileExtension,
time: 3.333,
transparent: false,
+ color_mapped: false,
});
const stats2 = await compositor.executeCommand('GetOpenVideoStats', {});
@@ -91,6 +93,7 @@ test('Memory usage should be determined ', async () => {
original_src: exampleVideos.framerWithoutFileExtension,
time: 3.333,
transparent: false,
+ color_mapped: false,
});
});
@@ -106,6 +109,7 @@ test('Should respect the maximum frame cache limit', async () => {
original_src: exampleVideos.bigBuckBunny,
time: 3.333,
transparent: false,
+ color_mapped: false,
});
const stats = await compositor.executeCommand('GetOpenVideoStats', {});
@@ -137,6 +141,7 @@ test('Should be able to take commands for freeing up memory', async () => {
original_src: exampleVideos.bigBuckBunny,
time: 3.333,
transparent: false,
+ color_mapped: false,
});
expect(