🎥 Make videos programmatically with React
add docs
Jonny Burgerb5ee9d45d75d
diff --git a/packages/cli/src/get-cli-options.ts b/packages/cli/src/get-cli-options.tsindex 589b4461c3..9d68f0aa2c 100644--- a/packages/cli/src/get-cli-options.ts+++ b/packages/cli/src/get-cli-options.ts@@ -36,9 +36,10 @@ const getFinalCodec = async () => {fileExtension: getUserPassedFileExtension(),emitWarning: true,});+ const ffmpegExecutable = Internals.getCustomFfmpegExecutable();if (codec === 'vp8' &&- !(await RenderInternals.ffmpegHasFeature('enable-libvpx'))+ !(await RenderInternals.ffmpegHasFeature(ffmpegExecutable, 'enable-libvpx'))) {Log.error("The Vp8 codec has been selected, but your FFMPEG binary wasn't compiled with the --enable-lipvpx flag."@@ -50,7 +51,10 @@ const getFinalCodec = async () => {if (codec === 'h265' &&- !(await RenderInternals.ffmpegHasFeature('enable-gpl'))+ !(await RenderInternals.ffmpegHasFeature(+ Internals.getCustomFfmpegExecutable(),+ 'enable-gpl'+ ))) {Log.error("The H265 codec has been selected, but your FFMPEG binary wasn't compiled with the --enable-gpl flag."@@ -62,7 +66,10 @@ const getFinalCodec = async () => {if (codec === 'h265' &&- !(await RenderInternals.ffmpegHasFeature('enable-libx265'))+ !(await RenderInternals.ffmpegHasFeature(+ Internals.getCustomFfmpegExecutable(),+ 'enable-libx265'+ ))) {Log.error("The H265 codec has been selected, but your FFMPEG binary wasn't compiled with the --enable-libx265 flag."@@ -97,9 +104,8 @@ const getAndValidateAbsoluteOutputFile = (const getAndValidateShouldOutputImageSequence = async (frameRange: FrameRange | null) => {- const shouldOutputImageSequence = Internals.getShouldOutputImageSequence(- frameRange- );+ const shouldOutputImageSequence =+ Internals.getShouldOutputImageSequence(frameRange);if (!shouldOutputImageSequence) {await RenderInternals.validateFfmpeg();}@@ -190,7 +196,7 @@ export const getCliOptions = async (type: 'still' | 'series') => {});const proResProfile = getAndValidateProResProfile(codec);const browserExecutable = Internals.getBrowserExecutable();- const ffmpegExecutable = Internals.getFfmpegExecutable();+ const ffmpegExecutable = Internals.getCustomFfmpegExecutable();return {parallelism: Internals.getConcurrency(),diff --git a/packages/cli/src/parse-command-line.ts b/packages/cli/src/parse-command-line.tsindex 297613fd0a..d702db89fe 100644--- a/packages/cli/src/parse-command-line.ts+++ b/packages/cli/src/parse-command-line.ts@@ -56,7 +56,9 @@ export const parseCommandLine = (type: 'still' | 'sequence') => {}if (parsedCli['ffmpeg-executable']) {- Config.Output.setFfmpegExecutable(resolve(parsedCli['ffmpeg-executable']));+ Config.Rendering.setFfmpegExecutable(+ resolve(parsedCli['ffmpeg-executable'])+ );}if (typeof parsedCli['bundle-cache'] !== 'undefined') {diff --git a/packages/cli/src/render.tsx b/packages/cli/src/render.tsxindex 1e08f760fd..2a2ae80eb7 100644--- a/packages/cli/src/render.tsx+++ b/packages/cli/src/render.tsx@@ -69,7 +69,9 @@ export const render = async () => {ffmpegExecutable,} = await getCliOptions('series');- await checkAndValidateFfmpegVersion();+ await checkAndValidateFfmpegVersion({+ ffmpegExecutable: Internals.getCustomFfmpegExecutable(),+ });const browserInstance = RenderInternals.openBrowser(browser, {browserExecutable,diff --git a/packages/cli/src/validate-ffmpeg-version.ts b/packages/cli/src/validate-ffmpeg-version.tsindex e0750d7527..44fbab95c1 100644--- a/packages/cli/src/validate-ffmpeg-version.ts+++ b/packages/cli/src/validate-ffmpeg-version.ts@@ -2,9 +2,15 @@ import {RenderInternals} from '@remotion/renderer';import {Log} from './log';import {warnAboutFfmpegVersion} from './warn-about-ffmpeg-version';-export const checkAndValidateFfmpegVersion = async () => {- const ffmpegVersion = await RenderInternals.getFfmpegVersion();- const buildConf = await RenderInternals.getFfmpegBuildInfo();+export const checkAndValidateFfmpegVersion = async (options: {+ ffmpegExecutable: string | null;+}) => {+ const ffmpegVersion = await RenderInternals.getFfmpegVersion({+ ffmpegExecutable: options.ffmpegExecutable,+ });+ const buildConf = await RenderInternals.getFfmpegBuildInfo({+ ffmpegExecutable: options.ffmpegExecutable,+ });Log.verbose('Your FFMPEG version:',ffmpegVersion ? ffmpegVersion.join('.') : 'Built from source'diff --git a/packages/core/src/config/ffmpeg-executable.ts b/packages/core/src/config/ffmpeg-executable.tsindex 14cd60e169..65cb5948fa 100644--- a/packages/core/src/config/ffmpeg-executable.ts+++ b/packages/core/src/config/ffmpeg-executable.ts@@ -2,12 +2,10 @@ export type FfmpegExecutable = string | null;let currentFfmpegExecutablePath: FfmpegExecutable = null;-export const setFfmpegExecutable = (- ffmpegPath: FfmpegExecutable-) => {+export const setFfmpegExecutable = (ffmpegPath: FfmpegExecutable) => {currentFfmpegExecutablePath = ffmpegPath;};-export const getFfmpegExecutable = () => {+export const getCustomFfmpegExecutable = () => {return currentFfmpegExecutablePath;};diff --git a/packages/core/src/config/index.ts b/packages/core/src/config/index.tsindex c44fb1d7d1..9b08580001 100644--- a/packages/core/src/config/index.ts+++ b/packages/core/src/config/index.ts@@ -96,6 +96,11 @@ export const Config = {* The frame count starts at 0.*/setFrameRange,+ /**+ * Specify local ffmpeg executable.+ * Default: null, which will use ffmpeg available in PATH.+ */+ setFfmpegExecutable,},Output: {/**@@ -136,11 +141,6 @@ export const Config = {* See https://avpres.net/FFmpeg/im_ProRes.html for meaning of possible values.*/setProResProfile,- /**- * Specify local ffmpeg executable.- * Default: null, which will use ffmpeg available in PATH.- */- setFfmpegExecutable,},} as const;diff --git a/packages/core/src/internals.ts b/packages/core/src/internals.tsindex 43e077cacd..a77d49395f 100644--- a/packages/core/src/internals.ts+++ b/packages/core/src/internals.ts@@ -15,7 +15,7 @@ import {} from './CompositionManager';import {DEFAULT_BROWSER, getBrowser} from './config/browser';import {getBrowserExecutable} from './config/browser-executable';-import {getFfmpegExecutable} from './config/ffmpeg-executable';+import {getCustomFfmpegExecutable} from './config/ffmpeg-executable';import {DEFAULT_CODEC,getFinalOutputCodec,@@ -136,7 +136,7 @@ export const Internals = {useVideo,getRoot,getBrowserExecutable,- getFfmpegExecutable,+ getCustomFfmpegExecutable,getCompositionName,getIsEvaluation,getPixelFormat,diff --git a/packages/docs/docs/cli.md b/packages/docs/docs/cli.mdindex cdb4394195..dcaf4a3519 100644--- a/packages/docs/docs/cli.md+++ b/packages/docs/docs/cli.md@@ -162,6 +162,12 @@ _available for `preview`, `still`, `render` commands_[Set a custom HTTP server port](/docs/config#setPort). If not defined, Remotion will try to find a free port.+### `--ffmpeg-executable`++_available for `render` command_++[Set a custom FFMPEG executable](/docs/config#setFfmpegExecutable). If not defined, a `ffmpeg` executable will be searched in `PATH`.+### `--help`Print the list of available CLI commands and flags.diff --git a/packages/docs/docs/config.mdx b/packages/docs/docs/config.mdsimilarity index 96%rename from packages/docs/docs/config.mdxrename to packages/docs/docs/config.mdindex e021f098e9..ec9a8bf0d1 100644--- a/packages/docs/docs/config.mdx+++ b/packages/docs/docs/config.md@@ -200,6 +200,18 @@ Config.Rendering.setDotEnvLocation(".my-env");The [command line flag](/docs/cli#--env-file) `--env-file` will take precedence over this option.+### setFfmpegExecutable()++Allows you to use a custom FFMPEG binary. Must be an absolute path. By default, this is null and the FFMPEG in `PATH` will be used.++```ts twoslash+import { Config } from "remotion";+// ---cut---+Config.Rendering.setFfmpegExecutable("/path/to/custom/ffmpeg");+```++The [command line flag](/docs/cli#--ffmpeg-executable) `--ffmpeg-executable` will take precedence over this option.+## Output### setOverwriteOutput()diff --git a/packages/renderer/src/ffmpeg-flags.ts b/packages/renderer/src/ffmpeg-flags.tsindex 20fa47e20c..85a7166420 100644--- a/packages/renderer/src/ffmpeg-flags.ts+++ b/packages/renderer/src/ffmpeg-flags.ts@@ -6,29 +6,36 @@ let buildConfig: string | null = null;export type FfmpegVersion = [number, number, number] | null;-export const getFfmpegBuildInfo = async () => {+export const getFfmpegBuildInfo = async (options: {+ ffmpegExecutable: string | null;+}) => {if (buildConfig !== null) {return buildConfig;}- const data = await execa(Internals.getFfmpegExecutable() ?? 'ffmpeg', ['-buildconf']);+ const data = await execa(options.ffmpegExecutable ?? 'ffmpeg', [+ '-buildconf',+ ]);buildConfig = data.stderr;return buildConfig;};export const ffmpegHasFeature = async (+ ffmpegExecutable: string | null,feature: 'enable-gpl' | 'enable-libx265' | 'enable-libvpx') => {- if (!await binaryExists('ffmpeg')) {+ if (!(await binaryExists('ffmpeg'))) {return false;}- const config = await getFfmpegBuildInfo();+ const config = await getFfmpegBuildInfo({ffmpegExecutable});return config.includes(feature);};export const parseFfmpegVersion = (buildconf: string): FfmpegVersion => {- const match = buildconf.match(/ffmpeg version ([0-9]+).([0-9]+)(?:.([0-9]+))?/);+ const match = buildconf.match(+ /ffmpeg version ([0-9]+).([0-9]+)(?:.([0-9]+))?/+ );if (!match) {return null;}@@ -36,7 +43,11 @@ export const parseFfmpegVersion = (buildconf: string): FfmpegVersion => {return [Number(match[1]), Number(match[2]), Number(match[3] ?? 0)];};-export const getFfmpegVersion = async (): Promise<FfmpegVersion> => {- const buildInfo = await getFfmpegBuildInfo();+export const getFfmpegVersion = async (options: {+ ffmpegExecutable: string | null;+}): Promise<FfmpegVersion> => {+ const buildInfo = await getFfmpegBuildInfo({+ ffmpegExecutable: options.ffmpegExecutable,+ });return parseFfmpegVersion(buildInfo);};diff --git a/packages/renderer/src/stitcher.ts b/packages/renderer/src/stitcher.tsindex 742c24c2ef..f8e81de843 100644--- a/packages/renderer/src/stitcher.ts+++ b/packages/renderer/src/stitcher.ts@@ -78,12 +78,11 @@ export const stitchFramesToVideo = async (options: {const isAudioOnly = encoderName === null;const supportsCrf = encoderName && codec !== 'prores';- if (options.ffmpegExecutable) {- Config.Output.setFfmpegExecutable(resolve(options.ffmpegExecutable));- }-if (options.verbose) {- console.log('[verbose] ffmpeg', Internals.getFfmpegExecutable() ?? 'ffmpeg in PATH');+ console.log(+ '[verbose] ffmpeg',+ Internals.getCustomFfmpegExecutable() ?? 'ffmpeg in PATH'+ );console.log('[verbose] encoder', encoderName);console.log('[verbose] audioCodec', audioCodecName);console.log('[verbose] pixelFormat', pixelFormat);@@ -188,7 +187,11 @@ export const stitchFramesToVideo = async (options: {.reduce<(string | null)[]>((acc, val) => acc.concat(val), []).filter(Boolean) as string[];- const task = execa(Internals.getFfmpegExecutable() ?? 'ffmpeg', ffmpegString, {cwd: options.dir});+ const task = execa(+ Internals.getCustomFfmpegExecutable() ?? 'ffmpeg',+ ffmpegString,+ {cwd: options.dir}+ );task.stderr?.on('data', (data: Buffer) => {if (options.onProgress) {diff --git a/packages/renderer/src/validate-ffmpeg.ts b/packages/renderer/src/validate-ffmpeg.tsindex b251f33563..5796d6b78a 100644--- a/packages/renderer/src/validate-ffmpeg.ts+++ b/packages/renderer/src/validate-ffmpeg.ts@@ -10,7 +10,7 @@ export const binaryExists = async (name: 'ffmpeg' | 'brew') => {return existsMap[name];}- const localFFmpeg = Internals.getFfmpegExecutable();+ const localFFmpeg = Internals.getCustomFfmpegExecutable();if (name === 'ffmpeg' && localFFmpeg) {try {statSync(localFFmpeg);@@ -39,11 +39,11 @@ export const isHomebrewInstalled = async (): Promise<boolean> => {};export const validateFfmpeg = async (): Promise<void> => {- const ffmpegExists = await binaryExists('ffmpeg');+ const ffmpegExists = await binaryExists('ffmpeg');if (!ffmpegExists) {- if (Internals.getFfmpegExecutable()) {- console.error("FFmpeg executable not found:");- console.error(Internals.getFfmpegExecutable());+ if (Internals.getCustomFfmpegExecutable()) {+ console.error('FFmpeg executable not found:');+ console.error(Internals.getCustomFfmpegExecutable());process.exit(1);}