🎥 Make videos programmatically with React
simplify ffmpeg install flow
Jonny Burgere60563e27a79
diff --git a/packages/cli/src/get-cli-options.ts b/packages/cli/src/get-cli-options.tsindex 66aa080dba..b53e514e81 100644--- a/packages/cli/src/get-cli-options.ts+++ b/packages/cli/src/get-cli-options.ts@@ -131,7 +131,8 @@ const getAndValidateShouldOutputImageSequence = async ({if (!shouldOutputImageSequence && !isLambda) {await RenderInternals.validateFfmpeg(ConfigInternals.getCustomFfmpegExecutable(),- remotionRoot+ remotionRoot,+ 'ffmpeg');}diff --git a/packages/renderer/src/ffmpeg-flags.ts b/packages/renderer/src/ffmpeg-flags.tsindex 506cfac0ae..abe1c6aab2 100644--- a/packages/renderer/src/ffmpeg-flags.ts+++ b/packages/renderer/src/ffmpeg-flags.ts@@ -60,7 +60,13 @@ export const ffmpegInNodeModules = (return false;}- const expectedLength = getBinaryDownloadUrl(binary).contentLength;+ const dlUrl = getBinaryDownloadUrl(binary);++ if (!dlUrl) {+ return false;+ }++ const expectedLength = dlUrl.contentLength;if (fs.statSync(path.join(folderName, filename)).size === expectedLength) {return true;@@ -196,19 +202,18 @@ export const downloadBinary = async (return destinationPath;};+export const lambdaFfmpegPaths = {+ ffmpeg: '/opt/bin/ffmpeg',+ ffprobe: '/opt/bin/ffprobe',+} as const;+export const getExecutableBinary = (ffmpegExecutable: FfmpegExecutable,remotionRoot: string,binary: 'ffmpeg' | 'ffprobe') => {- if (binary === 'ffmpeg') {- if (fs.existsSync('/opt/bin/ffmpeg')) {- return '/opt/bin/ffmpeg';- }- } else if (binary === 'ffprobe') {- if (fs.existsSync('/opt/bin/ffprobe')) {- return '/opt/bin/ffprobe';- }+ if (fs.existsSync(lambdaFfmpegPaths[binary])) {+ return lambdaFfmpegPaths[binary];}if (ffmpegExecutable && customExecutableExists(ffmpegExecutable)) {@@ -219,10 +224,10 @@ export const getExecutableBinary = (return binary;}- const {url} = getBinaryDownloadUrl(binary);+ const dlUrl = getBinaryDownloadUrl(binary);- if (isDownloading[url]) {- return waitForFfmpegToBeDownloaded(url);+ if (dlUrl && isDownloading[dlUrl.url]) {+ return waitForFfmpegToBeDownloaded(dlUrl.url);}const inNodeMod = ffmpegInNodeModules(remotionRoot, binary);@@ -231,7 +236,15 @@ export const getExecutableBinary = (return inNodeMod;}- return downloadBinary(remotionRoot, url, binary);+ if (!dlUrl) {+ throw new Error(+ `${binary} could not be installed automatically. Your architecture and OS combination (os = ${os.platform()}, arch = ${+ process.arch+ }) is not supported. Please install ${binary} manually and add "${binary}" to your PATH.`+ );+ }++ return downloadBinary(remotionRoot, dlUrl.url, binary);};function toMegabytes(bytes: number) {@@ -244,7 +257,7 @@ export const getBinaryDownloadUrl = (): {url: string;contentLength: number;-} => {+} | null => {if (os.platform() === 'win32') {return binary === 'ffmpeg'? {diff --git a/packages/renderer/src/get-compositions.ts b/packages/renderer/src/get-compositions.tsindex 3fcae9d043..b9e165787b 100644--- a/packages/renderer/src/get-compositions.ts+++ b/packages/renderer/src/get-compositions.ts@@ -92,7 +92,16 @@ export const getCompositions = async (serveUrlOrWebpackUrl: string,config?: GetCompositionsConfig) => {- await validateFfmpeg(config?.ffmpegExecutable ?? null, findRemotionRoot());+ await validateFfmpeg(+ config?.ffmpegExecutable ?? null,+ findRemotionRoot(),+ 'ffmpeg'+ );+ await validateFfmpeg(+ config?.ffprobeExecutable ?? null,+ findRemotionRoot(),+ 'ffprobe'+ );const downloadMap = config?.downloadMap ?? makeDownloadMap();diff --git a/packages/renderer/src/prespawn-ffmpeg.ts b/packages/renderer/src/prespawn-ffmpeg.tsindex ca9252d987..1e9ec9c471 100644--- a/packages/renderer/src/prespawn-ffmpeg.ts+++ b/packages/renderer/src/prespawn-ffmpeg.ts@@ -65,7 +65,11 @@ export const prespawnFfmpeg = async (scale: 1,});const pixelFormat = options.pixelFormat ?? DEFAULT_PIXEL_FORMAT;- await validateFfmpeg(options.ffmpegExecutable ?? null, remotionRoot);+ await validateFfmpeg(+ options.ffmpegExecutable ?? null,+ remotionRoot,+ 'ffmpeg'+ );const encoderName = getCodecName(codec);const proResProfileName = getProResProfileName(codec, options.proResProfile);diff --git a/packages/renderer/src/render-media.ts b/packages/renderer/src/render-media.tsindex 3a637d5d1c..a0581e33e4 100644--- a/packages/renderer/src/render-media.ts+++ b/packages/renderer/src/render-media.ts@@ -177,7 +177,7 @@ export const renderMedia = ({...options}: RenderMediaOptions): Promise<Buffer | null> => {const remotionRoot = findRemotionRoot();- validateFfmpeg(ffmpegExecutable ?? null, remotionRoot);+ validateFfmpeg(ffmpegExecutable ?? null, remotionRoot, 'ffmpeg');validateQuality(options.quality);validateQualitySettings({crf, codec, videoBitrate});validateBitrate(audioBitrate, 'audioBitrate');diff --git a/packages/renderer/src/stitch-frames-to-video.ts b/packages/renderer/src/stitch-frames-to-video.tsindex 4511bd232c..b14f58369c 100644--- a/packages/renderer/src/stitch-frames-to-video.ts+++ b/packages/renderer/src/stitch-frames-to-video.ts@@ -200,7 +200,11 @@ export const spawnFfmpeg = async (Internals.validateFps(options.fps, 'in `stitchFramesToVideo()`', false);const pixelFormat = options.pixelFormat ?? DEFAULT_PIXEL_FORMAT;- await validateFfmpeg(options.ffmpegExecutable ?? null, remotionRoot);+ await validateFfmpeg(+ options.ffmpegExecutable ?? null,+ remotionRoot,+ 'ffmpeg'+ );const encoderName = getCodecName(codec);const audioCodecName = getAudioCodecName(codec);diff --git a/packages/renderer/src/validate-ffmpeg.ts b/packages/renderer/src/validate-ffmpeg.tsindex 1e422f780c..dae2e07ed9 100644--- a/packages/renderer/src/validate-ffmpeg.ts+++ b/packages/renderer/src/validate-ffmpeg.ts@@ -7,6 +7,7 @@ import {getBinaryDownloadUrl,getFfmpegBuildInfo,getFfmpegVersion,+ lambdaFfmpegPaths,} from './ffmpeg-flags';import {warnAboutFfmpegVersion} from './warn-about-ffmpeg-version';@@ -23,7 +24,7 @@ export const customExecutableExists = (localExecutable: string): boolean => {return existsMap[localExecutable];};-export const binaryExists = (name: 'ffmpeg' | 'ffprobe' | 'brew') => {+export const binaryExists = (name: 'ffmpeg' | 'ffprobe') => {if (typeof existsMap[name] !== 'undefined') {return existsMap[name];}@@ -40,10 +41,6 @@ export const binaryExists = (name: 'ffmpeg' | 'ffprobe' | 'brew') => {}};-const isHomebrewInstalled = (): boolean => {- return binaryExists('brew');-};-export const checkAndValidateFfmpegVersion = async (options: {ffmpegExecutable: string | null;remotionRoot: string;@@ -61,77 +58,42 @@ export const checkAndValidateFfmpegVersion = async (options: {export const validateFfmpeg = async (customFfmpegBinary: string | null,- remotionRoot: string+ remotionRoot: string,+ binary: 'ffmpeg' | 'ffprobe'): Promise<void> => {- if (process.platform === 'linux' && existsSync('/opt/bin/ffmpeg')) {- return;- }-- const ffmpegExists = binaryExists('ffmpeg');+ const ffmpegExists = binaryExists(binary);if (ffmpegExists) {return;}if (customFfmpegBinary) {- const exists = customExecutableExists(customFfmpegBinary);- if (exists) {- return;+ if (!customExecutableExists(customFfmpegBinary)) {+ throw new Error(+ 'Custom FFmpeg executable not found: ' + customFfmpegBinary+ );}- throw new Error(- 'Custom FFmpeg executable not found: ' + customFfmpegBinary- );+ return;}- if (ffmpegInNodeModules(remotionRoot, 'ffmpeg')) {+ if (process.platform === 'linux' && existsSync(lambdaFfmpegPaths[binary])) {return;}- if (- os.platform() === 'darwin' ||- (os.platform() === 'win32' && process.arch === 'x64') ||- (os.platform() === 'linux' && process.arch === 'x64')- ) {- await downloadBinary(- remotionRoot,- getBinaryDownloadUrl('ffmpeg').url,- 'ffmpeg'- );- return validateFfmpeg(customFfmpegBinary, remotionRoot);+ if (ffmpegInNodeModules(remotionRoot, binary)) {+ return;}- if (customFfmpegBinary) {- console.error('FFmpeg executable not found:');- console.error(customFfmpegBinary);- throw new Error('FFmpeg not found');- }+ const binaryUrl = getBinaryDownloadUrl('ffmpeg');- console.error('It looks like FFMPEG is not installed');- if (os.platform() === 'darwin' && isHomebrewInstalled()) {- console.error('Run `brew install ffmpeg` to install ffmpeg');- } else if (os.platform() === 'win32') {- console.error('1. Install FFMPEG for Windows here:');- console.error(- 'https://github.com/adaptlearning/adapt_authoring/wiki/Installing-FFmpeg#installing-ffmpeg-in-windows'- );- console.error('2. Add FFMPEG to your PATH');- console.error(' a. Go to the settings app.');- console.error(' b. Click System.');- console.error(' c. Click About.');- console.error(' d. Click Advanced system settings.');- console.error(' e. Click Environment variables.');- console.error(- ' f. Search for PATH environemnt variable, click edit and the folder where you installed FFMPEG.'- );- console.error(- ' g. Important: Restart your terminal completely to apply the new PATH.'- );- console.error('3. Re-run this command.');- } else {- console.error(- 'See https://github.com/adaptlearning/adapt_authoring/wiki/Installing-FFmpeg on how to install FFMPEG.'- );+ if (binaryUrl) {+ await downloadBinary(remotionRoot, binaryUrl.url, 'ffmpeg');+ return validateFfmpeg(customFfmpegBinary, remotionRoot, binary);}- throw new Error('FFmpeg not found');+ throw new Error(+ `${binary} could not be installed automatically. Your architecture and OS combination (os = ${os.platform()}, arch = ${+ process.arch+ }) is not supported. Please install ${binary} manually and add "${binary}" to your PATH.`+ );};