🎥 Make videos programmatically with React
progress + fix final audio codec
Jonny Burger17bb2d37bb59
diff --git a/packages/it-tests/src/rendering/rendering.test.ts b/packages/it-tests/src/rendering/rendering.test.tsindex 37ea26d7df..3752a139a6 100644--- a/packages/it-tests/src/rendering/rendering.test.ts+++ b/packages/it-tests/src/rendering/rendering.test.ts@@ -286,7 +286,7 @@ test("Should render a video with Offline Audio-context", async () => {fs.unlinkSync(out);});-test("Should fail to render an audio file that doesn't have any audio inputs", async () => {+test("Should succeed to render an audio file that doesn't have any audio inputs", async () => {const out = outputPath.replace(".mp4", ".mp3");const task = await execa("pnpx",diff --git a/packages/renderer/src/stitch-frames-to-video.ts b/packages/renderer/src/stitch-frames-to-video.tsindex 6f4068fe3d..25338ed77b 100644--- a/packages/renderer/src/stitch-frames-to-video.ts+++ b/packages/renderer/src/stitch-frames-to-video.ts@@ -1,5 +1,4 @@import execa from 'execa';-import fs from 'fs';import path from 'path';import {Codec,@@ -188,6 +187,12 @@ export const spawnFfmpeg = async (const expectedFrames = options.assetsInfo.assets.length;+ const updateProgress = (preStitchProgress: number, muxProgress: number) => {+ const totalFrameProgress =+ 0.5 * preStitchProgress * expectedFrames + muxProgress * 0.5;+ options.onProgress?.(Math.round(totalFrameProgress));+ };+const audio = await getAssetsData({assets: options.assetsInfo.assets,downloadDir: options.assetsInfo.downloadDir,@@ -196,12 +201,28 @@ export const spawnFfmpeg = async (expectedFrames,verbose: options.verbose ?? false,ffmpegExecutable: options.ffmpegExecutable ?? null,- onProgress: (prog) => options.onProgress?.(prog),+ onProgress: (prog) => updateProgress(prog, 0),});if (isAudioOnly) {- await fs.promises.copyFile(audio, options.outputLocation);- options.onProgress?.(1);+ if (!audioCodecName) {+ throw new TypeError(+ 'exporting audio but has no audio codec name. Report this in the Remotion repo.'+ );+ }++ await execa(+ 'ffmpeg',+ [+ '-i',+ audio,+ '-c:a',+ audioCodecName,+ options.force ? '-y' : null,+ options.outputLocation,+ ].filter(Internals.truthy)+ );+ options.onProgress?.(expectedFrames);return {getLogs: () => '',task: Promise.resolve(),@@ -270,7 +291,7 @@ export const spawnFfmpeg = async (}}- options.onProgress(parsed);+ updateProgress(1, parsed);}}});