Skip to content

🎥 Make videos programmatically with React

Added support for webm-v8 and webm-v9

Shankhadeep Dey4130f76495eb
diff --git a/packages/cli/src/get-filename.ts b/packages/cli/src/get-filename.ts
index a8ec35c951..ab2526000b 100644
--- a/packages/cli/src/get-filename.ts
+++ b/packages/cli/src/get-filename.ts
@@ -6,5 +6,5 @@ export const getOutputFilename = () => {
console.log('Pass an extra argument <output-filename>.');
process.exit(1);
}
- return args._[3];
+ return args._[3].split('.')[0];
};
diff --git a/packages/cli/src/parse-command-line.ts b/packages/cli/src/parse-command-line.ts
index 2993b75f40..c3adfa7166 100644
--- a/packages/cli/src/parse-command-line.ts
+++ b/packages/cli/src/parse-command-line.ts
@@ -1,5 +1,5 @@
import minimist from 'minimist';
-import {Config, PixelFormat} from 'remotion';
+import {Config, OutputFormat, PixelFormat} from 'remotion';
export type CommandLineOptions = {
pixelFormat: PixelFormat;
@@ -9,6 +9,7 @@ export type CommandLineOptions = {
png: boolean;
quality: number | undefined;
force: boolean;
+ format: OutputFormat;
props: string;
};
@@ -24,6 +25,9 @@ export const parseCommandLine = () => {
if (parsedCli.png) {
Config.Output.setOutputFormat('png-sequence');
}
+ if (parsedCli.format && !parsedCli.png) {
+ Config.Output.setOutputFormat(parsedCli.format);
+ }
if (typeof parsedCli.overwrite !== 'undefined') {
Config.Output.setOverwriteOutput(parsedCli.overwrite);
}
diff --git a/packages/cli/src/render.tsx b/packages/cli/src/render.tsx
index d8d9d0c39a..d9c31a0a03 100644
--- a/packages/cli/src/render.tsx
+++ b/packages/cli/src/render.tsx
@@ -28,20 +28,33 @@ export const render = async () => {
loadConfigFile(configFileName);
parseCommandLine();
const parallelism = Internals.getConcurrency();
- const renderMode = Internals.getFormat();
+ const renderMode = Internals.getOutputFormat();
const outputFile = getOutputFilename();
const overwrite = Internals.getShouldOverwrite();
const userProps = getUserProps();
const quality = Internals.getQuality();
const absoluteOutputFile = path.resolve(process.cwd(), outputFile);
+ const absoluteOutputFileWithExtension = (): string => {
+ if (renderMode === 'mp4') {
+ return absoluteOutputFile + '.mp4';
+ }
+ if (renderMode === 'webm-v8' || renderMode === 'webm-v9') {
+ return absoluteOutputFile + '.webm';
+ }
+ return absoluteOutputFile;
+ };
if (fs.existsSync(absoluteOutputFile) && !overwrite) {
console.log(
`File at ${absoluteOutputFile} already exists. Use --overwrite to overwrite.`
);
process.exit(1);
}
- if (renderMode === 'mp4') {
+ if (
+ renderMode === 'mp4' ||
+ renderMode === 'webm-v8' ||
+ renderMode === 'webm-v9'
+ ) {
await validateFfmpeg();
}
if (renderMode === 'png-sequence') {
@@ -114,17 +127,22 @@ export const render = async () => {
if (process.env.DEBUG) {
Internals.perf.logPerf();
}
- if (renderMode === 'mp4') {
+ if (
+ renderMode === 'mp4' ||
+ renderMode === 'webm-v8' ||
+ renderMode === 'webm-v9'
+ ) {
process.stdout.write(`🧵 (3/${steps}) Stitching frames together...\n`);
await stitchFramesToVideo({
dir: outputDir,
width: config.width,
height: config.height,
fps: config.fps,
- outputLocation: absoluteOutputFile,
+ outputLocation: absoluteOutputFileWithExtension(),
force: overwrite,
imageFormat: getFrameFormat(renderMode),
pixelFormat: Internals.getPixelFormat(),
+ outputFormat: Internals.getOutputFormat(),
});
console.log('Cleaning up...');
await fs.promises.rmdir(outputDir, {
diff --git a/packages/core/src/config/render-mode.ts b/packages/core/src/config/render-mode.ts
index 21abafc6c9..e7f8784898 100644
--- a/packages/core/src/config/render-mode.ts
+++ b/packages/core/src/config/render-mode.ts
@@ -1,10 +1,10 @@
-const validRenderModes = ['png-sequence', 'mp4'] as const;
+const validRenderModes = ['png-sequence', 'mp4', 'webm-v8', 'webm-v9'] as const;
export type OutputFormat = typeof validRenderModes[number];
let format: OutputFormat = 'mp4';
-export const getFormat = (): OutputFormat => {
+export const getOutputFormat = (): OutputFormat => {
return format;
};
diff --git a/packages/core/src/internals.ts b/packages/core/src/internals.ts
index b2509e1b80..2bfb00f36f 100644
--- a/packages/core/src/internals.ts
+++ b/packages/core/src/internals.ts
@@ -12,7 +12,7 @@ import {
import {getShouldOverwrite} from './config/overwrite';
import {getPixelFormat} from './config/pixel-format';
import {getQuality} from './config/quality';
-import {getFormat} from './config/render-mode';
+import {getOutputFormat} from './config/render-mode';
import * as perf from './perf';
import {getCompositionName, getIsEvaluation, getRoot} from './register-root';
import {RemotionRoot} from './RemotionRoot';
@@ -35,7 +35,7 @@ export const Internals = {
getPixelFormat,
getConcurrency,
getShouldOverwrite,
- getFormat,
+ getOutputFormat,
getWebpackOverrideFn,
getQuality,
};
diff --git a/packages/example/remotion.config.ts b/packages/example/remotion.config.ts
index bbc412e610..d35573ed0f 100644
--- a/packages/example/remotion.config.ts
+++ b/packages/example/remotion.config.ts
@@ -1,6 +1,6 @@
import {Config} from 'remotion';
-Config.Rendering.setConcurrency(16);
+Config.Rendering.setConcurrency(4);
Config.Output.setOverwriteOutput(true);
Config.Output.setPixelFormat('yuv420p');
diff --git a/packages/renderer/src/stitcher.ts b/packages/renderer/src/stitcher.ts
index f8883c790f..b9fb2d4457 100644
--- a/packages/renderer/src/stitcher.ts
+++ b/packages/renderer/src/stitcher.ts
@@ -1,5 +1,5 @@
import execa from 'execa';
-import {PixelFormat} from 'remotion';
+import {OutputFormat, PixelFormat} from 'remotion';
import {DEFAULT_IMAGE_FORMAT, ImageFormat} from './image-format';
import {validateFfmpeg} from './validate-ffmpeg';
@@ -12,6 +12,7 @@ export const stitchFramesToVideo = async (options: {
force: boolean;
imageFormat?: ImageFormat;
pixelFormat?: PixelFormat;
+ outputFormat?: OutputFormat;
}): Promise<void> => {
const format = options.imageFormat ?? DEFAULT_IMAGE_FORMAT;
await validateFfmpeg();
@@ -28,8 +29,12 @@ export const stitchFramesToVideo = async (options: {
'glob',
'-i',
`element-*.${format}`,
- '-vcodec',
- 'libx264',
+ options.outputFormat === 'mp4' ? '-vcodec' : '-c:v',
+ options.outputFormat === 'mp4'
+ ? 'libx264'
+ : options.outputFormat === 'webm-v8'
+ ? 'libvpx'
+ : 'libvpx-vp9',
'-crf',
'16',
options.force ? '-y' : null,