🎥 Make videos programmatically with React
Add the ffmpegArgsHook parameter in renderMedia. You can control the final running parameters of ffmpeg yourself
river15f01650c500
diff --git a/packages/renderer/src/render-media.ts b/packages/renderer/src/render-media.tsindex 7f86612873..f35f824f3b 100644--- a/packages/renderer/src/render-media.ts+++ b/packages/renderer/src/render-media.ts@@ -91,6 +91,7 @@ export type RenderMediaOptions = {downloadMap?: DownloadMap;muted?: boolean;enforceAudioTrack?: boolean;+ ffmpegArgsHook?: (args: string[]) => string[];} & ServeUrlOrWebpackBundle;type Await<T> = T extends PromiseLike<infer U> ? U : T;@@ -128,6 +129,7 @@ export const renderMedia = ({cancelSignal,muted,enforceAudioTrack,+ ffmpegArgsHook,...options}: RenderMediaOptions): Promise<Buffer | null> => {validateQuality(options.quality);@@ -374,6 +376,7 @@ export const renderMedia = ({cancelSignal: cancelStitcher.cancelSignal,muted: disableAudio,enforceAudioTrack,+ ffmpegArgsHook,}),stitchStart,]);diff --git a/packages/renderer/src/stitch-frames-to-video.ts b/packages/renderer/src/stitch-frames-to-video.tsindex 5681ff3ec4..0a28ccaa11 100644--- a/packages/renderer/src/stitch-frames-to-video.ts+++ b/packages/renderer/src/stitch-frames-to-video.ts@@ -70,6 +70,7 @@ export type StitcherOptions = {};muted?: boolean;enforceAudioTrack?: boolean;+ ffmpegArgsHook?: (args: string[]) => string[];};type ReturnType = {@@ -225,6 +226,10 @@ export const spawnFfmpeg = async (console.log('[verbose] crf', crf);}+ if (options.ffmpegArgsHook) {+ console.log('[verbose] ffmpegArgsHook', options.ffmpegArgsHook);+ }+console.log('[verbose] codec', codec);console.log('[verbose] shouldRenderAudio', shouldRenderAudio);console.log('[verbose] shouldRenderVideo', shouldRenderVideo);@@ -363,8 +368,16 @@ export const spawnFfmpeg = async (}const ffmpegString = ffmpegArgs.flat(2).filter(Boolean) as string[];+ const finalFfmpegString = options.ffmpegArgsHook+ ? options.ffmpegArgsHook(ffmpegString)+ : ffmpegString;++ if (options.verbose) {+ console.log('Generated final FFMPEG command:');+ console.log(finalFfmpegString);+ }- const task = execa(options.ffmpegExecutable ?? 'ffmpeg', ffmpegString, {+ const task = execa(options.ffmpegExecutable ?? 'ffmpeg', finalFfmpegString, {cwd: options.dir,});options.cancelSignal?.(() => {