Skip to content

🎥 Make videos programmatically with React

`@remotion/renderer`: Fix streaming when a response payload is chunked in the header

Jonny Burgerd1123d8e060c
diff --git a/packages/renderer/src/compositor/compositor.ts b/packages/renderer/src/compositor/compositor.ts
index a32e095105..f318b3095f 100644
--- a/packages/renderer/src/compositor/compositor.ts
+++ b/packages/renderer/src/compositor/compositor.ts
@@ -118,6 +118,7 @@ export const startCompositor = <T extends keyof CompositorCommand>({
nonce: string,
data: Buffer,
) => {
+ // Nonce '0' just means that the message should be logged
if (nonce === '0') {
Log.verbose({indent, logLevel, tag: 'compositor'}, data.toString('utf8'));
}
@@ -159,38 +160,38 @@ export const startCompositor = <T extends keyof CompositorCommand>({
let lengthString = '';
let statusString = '';
- // Each message from Rust is prefixed with `remotion_buffer;{[nonce]}:{[length]}`
+ // Each message from Rust is prefixed with `remotion_buffer:{[nonce]}:{[length]}`
// Let's read the buffer to extract the nonce, and if the full length is available,
// we'll extract the data and pass it to the callback.
// eslint-disable-next-line no-constant-condition
while (true) {
+ if (separatorIndex > outputBuffer.length - 1) {
+ return;
+ }
+
const nextDigit = outputBuffer[separatorIndex];
+ separatorIndex++;
+
// 0x3a is the character ":"
if (nextDigit === 0x3a) {
- separatorIndex++;
break;
}
- separatorIndex++;
- if (separatorIndex > outputBuffer.length) {
- throw new Error('separatorIndex out of bounds: '+ JSON.stringify(outputBuffer));
- }
-
nonceString += String.fromCharCode(nextDigit);
}
// eslint-disable-next-line no-constant-condition
while (true) {
- const nextDigit = outputBuffer[separatorIndex];
- if (nextDigit === 0x3a) {
- separatorIndex++;
- break;
+ if (separatorIndex > outputBuffer.length - 1) {
+ return;
}
+ const nextDigit = outputBuffer[separatorIndex];
separatorIndex++;
- if (separatorIndex > outputBuffer.length) {
- throw new Error('separatorIndex out of bounds ' + JSON.stringify(outputBuffer));
+
+ if (nextDigit === 0x3a) {
+ break;
}
lengthString += String.fromCharCode(nextDigit);
@@ -198,6 +199,10 @@ export const startCompositor = <T extends keyof CompositorCommand>({
// eslint-disable-next-line no-constant-condition
while (true) {
+ if (separatorIndex > outputBuffer.length - 1) {
+ return;
+ }
+
const nextDigit = outputBuffer[separatorIndex];
if (nextDigit === 0x3a) {
break;
@@ -205,10 +210,6 @@ export const startCompositor = <T extends keyof CompositorCommand>({
separatorIndex++;
- if (separatorIndex > outputBuffer.length) {
- throw new Error('separatorIndex out of bounds ' + JSON.stringify(outputBuffer));
- }
-
statusString += String.fromCharCode(nextDigit);
}
@@ -254,7 +255,6 @@ export const startCompositor = <T extends keyof CompositorCommand>({
}
unprocessedBuffers.unshift(outputBuffer);
-
outputBuffer = Buffer.concat(unprocessedBuffers);
unprocessedBuffers = [];