Skip to content

🎥 Make videos programmatically with React

fix remotion hanging while encoding

Jonny Burger6dbdf622b86a
diff --git a/packages/renderer/src/stitch-frames-to-video.ts b/packages/renderer/src/stitch-frames-to-video.ts
index 9ba4173639..34b2e5b233 100644
--- a/packages/renderer/src/stitch-frames-to-video.ts
+++ b/packages/renderer/src/stitch-frames-to-video.ts
@@ -145,6 +145,8 @@ export const spawnFfmpeg = async (options: StitcherOptions) => {
options
);
+ const expectedFrames = options.assetsInfo.assets.length;
+
const ffmpegArgs = [
['-r', String(options.fps)],
...(options.internalOptions?.preEncodedFileLocation
@@ -208,12 +210,23 @@ export const spawnFfmpeg = async (options: StitcherOptions) => {
cwd: options.dir,
});
let ffmpegOutput = '';
+ let isFinished = false;
task.stderr?.on('data', (data: Buffer) => {
const str = data.toString();
ffmpegOutput += str;
if (options.onProgress) {
const parsed = parseFfmpegProgress(str);
+ // FFMPEG bug: In some cases, FFMPEG does hang after it is finished with it's job
+ // Example repo: https://github.com/JonnyBurger/ffmpeg-repro (access can be given upon request)
if (parsed !== undefined) {
+ if (parsed === expectedFrames) {
+ if (isFinished) {
+ task.stdin?.write('q');
+ } else {
+ isFinished = true;
+ }
+ }
+
options.onProgress(parsed);
}
}