Skip to content

🎥 Make videos programmatically with React

shuffle around

Jonny Burger64f8611ed79c
diff --git a/packages/config/.prettierrc.js b/packages/config/.prettierrc.js
new file mode 100644
index 0000000000..7129f6a51c
--- /dev/null
+++ b/packages/config/.prettierrc.js
@@ -0,0 +1,14 @@
+module.exports = {
+ singleQuote: true,
+ bracketSpacing: false,
+ useTabs: true,
+ overrides: [
+ {
+ files: ["*.yml"],
+ options: {
+ singleQuote: false,
+ },
+ },
+ ],
+ plugins: [require.resolve("prettier-plugin-organize-imports")],
+};
diff --git a/packages/config/src/config/browser-executable.ts b/packages/config/src/config/browser-executable.ts
index 9d3243cc40..95b3d5d1c0 100644
--- a/packages/config/src/config/browser-executable.ts
+++ b/packages/config/src/config/browser-executable.ts
@@ -1,11 +1,13 @@
+import {BrowserExecutable} from '@remotion/renderer';
+
let currentBrowserExecutablePath: BrowserExecutable = null;
export const setBrowserExecutable = (
- newBrowserExecutablePath: BrowserExecutable
+ newBrowserExecutablePath: BrowserExecutable
) => {
- currentBrowserExecutablePath = newBrowserExecutablePath;
+ currentBrowserExecutablePath = newBrowserExecutablePath;
};
export const getBrowserExecutable = () => {
- return currentBrowserExecutablePath;
+ return currentBrowserExecutablePath;
};
diff --git a/packages/config/src/config/browser.ts b/packages/config/src/config/browser.ts
index 50af4ba801..cedbf5c35c 100644
--- a/packages/config/src/config/browser.ts
+++ b/packages/config/src/config/browser.ts
@@ -1,17 +1,19 @@
+import {Browser} from '@remotion/renderer';
+
let currentBrowser: Browser | null = null;
export const setBrowser = (browser: Browser) => {
- if (browser === "chrome") {
- process.env.PUPPETEER_PRODUCT = "chrome";
- }
+ if (browser === 'chrome') {
+ process.env.PUPPETEER_PRODUCT = 'chrome';
+ }
- if (browser === "firefox") {
- process.env.PUPPETEER_PRODUCT = "firefox";
- }
+ if (browser === 'firefox') {
+ process.env.PUPPETEER_PRODUCT = 'firefox';
+ }
- currentBrowser = browser;
+ currentBrowser = browser;
};
export const getBrowser = () => {
- return currentBrowser;
+ return currentBrowser;
};
diff --git a/packages/config/src/config/chromium-flags.ts b/packages/config/src/config/chromium-flags.ts
index ce4b92dadc..09711b0200 100644
--- a/packages/config/src/config/chromium-flags.ts
+++ b/packages/config/src/config/chromium-flags.ts
@@ -1,28 +1,28 @@
-import type { OpenGlRenderer } from "../validation/validate-opengl-renderer";
-import { validateOpenGlRenderer } from "../validation/validate-opengl-renderer";
+import {OpenGlRenderer, RenderInternals} from '@remotion/renderer';
let chromiumDisableWebSecurity = false;
let ignoreCertificateErrors = false;
-let openGlRenderer: OpenGlRenderer | null = DEFAULT_OPENGL_RENDERER;
+let openGlRenderer: OpenGlRenderer | null =
+ RenderInternals.DEFAULT_OPENGL_RENDERER;
let headlessMode = true;
export const getChromiumDisableWebSecurity = () => chromiumDisableWebSecurity;
export const setChromiumDisableWebSecurity = (should: boolean) => {
- chromiumDisableWebSecurity = should;
+ chromiumDisableWebSecurity = should;
};
export const getIgnoreCertificateErrors = () => ignoreCertificateErrors;
export const setChromiumIgnoreCertificateErrors = (should: boolean) => {
- ignoreCertificateErrors = should;
+ ignoreCertificateErrors = should;
};
export const getChromiumOpenGlRenderer = () => openGlRenderer;
export const setChromiumOpenGlRenderer = (renderer: OpenGlRenderer) => {
- validateOpenGlRenderer(renderer);
- openGlRenderer = renderer;
+ RenderInternals.validateOpenGlRenderer(renderer);
+ openGlRenderer = renderer;
};
export const getChromiumHeadlessMode = () => headlessMode;
export const setChromiumHeadlessMode = (should: boolean) => {
- headlessMode = should;
+ headlessMode = should;
};
diff --git a/packages/config/src/config/codec.ts b/packages/config/src/config/codec.ts
new file mode 100644
index 0000000000..398c3b498b
--- /dev/null
+++ b/packages/config/src/config/codec.ts
@@ -0,0 +1,56 @@
+import type {CodecOrUndefined} from '@remotion/renderer';
+import {RenderInternals} from '@remotion/renderer';
+
+const validLegacyFormats = ['mp4', 'png-sequence'] as const;
+
+type LegacyFormat = typeof validLegacyFormats[number];
+
+let codec: CodecOrUndefined;
+
+export const setCodec = (newCodec: CodecOrUndefined) => {
+ if (newCodec === undefined) {
+ codec = undefined;
+ return;
+ }
+
+ if (!RenderInternals.validCodecs.includes(newCodec)) {
+ throw new Error(
+ `Codec must be one of the following: ${RenderInternals.validCodecs.join(
+ ', '
+ )}, but got ${newCodec}`
+ );
+ }
+
+ codec = newCodec;
+};
+
+export const getOutputCodecOrUndefined = (): CodecOrUndefined => {
+ return codec;
+};
+
+export const setOutputFormat = (newLegacyFormat: LegacyFormat) => {
+ if (newLegacyFormat === undefined) {
+ codec = undefined;
+ return;
+ }
+
+ if (!validLegacyFormats.includes(newLegacyFormat)) {
+ throw new Error(
+ `Output format must be one of the following: ${validLegacyFormats.join(
+ ', '
+ )}, but got ${newLegacyFormat}`
+ );
+ }
+
+ console.warn(
+ 'setOutputFormat() is deprecated. Use the setCodec() and setImageSequence() instead.'
+ );
+ if (newLegacyFormat === 'mp4') {
+ codec = 'h264';
+ return;
+ }
+
+ if (newLegacyFormat === 'png-sequence') {
+ codec = undefined;
+ }
+};
diff --git a/packages/config/src/config/crf.ts b/packages/config/src/config/crf.ts
index a3fbcf3fb5..8bc0fe9725 100644
--- a/packages/config/src/config/crf.ts
+++ b/packages/config/src/config/crf.ts
@@ -1,22 +1,22 @@
-import { isAudioCodec } from "../is-audio-codec";
-import type { Codec } from "./codec";
+import {Codec, Crf, RenderInternals} from '@remotion/renderer';
let currentCrf: Crf;
export const setCrf = (newCrf: Crf) => {
- if (typeof newCrf !== "number" && newCrf !== undefined) {
- throw new TypeError("The CRF must be a number or undefined.");
- }
+ if (typeof newCrf !== 'number' && newCrf !== undefined) {
+ throw new TypeError('The CRF must be a number or undefined.');
+ }
- currentCrf = newCrf;
+ currentCrf = newCrf;
};
export const getCrfOrUndefined = () => {
- return currentCrf;
+ return currentCrf;
};
export const getActualCrf = (codec: Codec) => {
- const crf = getCrfOrUndefined() ?? getDefaultCrfForCodec(codec);
- validateSelectedCrfAndCodecCombination(crf, codec);
- return crf;
+ const crf =
+ getCrfOrUndefined() ?? RenderInternals.getDefaultCrfForCodec(codec);
+ RenderInternals.validateSelectedCrfAndCodecCombination(crf, codec);
+ return crf;
};
diff --git a/packages/config/src/config/every-nth-frame.ts b/packages/config/src/config/every-nth-frame.ts
index 7c0e9271e5..10b388920c 100644
--- a/packages/config/src/config/every-nth-frame.ts
+++ b/packages/config/src/config/every-nth-frame.ts
@@ -1,5 +1,5 @@
+import {Codec} from '@remotion/renderer';
import {validateEveryNthFrame} from '../validation/validate-every-nth-frame';
-import type {Codec} from './codec';
let everyNthFrame = 1;
diff --git a/packages/config/src/config/ffmpeg-executable.ts b/packages/config/src/config/ffmpeg-executable.ts
index 4d2214a594..0586e70c5c 100644
--- a/packages/config/src/config/ffmpeg-executable.ts
+++ b/packages/config/src/config/ffmpeg-executable.ts
@@ -1,20 +1,20 @@
-import { FfmpegExecutable } from "@remotion/renderer";
+import {FfmpegExecutable} from '@remotion/renderer';
let currentFfmpegExecutablePath: FfmpegExecutable = null;
let currentFfprobeExecutablePath: FfmpegExecutable = null;
export const setFfmpegExecutable = (ffmpegPath: FfmpegExecutable) => {
- currentFfmpegExecutablePath = ffmpegPath;
+ currentFfmpegExecutablePath = ffmpegPath;
};
export const getCustomFfmpegExecutable = () => {
- return currentFfmpegExecutablePath;
+ return currentFfmpegExecutablePath;
};
export const setFfprobeExecutable = (ffprobePath: FfmpegExecutable) => {
- currentFfprobeExecutablePath = ffprobePath;
+ currentFfprobeExecutablePath = ffprobePath;
};
export const getCustomFfprobeExecutable = () => {
- return currentFfprobeExecutablePath;
+ return currentFfprobeExecutablePath;
};
diff --git a/packages/config/src/config/frame-range.ts b/packages/config/src/config/frame-range.ts
index dbf00ab993..0e74b68fa9 100644
--- a/packages/config/src/config/frame-range.ts
+++ b/packages/config/src/config/frame-range.ts
@@ -1,41 +1,43 @@
+import {FrameRange, RenderInternals} from '@remotion/renderer';
+
let range: FrameRange | null = null;
export const setFrameRange = (newFrameRange: FrameRange | null) => {
- validateFrameRange(newFrameRange);
- range = newFrameRange;
+ RenderInternals.validateFrameRange(newFrameRange);
+ range = newFrameRange;
};
export const setFrameRangeFromCli = (newFrameRange: string | number) => {
- if (typeof newFrameRange === "number") {
- setFrameRange(newFrameRange);
- range = newFrameRange;
- return;
- }
-
- if (typeof newFrameRange === "string") {
- const parsed = newFrameRange.split("-").map((f) => Number(f)) as number[];
- if (parsed.length > 2 || parsed.length <= 0) {
- throw new Error(
- `--frames flag must be a number or 2 numbers separated by '-', instead got ${parsed.length} numbers`
- );
- }
-
- if (parsed.length === 2 && parsed[1] < parsed[0]) {
- throw new Error(
- "The second number of the --frames flag number should be greater or equal than first number"
- );
- }
-
- for (const value of parsed) {
- if (isNaN(value)) {
- throw new Error(
- "--frames flag must be a single number, or 2 numbers separated by `-`"
- );
- }
- }
-
- setFrameRange(parsed as [number, number]);
- }
+ if (typeof newFrameRange === 'number') {
+ setFrameRange(newFrameRange);
+ range = newFrameRange;
+ return;
+ }
+
+ if (typeof newFrameRange === 'string') {
+ const parsed = newFrameRange.split('-').map((f) => Number(f)) as number[];
+ if (parsed.length > 2 || parsed.length <= 0) {
+ throw new Error(
+ `--frames flag must be a number or 2 numbers separated by '-', instead got ${parsed.length} numbers`
+ );
+ }
+
+ if (parsed.length === 2 && parsed[1] < parsed[0]) {
+ throw new Error(
+ 'The second number of the --frames flag number should be greater or equal than first number'
+ );
+ }
+
+ for (const value of parsed) {
+ if (isNaN(value)) {
+ throw new Error(
+ '--frames flag must be a single number, or 2 numbers separated by `-`'
+ );
+ }
+ }
+
+ setFrameRange(parsed as [number, number]);
+ }
};
export const getRange = () => range;
diff --git a/packages/config/src/config/image-format.ts b/packages/config/src/config/image-format.ts
index 8d901326f6..7d2e718748 100644
--- a/packages/config/src/config/image-format.ts
+++ b/packages/config/src/config/image-format.ts
@@ -1,20 +1,20 @@
-import type { PixelFormat } from "./pixel-format";
+import {ImageFormat, RenderInternals} from '@remotion/renderer';
let currentImageFormat: ImageFormat | undefined;
export const setImageFormat = (format: ImageFormat) => {
- if (typeof format === "undefined") {
- currentImageFormat = undefined;
- return;
- }
+ if (typeof format === 'undefined') {
+ currentImageFormat = undefined;
+ return;
+ }
- if (!validOptions.includes(format)) {
- throw new TypeError(`Value ${format} is not valid as an image format.`);
- }
+ if (!RenderInternals.validImageFormats.includes(format)) {
+ throw new TypeError(`Value ${format} is not valid as an image format.`);
+ }
- currentImageFormat = format;
+ currentImageFormat = format;
};
export const getUserPreferredImageFormat = () => {
- return currentImageFormat;
+ return currentImageFormat;
};
diff --git a/packages/config/src/config/image-sequence.ts b/packages/config/src/config/image-sequence.ts
index d8f887e6e7..5d652b03ef 100644
--- a/packages/config/src/config/image-sequence.ts
+++ b/packages/config/src/config/image-sequence.ts
@@ -1,4 +1,4 @@
-import type {FrameRange} from './frame-range';
+import {FrameRange} from '@remotion/renderer';
let imageSequence = false;
diff --git a/packages/config/src/config/index.ts b/packages/config/src/config/index.ts
index 33476d096a..72cae246e3 100644
--- a/packages/config/src/config/index.ts
+++ b/packages/config/src/config/index.ts
@@ -1,228 +1,207 @@
-import type { Browser } from "./browser";
-import type { BrowserExecutable } from "./browser-executable";
-import { setBrowserExecutable } from "./browser-executable";
+import {setBrowserExecutable} from './browser-executable';
import {
- setChromiumDisableWebSecurity,
- setChromiumHeadlessMode,
- setChromiumIgnoreCertificateErrors,
- setChromiumOpenGlRenderer,
-} from "./chromium-flags";
-import type { Codec } from "./codec";
-import { setCodec, setOutputFormat } from "./codec";
-import type { Concurrency } from "./concurrency";
-import { setConcurrency } from "./concurrency";
-import { setCrf } from "./crf";
-import { setDotEnvLocation } from "./env-file";
-import { setEveryNthFrame } from "./every-nth-frame";
-import { setFfmpegExecutable, setFfprobeExecutable } from "./ffmpeg-executable";
-import type { FrameRange } from "./frame-range";
-import { setFrameRange } from "./frame-range";
-import type { ImageFormat, StillImageFormat } from "./image-format";
-import { setImageFormat } from "./image-format";
-import { setImageSequence } from "./image-sequence";
-import type { LogLevel } from "./log";
-import { setLogLevel } from "./log";
-import { setMaxTimelineTracks } from "./max-timeline-tracks";
-import { setNumberOfGifLoops } from "./number-of-gif-loops";
-import { setOutputLocation } from "./output-location";
-import type {
- WebpackConfiguration,
- WebpackOverrideFn,
-} from "./override-webpack";
-import { overrideWebpackConfig } from "./override-webpack";
-import { setOverwriteOutput } from "./overwrite";
-import type { PixelFormat } from "./pixel-format";
-import { setPixelFormat } from "./pixel-format";
-import { setPort } from "./preview-server";
-import { setProResProfile } from "./prores-profile";
-import { setQuality } from "./quality";
-import { setScale } from "./scale";
-import { setPuppeteerTimeout } from "./timeout";
-import { setWebpackCaching } from "./webpack-caching";
+ setChromiumDisableWebSecurity,
+ setChromiumHeadlessMode,
+ setChromiumIgnoreCertificateErrors,
+ setChromiumOpenGlRenderer,
+} from './chromium-flags';
+import {setCodec, setOutputFormat} from './codec';
+import type {Concurrency} from './concurrency';
+import {setConcurrency} from './concurrency';
+import {setCrf} from './crf';
+import {setDotEnvLocation} from './env-file';
+import {setEveryNthFrame} from './every-nth-frame';
+import {setFfmpegExecutable, setFfprobeExecutable} from './ffmpeg-executable';
+import {setFrameRange} from './frame-range';
+import {setImageFormat} from './image-format';
+import {setImageSequence} from './image-sequence';
+import type {LogLevel} from './log';
+import {setLogLevel} from './log';
+import {setMaxTimelineTracks} from './max-timeline-tracks';
+import {setNumberOfGifLoops} from './number-of-gif-loops';
+import {setOutputLocation} from './output-location';
+import type {WebpackConfiguration, WebpackOverrideFn} from './override-webpack';
+import {overrideWebpackConfig} from './override-webpack';
+import {setOverwriteOutput} from './overwrite';
+import {setPixelFormat} from './pixel-format';
+import {setPort} from './preview-server';
+import {setProResProfile} from './prores-profile';
+import {setQuality} from './quality';
+import {setScale} from './scale';
+import {setPuppeteerTimeout} from './timeout';
+import {setWebpackCaching} from './webpack-caching';
export const Config = {
- Preview: {
- /**
- * Change the maximum amount of tracks that are shown in the timeline.
- * @param maxTracks The maximum amount of timeline tracks that you would like to show.
- * @default 15
- */
- setMaxTimelineTracks,
- },
- Bundling: {
- /**
- * Pass in a function which takes the current Webpack config
- * and return a modified Webpack configuration.
- * Docs: http://remotion.dev/docs/webpack
- */
- overrideWebpackConfig,
- /**
- * Whether Webpack bundles should be cached to make
- * subsequent renders faster. Default: true
- */
- setCachingEnabled: setWebpackCaching,
- /**
- * Define on which port Remotion should start it's HTTP servers during preview and rendering.
- * By default, Remotion will try to find a free port.
- * If you specify a port, but it's not available, Remotion will throw an error.
- */
- setPort,
- },
- Log: {
- /**
- * Set the log level.
- * Acceptable values: 'error' | 'warning' | 'info' | 'verbose'
- * Default value: 'info'
- *
- * Set this to 'verbose' to get browser logs and other IO.
- */
- setLevel: setLogLevel,
- },
- Puppeteer: {
- /**
- * Specify executable path for the browser to use.
- * Default: null, which will make Remotion find or download a version of said browser.
- */
- setBrowserExecutable,
- /**
- * Set how many milliseconds a frame may take to render before it times out.
- * Default: `30000`
- */
- setTimeoutInMilliseconds: setPuppeteerTimeout,
- /**
- * Setting deciding whether to disable CORS and other Chrome security features.
- * Default: false
- */
- setChromiumDisableWebSecurity,
- /**
- * Setting whether to ignore any invalid SSL certificates, such as self-signed ones.
- * Default: false
- */
- setChromiumIgnoreCertificateErrors,
- /**
- * If false, will open an actual browser during rendering to observe progress.
- * Default: true
- */
- setChromiumHeadlessMode,
- /**
- * Set the OpenGL rendering backend for Chrome. Possible values: 'egl', 'angle', 'swiftshader' and 'swangle'.
- * Default: 'swangle' in Lambda, null elsewhere.
- */
- setChromiumOpenGlRenderer,
- },
- Rendering: {
- /**
- * Set a custom location for a .env file.
- * Default: `.env`
- */
- setDotEnvLocation,
- /**
- * Sets how many Puppeteer instances will work on rendering your video in parallel.
- * Default: `null`, meaning half of the threads available on your CPU.
- */
- setConcurrency,
- /**
- * Set the JPEG quality for the frames.
- * Must be between 0 and 100.
- * Must be between 0 and 100.
- * Default: 80
- */
- setQuality,
- /** Decide in which image format to render. Can be either 'jpeg' or 'png'.
- * PNG is slower, but supports transparency.
- */
- setImageFormat,
- /**
- * Render only a subset of a video.
- * Pass in a tuple [20, 30] to only render frames 20-30 into a video.
- * Pass in a single number `20` to only render a single frame as an image.
- * The frame count starts at 0.
- */
- setFrameRange,
+ Preview: {
+ /**
+ * Change the maximum amount of tracks that are shown in the timeline.
+ * @param maxTracks The maximum amount of timeline tracks that you would like to show.
+ * @default 15
+ */
+ setMaxTimelineTracks,
+ },
+ Bundling: {
+ /**
+ * Pass in a function which takes the current Webpack config
+ * and return a modified Webpack configuration.
+ * Docs: http://remotion.dev/docs/webpack
+ */
+ overrideWebpackConfig,
+ /**
+ * Whether Webpack bundles should be cached to make
+ * subsequent renders faster. Default: true
+ */
+ setCachingEnabled: setWebpackCaching,
+ /**
+ * Define on which port Remotion should start it's HTTP servers during preview and rendering.
+ * By default, Remotion will try to find a free port.
+ * If you specify a port, but it's not available, Remotion will throw an error.
+ */
+ setPort,
+ },
+ Log: {
+ /**
+ * Set the log level.
+ * Acceptable values: 'error' | 'warning' | 'info' | 'verbose'
+ * Default value: 'info'
+ *
+ * Set this to 'verbose' to get browser logs and other IO.
+ */
+ setLevel: setLogLevel,
+ },
+ Puppeteer: {
+ /**
+ * Specify executable path for the browser to use.
+ * Default: null, which will make Remotion find or download a version of said browser.
+ */
+ setBrowserExecutable,
+ /**
+ * Set how many milliseconds a frame may take to render before it times out.
+ * Default: `30000`
+ */
+ setTimeoutInMilliseconds: setPuppeteerTimeout,
+ /**
+ * Setting deciding whether to disable CORS and other Chrome security features.
+ * Default: false
+ */
+ setChromiumDisableWebSecurity,
+ /**
+ * Setting whether to ignore any invalid SSL certificates, such as self-signed ones.
+ * Default: false
+ */
+ setChromiumIgnoreCertificateErrors,
+ /**
+ * If false, will open an actual browser during rendering to observe progress.
+ * Default: true
+ */
+ setChromiumHeadlessMode,
+ /**
+ * Set the OpenGL rendering backend for Chrome. Possible values: 'egl', 'angle', 'swiftshader' and 'swangle'.
+ * Default: 'swangle' in Lambda, null elsewhere.
+ */
+ setChromiumOpenGlRenderer,
+ },
+ Rendering: {
+ /**
+ * Set a custom location for a .env file.
+ * Default: `.env`
+ */
+ setDotEnvLocation,
+ /**
+ * Sets how many Puppeteer instances will work on rendering your video in parallel.
+ * Default: `null`, meaning half of the threads available on your CPU.
+ */
+ setConcurrency,
+ /**
+ * Set the JPEG quality for the frames.
+ * Must be between 0 and 100.
+ * Must be between 0 and 100.
+ * Default: 80
+ */
+ setQuality,
+ /** Decide in which image format to render. Can be either 'jpeg' or 'png'.
+ * PNG is slower, but supports transparency.
+ */
+ setImageFormat,
+ /**
+ * Render only a subset of a video.
+ * Pass in a tuple [20, 30] to only render frames 20-30 into a video.
+ * Pass in a single number `20` to only render a single frame as an image.
+ * The frame count starts at 0.
+ */
+ setFrameRange,
- /**
- * Specify local ffmpeg executable.
- * Default: null, which will use ffmpeg available in PATH.
- */
- setFfmpegExecutable,
- /**
- * Specify local ffprobe executable.
- * Default: null, which will use ffprobe available in PATH.
- */
- setFfprobeExecutable,
- /**
- * Scales the output dimensions by a factor.
- * Default: 1.
- */
- setScale,
- /**
- * Specify which frames should be picked for rendering a GIF
- * Default: 1, which means every frame
- * https://remotion.dev/docs/render-as-gif
- */
- setEveryNthFrame,
- /**
- * Specify the number of Loop a GIF should have.
- * Default: null (means GIF will loop infinite)
- */
- setNumberOfGifLoops,
- },
- Output: {
- /**
- * Set the output file location string. Default: `out/{composition}.{codec}`
- */
- setOutputLocation,
- /**
- * If the video file already exists, should Remotion overwrite
- * the output? Default: true
- */
- setOverwriteOutput,
- /**
- * Sets the pixel format in FFMPEG.
- * See https://trac.ffmpeg.org/wiki/Chroma%20Subsampling for an explanation.
- * You can override this using the `--pixel-format` Cli flag.
- */
- setPixelFormat,
- /**
- * @deprecated Use setCodec() and setImageSequence() instead.
- * Specify what kind of output you, either `mp4` or `png-sequence`.
- */
- setOutputFormat,
- /**
- * Specify the codec for stitching the frames into a video.
- * Can be `h264` (default), `h265`, `vp8` or `vp9`
- */
- setCodec,
- /**
- * Set the Constant Rate Factor to pass to FFMPEG.
- * Lower values mean better quality, but be aware that the ranges of
- * possible values greatly differs between codecs.
- */
- setCrf,
- /**
- * Set to true if don't want a video but an image sequence as the output.
- */
- setImageSequence,
- /**
- * Set the ProRes profile.
- * This method is only valid if the codec has been set to 'prores'.
- * Possible values: 4444-xq, 4444, hq, standard, light, proxy. Default: 'hq'
- * 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,
+ /**
+ * Specify local ffprobe executable.
+ * Default: null, which will use ffprobe available in PATH.
+ */
+ setFfprobeExecutable,
+ /**
+ * Scales the output dimensions by a factor.
+ * Default: 1.
+ */
+ setScale,
+ /**
+ * Specify which frames should be picked for rendering a GIF
+ * Default: 1, which means every frame
+ * https://remotion.dev/docs/render-as-gif
+ */
+ setEveryNthFrame,
+ /**
+ * Specify the number of Loop a GIF should have.
+ * Default: null (means GIF will loop infinite)
+ */
+ setNumberOfGifLoops,
+ },
+ Output: {
+ /**
+ * Set the output file location string. Default: `out/{composition}.{codec}`
+ */
+ setOutputLocation,
+ /**
+ * If the video file already exists, should Remotion overwrite
+ * the output? Default: true
+ */
+ setOverwriteOutput,
+ /**
+ * Sets the pixel format in FFMPEG.
+ * See https://trac.ffmpeg.org/wiki/Chroma%20Subsampling for an explanation.
+ * You can override this using the `--pixel-format` Cli flag.
+ */
+ setPixelFormat,
+ /**
+ * @deprecated Use setCodec() and setImageSequence() instead.
+ * Specify what kind of output you, either `mp4` or `png-sequence`.
+ */
+ setOutputFormat,
+ /**
+ * Specify the codec for stitching the frames into a video.
+ * Can be `h264` (default), `h265`, `vp8` or `vp9`
+ */
+ setCodec,
+ /**
+ * Set the Constant Rate Factor to pass to FFMPEG.
+ * Lower values mean better quality, but be aware that the ranges of
+ * possible values greatly differs between codecs.
+ */
+ setCrf,
+ /**
+ * Set to true if don't want a video but an image sequence as the output.
+ */
+ setImageSequence,
+ /**
+ * Set the ProRes profile.
+ * This method is only valid if the codec has been set to 'prores'.
+ * Possible values: 4444-xq, 4444, hq, standard, light, proxy. Default: 'hq'
+ * See https://avpres.net/FFmpeg/im_ProRes.html for meaning of possible values.
+ */
+ setProResProfile,
+ },
} as const;
-export type {
- PixelFormat,
- Concurrency,
- WebpackConfiguration,
- WebpackOverrideFn,
- BrowserExecutable,
- ImageFormat,
- Codec,
- Browser,
- FrameRange,
- LogLevel,
- StillImageFormat,
-};
+export type {Concurrency, WebpackConfiguration, WebpackOverrideFn, LogLevel};
diff --git a/packages/config/src/config/number-of-gif-loops.ts b/packages/config/src/config/number-of-gif-loops.ts
index eaf4aa1ebf..9e53221878 100644
--- a/packages/config/src/config/number-of-gif-loops.ts
+++ b/packages/config/src/config/number-of-gif-loops.ts
@@ -1,4 +1,4 @@
-import type {Codec} from './codec';
+import {Codec} from '@remotion/renderer';
export type Loop = number | null;
diff --git a/packages/config/src/config/overwrite.ts b/packages/config/src/config/overwrite.ts
index 640ddbd8a1..82fbd101f4 100644
--- a/packages/config/src/config/overwrite.ts
+++ b/packages/config/src/config/overwrite.ts
@@ -1,15 +1,17 @@
-let shouldOverwrite = DEFAULT_OVERWRITE;
+import {RenderInternals} from '@remotion/renderer';
+
+let shouldOverwrite = RenderInternals.DEFAULT_OVERWRITE;
export const setOverwriteOutput = (newOverwrite: boolean) => {
- if (typeof newOverwrite !== "boolean") {
- throw new Error(
- `overwriteExisting must be a boolean but got ${typeof newOverwrite} (${JSON.stringify(
- newOverwrite
- )})`
- );
- }
-
- shouldOverwrite = newOverwrite;
+ if (typeof newOverwrite !== 'boolean') {
+ throw new Error(
+ `overwriteExisting must be a boolean but got ${typeof newOverwrite} (${JSON.stringify(
+ newOverwrite
+ )})`
+ );
+ }
+
+ shouldOverwrite = newOverwrite;
};
export const getShouldOverwrite = () => shouldOverwrite;
diff --git a/packages/config/src/config/pixel-format.ts b/packages/config/src/config/pixel-format.ts
index 31383ef78f..7d303d121d 100644
--- a/packages/config/src/config/pixel-format.ts
+++ b/packages/config/src/config/pixel-format.ts
@@ -1,15 +1,15 @@
-import { PixelFormat, RenderInternals, Codec } from "@remotion/renderer";
+import {PixelFormat, RenderInternals} from '@remotion/renderer';
-let currentPixelFormat: PixelFormat = DEFAULT_PIXEL_FORMAT;
+let currentPixelFormat: PixelFormat = RenderInternals.DEFAULT_PIXEL_FORMAT;
export const setPixelFormat = (format: PixelFormat) => {
- if (!RenderInternals.validPixelFormats.includes(format)) {
- throw new TypeError(`Value ${format} is not valid as a pixel format.`);
- }
+ if (!RenderInternals.validPixelFormats.includes(format)) {
+ throw new TypeError(`Value ${format} is not valid as a pixel format.`);
+ }
- currentPixelFormat = format;
+ currentPixelFormat = format;
};
export const getPixelFormat = () => {
- return currentPixelFormat;
+ return currentPixelFormat;
};
diff --git a/packages/config/src/config/prores-profile.ts b/packages/config/src/config/prores-profile.ts
index 9a9e5e04e6..421ae77533 100644
--- a/packages/config/src/config/prores-profile.ts
+++ b/packages/config/src/config/prores-profile.ts
@@ -1,11 +1,11 @@
-import type { Codec } from "./codec";
+import type {ProResProfile} from '@remotion/renderer';
let proResProfile: ProResProfile | undefined;
export const getProResProfile = (): ProResProfile | undefined => {
- return proResProfile;
+ return proResProfile;
};
export const setProResProfile = (profile: ProResProfile | undefined) => {
- proResProfile = profile;
+ proResProfile = profile;
};
diff --git a/packages/config/src/config/quality.ts b/packages/config/src/config/quality.ts
index 56661ceca1..f5c1a01f29 100644
--- a/packages/config/src/config/quality.ts
+++ b/packages/config/src/config/quality.ts
@@ -1,10 +1,10 @@
-import {validateQuality} from '../validation/validate-quality';
+import {RenderInternals} from '@remotion/renderer';
const defaultValue = undefined;
let quality: number | undefined = defaultValue;
export const setQuality = (q: number | undefined) => {
- validateQuality(q);
+ RenderInternals.validateQuality(q);
if (q === 0 || q === undefined) {
quality = defaultValue;
diff --git a/packages/config/src/config/still-frame.ts b/packages/config/src/config/still-frame.ts
index 9ffceabcb9..0210555f45 100644
--- a/packages/config/src/config/still-frame.ts
+++ b/packages/config/src/config/still-frame.ts
@@ -1,9 +1,9 @@
-import {validateFrame} from '../validation/validate-frame';
+import {RenderInternals} from '@remotion/renderer';
let stillFrame = 0;
export const setStillFrame = (frame: number) => {
- validateFrame(frame, Infinity);
+ RenderInternals.validateFrame(frame, Infinity);
stillFrame = frame;
};
diff --git a/packages/config/src/config/timeout.ts b/packages/config/src/config/timeout.ts
index d34f852cc9..efe016f649 100644
--- a/packages/config/src/config/timeout.ts
+++ b/packages/config/src/config/timeout.ts
@@ -1,6 +1,6 @@
-import {DEFAULT_PUPPETEER_TIMEOUT} from '../timeout';
+import {RenderInternals} from '@remotion/renderer';
-let currentTimeout: number = DEFAULT_PUPPETEER_TIMEOUT;
+let currentTimeout: number = RenderInternals.DEFAULT_TIMEOUT;
export const setPuppeteerTimeout = (newPuppeteerTimeout: number) => {
if (typeof newPuppeteerTimeout !== 'number') {
diff --git a/packages/config/src/test/codec.test.ts b/packages/config/src/test/codec.test.ts
index ad5e70b410..8135d6ccdf 100644
--- a/packages/config/src/test/codec.test.ts
+++ b/packages/config/src/test/codec.test.ts
@@ -1,101 +1,97 @@
-import { describe, expect, test } from "vitest";
-import type { CodecOrUndefined } from "../config/codec";
-import {
- getFinalOutputCodec,
- getOutputCodecOrUndefined,
- setCodec,
-} from "../config/codec";
-import { expectToThrow } from "./expect-to-throw";
+import {CodecOrUndefined, RenderInternals} from '@remotion/renderer';
+import {describe, expect, test} from 'vitest';
+import {getOutputCodecOrUndefined, setCodec} from '../config/codec';
+import {expectToThrow} from './expect-to-throw';
// getFinalOutputCodec
-describe("Codec tests valid codec input", () => {
- const validCodecInput: CodecOrUndefined[] = [
- "h264",
- "h265",
- "vp8",
- "vp9",
- "mp3",
- "aac",
- "wav",
- "h264-mkv",
- ];
- validCodecInput.forEach((entry) =>
- test(`codec ${entry}`, () =>
- expect(
- getFinalOutputCodec({
- codec: entry,
- emitWarning: false,
- fileExtension: "",
- })
- ).toEqual(entry))
- );
+describe('Codec tests valid codec input', () => {
+ const validCodecInput: CodecOrUndefined[] = [
+ 'h264',
+ 'h265',
+ 'vp8',
+ 'vp9',
+ 'mp3',
+ 'aac',
+ 'wav',
+ 'h264-mkv',
+ ];
+ validCodecInput.forEach((entry) =>
+ test(`codec ${entry}`, () =>
+ expect(
+ RenderInternals.getFinalOutputCodec({
+ codec: entry,
+ emitWarning: false,
+ fileExtension: '',
+ })
+ ).toEqual(entry))
+ );
});
-describe("Codec tests undefined codec input with known extension", () => {
- const codecExtensionCombination: [string, string][] = [
- ["vp8", "webm"],
- ["h265", "hevc"],
- ["mp3", "mp3"],
- ["wav", "wav"],
- ["aac", "aac"],
- ["aac", "m4a"],
- ];
- const inputCodecs: CodecOrUndefined[] = ["h264", undefined];
- inputCodecs.forEach((codec) =>
- codecExtensionCombination.forEach((entry) =>
- test(
- codec
- ? `should not look for extension ${entry[1]}`
- : `${entry[1]} should be recognized as ${entry[0]}`,
- () =>
- expect(
- getFinalOutputCodec({
- codec,
- emitWarning: false,
- fileExtension: entry[1],
- })
- ).toEqual(codec ?? entry[0])
- )
- )
- );
+describe('Codec tests undefined codec input with known extension', () => {
+ const codecExtensionCombination: [string, string][] = [
+ ['vp8', 'webm'],
+ ['h265', 'hevc'],
+ ['mp3', 'mp3'],
+ ['wav', 'wav'],
+ ['aac', 'aac'],
+ ['aac', 'm4a'],
+ ];
+ const inputCodecs: CodecOrUndefined[] = ['h264', undefined];
+ inputCodecs.forEach((codec) =>
+ codecExtensionCombination.forEach((entry) =>
+ test(
+ codec
+ ? `should not look for extension ${entry[1]}`
+ : `${entry[1]} should be recognized as ${entry[0]}`,
+ () =>
+ expect(
+ RenderInternals.getFinalOutputCodec({
+ codec,
+ emitWarning: false,
+ fileExtension: entry[1],
+ })
+ ).toEqual(codec ?? entry[0])
+ )
+ )
+ );
});
-describe("Codec tests undefined codec input with unknown extension", () => {
- const unknownExtensions = ["", "abc"];
- unknownExtensions.forEach((entry) =>
- test(`testing with "${entry}" as extension`, () =>
- expect(
- getFinalOutputCodec({
- codec: undefined,
- emitWarning: false,
- fileExtension: entry,
- })
- ).toEqual("h264"))
- );
+describe('Codec tests undefined codec input with unknown extension', () => {
+ const unknownExtensions = ['', 'abc'];
+ unknownExtensions.forEach((entry) =>
+ test(`testing with "${entry}" as extension`, () =>
+ expect(
+ RenderInternals.getFinalOutputCodec({
+ codec: undefined,
+ emitWarning: false,
+ fileExtension: entry,
+ })
+ ).toEqual('h264'))
+ );
});
// setCodec
-describe("Codec tests setOutputFormat", () => {
- const validCodecInputs: CodecOrUndefined[] = [
- "h264",
- "h265",
- "vp8",
- "vp9",
- undefined,
- ];
- validCodecInputs.forEach((entry) =>
- test(`testing with ${entry}`, () => {
- setCodec(entry);
- expect(getOutputCodecOrUndefined()).toEqual(entry);
- })
- );
- test("setCodec with invalid coded", () => {
- expectToThrow(
- // @ts-expect-error
- () => setCodec("invalid"),
- /Codec must be one of the following:/
- );
- });
+describe('Codec tests setOutputFormat', () => {
+ const validCodecInputs: CodecOrUndefined[] = [
+ 'h264',
+ 'h265',
+ 'vp8',
+ 'vp9',
+ undefined,
+ ];
+ validCodecInputs.forEach((entry) =>
+ test(`testing with ${entry}`, () => {
+ setCodec(entry);
+ expect(getOutputCodecOrUndefined()).toEqual(entry);
+ })
+ );
+ test('setCodec with invalid coded', () => {
+ expectToThrow(
+ // @ts-expect-error
+ () => setCodec('invalid'),
+ /Codec must be one of the following:/
+ );
+ });
});
diff --git a/packages/config/src/test/crf.test.ts b/packages/config/src/test/crf.test.ts
index 0912d30e48..557bed2434 100644
--- a/packages/config/src/test/crf.test.ts
+++ b/packages/config/src/test/crf.test.ts
@@ -1,174 +1,57 @@
-import { describe, expect, test } from "vitest";
-import type { Codec } from "../config";
-import {
- getActualCrf,
- getDefaultCrfForCodec,
- getValidCrfRanges,
- setCrf,
- validateSelectedCrfAndCodecCombination,
-} from "../config/crf";
-import { expectToThrow } from "./expect-to-throw";
-
-describe("crf tests getDefaultCrfForCodec valid input", () => {
- // input codec, output
- const validCodecIOs: [Codec, number][] = [
- ["h264", 18],
- ["h265", 23],
- ["vp8", 9],
- ["vp9", 28],
- ["mp3", 0],
- ["aac", 0],
- ["wav", 0],
- ] as [Codec, number][];
- validCodecIOs.forEach((entry) =>
- test(`default for ${entry[0]} should be ${entry[1]}`, () =>
- expect(getDefaultCrfForCodec(entry[0])).toEqual(entry[1]))
- );
-});
-
-describe("crf tests getDefaultCrfForCodec invalid input", () => {
- // input codec
- const invalidCodecs = ["abc", "", 3, undefined];
- invalidCodecs.forEach((entry) =>
- test(`testing with ${entry}`, () =>
- expectToThrow(
- // @ts-expect-error
- () => getDefaultCrfForCodec(entry),
- new RegExp(`Got unexpected codec "${entry}"`)
- ))
- );
-});
-
-describe("crf tests getValidCrfRanges valid input", () => {
- // input crf, input codec, valid range
- const validInputs: [Codec, [number, number]][] = [
- ["h264", [1, 51]],
- ["h265", [0, 51]],
- ["vp8", [4, 63]],
- ["vp9", [0, 63]],
- ["mp3", [0, 0]],
- ["aac", [0, 0]],
- ["wav", [0, 0]],
- ] as [Codec, [number, number]][];
- validInputs.forEach((entry) =>
- test(`valid range for ${entry[0]} should be [${entry[1]}]`, () =>
- expect(getValidCrfRanges(entry[0])).toEqual(entry[1]))
- );
-});
-
-describe("crf tests getValidCrfRanges invalid input", () => {
- // input codec
- const invalidInputs = ["abc", "", 3, undefined];
- invalidInputs.forEach((entry) =>
- test(`testing with "${entry}"`, () =>
- expectToThrow(
- // @ts-expect-error
- () => getValidCrfRanges(entry),
- new RegExp(`Got unexpected codec "${entry}"`)
- ))
- );
-});
-
-describe("validateSelectedCrfAndCodecCombination valid input", () => {
- // input crf, input codec
- const validInputs: [number, Codec][] = [
- [20, "h264"],
- [1, "h264"],
- [51, "h264"],
- [20, "h265"],
- [0, "h265"],
- [51, "h265"],
- [20, "vp8"],
- [4, "vp8"],
- [63, "vp8"],
- [20, "vp9"],
- [0, "vp9"],
- [63, "vp9"],
- ] as [number, Codec][];
- validInputs.forEach((entry) =>
- test(`validate with crf ${entry[0]} and codec ${entry[1]}`, () =>
- expect(() =>
- validateSelectedCrfAndCodecCombination(entry[0], entry[1])
- ).not.toThrow())
- );
-});
-
-describe("validateSelectedCrfAndCodecCombination invalid input", () => {
- // input crf, input codec, valid range
- const invalidInputs: [number, Codec, [number, number]][] = [
- [80, "h264", [1, 51]],
- [-1, "h264", [1, 51]],
- [52, "h264", [1, 51]],
- [80, "h265", [0, 51]],
- [-1, "h265", [0, 51]],
- [52, "h265", [0, 51]],
- [80, "vp8", [4, 63]],
- [3, "vp8", [4, 63]],
- [64, "vp8", [4, 63]],
- [80, "vp9", [0, 63]],
- [-1, "vp9", [0, 63]],
- [64, "vp9", [0, 63]],
- ] as [number, Codec, [number, number]][];
- invalidInputs.forEach((entry) =>
- test(`validate with crf ${entry[0]} and codec ${entry[1]}`, () =>
- expectToThrow(
- () => validateSelectedCrfAndCodecCombination(entry[0], entry[1]),
- new RegExp(
- `CRF must be between ${entry[2][0]} and ${entry[2][1]} for codec ${entry[1]}. Passed: ${entry[0]}`
- )
- ))
- );
-});
-
-describe("get crf valid input", () => {
- // input crf, input codec, output crf
- const validInputs: [number | undefined, Codec, number][] = [
- [20, "h264", 20],
- [undefined, "h264", 18],
- [20, "h265", 20],
- [undefined, "h265", 23],
- [20, "vp8", 20],
- [undefined, "vp8", 9],
- [20, "vp9", 20],
- [undefined, "vp9", 28],
- ] as [number | undefined, Codec, number][];
- validInputs.forEach((entry) =>
- test(`test with crf ${entry[0]} and codec ${entry[1]}`, () => {
- setCrf(entry[0]);
- expect(getActualCrf(entry[1])).toEqual(entry[2]);
- })
- );
-});
-
-describe("get crf invalid input", () => {
- // input crf, input codec, valid range
- const invalidInputs: [number, Codec, [number, number]][] = [
- [80, "h264", [1, 51]],
- [80, "h265", [0, 51]],
- [80, "vp8", [4, 63]],
- [80, "vp9", [0, 63]],
- ] as [number, Codec, [number, number]][];
- invalidInputs.forEach((entry) =>
- test(`test for ${entry[1]}`, () => {
- setCrf(entry[0]);
- expectToThrow(
- () => getActualCrf(entry[1]),
- new RegExp(
- `CRF must be between ${entry[2][0]} and ${entry[2][1]} for codec ${entry[1]}. Passed: ${entry[0]}`
- )
- );
- })
- );
-});
-
-describe("set crf invalid input", () => {
- const invalidInputs = [null, "abc"];
- invalidInputs.forEach((entry) =>
- test(`test for ${entry}`, () =>
- expectToThrow(
- // @ts-expect-error
- () => setCrf(entry),
- /The CRF must be a number or undefined/
- ))
- );
+import {Codec} from '@remotion/renderer';
+import {describe, expect, test} from 'vitest';
+import {getActualCrf, setCrf} from '../config/crf';
+import {expectToThrow} from './expect-to-throw';
+
+describe('get crf valid input', () => {
+ // input crf, input codec, output crf
+ const validInputs: [number | undefined, Codec, number][] = [
+ [20, 'h264', 20],
+ [undefined, 'h264', 18],
+ [20, 'h265', 20],
+ [undefined, 'h265', 23],
+ [20, 'vp8', 20],
+ [undefined, 'vp8', 9],
+ [20, 'vp9', 20],
+ [undefined, 'vp9', 28],
+ ] as [number | undefined, Codec, number][];
+ validInputs.forEach((entry) =>
+ test(`test with crf ${entry[0]} and codec ${entry[1]}`, () => {
+ setCrf(entry[0]);
+ expect(getActualCrf(entry[1])).toEqual(entry[2]);
+ })
+ );
+});
+
+describe('get crf invalid input', () => {
+ // input crf, input codec, valid range
+ const invalidInputs: [number, Codec, [number, number]][] = [
+ [80, 'h264', [1, 51]],
+ [80, 'h265', [0, 51]],
+ [80, 'vp8', [4, 63]],
+ [80, 'vp9', [0, 63]],
+ ] as [number, Codec, [number, number]][];
+ invalidInputs.forEach((entry) =>
+ test(`test for ${entry[1]}`, () => {
+ setCrf(entry[0]);
+ expectToThrow(
+ () => getActualCrf(entry[1]),
+ new RegExp(
+ `CRF must be between ${entry[2][0]} and ${entry[2][1]} for codec ${entry[1]}. Passed: ${entry[0]}`
+ )
+ );
+ })
+ );
+});
+
+describe('set crf invalid input', () => {
+ const invalidInputs = [null, 'abc'];
+ invalidInputs.forEach((entry) =>
+ test(`test for ${entry}`, () =>
+ expectToThrow(
+ // @ts-expect-error
+ () => setCrf(entry),
+ /The CRF must be a number or undefined/
+ ))
+ );
});
diff --git a/packages/config/src/test/expect-to-throw.ts b/packages/config/src/test/expect-to-throw.ts
index 6d40912130..2a31ce7377 100644
--- a/packages/config/src/test/expect-to-throw.ts
+++ b/packages/config/src/test/expect-to-throw.ts
@@ -1,14 +1,14 @@
-import { expect, vitest } from "vitest";
+import {expect, vitest} from 'vitest';
export const expectToThrow = (func: Function, err: RegExp) => {
- // Even though the error is caught, it still gets printed to the console
- // so we mock that out to avoid the wall of red text.
- vitest.spyOn(console, "error");
- // @ts-expect-error
- console.error.mockImplementation(() => undefined);
+ // Even though the error is caught, it still gets printed to the console
+ // so we mock that out to avoid the wall of red text.
+ vitest.spyOn(console, 'error');
+ // @ts-expect-error
+ console.error.mockImplementation(() => undefined);
- expect(func).toThrow(err);
+ expect(func).toThrow(err);
- // @ts-expect-error
- console.error.mockRestore();
+ // @ts-expect-error
+ console.error.mockRestore();
};
diff --git a/packages/config/src/test/image-sequence.test.ts b/packages/config/src/test/image-sequence.test.ts
index d6a0ebe77a..4c6b2c9dfd 100644
--- a/packages/config/src/test/image-sequence.test.ts
+++ b/packages/config/src/test/image-sequence.test.ts
@@ -1,37 +1,37 @@
-import { afterEach, beforeAll, expect, test } from "vitest";
+import {afterEach, beforeAll, expect, test} from 'vitest';
import {
- getShouldOutputImageSequence,
- setImageSequence,
-} from "../config/image-sequence";
-import { expectToThrow } from "./expect-to-throw";
+ getShouldOutputImageSequence,
+ setImageSequence,
+} from '../config/image-sequence';
+import {expectToThrow} from './expect-to-throw';
-const invalidImageSequence: String = "invalidImageSequence";
+const invalidImageSequence: String = 'invalidImageSequence';
let defaultImageSequence: boolean;
beforeAll(() => {
- defaultImageSequence = getShouldOutputImageSequence(null);
+ defaultImageSequence = getShouldOutputImageSequence(null);
});
afterEach(() => {
- setImageSequence(defaultImageSequence);
+ setImageSequence(defaultImageSequence);
});
-test("setImageSequence should throw if image sequence is not a boolean value", () => {
- expectToThrow(
- () =>
- // @ts-expect-error
- setImageSequence(invalidImageSequence),
- /setImageSequence accepts a Boolean Value/
- );
+test('setImageSequence should throw if image sequence is not a boolean value', () => {
+ expectToThrow(
+ () =>
+ // @ts-expect-error
+ setImageSequence(invalidImageSequence),
+ /setImageSequence accepts a Boolean Value/
+ );
});
-test("setImageSequence should NOT throw if image sequence is a boolean value", () => {
- expect(() => setImageSequence(true)).not.toThrow();
+test('setImageSequence should NOT throw if image sequence is a boolean value', () => {
+ expect(() => setImageSequence(true)).not.toThrow();
});
-test("getShouldOutputImageSequence should return false by default", () => {
- expect(getShouldOutputImageSequence(null)).toEqual(false);
+test('getShouldOutputImageSequence should return false by default', () => {
+ expect(getShouldOutputImageSequence(null)).toEqual(false);
});
-test("getShouldOutputImageSequence should return true if a single frame number is passed", () => {
- expect(getShouldOutputImageSequence(1)).toEqual(true);
+test('getShouldOutputImageSequence should return true if a single frame number is passed', () => {
+ expect(getShouldOutputImageSequence(1)).toEqual(true);
});
-test("getShouldOutputImageSequence should return true", () => {
- setImageSequence(true);
- expect(getShouldOutputImageSequence(null)).toEqual(true);
+test('getShouldOutputImageSequence should return true', () => {
+ setImageSequence(true);
+ expect(getShouldOutputImageSequence(null)).toEqual(true);
});
diff --git a/packages/config/src/test/log.test.ts b/packages/config/src/test/log.test.ts
index 7fd273936f..8fb2f8583d 100644
--- a/packages/config/src/test/log.test.ts
+++ b/packages/config/src/test/log.test.ts
@@ -1,65 +1,65 @@
-import { describe, expect, test } from "vitest";
-import type { LogLevel } from "../config/log";
+import {describe, expect, test} from 'vitest';
+import type {LogLevel} from '../config/log';
import {
- getLogLevel,
- isEqualOrBelowLogLevel,
- isValidLogLevel,
- setLogLevel,
-} from "../config/log";
-describe("test loglevel getter and setter", () => {
- test("default log level", () => {
- expect(getLogLevel()).toEqual("info");
- });
- test.each<LogLevel>(["verbose", "warn", "error", "info"])(
- "test for %s",
- (loglevel) => {
- setLogLevel(loglevel);
- expect(getLogLevel()).toEqual(loglevel);
- }
- );
+ getLogLevel,
+ isEqualOrBelowLogLevel,
+ isValidLogLevel,
+ setLogLevel,
+} from '../config/log';
+describe('test loglevel getter and setter', () => {
+ test('default log level', () => {
+ expect(getLogLevel()).toEqual('info');
+ });
+ test.each<LogLevel>(['verbose', 'warn', 'error', 'info'])(
+ 'test for %s',
+ (loglevel) => {
+ setLogLevel(loglevel);
+ expect(getLogLevel()).toEqual(loglevel);
+ }
+ );
});
-describe("loglevel validity", () => {
- test.each<string>(["abc", "aalsadj", ""])(
- "is %s an invalid level",
- (level) => {
- expect(isValidLogLevel(level)).toEqual(false);
- }
- );
- test.each<string | LogLevel>(["verbose", "info", "warn", "error"])(
- "is %s a valid level",
- (level) => {
- expect(isValidLogLevel(level)).toEqual(true);
- }
- );
+describe('loglevel validity', () => {
+ test.each<string>(['abc', 'aalsadj', ''])(
+ 'is %s an invalid level',
+ (level) => {
+ expect(isValidLogLevel(level)).toEqual(false);
+ }
+ );
+ test.each<string | LogLevel>(['verbose', 'info', 'warn', 'error'])(
+ 'is %s a valid level',
+ (level) => {
+ expect(isValidLogLevel(level)).toEqual(true);
+ }
+ );
});
-describe("loglevel comparison", () => {
- test.each<[LogLevel, LogLevel]>([
- ["verbose", "verbose"],
- ["verbose", "info"],
- ["verbose", "warn"],
- ["verbose", "error"],
- ["info", "info"],
- ["info", "warn"],
- ["info", "error"],
- ["warn", "warn"],
- ["warn", "error"],
- ["error", "error"],
- ])("%s is equal or below %s", (level1, level2) => {
- setLogLevel(level1);
- expect(isEqualOrBelowLogLevel(getLogLevel(), level2)).toEqual(true);
- });
+describe('loglevel comparison', () => {
+ test.each<[LogLevel, LogLevel]>([
+ ['verbose', 'verbose'],
+ ['verbose', 'info'],
+ ['verbose', 'warn'],
+ ['verbose', 'error'],
+ ['info', 'info'],
+ ['info', 'warn'],
+ ['info', 'error'],
+ ['warn', 'warn'],
+ ['warn', 'error'],
+ ['error', 'error'],
+ ])('%s is equal or below %s', (level1, level2) => {
+ setLogLevel(level1);
+ expect(isEqualOrBelowLogLevel(getLogLevel(), level2)).toEqual(true);
+ });
- test.each<[LogLevel, LogLevel]>([
- ["info", "verbose"],
- ["warn", "verbose"],
- ["error", "verbose"],
- ["warn", "info"],
- ["error", "info"],
- ["error", "warn"],
- ])("%s is not equal or below %s", (level1, level2) => {
- setLogLevel(level1);
- expect(isEqualOrBelowLogLevel(getLogLevel(), level2)).toEqual(false);
- });
+ test.each<[LogLevel, LogLevel]>([
+ ['info', 'verbose'],
+ ['warn', 'verbose'],
+ ['error', 'verbose'],
+ ['warn', 'info'],
+ ['error', 'info'],
+ ['error', 'warn'],
+ ])('%s is not equal or below %s', (level1, level2) => {
+ setLogLevel(level1);
+ expect(isEqualOrBelowLogLevel(getLogLevel(), level2)).toEqual(false);
+ });
});
diff --git a/packages/config/src/test/overwrite.test.ts b/packages/config/src/test/overwrite.test.ts
index 8fe2375ff7..9d284f57e9 100644
--- a/packages/config/src/test/overwrite.test.ts
+++ b/packages/config/src/test/overwrite.test.ts
@@ -1,31 +1,31 @@
-import { afterEach, beforeAll, expect, test } from "vitest";
-import { getShouldOverwrite, setOverwriteOutput } from "../config/overwrite";
-import { expectToThrow } from "./expect-to-throw";
+import {afterEach, beforeAll, expect, test} from 'vitest';
+import {getShouldOverwrite, setOverwriteOutput} from '../config/overwrite';
+import {expectToThrow} from './expect-to-throw';
const invalidOverwrite = 555;
let defaultOverwriteValue: boolean;
beforeAll(() => {
- defaultOverwriteValue = getShouldOverwrite();
+ defaultOverwriteValue = getShouldOverwrite();
});
afterEach(() => {
- setOverwriteOutput(defaultOverwriteValue);
+ setOverwriteOutput(defaultOverwriteValue);
});
-test("setOverwriteOutput should throw if overwrite is not a boolean value", () => {
- expectToThrow(
- // @ts-expect-error
- () => setOverwriteOutput(invalidOverwrite),
- /overwriteExisting must be a boolean but got number [(]555[)]/
- );
+test('setOverwriteOutput should throw if overwrite is not a boolean value', () => {
+ expectToThrow(
+ // @ts-expect-error
+ () => setOverwriteOutput(invalidOverwrite),
+ /overwriteExisting must be a boolean but got number [(]555[)]/
+ );
});
-test("setOverwriteOutput should NOT throw if image format is a boolean value", () => {
- expect(() => setOverwriteOutput(true)).not.toThrow();
+test('setOverwriteOutput should NOT throw if image format is a boolean value', () => {
+ expect(() => setOverwriteOutput(true)).not.toThrow();
});
-test("getShouldOverwrite should return true by default", () => {
- expect(getShouldOverwrite()).toEqual(true);
+test('getShouldOverwrite should return true by default', () => {
+ expect(getShouldOverwrite()).toEqual(true);
});
-test("setOverwriteOutput should return a boolean value", () => {
- setOverwriteOutput(false);
- expect(getShouldOverwrite()).toEqual(false);
+test('setOverwriteOutput should return a boolean value', () => {
+ setOverwriteOutput(false);
+ expect(getShouldOverwrite()).toEqual(false);
});
diff --git a/packages/config/src/test/pixel-format.test.ts b/packages/config/src/test/pixel-format.test.ts
index cf7cc1d725..9660fbbf33 100644
--- a/packages/config/src/test/pixel-format.test.ts
+++ b/packages/config/src/test/pixel-format.test.ts
@@ -1,11 +1,6 @@
+import {PixelFormat} from '@remotion/renderer';
import {describe, expect, test} from 'vitest';
-import type {Codec} from '../config';
-import type {PixelFormat} from '../config/pixel-format';
-import {
- getPixelFormat,
- setPixelFormat,
- validateSelectedPixelFormatAndCodecCombination,
-} from '../config/pixel-format';
+import {getPixelFormat, setPixelFormat} from '../config/pixel-format';
import {expectToThrow} from './expect-to-throw';
describe('pixel-format tests setPixelFormat', () => {
@@ -37,52 +32,3 @@ describe('pixel-format tests setPixelFormat', () => {
))
);
});
-
-describe('pixel-format tests validateSelectedPixelFormatAndCodecCombination', () => {
- const formats: PixelFormat[] = [
- 'yuv420p',
- 'yuv422p',
- 'yuv444p',
- 'yuv420p10le',
- 'yuv422p10le',
- 'yuv444p10le',
- ];
-
- const codecs: Codec[] = ['h264', 'h265', 'vp8', 'vp9'];
-
- for (const format of formats) {
- for (const codec of codecs) {
- test(`test for valid combination ${format} and ${codec}`, () => {
- expect(() =>
- validateSelectedPixelFormatAndCodecCombination(format, codec)
- ).not.toThrow();
- });
- }
- }
-
- const invalidCodecs: Codec[] = ['h264', 'h265'];
- invalidCodecs.forEach((entry) =>
- test(`test for invalid combination yuva420p and ${entry}`, () =>
- expectToThrow(
- () => validateSelectedPixelFormatAndCodecCombination('yuva420p', entry),
- /Pixel format was set to 'yuva420p' but codec is not 'vp8' or 'vp9'. To render videos with alpha channel, you must choose a codec that supports it./
- ))
- );
- const validCodecs: Codec[] = ['vp8', 'vp9'];
- validCodecs.forEach((c) =>
- test(`test for valid combination yuva420p and ${c}`, () =>
- expect(() =>
- validateSelectedPixelFormatAndCodecCombination('yuva420p', c)
- ).not.toThrow())
- );
-
- const invalidFormats = ['abc', '', 3];
- invalidFormats.forEach((entry) =>
- test(`test for invalid input "${entry}"`, () =>
- expectToThrow(
- // @ts-expect-error
- () => validateSelectedPixelFormatAndCodecCombination(entry, 'h264'),
- new RegExp(`Value ${entry} is not valid as a pixel format.`)
- ))
- );
-});
diff --git a/packages/config/src/test/pro-res-profile.test.ts b/packages/config/src/test/pro-res-profile.test.ts
deleted file mode 100644
index 0ac4ce73fe..0000000000
--- a/packages/config/src/test/pro-res-profile.test.ts
+++ /dev/null
@@ -1,38 +0,0 @@
-import {describe, expect, test} from 'vitest';
-import type {ProResProfile} from '../config/prores-profile';
-import {
- getProResProfile,
- setProResProfile,
- validateSelectedCodecAndProResCombination,
-} from '../config/prores-profile';
-import {expectToThrow} from './expect-to-throw';
-
-describe('Pro Res Profile', () => {
- const validProResProfile: ProResProfile = 'standard';
-
- test('Should be able to set a ProRes profile', () => {
- setProResProfile(validProResProfile);
- expect(getProResProfile()).toBe(validProResProfile);
- });
-
- test("Just a ProRes profile is not enough, because codec doesn't default to ProRes", () => {
- expectToThrow(() => {
- validateSelectedCodecAndProResCombination('aac', '4444-xq');
- }, /You have set a ProRes profile but the codec is not "prores". Set the codec to "prores" or remove the ProRes profile./);
- });
-
- test('Should accept a valid codec and ProRes combination', () => {
- expect(validateSelectedCodecAndProResCombination('prores', '4444')).toBe(
- undefined
- );
- });
-
- test('Should throw on invalid ProRes name', () => {
- expectToThrow(
- () =>
- // @ts-expect-error
- validateSelectedCodecAndProResCombination('prores', 'typoed'),
- /The ProRes profile "typoed" is not valid. Valid options are "4444-xq", "4444", "hq", "standard", "light", "proxy"/
- );
- });
-});
diff --git a/packages/config/src/test/range.test.tsx b/packages/config/src/test/range.test.tsx
index 3634125134..4511291dc4 100644
--- a/packages/config/src/test/range.test.tsx
+++ b/packages/config/src/test/range.test.tsx
@@ -1,102 +1,102 @@
-import { describe, expect, test } from "vitest";
+import {describe, expect, test} from 'vitest';
import {
- getRange,
- setFrameRange,
- setFrameRangeFromCli,
-} from "../config/frame-range";
-import { expectToThrow } from "./expect-to-throw";
+ getRange,
+ setFrameRange,
+ setFrameRangeFromCli,
+} from '../config/frame-range';
+import {expectToThrow} from './expect-to-throw';
-describe("Frame range should throw exception with invalid inputs", () => {
- const testValues: [number | [number, number] | null, RegExp][] = [
- [-1, /non-negative/],
- [1.111, /Frame must be an integer, but got a float \(1.111\)/],
- [Infinity, /finite number, got Infinity/],
- // @ts-expect-error
- [[0, 2, 4], /Frame range must be a tuple, got an array with length 3/],
- // @ts-expect-error
- [[], /Frame range must be a tuple, got an array with length 0/],
- [
- // @ts-expect-error
- ["0", 2],
- /Each value of frame range must be a number, but got string \("0"\)/,
- ],
- [
- [0.111, 2],
- /Each value of frame range must be an integer, but got a float \(0.111\)/,
- ],
- [
- [0, Infinity],
- /Each value of frame range must be finite, but got Infinity/,
- ],
- [[-1, 0], /Each value of frame range must be non-negative, but got -1/],
- [
- [10, 0],
- /The second value of frame range must be not smaller than the first one, but got 10-0/,
- ],
- [
- // @ts-expect-error
- "10",
- /Frame range must be a number or a tuple of numbers, but got object of type string/,
- ],
- ];
+describe('Frame range should throw exception with invalid inputs', () => {
+ const testValues: [number | [number, number] | null, RegExp][] = [
+ [-1, /non-negative/],
+ [1.111, /Frame must be an integer, but got a float \(1.111\)/],
+ [Infinity, /finite number, got Infinity/],
+ // @ts-expect-error
+ [[0, 2, 4], /Frame range must be a tuple, got an array with length 3/],
+ // @ts-expect-error
+ [[], /Frame range must be a tuple, got an array with length 0/],
+ [
+ // @ts-expect-error
+ ['0', 2],
+ /Each value of frame range must be a number, but got string \("0"\)/,
+ ],
+ [
+ [0.111, 2],
+ /Each value of frame range must be an integer, but got a float \(0.111\)/,
+ ],
+ [
+ [0, Infinity],
+ /Each value of frame range must be finite, but got Infinity/,
+ ],
+ [[-1, 0], /Each value of frame range must be non-negative, but got -1/],
+ [
+ [10, 0],
+ /The second value of frame range must be not smaller than the first one, but got 10-0/,
+ ],
+ [
+ // @ts-expect-error
+ '10',
+ /Frame range must be a number or a tuple of numbers, but got object of type string/,
+ ],
+ ];
- testValues.forEach((entry) =>
- test(`test with input ${JSON.stringify(entry[0])}`, () =>
- expectToThrow(() => setFrameRange(entry[0]), entry[1]))
- );
+ testValues.forEach((entry) =>
+ test(`test with input ${JSON.stringify(entry[0])}`, () =>
+ expectToThrow(() => setFrameRange(entry[0]), entry[1]))
+ );
});
-describe("Frame range tests with valid inputs", () => {
- const testValues: (number | [number, number] | null)[] = [
- null,
- [10, 20],
- [10, 10],
- 10,
- 0,
- ];
- testValues.forEach((entry) =>
- test(`test with input ${entry}`, () => {
- setFrameRange(entry);
- expect(getRange()).toEqual(entry);
- })
- );
+describe('Frame range tests with valid inputs', () => {
+ const testValues: (number | [number, number] | null)[] = [
+ null,
+ [10, 20],
+ [10, 10],
+ 10,
+ 0,
+ ];
+ testValues.forEach((entry) =>
+ test(`test with input ${entry}`, () => {
+ setFrameRange(entry);
+ expect(getRange()).toEqual(entry);
+ })
+ );
});
-describe("Frame range CLI should throw exception with invalid inputs", () => {
- const testValues: [string, RegExp][] = [
- [
- "1-2-3",
- /--frames flag must be a number or 2 numbers separated by '-', instead got 3 numbers/,
- ],
- [
- "2-1",
- /The second number of the --frames flag number should be greater or equal than first number/,
- ],
- [
- "one-two",
- /--frames flag must be a single number, or 2 numbers separated by `-`/,
- ],
- [" ", /Frame range must be a tuple, got an array with length 1/],
- ["", /Frame range must be a tuple, got an array with length 1/],
- ];
- testValues.forEach((entry) =>
- test(`test with input ${entry[0]}`, () =>
- expectToThrow(() => setFrameRangeFromCli(entry[0]), entry[1]))
- );
+describe('Frame range CLI should throw exception with invalid inputs', () => {
+ const testValues: [string, RegExp][] = [
+ [
+ '1-2-3',
+ /--frames flag must be a number or 2 numbers separated by '-', instead got 3 numbers/,
+ ],
+ [
+ '2-1',
+ /The second number of the --frames flag number should be greater or equal than first number/,
+ ],
+ [
+ 'one-two',
+ /--frames flag must be a single number, or 2 numbers separated by `-`/,
+ ],
+ [' ', /Frame range must be a tuple, got an array with length 1/],
+ ['', /Frame range must be a tuple, got an array with length 1/],
+ ];
+ testValues.forEach((entry) =>
+ test(`test with input ${entry[0]}`, () =>
+ expectToThrow(() => setFrameRangeFromCli(entry[0]), entry[1]))
+ );
});
-describe("Frame range CLI tests with valid inputs", () => {
- setFrameRange(null);
+describe('Frame range CLI tests with valid inputs', () => {
+ setFrameRange(null);
- const testValues: [number | string, number | [number, number]][] = [
- [0, 0],
- [10, 10],
- ["1-10", [1, 10]],
- ["10-10", [10, 10]],
- ["-", [0, 0]],
- ];
- testValues.forEach((entry) =>
- test(`test with input ${entry[0]}`, () => {
- setFrameRangeFromCli(entry[0]);
- expect(getRange()).toEqual(entry[1]);
- })
- );
+ const testValues: [number | string, number | [number, number]][] = [
+ [0, 0],
+ [10, 10],
+ ['1-10', [1, 10]],
+ ['10-10', [10, 10]],
+ ['-', [0, 0]],
+ ];
+ testValues.forEach((entry) =>
+ test(`test with input ${entry[0]}`, () => {
+ setFrameRangeFromCli(entry[0]);
+ expect(getRange()).toEqual(entry[1]);
+ })
+ );
});
diff --git a/packages/config/src/test/validate-frame.test.ts b/packages/config/src/test/validate-frame.test.ts
deleted file mode 100644
index e8745f84a1..0000000000
--- a/packages/config/src/test/validate-frame.test.ts
+++ /dev/null
@@ -1,26 +0,0 @@
-import { expect, test } from "vitest";
-import { validateFrame } from "../validation/validate-frame";
-import { expectToThrow } from "./expect-to-throw";
-
-test("Validate frame", () => {
- expectToThrow(() => validateFrame(-1, 100), /Frame -1 cannot be negative/);
- expectToThrow(
- () => validateFrame(Infinity, 100),
- /Frame Infinity is not finite/
- );
- expectToThrow(
- // @ts-expect-error
- () => validateFrame("hithere", 100),
- /Argument passed for "frame" is not a number: hithere/
- );
- expectToThrow(
- () => validateFrame(3, 1),
- /Cannot use frame 3: Duration of composition is 1, therefore the highest frame that can be rendered is 0/
- );
- expectToThrow(
- () => validateFrame(2.99, 10),
- /Argument for frame must be an integer, but got 2.99/
- );
- expect(() => validateFrame(0, 1)).not.toThrow();
- expect(() => validateFrame(1, 2)).not.toThrow();
-});
diff --git a/packages/config/src/test/validate-image-format.test.ts b/packages/config/src/test/validate-image-format.test.ts
deleted file mode 100644
index 4a6dfc8e4d..0000000000
--- a/packages/config/src/test/validate-image-format.test.ts
+++ /dev/null
@@ -1,10 +0,0 @@
-import { expect, test } from "vitest";
-import { validateNonNullImageFormat } from "../validation/validate-image-format";
-
-test('"none" is not a valid image format', () => {
- expect(() => validateNonNullImageFormat("jpeg")).not.toThrow();
- expect(() => validateNonNullImageFormat("png")).not.toThrow();
- expect(() => validateNonNullImageFormat("none")).toThrow(
- /Image format should be either "png" or "jpeg"/
- );
-});
diff --git a/packages/config/src/test/webpack-caching.test.ts b/packages/config/src/test/webpack-caching.test.ts
index 83075e7944..3fc6b781ab 100644
--- a/packages/config/src/test/webpack-caching.test.ts
+++ b/packages/config/src/test/webpack-caching.test.ts
@@ -1,29 +1,29 @@
-import { expect, test } from "vitest";
+import {expect, test} from 'vitest';
import {
- DEFAULT_WEBPACK_CACHE_ENABLED,
- getWebpackCaching,
- setWebpackCaching,
-} from "../config/webpack-caching";
-import { expectToThrow } from "./expect-to-throw";
+ DEFAULT_WEBPACK_CACHE_ENABLED,
+ getWebpackCaching,
+ setWebpackCaching,
+} from '../config/webpack-caching';
+import {expectToThrow} from './expect-to-throw';
-test("getWebpackCaching - default value", () => {
- expect(getWebpackCaching()).toEqual(DEFAULT_WEBPACK_CACHE_ENABLED);
+test('getWebpackCaching - default value', () => {
+ expect(getWebpackCaching()).toEqual(DEFAULT_WEBPACK_CACHE_ENABLED);
});
-test("webpack caching - setter - valid input", () => {
- const valuesToTest = [true, false];
- valuesToTest.forEach((entry) => {
- setWebpackCaching(entry);
- expect(getWebpackCaching()).toEqual(entry);
- });
+test('webpack caching - setter - valid input', () => {
+ const valuesToTest = [true, false];
+ valuesToTest.forEach((entry) => {
+ setWebpackCaching(entry);
+ expect(getWebpackCaching()).toEqual(entry);
+ });
});
-test("webpack caching - setter - invalid input", () => {
- const valuesToTest = [undefined, "true", "false"];
- valuesToTest.forEach((entry) => {
- expectToThrow(() => {
- // @ts-expect-error
- setWebpackCaching(entry);
- }, /Caching flag must be a boolean./);
- });
+test('webpack caching - setter - invalid input', () => {
+ const valuesToTest = [undefined, 'true', 'false'];
+ valuesToTest.forEach((entry) => {
+ expectToThrow(() => {
+ // @ts-expect-error
+ setWebpackCaching(entry);
+ }, /Caching flag must be a boolean./);
+ });
});
diff --git a/packages/renderer/src/codec.ts b/packages/renderer/src/codec.ts
index b5d3b3bd86..4c4045cb8e 100644
--- a/packages/renderer/src/codec.ts
+++ b/packages/renderer/src/codec.ts
@@ -1,4 +1,4 @@
-const validCodecs = [
+export const validCodecs = [
'h264',
'h265',
'vp8',
@@ -13,14 +13,6 @@ const validCodecs = [
export type Codec = typeof validCodecs[number];
export type CodecOrUndefined = Codec | undefined;
-const validLegacyFormats = ['mp4', 'png-sequence'] as const;
-type LegacyFormat = typeof validLegacyFormats[number];
-
-let codec: CodecOrUndefined;
-
-export const getOutputCodecOrUndefined = (): CodecOrUndefined => {
- return codec;
-};
export const DEFAULT_CODEC: Codec = 'h264';
@@ -123,47 +115,3 @@ export const getFinalOutputCodec = ({
return inputCodec ?? DEFAULT_CODEC;
};
-
-export const setOutputFormat = (newLegacyFormat: LegacyFormat) => {
- if (newLegacyFormat === undefined) {
- codec = undefined;
- return;
- }
-
- if (!validLegacyFormats.includes(newLegacyFormat)) {
- throw new Error(
- `Output format must be one of the following: ${validLegacyFormats.join(
- ', '
- )}, but got ${newLegacyFormat}`
- );
- }
-
- console.warn(
- 'setOutputFormat() is deprecated. Use the setCodec() and setImageSequence() instead.'
- );
- if (newLegacyFormat === 'mp4') {
- codec = 'h264';
- return;
- }
-
- if (newLegacyFormat === 'png-sequence') {
- codec = undefined;
- }
-};
-
-export const setCodec = (newCodec: CodecOrUndefined) => {
- if (newCodec === undefined) {
- codec = undefined;
- return;
- }
-
- if (!validCodecs.includes(newCodec)) {
- throw new Error(
- `Codec must be one of the following: ${validCodecs.join(
- ', '
- )}, but got ${newCodec}`
- );
- }
-
- codec = newCodec;
-};
diff --git a/packages/renderer/src/image-format.ts b/packages/renderer/src/image-format.ts
index 413eed1cff..1530caf669 100644
--- a/packages/renderer/src/image-format.ts
+++ b/packages/renderer/src/image-format.ts
@@ -3,7 +3,7 @@
import type {PixelFormat} from './pixel-format';
-const validImageFormats = ['png', 'jpeg', 'none'] as const;
+export const validImageFormats = ['png', 'jpeg', 'none'] as const;
export type ImageFormat = typeof validImageFormats[number];
diff --git a/packages/renderer/src/index.ts b/packages/renderer/src/index.ts
index 2fcca5c03a..85219216a2 100644
--- a/packages/renderer/src/index.ts
+++ b/packages/renderer/src/index.ts
@@ -1,7 +1,14 @@
import execa from 'execa';
import {downloadFile} from './assets/download-file';
import {DEFAULT_BROWSER} from './browser';
+import {DEFAULT_TIMEOUT} from './browser/TimeoutSettings';
import {canUseParallelEncoding} from './can-use-parallel-encoding';
+import {getFinalOutputCodec, validCodecs} from './codec';
+import {
+ getDefaultCrfForCodec,
+ getValidCrfRanges,
+ validateSelectedCrfAndCodecCombination,
+} from './crf';
import {deleteDirectory} from './delete-directory';
import {ensureOutputDirectory} from './ensure-output-directory';
import {symbolicateError} from './error-handling/symbolicate-error';
@@ -19,12 +26,15 @@ import {getExtensionOfFilename} from './get-extension-of-filename';
import {getRealFrameRange} from './get-frame-to-render';
import {ensureLocalBrowser} from './get-local-browser-executable';
import {getDesiredPort} from './get-port';
+import {validImageFormats} from './image-format';
import {isServeUrl} from './is-serve-url';
import {mimeContentType, mimeLookup} from './mime-types';
import {normalizeServeUrl} from './normalize-serve-url';
import {killAllBrowsers} from './open-browser';
+import {DEFAULT_OVERWRITE} from './overwrite';
import {parseStack} from './parse-browser-error-stack';
-import {validPixelFormats} from './pixel-format';
+import {DEFAULT_PIXEL_FORMAT, validPixelFormats} from './pixel-format';
+import {validateQuality} from './quality';
import {isPathInside} from './serve-handler/is-path-inside';
import {serveStatic} from './serve-static';
import {spawnFfmpeg} from './stitch-frames-to-video';
@@ -32,6 +42,11 @@ import {tmpDir} from './tmp-dir';
import {validateConcurrency} from './validate-concurrency';
import {validateEvenDimensionsWithCodec} from './validate-even-dimensions-with-codec';
import {binaryExists, validateFfmpeg} from './validate-ffmpeg';
+import {validateFrame} from './validate-frame';
+import {
+ DEFAULT_OPENGL_RENDERER,
+ validateOpenGlRenderer,
+} from './validate-opengl-renderer';
import {validatePuppeteerTimeout} from './validate-puppeteer-timeout';
import {validateScale} from './validate-scale';
import {
@@ -42,17 +57,20 @@ export type {RenderMediaOnDownload} from './assets/download-and-map-assets-to-fi
export {Browser} from './browser';
export {BrowserExecutable} from './browser-executable';
export {BrowserLog} from './browser-log';
-export {Codec} from './codec';
+export {Codec, CodecOrUndefined} from './codec';
export {combineVideos} from './combine-videos';
+export {Crf} from './crf';
export {ErrorWithStackFrame} from './error-handling/handle-javascript-exception';
export {FfmpegExecutable} from './ffmpeg-executable';
export {FfmpegVersion} from './ffmpeg-flags';
export {FrameRange} from './frame-range';
export {getCompositions} from './get-compositions';
+export {ImageFormat} from './image-format';
export {CancelSignal, makeCancelSignal} from './make-cancel-signal';
export {openBrowser} from './open-browser';
export type {ChromiumOptions} from './open-browser';
export {PixelFormat} from './pixel-format';
+export {ProResProfile} from './prores-profile';
export {renderFrames} from './render-frames';
export {
renderMedia,
@@ -64,6 +82,8 @@ export {renderStill} from './render-still';
export {StitcherOptions, stitchFramesToVideo} from './stitch-frames-to-video';
export {SymbolicatedStackFrame} from './symbolicate-stacktrace';
export {OnStartData, RenderFramesOutput} from './types';
+export {OpenGlRenderer} from './validate-opengl-renderer';
+
export const RenderInternals = {
ensureLocalBrowser,
ffmpegHasFeature,
@@ -103,4 +123,17 @@ export const RenderInternals = {
validPixelFormats,
DEFAULT_BROWSER,
validateFrameRange,
+ DEFAULT_OPENGL_RENDERER,
+ validateOpenGlRenderer,
+ getDefaultCrfForCodec,
+ validateSelectedCrfAndCodecCombination,
+ validImageFormats,
+ validCodecs,
+ DEFAULT_OVERWRITE,
+ DEFAULT_PIXEL_FORMAT,
+ validateQuality,
+ validateFrame,
+ DEFAULT_TIMEOUT,
+ getFinalOutputCodec,
+ getValidCrfRanges,
};
diff --git a/packages/renderer/src/test/crf.test.ts b/packages/renderer/src/test/crf.test.ts
new file mode 100644
index 0000000000..c947db9e63
--- /dev/null
+++ b/packages/renderer/src/test/crf.test.ts
@@ -0,0 +1,117 @@
+import {describe, expect, test} from 'vitest';
+import type {Codec} from '../codec';
+import {
+ getDefaultCrfForCodec,
+ getValidCrfRanges,
+ validateSelectedCrfAndCodecCombination,
+} from '../crf';
+
+describe('crf tests getValidCrfRanges valid input', () => {
+ // input crf, input codec, valid range
+ const validInputs: [Codec, [number, number]][] = [
+ ['h264', [1, 51]],
+ ['h265', [0, 51]],
+ ['vp8', [4, 63]],
+ ['vp9', [0, 63]],
+ ['mp3', [0, 0]],
+ ['aac', [0, 0]],
+ ['wav', [0, 0]],
+ ] as [Codec, [number, number]][];
+ validInputs.forEach((entry) =>
+ test(`valid range for ${entry[0]} should be [${entry[1]}]`, () =>
+ expect(getValidCrfRanges(entry[0])).toEqual(entry[1]))
+ );
+});
+
+describe('validateSelectedCrfAndCodecCombination valid input', () => {
+ // input crf, input codec
+ const validInputs: [number, Codec][] = [
+ [20, 'h264'],
+ [1, 'h264'],
+ [51, 'h264'],
+ [20, 'h265'],
+ [0, 'h265'],
+ [51, 'h265'],
+ [20, 'vp8'],
+ [4, 'vp8'],
+ [63, 'vp8'],
+ [20, 'vp9'],
+ [0, 'vp9'],
+ [63, 'vp9'],
+ ] as [number, Codec][];
+ validInputs.forEach((entry) =>
+ test(`validate with crf ${entry[0]} and codec ${entry[1]}`, () =>
+ expect(() =>
+ validateSelectedCrfAndCodecCombination(entry[0], entry[1])
+ ).not.toThrow())
+ );
+});
+
+describe('validateSelectedCrfAndCodecCombination invalid input', () => {
+ // input crf, input codec, valid range
+ const invalidInputs: [number, Codec, [number, number]][] = [
+ [80, 'h264', [1, 51]],
+ [-1, 'h264', [1, 51]],
+ [52, 'h264', [1, 51]],
+ [80, 'h265', [0, 51]],
+ [-1, 'h265', [0, 51]],
+ [52, 'h265', [0, 51]],
+ [80, 'vp8', [4, 63]],
+ [3, 'vp8', [4, 63]],
+ [64, 'vp8', [4, 63]],
+ [80, 'vp9', [0, 63]],
+ [-1, 'vp9', [0, 63]],
+ [64, 'vp9', [0, 63]],
+ ] as [number, Codec, [number, number]][];
+ invalidInputs.forEach((entry) =>
+ test(`validate with crf ${entry[0]} and codec ${entry[1]}`, () =>
+ expect(() =>
+ validateSelectedCrfAndCodecCombination(entry[0], entry[1])
+ ).toThrow(
+ new RegExp(
+ `CRF must be between ${entry[2][0]} and ${entry[2][1]} for codec ${entry[1]}. Passed: ${entry[0]}`
+ )
+ ))
+ );
+});
+
+describe('crf tests getValidCrfRanges invalid input', () => {
+ // input codec
+ const invalidInputs = ['abc', '', 3, undefined];
+ invalidInputs.forEach((entry) =>
+ test(`testing with "${entry}"`, () =>
+ expect(
+ // @ts-expect-error
+ () => getValidCrfRanges(entry)
+ ).toThrow(new RegExp(`Got unexpected codec "${entry}"`)))
+ );
+});
+
+describe('crf tests getDefaultCrfForCodec valid input', () => {
+ // input codec, output
+ const validCodecIOs: [Codec, number][] = [
+ ['h264', 18],
+ ['h265', 23],
+ ['vp8', 9],
+ ['vp9', 28],
+ ['mp3', 0],
+ ['aac', 0],
+ ['wav', 0],
+ ] as [Codec, number][];
+ validCodecIOs.forEach((entry) =>
+ test(`default for ${entry[0]} should be ${entry[1]}`, () =>
+ expect(getDefaultCrfForCodec(entry[0])).toEqual(entry[1]))
+ );
+});
+
+describe('crf tests getDefaultCrfForCodec invalid input', () => {
+ // input codec
+ const invalidCodecs = ['abc', '', 3, undefined];
+ invalidCodecs.forEach((entry) =>
+ test(`testing with ${entry}`, () =>
+ expect(
+ // @ts-expect-error
+ () => getDefaultCrfForCodec(entry)
+ ).toThrow(new RegExp(`Got unexpected codec "${entry}"`)))
+ );
+});
diff --git a/packages/renderer/src/test/frame.test.ts b/packages/renderer/src/test/frame.test.ts
new file mode 100644
index 0000000000..60380d91e3
--- /dev/null
+++ b/packages/renderer/src/test/frame.test.ts
@@ -0,0 +1,21 @@
+import {expect, test} from 'vitest';
+import {validateFrame} from '../validate-frame';
+
+test('Validate frame', () => {
+ expect(() => validateFrame(-1, 100)).toThrow(/Frame -1 cannot be negative/);
+ expect(() => validateFrame(Infinity, 100)).toThrow(
+ /Frame Infinity is not finite/
+ );
+ expect(
+ // @ts-expect-error
+ () => validateFrame('hithere', 100)
+ ).toThrow(/Argument passed for "frame" is not a number: hithere/);
+ expect(() => validateFrame(3, 1)).toThrow(
+ /Cannot use frame 3: Duration of composition is 1, therefore the highest frame that can be rendered is 0/
+ );
+ expect(() => validateFrame(2.99, 10)).toThrow(
+ /Argument for frame must be an integer, but got 2.99/
+ );
+ expect(() => validateFrame(0, 1)).not.toThrow();
+ expect(() => validateFrame(1, 2)).not.toThrow();
+});
diff --git a/packages/renderer/src/test/pixel-format.test.ts b/packages/renderer/src/test/pixel-format.test.ts
new file mode 100644
index 0000000000..0aeb5a18f6
--- /dev/null
+++ b/packages/renderer/src/test/pixel-format.test.ts
@@ -0,0 +1,53 @@
+import {describe, expect, test} from 'vitest';
+import type {Codec} from '../codec';
+import type {PixelFormat} from '../pixel-format';
+import {validateSelectedPixelFormatAndCodecCombination} from '../pixel-format';
+
+describe('pixel-format tests validateSelectedPixelFormatAndCodecCombination', () => {
+ const formats: PixelFormat[] = [
+ 'yuv420p',
+ 'yuv422p',
+ 'yuv444p',
+ 'yuv420p10le',
+ 'yuv422p10le',
+ 'yuv444p10le',
+ ];
+
+ const codecs: Codec[] = ['h264', 'h265', 'vp8', 'vp9'];
+
+ for (const format of formats) {
+ for (const codec of codecs) {
+ test(`test for valid combination ${format} and ${codec}`, () => {
+ expect(() =>
+ validateSelectedPixelFormatAndCodecCombination(format, codec)
+ ).not.toThrow();
+ });
+ }
+ }
+
+ const invalidCodecs: Codec[] = ['h264', 'h265'];
+ invalidCodecs.forEach((entry) =>
+ test(`test for invalid combination yuva420p and ${entry}`, () =>
+ expect(() =>
+ validateSelectedPixelFormatAndCodecCombination('yuva420p', entry)
+ ).toThrow(
+ /Pixel format was set to 'yuva420p' but codec is not 'vp8' or 'vp9'. To render videos with alpha channel, you must choose a codec that supports it./
+ ))
+ );
+ const validCodecs: Codec[] = ['vp8', 'vp9'];
+ validCodecs.forEach((c) =>
+ test(`test for valid combination yuva420p and ${c}`, () =>
+ expect(() =>
+ validateSelectedPixelFormatAndCodecCombination('yuva420p', c)
+ ).not.toThrow())
+ );
+
+ const invalidFormats = ['abc', '', 3];
+ invalidFormats.forEach((entry) =>
+ test(`test for invalid input "${entry}"`, () =>
+ expect(
+ // @ts-expect-error
+ () => validateSelectedPixelFormatAndCodecCombination(entry, 'h264')
+ ).toThrow(new RegExp(`Value ${entry} is not valid as a pixel format.`)))
+ );
+});
diff --git a/packages/renderer/src/test/prores-profile.test.ts b/packages/renderer/src/test/prores-profile.test.ts
new file mode 100644
index 0000000000..706ab33865
--- /dev/null
+++ b/packages/renderer/src/test/prores-profile.test.ts
@@ -0,0 +1,27 @@
+import {describe, expect, test} from 'vitest';
+import {validateSelectedCodecAndProResCombination} from '../prores-profile';
+
+describe('Pro Res Profile', () => {
+ test("Just a ProRes profile is not enough, because codec doesn't default to ProRes", () => {
+ expect(() => {
+ validateSelectedCodecAndProResCombination('aac', '4444-xq');
+ }).toThrow(
+ /You have set a ProRes profile but the codec is not "prores". Set the codec to "prores" or remove the ProRes profile./
+ );
+ });
+
+ test('Should accept a valid codec and ProRes combination', () => {
+ expect(validateSelectedCodecAndProResCombination('prores', '4444')).toBe(
+ undefined
+ );
+ });
+
+ test('Should throw on invalid ProRes name', () => {
+ expect(() =>
+ // @ts-expect-error
+ validateSelectedCodecAndProResCombination('prores', 'typoed')
+ ).toThrow(
+ /The ProRes profile "typoed" is not valid. Valid options are "4444-xq", "4444", "hq", "standard", "light", "proxy"/
+ );
+ });
+});
diff --git a/packages/renderer/src/test/validate-image-format.test.ts b/packages/renderer/src/test/validate-image-format.test.ts
new file mode 100644
index 0000000000..0b9dd06a48
--- /dev/null
+++ b/packages/renderer/src/test/validate-image-format.test.ts
@@ -0,0 +1,10 @@
+import {expect, test} from 'vitest';
+import {validateNonNullImageFormat} from '../image-format';
+
+test('"none" is not a valid image format', () => {
+ expect(() => validateNonNullImageFormat('jpeg')).not.toThrow();
+ expect(() => validateNonNullImageFormat('png')).not.toThrow();
+ expect(() => validateNonNullImageFormat('none')).toThrow(
+ /Image format should be either "png" or "jpeg"/
+ );
+});