Skip to content

πŸŽ₯ Make videos programmatically with React

remove png as codec

Jonny Burger90326f4709cf
diff --git a/packages/cli/src/get-filename.ts b/packages/cli/src/get-filename.ts
index 3fdb9f1102..f04b205e11 100644
--- a/packages/cli/src/get-filename.ts
+++ b/packages/cli/src/get-filename.ts
@@ -4,17 +4,20 @@ import {
getUserPassedOutputLocation,
} from './user-passed-output-location';
-export const getOutputFilename = (codec: Codec): string => {
+export const getOutputFilename = (
+ codec: Codec,
+ imageSequence: boolean
+): string => {
let filename = getUserPassedOutputLocation();
let extension = getUserPassedFileExtension();
- if (extension === null && codec !== 'png') {
+ if (extension === null && !imageSequence) {
if (codec === 'h264' || codec === 'h265') {
console.info('No file extension specified, adding .mp4 automatically.');
filename += '.mp4';
extension = 'mp4';
}
if (codec === 'vp8' || codec === 'vp9') {
- console.log('No file extension specified, adding .webm automatically');
+ console.info('No file extension specified, adding .webm automatically');
filename += '.webm';
extension = 'webm';
}
@@ -37,11 +40,9 @@ export const getOutputFilename = (codec: Codec): string => {
process.exit(1);
}
}
- if (codec === 'png') {
- if (extension !== null) {
- console.error('The output directory cannot have an extension.');
- process.exit(1);
- }
+ if (imageSequence && extension !== null) {
+ console.error('The output directory cannot have an extension.');
+ process.exit(1);
}
return filename;
};
diff --git a/packages/cli/src/parse-command-line.ts b/packages/cli/src/parse-command-line.ts
index 8ab9c4482e..3b8af36c11 100644
--- a/packages/cli/src/parse-command-line.ts
+++ b/packages/cli/src/parse-command-line.ts
@@ -24,8 +24,7 @@ export const parseCommandLine = () => {
Config.Rendering.setConcurrency(parsedCli.concurrency);
}
if (parsedCli.png) {
- // TODO: Make this a separate flag
- Config.Output.setOutputFormat('png-sequence');
+ Config.Output.setImageSequence(true);
}
if (parsedCli.codec) {
Config.Output.setCodec(parsedCli.codec);
diff --git a/packages/cli/src/render.tsx b/packages/cli/src/render.tsx
index 0353bf112e..9eeffca490 100644
--- a/packages/cli/src/render.tsx
+++ b/packages/cli/src/render.tsx
@@ -35,7 +35,8 @@ export const render = async () => {
fileExtension: getUserPassedFileExtension(),
emitWarning: true,
});
- const outputFile = getOutputFilename(codec);
+ const shouldOutputImageSequence = Internals.getShouldOutputImageSequence();
+ const outputFile = getOutputFilename(codec, shouldOutputImageSequence);
const overwrite = Internals.getShouldOverwrite();
const userProps = getUserProps();
const quality = Internals.getQuality();
@@ -55,12 +56,12 @@ export const render = async () => {
) {
await validateFfmpeg();
}
- if (codec === 'png') {
+ if (shouldOutputImageSequence) {
fs.mkdirSync(absoluteOutputFile, {
recursive: true,
});
}
- const steps = codec === 'png' ? 2 : 3;
+ const steps = shouldOutputImageSequence ? 2 : 3;
process.stdout.write(`πŸ“¦ (1/${steps}) Bundling video...\n`);
const bundlingProgress = new cliProgress.Bar(
@@ -87,12 +88,9 @@ export const render = async () => {
}
const {durationInFrames: frames} = config;
- const outputDir =
- codec === 'png'
- ? absoluteOutputFile
- : await fs.promises.mkdtemp(
- path.join(os.tmpdir(), 'react-motion-render')
- );
+ const outputDir = shouldOutputImageSequence
+ ? absoluteOutputFile
+ : await fs.promises.mkdtemp(path.join(os.tmpdir(), 'react-motion-render'));
const renderProgress = new cliProgress.Bar(
{
@@ -125,12 +123,7 @@ export const render = async () => {
if (process.env.DEBUG) {
Internals.perf.logPerf();
}
- if (
- codec === 'h264' ||
- codec === 'h265' ||
- codec === 'vp8' ||
- codec === 'vp9'
- ) {
+ if (!shouldOutputImageSequence) {
process.stdout.write(`🧡 (3/${steps}) Stitching frames together...\n`);
await stitchFramesToVideo({
dir: outputDir,
diff --git a/packages/core/src/config/codec.ts b/packages/core/src/config/codec.ts
index 06eff711a4..137e1ea1cd 100644
--- a/packages/core/src/config/codec.ts
+++ b/packages/core/src/config/codec.ts
@@ -1,4 +1,4 @@
-const validRenderModes = ['png', 'h264', 'h265', 'vp8', 'vp9'] as const;
+const validRenderModes = ['h264', 'h265', 'vp8', 'vp9'] as const;
export type Codec = typeof validRenderModes[number];
export type CodecOrUndefined = Codec | undefined;
diff --git a/packages/core/src/config/image-sequence.ts b/packages/core/src/config/image-sequence.ts
new file mode 100644
index 0000000000..6298640bdd
--- /dev/null
+++ b/packages/core/src/config/image-sequence.ts
@@ -0,0 +1,12 @@
+let imageSequence = false;
+
+export const setImageSequence = (newImageSequence: boolean) => {
+ if (typeof newImageSequence !== 'boolean') {
+ throw new TypeError('setImageSequence accepts a Boolean Value');
+ }
+ imageSequence = newImageSequence;
+};
+
+export const getShouldOutputImageSequence = () => {
+ return imageSequence;
+};
diff --git a/packages/core/src/config/index.ts b/packages/core/src/config/index.ts
index 50a2702e6d..c882bcd7f7 100644
--- a/packages/core/src/config/index.ts
+++ b/packages/core/src/config/index.ts
@@ -1,5 +1,6 @@
import {setCodec, setOutputFormat} from './codec';
import {Concurrency, setConcurrency} from './concurrency';
+import {setImageSequence} from './image-sequence';
import {
overrideWebpackConfig,
WebpackConfiguration,
@@ -45,7 +46,7 @@ export const Config = {
*/
setPixelFormat,
/**
- * @deprecated Use setCodec() instead.
+ * @deprecated Use setCodec() and setImageSequence() instead.
* Specify what kind of output you, either `mp4` or `png-sequence`.
*/
setOutputFormat,
@@ -54,6 +55,10 @@ export const Config = {
* Can be `h264` (default), `h265`, `vp8` or `vp9`
*/
setCodec,
+ /**
+ * Set to true if don't want a video but an image sequence as the output.
+ */
+ setImageSequence,
},
} as const;
diff --git a/packages/core/src/internals.ts b/packages/core/src/internals.ts
index cec346d640..a7e0cc0de9 100644
--- a/packages/core/src/internals.ts
+++ b/packages/core/src/internals.ts
@@ -6,6 +6,7 @@ import {
} from './CompositionManager';
import {getOutputCodecOrUndefined} from './config/codec';
import {getConcurrency} from './config/concurrency';
+import {getShouldOutputImageSequence} from './config/image-sequence';
import {
getWebpackOverrideFn,
WebpackOverrideFn,
@@ -38,6 +39,7 @@ export const Internals = {
getOutputCodecOrUndefined,
getWebpackOverrideFn,
getQuality,
+ getShouldOutputImageSequence,
};
export type {
diff --git a/packages/docs/docs/cli.md b/packages/docs/docs/cli.md
index e27a988b25..6fb7b9364b 100644
--- a/packages/docs/docs/cli.md
+++ b/packages/docs/docs/cli.md
@@ -17,7 +17,7 @@ Besides choosing a video and output location with the command line arguments, th
- `--concurrency`: [How many CPU threads to use.](config#setconcurrency) Minimum 1. The maximum is the amount of threads you have.
- `--pixel-format`: [Set a custom pixel format. See here for available values.](config#setpixelformat)
- `--config`: Specify a location for the Remotion config file.
-- `--quality`: [Value between 0 and 100 for JPEG rendering quality](config#setquality). Doesn't work when `--png` is set.
+- `--quality`: [Value between 0 and 100 for JPEG rendering quality](config#setquality). Doesn't work when PNG frames are rendered.
- `--overwrite`: [Write to output even if file already exists.](config#setoverwriteoutput)
- `--codec`: ['h264' or 'h265' or `png` or `vp8` or `vp9`](config#setoutputformat). If you don't supply `--codec`, it will use the H.264 encoder.
diff --git a/packages/docs/docs/config.md b/packages/docs/docs/config.md
index 3ad4cfd035..76ddaf78bd 100644
--- a/packages/docs/docs/config.md
+++ b/packages/docs/docs/config.md
@@ -78,9 +78,17 @@ Choose one of the supported codecs: `h264` _(default)_, `h265`, `vp8`, `vp9`.
Config.Output.setCodec('h265');
```
+### setImageSequence()
+
+Set to true if you want to output an image sequence instead of a video.
+
+```tsx
+Config.Output.setImageSequence(true);
+```
+
### setOutputFormat()
-_Deprecated_. Use `setCodec()` instead.
+_Deprecated_. Use `setCodec()` and `setImageSequence()` instead.
Either `'mp4'` or `'png-sequence'`.