Skip to content

🎥 Make videos programmatically with React

cool

Jonny Burger989504022039
diff --git a/packages/compositor-darwin-arm64/compositor b/packages/compositor-darwin-arm64/compositor
index cfaacc3c20..bf18089cce 100755
Binary files a/packages/compositor-darwin-arm64/compositor and b/packages/compositor-darwin-arm64/compositor differ
diff --git a/packages/renderer/rust/commands/mod.rs b/packages/renderer/rust/commands/mod.rs
index 766e8de3cb..7d41ab692f 100644
--- a/packages/renderer/rust/commands/mod.rs
+++ b/packages/renderer/rust/commands/mod.rs
@@ -5,19 +5,12 @@ use crate::image::{save_as_jpeg, save_as_png};
use crate::payloads::payloads::CliInputCommand;
use crate::{ffmpeg, global_printer};
use std::io::ErrorKind;
-use std::time::Instant;
pub fn execute_command(opts: CliInputCommand) -> Result<(), PossibleErrors> {
match opts {
CliInputCommand::ExtractFrame(command) => {
- let t = Instant::now();
let _result = ffmpeg::extract_frame(command.input, command.time)?;
global_printer::synchronized_write_buf(&command.nonce, &_result)?;
- _print_debug(&format!(
- "Time to get frame: {:?} {}",
- t.elapsed(),
- _result.len()
- ))?;
}
CliInputCommand::StartLongRunningProcess(_command) => {
Err(std::io::Error::new(
diff --git a/packages/renderer/rust/opened_video.rs b/packages/renderer/rust/opened_video.rs
index 413053cc3b..37860e5c64 100644
--- a/packages/renderer/rust/opened_video.rs
+++ b/packages/renderer/rust/opened_video.rs
@@ -44,15 +44,7 @@ impl OpenedVideo {
if position < self.last_seek || self.last_seek < min_position {
self.input
.seek(stream_index as i32, min_position, position, position, 0)?;
- _print_debug(&format!(
- "SEEKING, latest seek is {} position {}",
- self.last_seek, position
- ))?;
} else {
- _print_debug(&format!(
- "NOT SEEKING, latest seek is {} position {}",
- self.last_seek, position
- ))?;
}
let mut frame = Video::empty();
diff --git a/packages/renderer/src/compositor/compositor.ts b/packages/renderer/src/compositor/compositor.ts
index a750c1a51b..bafde3a9f2 100644
--- a/packages/renderer/src/compositor/compositor.ts
+++ b/packages/renderer/src/compositor/compositor.ts
@@ -76,6 +76,9 @@ export const startCompositor = <T extends keyof CompositorCommand>(
};
let quit = false;
+ let missingData: null | {
+ dataMissing: number;
+ } = null;
const processInput = () => {
let separatorIndex = outputBuffer.indexOf(separator);
@@ -123,6 +126,9 @@ export const startCompositor = <T extends keyof CompositorCommand>(
const dataLength = outputBuffer.length - separatorIndex - 1;
if (dataLength < length) {
+ missingData = {
+ dataMissing: length - dataLength,
+ };
return;
}
@@ -131,6 +137,7 @@ export const startCompositor = <T extends keyof CompositorCommand>(
separatorIndex + 1 + Number(lengthString)
);
onMessage(nonceString, data);
+ missingData = null;
outputBuffer = outputBuffer.subarray(
separatorIndex + Number(lengthString) + 1
@@ -144,7 +151,13 @@ export const startCompositor = <T extends keyof CompositorCommand>(
unprocessedBuffers.push(data);
const separatorIndex = data.indexOf(separator);
if (separatorIndex === -1) {
- return;
+ if (missingData) {
+ missingData.dataMissing -= data.length;
+ }
+
+ if (!missingData || missingData.dataMissing > 0) {
+ return;
+ }
}
unprocessedBuffers.unshift(outputBuffer);
@@ -155,6 +168,12 @@ export const startCompositor = <T extends keyof CompositorCommand>(
});
child.stderr.on('data', (data) => {
+ if (
+ data.toString('utf-8').includes('No accelerated colorspace conversion')
+ ) {
+ return;
+ }
+
console.log(data.toString('utf-8'));
});
diff --git a/packages/renderer/src/test/extract-frame-rust.test.ts b/packages/renderer/src/test/extract-frame-rust.test.ts
index b89cfc4dcf..d555b48d4c 100644
--- a/packages/renderer/src/test/extract-frame-rust.test.ts
+++ b/packages/renderer/src/test/extract-frame-rust.test.ts
@@ -13,26 +13,21 @@ test(
},
});
- console.time('first frame');
const data = await compositor.executeCommand('ExtractFrame', {
input: '/Users/jonathanburger/Downloads/fullmovie.mp4',
time: 40,
});
expect(data.length).toBe(2764854);
- console.timeEnd('first frame');
fs.writeFileSync('test.png', data);
- console.time('second frame');
const data2 = await compositor.executeCommand('ExtractFrame', {
input: '/Users/jonathanburger/Downloads/fullmovie.mp4',
time: 40.4,
});
expect(data2.length).toBe(2764854);
- console.timeEnd('second frame');
fs.writeFileSync('test2.png', data2);
- // TODO: When not calling finishCommands, the compositor hangs with 400%
compositor.finishCommands();
await compositor.waitForDone();
},