🎥 Make videos programmatically with React
handle review comments
Antoine Caronfb06c572c6c0
diff --git a/packages/cli/src/config/bitrate.ts b/packages/cli/src/config/bitrate.tsnew file mode 100644index 0000000000..8d6b87863c--- /dev/null+++ b/packages/cli/src/config/bitrate.ts@@ -0,0 +1,19 @@+let audioBitrate: string | null;++export const setAudioBitrate = (bitrate: string) =>{+ audioBitrate = bitrate;+}++export const getAudioBitrate = () => {+ return audioBitrate;+}++let videoBitrate: string | null;++export const setVideoBitrate = (bitrate: string) => {+ videoBitrate = bitrate;+}++export const getVideoBitrate = () => {+ return videoBitrate;+}\ No newline at end of filediff --git a/packages/cli/src/config/index.ts b/packages/cli/src/config/index.tsindex 2bb9b98ba9..96c539c682 100644--- a/packages/cli/src/config/index.ts+++ b/packages/cli/src/config/index.ts@@ -86,6 +86,7 @@ import {setQuality} from './quality';import {setScale} from './scale';import {setPuppeteerTimeout} from './timeout';import {setWebpackCaching} from './webpack-caching';+import {getAudioBitrate, getVideoBitrate, setAudioBitrate, setVideoBitrate} from "./bitrate";export const Config: ConfigType = {Preview: {@@ -132,6 +133,8 @@ export const Config: ConfigType = {setCrf,setImageSequence,setProResProfile,+ setAudioBitrate,+ setVideoBitrate,overrideFfmpegCommand: setFfmpegOverrideFunction,},} as ConfigType;@@ -181,6 +184,8 @@ export const ConfigInternals = {getKeyboardShortcutsEnabled,getPublicDir,getFfmpegOverrideFunction,+ getAudioBitrate,+ getVideoBitrate,};export const overrideRemotion = () => {diff --git a/packages/cli/src/get-cli-options.ts b/packages/cli/src/get-cli-options.tsindex 335d6680c7..7049fb31c8 100644--- a/packages/cli/src/get-cli-options.ts+++ b/packages/cli/src/get-cli-options.ts@@ -276,5 +276,7 @@ export const getCliOptions = async (options: {enforceAudioTrack: ConfigInternals.getEnforceAudioTrack(),publicDir: ConfigInternals.getPublicDir(),ffmpegOverride: ConfigInternals.getFfmpegOverrideFunction(),+ audioBitrate: ConfigInternals.getAudioBitrate(),+ videoBitrate: ConfigInternals.getVideoBitrate(),};};diff --git a/packages/cli/src/parse-command-line.ts b/packages/cli/src/parse-command-line.tsindex 59fb7c4148..52c598a0bb 100644--- a/packages/cli/src/parse-command-line.ts+++ b/packages/cli/src/parse-command-line.ts@@ -218,6 +218,14 @@ export const parseCommandLine = () => {if (typeof parsedCli['public-dir'] !== 'undefined') {Config.Bundling.setPublicDir(parsedCli['public-dir']);}++ if (typeof parsedCli['audio-bitrate'] !== 'undefined') {+ Config.Output.setAudioBitrate(parsedCli['audio-bitrate']);+ }++ if (typeof parsedCli['video-bitrate'] !== 'undefined') {+ Config.Output.setVideoBitrate(parsedCli['video-bitrate']);+ }};export const quietFlagProvided = () => parsedCli.quiet || parsedCli.q;diff --git a/packages/cli/src/print-help.ts b/packages/cli/src/print-help.tsindex 92e0607919..00fd7794ca 100644--- a/packages/cli/src/print-help.ts+++ b/packages/cli/src/print-help.ts@@ -35,6 +35,8 @@ export const printHelp = () => {['--overwrite', 'Overwrite if file exists, default true'],['--sequence', 'Output as an image sequence'],['--codec', 'Video of audio codec'],+ ['--audio-bitrate', 'Customize the output audio bitrate'],+ ['--video-bitrate', 'Customize the output video bitrate'],['--crf', 'FFMPEG CRF value, controls quality, see docs for info'],['--browser-executable', 'Custom path for browser executable'],['--frames', 'Render a portion or a still of a video'],diff --git a/packages/cli/src/render.tsx b/packages/cli/src/render.tsxindex 33ae2ef6cd..a5292ffb6e 100644--- a/packages/cli/src/render.tsx+++ b/packages/cli/src/render.tsx@@ -93,6 +93,8 @@ export const render = async (remotionRoot: string) => {enforceAudioTrack,publicDir,ffmpegOverride,+ audioBitrate,+ videoBitrate,} = await getCliOptions({isLambda: false,type: 'series',@@ -352,6 +354,8 @@ export const render = async (remotionRoot: string) => {enforceAudioTrack,browserExecutable,ffmpegOverride,+ audioBitrate,+ videoBitrate,});Log.info();diff --git a/packages/core/src/config.ts b/packages/core/src/config.tsindex f206f451b4..2b508dc091 100644--- a/packages/core/src/config.ts+++ b/packages/core/src/config.ts@@ -253,6 +253,11 @@ export type ConfigType = {args: string[];}) => string[]) => void;++ readonly setAudioBitrate: (bitrate: string | null) => void;++ readonly setVideoBitrate: (bitrate: string | null) => void;+};};export type {Concurrency, WebpackConfiguration, WebpackOverrideFn};diff --git a/packages/docs/docs/cli/render.md b/packages/docs/docs/cli/render.mdindex e08e0b568d..cb1bd8e164 100644--- a/packages/docs/docs/cli/render.md+++ b/packages/docs/docs/cli/render.md@@ -59,6 +59,16 @@ Specify a location for a dotenv file. Default `.env`. Available in v2.2 and late[`h264` or `h265` or `png` or `vp8` or `vp9` or `mp3` or `aac` or `wav` or `prores` or `h264-mkv`](/docs/config#setcodec). If you don't supply `--codec`, it will use the H.264 encoder. Available since v1.4.+### `--audio-bitrate`++Specify the output bitrate for the generated audio.+Beware, ffmpeg may, depending on the codec chosen, not take this parameter into account.++### `--video-bitrate`++Specify the output bitrate for the generated video.+Beware, ffmpeg may, depending on the codec chosen, not take this parameter into account.+### `--prores-profile`[Set the ProRes profile](/docs/config#setproresprofile). This option is only valid if the [`codec`](#--codec) has been set to `prores`. Possible values: `4444-xq`, `4444`, `hq`, `standard`, `light`, `proxy`. See [here](https://video.stackexchange.com/a/14715) for explanation of possible values. Default: `hq`. Available since v2.1.6.diff --git a/packages/docs/docs/lambda/cli/render.md b/packages/docs/docs/lambda/cli/render.mdindex 5d9a1e8ffb..364b6e7ef2 100644--- a/packages/docs/docs/lambda/cli/render.md+++ b/packages/docs/docs/lambda/cli/render.md@@ -120,6 +120,16 @@ _available from v3.2.1_[`h264` or `h265` or `png` or `vp8` or `mp3` or `aac` or `wav` or `prores`](/docs/config#setcodec). If you don't supply `--codec`, it will use `h264`.+### `--audio-bitrate`++Specify the output bitrate for the generated audio.+Beware, ffmpeg may, depending on the codec chosen, not take this parameter into account.++### `--video-bitrate`++Specify the output bitrate for the generated video.+Beware, ffmpeg may, depending on the codec chosen, not take this parameter into account.+### `--prores-profile`[Set the ProRes profile](/docs/config#setproresprofile). This option is only valid if the [`codec`](#--codec) has been set to `prores`. Possible values: `4444-xq`, `4444`, `hq`, `standard`, `light`, `proxy`. See [here](https://video.stackexchange.com/a/14715) for explanation of possible values. Default: `hq`.diff --git a/packages/lambda/src/cli/commands/render/render.ts b/packages/lambda/src/cli/commands/render/render.tsindex ae2f7b7066..f0db6c65e1 100644--- a/packages/lambda/src/cli/commands/render/render.ts+++ b/packages/lambda/src/cli/commands/render/render.ts@@ -72,6 +72,8 @@ export const renderCommand = async (args: string[]) => {numberOfGifLoops,muted,overwrite,+ audioBitrate,+ videoBitrate} = await CliInternals.getCliOptions({type: 'series',isLambda: true,@@ -117,6 +119,8 @@ export const renderCommand = async (args: string[]) => {concurrencyPerLambda: parsedLambdaCli['concurrency-per-lambda'],muted,overwrite,+ audioBitrate,+ videoBitrate,});const totalSteps = downloadName ? 5 : 4;diff --git a/packages/lambda/src/functions/renderer.ts b/packages/lambda/src/functions/renderer.tsindex 27031039c4..7732fa932a 100644--- a/packages/lambda/src/functions/renderer.ts+++ b/packages/lambda/src/functions/renderer.ts@@ -199,6 +199,8 @@ const renderHandler = async (downloadMap,muted: params.muted,enforceAudioTrack: true,+ audioBitrate: params.audioBitrate,+ videoBitrate: params.videoBitrate,}).then(() => resolve()).catch((err) => reject(err));diff --git a/packages/lambda/src/shared/constants.ts b/packages/lambda/src/shared/constants.tsindex 3878288f85..0fe86d60b2 100644--- a/packages/lambda/src/shared/constants.ts+++ b/packages/lambda/src/shared/constants.ts@@ -258,6 +258,8 @@ export type LambdaPayloads = {downloadBehavior: DownloadBehavior;muted: boolean;overwrite: boolean;+ audioBitrate?: string | null;+ videoBitrate?: string | null;};status: {type: LambdaRoutines.status;@@ -296,6 +298,8 @@ export type LambdaPayloads = {scale: number;everyNthFrame: number;muted: boolean;+ audioBitrate?: string | null;+ videoBitrate?: string | null;};still: {type: LambdaRoutines.still;diff --git a/packages/renderer/src/stitch-frames-to-video.ts b/packages/renderer/src/stitch-frames-to-video.tsindex 5b25180997..397d5c3841 100644--- a/packages/renderer/src/stitch-frames-to-video.ts+++ b/packages/renderer/src/stitch-frames-to-video.ts@@ -280,7 +280,7 @@ export const spawnFfmpeg = async (audioCodecName,// Set bitrate up to 320k, for aac it might effectively be lower'-b:a',- options.audioBitrate || '320k',+ options.audioBitrate ?? '320k',options.force ? '-y' : null,options.outputLocation ?? tempFile,].filter(Internals.truthy)@@ -346,13 +346,12 @@ export const spawnFfmpeg = async (// Without explicitly disabling auto-alt-ref,// transparent WebM generation doesn't workpixelFormat === 'yuva420p' ? ['-auto-alt-ref', '0'] : null,- ['-b:v', '1M'],+ ['-b:v', options.videoBitrate ?? '1M'],]),codec === 'h264' ? ['-movflags', 'faststart'] : null,audioCodecName ? ['-c:a', audioCodecName] : null,// Set max bitrate up to 1024kbps, will choose lower if that's too muchaudioCodecName ? ['-b:a', options.audioBitrate || '512K'] : null,- options.videoBitrate ? ['-b:v', options.videoBitrate] : null,// Ignore metadata that may come from remote media['-map_metadata', '-1'],[