🎥 Make videos programmatically with React
required
Jonny Burger9103f858f719
diff --git a/packages/renderer/src/ffmpeg-args.ts b/packages/renderer/src/ffmpeg-args.tsindex 5546ee46d9..d919f6cc10 100644--- a/packages/renderer/src/ffmpeg-args.ts+++ b/packages/renderer/src/ffmpeg-args.ts@@ -2,6 +2,8 @@ import type {HardwareAccelerationOption} from './client';import type {Codec} from './codec';import {validateQualitySettings} from './crf';import {getCodecName} from './get-codec-name';+import type {LogLevel} from './log-level';+import {Log} from './logger';import {DEFAULT_COLOR_SPACE, type ColorSpace} from './options/color-space';import type {X264Preset} from './options/x264-preset';import type {PixelFormat} from './pixel-format';@@ -61,7 +63,9 @@ export const generateFfmpegArgs = ({encodingMaxRate,encodingBufferSize,colorSpace,- hardwareAcceleration: hwAcceleration,+ hardwareAcceleration,+ indent,+ logLevel,}: {hasPreencoded: boolean;proResProfileName: string | null;@@ -74,13 +78,33 @@ export const generateFfmpegArgs = ({encodingBufferSize: string | null;colorSpace: ColorSpace | null;hardwareAcceleration: HardwareAccelerationOption;+ indent: boolean;+ logLevel: LogLevel;}): string[][] => {- const encoderName = getCodecName(codec, hwAcceleration);+ const encoderSettings = getCodecName(+ codec,+ hardwareAcceleration === 'required' ||+ hardwareAcceleration === 'if-possible',+ );- if (encoderName === null) {- throw new TypeError('encoderName is null: ' + JSON.stringify(codec));+ if (encoderSettings === null) {+ throw new TypeError(+ `encoderSettings is null: ${JSON.stringify(codec)} (hwaccel = ${hardwareAcceleration})`,+ );}+ const {encoderName, hardwareAccelerated} = encoderSettings;+ if (!hardwareAccelerated && hardwareAcceleration === 'required') {+ throw new Error(+ `Codec ${codec} does not support hardware acceleration on ${process.platform}, but "hardwareAcceleration" is set to "required"`,+ );+ }++ Log.verbose(+ {indent, logLevel, tag: 'stitchFramesToVideo()'},+ `Encoder: ${encoderName}, hardware accelerated: ${hardwareAccelerated}`,+ );+const resolvedColorSpace = colorSpace ?? DEFAULT_COLOR_SPACE;const colorSpaceOptions: string[][] =diff --git a/packages/renderer/src/get-codec-name.ts b/packages/renderer/src/get-codec-name.tsindex 1eefbb431f..bb4ad43787 100644--- a/packages/renderer/src/get-codec-name.ts+++ b/packages/renderer/src/get-codec-name.ts@@ -1,55 +1,40 @@-import type {HardwareAccelerationOption} from './client';import type {Codec} from './codec';+export type CodecSettings = {+ encoderName: string;+ hardwareAccelerated: boolean;+};+export const getCodecName = (codec: Codec,- hwAcceleration: HardwareAccelerationOption,-): string | null => {+ preferredHwAcceleration: boolean,+): CodecSettings | null => {if (codec === 'prores') {- if (hwAcceleration === 'disable') {- return 'prores_ks';- }-- const availableHwAcceleration =- process.platform === 'darwin' ? 'prores_videotoolbox' : null;-- if (hwAcceleration === 'force') {- if (!availableHwAcceleration) {- throw new Error(- `Cannot use hardware acceleration for ProRes on platform ${process.platform}`,- );- }-- return availableHwAcceleration;+ if (preferredHwAcceleration && process.platform === 'darwin') {+ return {encoderName: 'prores_videotoolbox', hardwareAccelerated: true};}- return availableHwAcceleration ?? 'prores_ks';- }-- if (hwAcceleration === 'force') {- throw new Error(- `Cannot use hardware acceleration for ${codec} on platform ${process.platform}`,- );+ return {encoderName: 'prores_ks', hardwareAccelerated: false};}if (codec === 'h264') {- return 'libx264';+ return {encoderName: 'libx264', hardwareAccelerated: false};}if (codec === 'h265') {- return 'libx265';+ return {encoderName: 'libx265', hardwareAccelerated: false};}if (codec === 'vp8') {- return 'libvpx';+ return {encoderName: 'libvpx', hardwareAccelerated: false};}if (codec === 'vp9') {- return 'libvpx-vp9';+ return {encoderName: 'libvpx-vp9', hardwareAccelerated: false};}if (codec === 'gif') {- return 'gif';+ return {encoderName: 'gif', hardwareAccelerated: false};}if (codec === 'mp3') {@@ -65,11 +50,11 @@ export const getCodecName = (}if (codec === 'h264-mkv') {- return 'libx264';+ return {encoderName: 'libx264', hardwareAccelerated: false};}if (codec === 'h264-ts') {- return 'libx264';+ return {encoderName: 'libx264', hardwareAccelerated: false};}throw new Error(`Could not get codec for ${codec satisfies never}`);diff --git a/packages/renderer/src/options/hardware-acceleration.tsx b/packages/renderer/src/options/hardware-acceleration.tsxindex d27cf293ab..51b25842c7 100644--- a/packages/renderer/src/options/hardware-acceleration.tsx+++ b/packages/renderer/src/options/hardware-acceleration.tsx@@ -3,7 +3,7 @@ import type {AnyRemotionOption} from './option';export const hardwareAccelerationOptions = ['disable','if-possible',- 'force',+ 'required',] as const;export type HardwareAccelerationOption =@@ -27,7 +27,7 @@ export const hardwareAccelerationOption = {hardwareAccelerationOptions.map((a) => JSON.stringify(a)),)}. Default "disable". Encode using a hardware-accelerated encoder if- available. If set to "force" and no hardware-accelerated encoder is+ available. If set to "required" and no hardware-accelerated encoder isavailable, then the render will fail.`,ssrName: 'hardwareAcceleration',diff --git a/packages/renderer/src/prespawn-ffmpeg.ts b/packages/renderer/src/prespawn-ffmpeg.tsindex c002b764b8..2624901b06 100644--- a/packages/renderer/src/prespawn-ffmpeg.ts+++ b/packages/renderer/src/prespawn-ffmpeg.ts@@ -107,6 +107,8 @@ export const prespawnFfmpeg = (options: PreStitcherOptions) => {encodingBufferSize: options.encodingBufferSize,colorSpace: options.colorSpace,hardwareAcceleration: options.hardwareAcceleration,+ indent: options.indent,+ logLevel: options.logLevel,}),'-y',diff --git a/packages/renderer/src/stitch-frames-to-video.ts b/packages/renderer/src/stitch-frames-to-video.tsindex 208d3f2aaa..5e0ad72d58 100644--- a/packages/renderer/src/stitch-frames-to-video.ts+++ b/packages/renderer/src/stitch-frames-to-video.ts@@ -363,6 +363,8 @@ const innerStitchFramesToVideo = async (x264Preset,colorSpace,hardwareAcceleration,+ indent,+ logLevel,}),codec === 'h264' ? ['-movflags', 'faststart'] : null,// Ignore metadata that may come from remote media