🎥 Make videos programmatically with React
split up default binary and custom binary
Jonny Burgerf23d263fad3a
diff --git a/packages/renderer/src/ffmpeg-flags.ts b/packages/renderer/src/ffmpeg-flags.tsindex b0611a5e8c..5bf3a138e7 100644--- a/packages/renderer/src/ffmpeg-flags.ts+++ b/packages/renderer/src/ffmpeg-flags.ts@@ -4,7 +4,7 @@ import os from 'os';import path from 'path';import {_downloadFile} from './browser/BrowserFetcher';import type {FfmpegExecutable} from './ffmpeg-executable';-import {binaryExists} from './validate-ffmpeg';+import {binaryExists, customExecutableExists} from './validate-ffmpeg';let buildConfig: string | null = null;const listeners: Record<string, ((path: string) => void)[]> = {};@@ -107,7 +107,11 @@ export const ffmpegHasFeature = async ({feature: 'enable-gpl' | 'enable-libx265' | 'enable-libvpx';remotionRoot: string;}) => {- if (!binaryExists('ffmpeg', ffmpegExecutable)) {+ if (ffmpegExecutable && !customExecutableExists(ffmpegExecutable)) {+ return false;+ }++ if (!binaryExists('ffmpeg')) {return false;}@@ -192,7 +196,7 @@ export const downloadBinary = async (return destinationPath;};-export const getExecutableBinary = async (+export const getExecutableBinary = (ffmpegExecutable: FfmpegExecutable | null,remotionRoot: string,binary: 'ffmpeg' | 'ffprobe'@@ -207,13 +211,11 @@ export const getExecutableBinary = async (}}- const exists = binaryExists(binary, ffmpegExecutable);-- if (exists) {- if (ffmpegExecutable !== null) {- return ffmpegExecutable;- }+ if (ffmpegExecutable && customExecutableExists(ffmpegExecutable)) {+ return ffmpegExecutable;+ }+ if (binaryExists(binary)) {return binary;}diff --git a/packages/renderer/src/validate-ffmpeg.ts b/packages/renderer/src/validate-ffmpeg.tsindex ddcd555c50..1e422f780c 100644--- a/packages/renderer/src/validate-ffmpeg.ts+++ b/packages/renderer/src/validate-ffmpeg.ts@@ -12,22 +12,19 @@ import {warnAboutFfmpegVersion} from './warn-about-ffmpeg-version';const existsMap: {[key: string]: boolean} = {};-export const binaryExists = (- name: 'ffmpeg' | 'ffprobe' | 'brew',- localExecutable: string | null-) => {- if (typeof existsMap[name] !== 'undefined') {- return existsMap[name];+export const customExecutableExists = (localExecutable: string): boolean => {+ try {+ statSync(localExecutable);+ existsMap[localExecutable] = true;+ } catch (err) {+ existsMap[localExecutable] = false;}- if (localExecutable) {- try {- statSync(localExecutable);- existsMap[name] = true;- } catch (err) {- existsMap[name] = false;- }+ return existsMap[localExecutable];+};+export const binaryExists = (name: 'ffmpeg' | 'ffprobe' | 'brew') => {+ if (typeof existsMap[name] !== 'undefined') {return existsMap[name];}@@ -44,7 +41,7 @@ export const binaryExists = (};const isHomebrewInstalled = (): boolean => {- return binaryExists('brew', null);+ return binaryExists('brew');};export const checkAndValidateFfmpegVersion = async (options: {@@ -67,18 +64,23 @@ export const validateFfmpeg = async (remotionRoot: string): Promise<void> => {if (process.platform === 'linux' && existsSync('/opt/bin/ffmpeg')) {- return Promise.resolve();+ return;}- const ffmpegExists = binaryExists('ffmpeg', customFfmpegBinary);+ const ffmpegExists = binaryExists('ffmpeg');if (ffmpegExists) {return;}if (customFfmpegBinary) {- console.error('FFmpeg executable not found:');- console.error(customFfmpegBinary);- throw new Error('FFmpeg not found');+ const exists = customExecutableExists(customFfmpegBinary);+ if (exists) {+ return;+ }++ throw new Error(+ 'Custom FFmpeg executable not found: ' + customFfmpegBinary+ );}if (ffmpegInNodeModules(remotionRoot, 'ffmpeg')) {