🎥 Make videos programmatically with React
close file
Jonny Burgerb5f8df3e812d
diff --git a/packages/renderer/src/browser/BrowserFetcher.ts b/packages/renderer/src/browser/BrowserFetcher.tsindex 2f051f499d..ca19d42bbc 100644--- a/packages/renderer/src/browser/BrowserFetcher.ts+++ b/packages/renderer/src/browser/BrowserFetcher.ts@@ -495,6 +495,7 @@ export function _downloadFile(const file = fs.createWriteStream(destinationPath);file.on('finish', () => {+ file.close();return fulfill(totalBytes);});file.on('error', (error) => {diff --git a/packages/renderer/src/ffmpeg-flags.ts b/packages/renderer/src/ffmpeg-flags.tsindex f9d84f817c..38475faf41 100644--- a/packages/renderer/src/ffmpeg-flags.ts+++ b/packages/renderer/src/ffmpeg-flags.ts@@ -46,21 +46,18 @@ export const ffmpegInNodeModules = (remotionRoot: string): string | null => {fs.mkdirSync(folderName);}- const items = fs.readdirSync(folderName);// Check if a version of FFMPEG is already installed.// To qualify, it must have the expected file size// to avoid finding binaries that are still being downloaded// A random ID is being assigned to the download to avoid conflicts when multiple Remotion processes are running- const ffmpegInstalled = items.find((i) => {- const matches = i.startsWith(ffmpegBinaryPrefix);- if (!matches) {+ const ffmpegInstalled = fs.readdirSync(folderName).find((filename) => {+ if (!filename.startsWith(ffmpegBinaryPrefix)) {return false;}const expectedLength = getFfmpegDownloadUrl().contentLength;- const stat = fs.statSync(path.join(folderName, i));- if (stat.size === expectedLength) {+ if (fs.statSync(path.join(folderName, filename)).size === expectedLength) {return true;}@@ -148,7 +145,7 @@ const waitForFfmpegToBeDownloaded = (url: string) => {const onProgress = (downloadedBytes: number, totalBytesToDownload: number) => {console.log(- 'Downloading ffmpeg: ',+ 'Downloading FFmpeg: ',`${toMegabytes(downloadedBytes)}/${toMegabytes(totalBytesToDownload)}`);};@@ -157,8 +154,6 @@ export const downloadFfmpeg = async (remotionRoot: string,url: string): Promise<string> => {- // implement callback instead-const destinationPath = getFfmpegAbsolutePath(remotionRoot);isDownloading[url] = true;diff --git a/packages/renderer/src/validate-ffmpeg.ts b/packages/renderer/src/validate-ffmpeg.tsindex 57cecadcca..9208997c9c 100644--- a/packages/renderer/src/validate-ffmpeg.ts+++ b/packages/renderer/src/validate-ffmpeg.ts@@ -49,53 +49,55 @@ export const validateFfmpeg = async (customFfmpegBinary: string | null,remotionRoot: string): Promise<void> => {- // binaryExists should also for node_modules- const ffmpegExists =- (await binaryExists('ffmpeg', customFfmpegBinary)) ||- ffmpegInNodeModules(remotionRoot);- if (!ffmpegExists) {- if (- os.platform() === 'darwin' ||- (os.platform() === 'win32' && process.arch === 'x64') ||- (os.platform() === 'linux' && process.arch === 'x64')- ) {- await downloadFfmpeg(remotionRoot, getFfmpegDownloadUrl().url);- return validateFfmpeg(customFfmpegBinary, remotionRoot);- }+ if (await binaryExists('ffmpeg', customFfmpegBinary)) {+ return;+ }- if (customFfmpegBinary) {- console.error('FFmpeg executable not found:');- console.error(customFfmpegBinary);- process.exit(1);- }+ if (ffmpegInNodeModules(remotionRoot)) {+ return;+ }- console.error('It looks like FFMPEG is not installed');- if (os.platform() === 'darwin' && (await 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 (+ os.platform() === 'darwin' ||+ (os.platform() === 'win32' && process.arch === 'x64') ||+ (os.platform() === 'linux' && process.arch === 'x64')+ ) {+ await downloadFfmpeg(remotionRoot, getFfmpegDownloadUrl().url);+ return validateFfmpeg(customFfmpegBinary, remotionRoot);+ }+ if (customFfmpegBinary) {+ console.error('FFmpeg executable not found:');+ console.error(customFfmpegBinary);process.exit(1);}++ console.error('It looks like FFMPEG is not installed');+ if (os.platform() === 'darwin' && (await 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.'+ );+ }++ process.exit(1);};