Skip to content

🎥 Make videos programmatically with React

main

Jonny Burger03e3346d175a
diff --git a/packages/compositor-darwin-arm64/remotion b/packages/compositor-darwin-arm64/remotion
index c71107b23d..b9de4837e6 100755
Binary files a/packages/compositor-darwin-arm64/remotion and b/packages/compositor-darwin-arm64/remotion differ
diff --git a/packages/compositor-darwin-x64/remotion b/packages/compositor-darwin-x64/remotion
index 11f87d1a2b..5796b88bb6 100755
Binary files a/packages/compositor-darwin-x64/remotion and b/packages/compositor-darwin-x64/remotion differ
diff --git a/packages/compositor-linux-arm64-gnu/remotion b/packages/compositor-linux-arm64-gnu/remotion
index 26846dbffd..a872e746b3 100755
Binary files a/packages/compositor-linux-arm64-gnu/remotion and b/packages/compositor-linux-arm64-gnu/remotion differ
diff --git a/packages/compositor-linux-arm64-musl/remotion b/packages/compositor-linux-arm64-musl/remotion
index 246da49942..f8fa6b63ae 100755
Binary files a/packages/compositor-linux-arm64-musl/remotion and b/packages/compositor-linux-arm64-musl/remotion differ
diff --git a/packages/compositor-linux-x64-gnu/remotion b/packages/compositor-linux-x64-gnu/remotion
index 4e189e05c5..4892550585 100755
Binary files a/packages/compositor-linux-x64-gnu/remotion and b/packages/compositor-linux-x64-gnu/remotion differ
diff --git a/packages/compositor-linux-x64-musl/remotion b/packages/compositor-linux-x64-musl/remotion
index 64f31307a5..82fe096aec 100755
Binary files a/packages/compositor-linux-x64-musl/remotion and b/packages/compositor-linux-x64-musl/remotion differ
diff --git a/packages/compositor-win32-x64-msvc/remotion.exe b/packages/compositor-win32-x64-msvc/remotion.exe
index 496834d1f0..515fe189a6 100755
Binary files a/packages/compositor-win32-x64-msvc/remotion.exe and b/packages/compositor-win32-x64-msvc/remotion.exe differ
diff --git a/packages/compositor/rust/main.rs b/packages/compositor/rust/main.rs
index fe95b7898f..222bb2fcda 100644
--- a/packages/compositor/rust/main.rs
+++ b/packages/compositor/rust/main.rs
@@ -62,7 +62,7 @@ fn mainfn() -> Result<(), ErrorWithBacktrace> {
start_long_running_process(payload.concurrency, max_video_cache_size)?;
}
_ => {
- execute_command_and_print(opts)?;
+ panic!("only supports long running compositor")
}
}
@@ -116,12 +116,17 @@ fn start_long_running_process(
CliInputCommandPayload::Eof(_) => {
break;
}
+ _ => {}
+ };
+
+ let res: Result<(), ErrorWithBacktrace> = match message.payload {
CliInputCommandPayload::CloseAllVideos(_) => {
opened_video_manager
.close_all_videos(&mut frame_cache_manager)
- .unwrap(); // TODO: UNWRAP
+ .unwrap();
+ // TODO: Unwrap x2
send_close_video_to_main_thread.send(()).unwrap();
- continue;
+ Ok(())
}
CliInputCommandPayload::ExtractFrame(command) => {
let res = ffmpeg::extract_frame(
@@ -135,7 +140,8 @@ fn start_long_running_process(
&mut opened_video_manager,
&mut frame_cache_manager,
)
- .unwrap(); // TODO: Unwrpa
+ .unwrap();
+ // TODO: Unwrap
global_printer::synchronized_write_buf(0, &message.nonce, &res).unwrap();
if current_maximum_cache_size.is_some() {
ffmpeg::keep_only_latest_frames_and_close_videos(
@@ -144,10 +150,10 @@ fn start_long_running_process(
&mut frame_cache_manager,
thread_index,
)
- .unwrap(); // TODO: Unwrap
+ .unwrap();
}
- continue;
+ Ok(())
}
CliInputCommandPayload::FreeUpMemory(payload) => {
_print_verbose(&format!("remaining {}", payload.remaining_bytes)).unwrap();
@@ -160,7 +166,7 @@ fn start_long_running_process(
.unwrap(); // TODO: Unwrap
send_free_to_main_thread.send(()).unwrap();
- continue;
+ Ok(())
}
CliInputCommandPayload::GetOpenVideoStats(_) => {
let res = ffmpeg::get_open_video_stats(
@@ -169,12 +175,10 @@ fn start_long_running_process(
)
.unwrap();
send_video_stats_to_main_thread.send(res.clone()).unwrap(); // TODO: unwrao
- continue;
+ Ok(())
}
- _ => (),
- }
-
- execute_command_and_print(message).unwrap();
+ _ => panic!("Command cannot be executed on thread"),
+ };
}
// Thread work here
diff --git a/packages/renderer/src/compositor/compose.ts b/packages/renderer/src/compositor/compose.ts
deleted file mode 100644
index 451d40d73b..0000000000
--- a/packages/renderer/src/compositor/compose.ts
+++ /dev/null
@@ -1,107 +0,0 @@
-import {spawn} from 'node:child_process';
-import path from 'node:path';
-import type {LogLevel} from '../log-level';
-import {getExecutablePath} from './get-executable-path';
-import {makeFileExecutableIfItIsNot} from './make-file-executable';
-import {makeNonce} from './make-nonce';
-import type {
- CompositorCommand,
- CompositorCommandSerialized,
- ErrorPayload,
-} from './payloads';
-
-export const serializeCommand = <Type extends keyof CompositorCommand>(
- command: Type,
- params: CompositorCommand[Type],
-): CompositorCommandSerialized<Type> => {
- return {
- nonce: makeNonce(),
- payload: {
- type: command,
- params,
- },
- };
-};
-
-export const callCompositor = (
- payload: string,
- indent: boolean,
- logLevel: LogLevel,
- binariesDirectory: string | null,
-) => {
- return new Promise<void>((resolve, reject) => {
- const execPath = getExecutablePath({
- type: 'compositor',
- indent,
- logLevel,
- binariesDirectory,
- });
- makeFileExecutableIfItIsNot(execPath);
-
- const child = spawn(execPath, [payload], {
- cwd: path.dirname(execPath),
- });
-
- const stderrChunks: Uint8Array[] = [];
- child.stderr.on('data', (d) => stderrChunks.push(d));
-
- child.on('close', (code) => {
- if (code === 0) {
- resolve();
- } else {
- const message = Buffer.concat(stderrChunks).toString('utf-8');
-
- try {
- // Try to see if the error is a JSON
- const parsed = JSON.parse(message) as ErrorPayload;
- const msg = `Compositor error: ${parsed.error}`;
- const err = new Error(`${msg}\n${parsed.backtrace}`);
-
- reject(err);
- } catch {
- reject(
- new Error(`Compositor panicked with code ${code}: ${message}`),
- );
- }
- }
- });
-
- if (child.stdin.closed) {
- reject(
- new Error(
- 'Compositor stdin closed unexpectedly,' +
- Buffer.concat(stderrChunks).toString('utf-8'),
- ),
- );
- return;
- }
-
- try {
- child.stdin.write(payload, (e) => {
- if (e) {
- if (e instanceof Error && e.message.includes('EPIPE')) {
- reject(
- new Error(
- 'Compositor stdin closed unexpectedly,' +
- Buffer.concat(stderrChunks).toString('utf-8'),
- ),
- );
- }
-
- return;
- }
-
- child.stdin.end();
- });
- } catch (err) {
- if (err instanceof Error && err.message.includes('EPIPE')) {
- reject(
- new Error(
- 'Compositor stdin closed unexpectedly,' +
- Buffer.concat(stderrChunks).toString('utf-8'),
- ),
- );
- }
- }
- });
-};
diff --git a/packages/renderer/src/compositor/compositor.ts b/packages/renderer/src/compositor/compositor.ts
index 9fc808702d..b782d156c3 100644
--- a/packages/renderer/src/compositor/compositor.ts
+++ b/packages/renderer/src/compositor/compositor.ts
@@ -5,7 +5,6 @@ import {resolveConcurrency} from '../get-concurrency';
import type {LogLevel} from '../log-level';
import {isEqualOrBelowLogLevel} from '../log-level';
import {Log} from '../logger';
-import {serializeCommand} from './compose';
import {getExecutablePath} from './get-executable-path';
import {makeFileExecutableIfItIsNot} from './make-file-executable';
import {makeNonce} from './make-nonce';
@@ -14,6 +13,7 @@ import type {
CompositorCommandSerialized,
ErrorPayload,
} from './payloads';
+import {serializeCommand} from './serialize-command';
export type Compositor = {
finishCommands: () => Promise<void>;
diff --git a/packages/renderer/src/compositor/serialize-command.ts b/packages/renderer/src/compositor/serialize-command.ts
new file mode 100644
index 0000000000..975831d0af
--- /dev/null
+++ b/packages/renderer/src/compositor/serialize-command.ts
@@ -0,0 +1,15 @@
+import {makeNonce} from './make-nonce';
+import type {CompositorCommand, CompositorCommandSerialized} from './payloads';
+
+export const serializeCommand = <Type extends keyof CompositorCommand>(
+ command: Type,
+ params: CompositorCommand[Type],
+): CompositorCommandSerialized<Type> => {
+ return {
+ nonce: makeNonce(),
+ payload: {
+ type: command,
+ params,
+ },
+ };
+};
diff --git a/packages/renderer/src/test/rust-errors.test.ts b/packages/renderer/src/test/rust-errors.test.ts
index 44daf24442..13352ef7f3 100644
--- a/packages/renderer/src/test/rust-errors.test.ts
+++ b/packages/renderer/src/test/rust-errors.test.ts
@@ -1,5 +1,4 @@
import {expect, test} from 'bun:test';
-import {callCompositor, serializeCommand} from '../compositor/compose';
import {startLongRunningCompositor} from '../compositor/compositor';
test('Should get Rust errors in a good way', async () => {
@@ -71,10 +70,15 @@ test('Handle panics', async () => {
test(
'Non-long running task panics should be handled',
async () => {
- const command = serializeCommand('DeliberatePanic', {});
+ const compositor = startLongRunningCompositor({
+ logLevel: 'info',
+ indent: false,
+ binariesDirectory: null,
+ maximumFrameCacheItemsInBytes: null,
+ });
try {
- await callCompositor(JSON.stringify(command), false, 'info', null);
+ await compositor.executeCommand('DeliberatePanic', {});
throw new Error('should not be reached');
} catch (err) {
expect((err as Error).message).toContain("thread 'main' panicked");
@@ -86,15 +90,21 @@ test(
test(
'Long running task failures should be handled',
async () => {
- const command = serializeCommand('ExtractFrame', {
- src: 'fsdfds',
- original_src: 'fsdfds',
- time: 1,
- transparent: false,
- tone_mapped: false,
+ const compositor = startLongRunningCompositor({
+ maximumFrameCacheItemsInBytes: null,
+ logLevel: 'info',
+ indent: false,
+ binariesDirectory: null,
});
+
try {
- await callCompositor(JSON.stringify(command), false, 'info', null);
+ await compositor.executeCommand('ExtractFrame', {
+ src: 'fsdfds',
+ original_src: 'fsdfds',
+ time: 1,
+ transparent: false,
+ tone_mapped: false,
+ });
throw new Error('should not be reached');
} catch (err) {
expect((err as Error).message).toContain(
@@ -109,14 +119,19 @@ test(
);
test('Invalid payloads will be handled', async () => {
- // @ts-expect-error
- const command = serializeCommand('ExtractFrame', {
- src: 'fsdfds',
- original_src: 'fsdfds',
- tone_mapped: false,
+ const compositor = startLongRunningCompositor({
+ maximumFrameCacheItemsInBytes: null,
+ logLevel: 'info',
+ indent: false,
+ binariesDirectory: null,
});
try {
- await callCompositor(JSON.stringify(command), false, 'info', null);
+ // @ts-expect-error
+ await compositor.executeCommand('ExtractFrame', {
+ src: 'fsdfds',
+ original_src: 'fsdfds',
+ tone_mapped: false,
+ });
} catch (err) {
expect((err as Error).message).toContain(
'Compositor error: missing field `time`',