Skip to content

🎥 Make videos programmatically with React

comments for overview

patsalv6951dcfee620
diff --git a/packages/renderer/src/ffmpeg-flags.ts b/packages/renderer/src/ffmpeg-flags.ts
index 1ee0f9a916..758c8c6917 100644
--- a/packages/renderer/src/ffmpeg-flags.ts
+++ b/packages/renderer/src/ffmpeg-flags.ts
@@ -13,7 +13,8 @@ export const getFfmpegBuildInfo = async (options: {
}
const data = await execa(
- options.ffmpegExecutable ?? 'ffmpeg',
+ await getExecutableFfmpeg(options.ffmpegExecutable),
+ // options.ffmpegExecutable ?? 'ffmpeg',
['-buildconf'],
{
reject: false,
@@ -64,3 +65,18 @@ export const getFfmpegVersion = async (options: {
});
return parseFfmpegVersion(buildInfo);
};
+
+// should check if ffmpeg is installed. If installed, return "ffmpeg" else return path to ffmpeg.exe in node modules
+export const getExecutableFfmpeg = async (ffmpegExecutable: string | null) => {
+ const path = require('path');
+ if (await binaryExists('ffmpeg', ffmpegExecutable)) {
+ return 'ffmpeg';
+ }
+
+ return path.resolve(
+ __dirname,
+ '..',
+ 'render/node_modules/ffmpeg-2022-09-19-full_build/bin',
+ 'ffmpeg.exe'
+ );
+};
diff --git a/packages/renderer/src/validate-ffmpeg.ts b/packages/renderer/src/validate-ffmpeg.ts
index b6c05d3035..b99420b539 100644
--- a/packages/renderer/src/validate-ffmpeg.ts
+++ b/packages/renderer/src/validate-ffmpeg.ts
@@ -12,9 +12,10 @@ export const binaryExists = async (
return existsMap[name];
}
+ // case where user has specified a custom ffmpeg executable --> we check if its valid
if (name === 'ffmpeg' && localFFmpeg) {
try {
- statSync(localFFmpeg);
+ statSync(localFFmpeg); // statSync searches for the file
existsMap[name] = true;
} catch (err) {
existsMap[name] = false;
@@ -23,6 +24,8 @@ export const binaryExists = async (
return existsMap[name];
}
+ // TODO: check if binary already exists, if not, check if it exists in node_modules
+
const isWin = os.platform() === 'win32';
const where = isWin ? 'where' : 'which';
try {
@@ -42,6 +45,7 @@ const isHomebrewInstalled = (): Promise<boolean> => {
export const validateFfmpeg = async (
customFfmpegBinary: string | null
): Promise<void> => {
+ // binaryExists should also for node_modules
const ffmpegExists = await binaryExists('ffmpeg', customFfmpegBinary);
if (!ffmpegExists) {
if (customFfmpegBinary) {