Skip to content

🎥 Make videos programmatically with React

get it working locally

Jonny Burger624be2f6a98e
diff --git a/packages/lambda/src/functions/helpers/concat-videos.ts b/packages/lambda/src/functions/helpers/concat-videos.ts
index 76272967a6..1acfbf220e 100644
--- a/packages/lambda/src/functions/helpers/concat-videos.ts
+++ b/packages/lambda/src/functions/helpers/concat-videos.ts
@@ -196,13 +196,16 @@ export const concatVideosS3 = async ({
const combine = timer('Combine videos');
const filelistDir = RenderInternals.tmpDir(REMOTION_FILELIST_TOKEN);
const encodingStart = Date.now();
+
+ const codecForCombining: Codec = codec === 'h264-mkv' ? 'h264' : codec;
+
await combineVideos({
files,
filelistDir,
output: outfile,
onProgress: (p) => onProgress(p, encodingStart),
numberOfFrames,
- codec,
+ codec: codecForCombining,
});
combine.end();
diff --git a/packages/lambda/src/functions/renderer.ts b/packages/lambda/src/functions/renderer.ts
index 71b8fe1dd0..d21b931258 100644
--- a/packages/lambda/src/functions/renderer.ts
+++ b/packages/lambda/src/functions/renderer.ts
@@ -153,6 +153,7 @@ const renderHandler = async (
outputLocation,
durationInFrames: params.frameRange[1] - params.frameRange[0] + 1,
fps: params.fps,
+ chunkCodec: params.codec,
});
const condensedTimingData: ChunkTimingData = {
diff --git a/packages/lambda/src/test/integration/render-handler.test.ts b/packages/lambda/src/test/integration/render-handler.test.ts
index cc17bb7c9d..2cc4016333 100644
--- a/packages/lambda/src/test/integration/render-handler.test.ts
+++ b/packages/lambda/src/test/integration/render-handler.test.ts
@@ -4,6 +4,7 @@ import {handler} from '../../functions';
import {killBrowserInstancesForIntegrationTest} from '../../functions/helpers/get-browser-instance';
import {lambdaReadFile} from '../../functions/helpers/io';
import {LambdaReturnValues} from '../../shared/return-values';
+import {disableLogs, enableLogs} from '../disable-logs';
jest.setTimeout(30000);
@@ -14,7 +15,12 @@ const extraContext = {
type Await<T> = T extends PromiseLike<infer U> ? U : T;
+beforeAll(() => {
+ disableLogs();
+});
+
afterAll(async () => {
+ enableLogs();
await killBrowserInstancesForIntegrationTest();
});
@@ -26,7 +32,7 @@ test('Render handler manually', async () => {
type: LambdaRoutines.start,
serveUrl: 'https://competent-mccarthy-56f7c9.netlify.app/',
chromiumOptions: {},
- codec: 'h264',
+ codec: 'h264-mkv',
composition: 'react-svg',
crf: 9,
enableChunkOptimization: false,
diff --git a/packages/lambda/src/test/integration/transparent-lambda.test.ts b/packages/lambda/src/test/integration/transparent-lambda.test.ts
index 2054422a8a..189fc4a630 100644
--- a/packages/lambda/src/test/integration/transparent-lambda.test.ts
+++ b/packages/lambda/src/test/integration/transparent-lambda.test.ts
@@ -4,6 +4,7 @@ import {handler} from '../../functions';
import {killBrowserInstancesForIntegrationTest} from '../../functions/helpers/get-browser-instance';
import {lambdaReadFile} from '../../functions/helpers/io';
import {LambdaReturnValues} from '../../shared/return-values';
+import {disableLogs, enableLogs} from '../disable-logs';
jest.setTimeout(30000);
@@ -14,7 +15,12 @@ const extraContext = {
type Await<T> = T extends PromiseLike<infer U> ? U : T;
+beforeAll(() => {
+ disableLogs();
+});
+
afterAll(async () => {
+ enableLogs();
await killBrowserInstancesForIntegrationTest();
});
diff --git a/packages/lambda/src/test/setup.ts b/packages/lambda/src/test/setup.ts
index 36b45bf6c4..dbae144ba4 100644
--- a/packages/lambda/src/test/setup.ts
+++ b/packages/lambda/src/test/setup.ts
@@ -7,6 +7,9 @@ jest.mock('../cli/helpers/quit', () =>
jest.mock('../functions/helpers/io', () =>
jest.requireActual('../functions/helpers/__mocks__/io')
);
+jest.mock('../functions/helpers/timer', () =>
+ jest.requireActual('../functions/helpers/__mocks__/timer')
+);
jest.mock('../functions/helpers/print-cloudwatch-helper', () =>
jest.requireActual('../functions/helpers/__mocks__/print-cloudwatch-helper')
);
diff --git a/packages/renderer/src/add-silent-audio-if-necessary.ts b/packages/renderer/src/add-silent-audio-if-necessary.ts
index 7aa04f191e..835d3cbd97 100644
--- a/packages/renderer/src/add-silent-audio-if-necessary.ts
+++ b/packages/renderer/src/add-silent-audio-if-necessary.ts
@@ -1,16 +1,20 @@
import execa from 'execa';
import {renameSync, unlinkSync} from 'fs';
+import {Codec} from 'remotion';
import {getAudioChannels} from './assets/get-audio-channels';
+import {getAudioCodecName} from './get-audio-codec-name';
import {DEFAULT_SAMPLE_RATE} from './sample-rate';
export const addSilentAudioIfNecessary = async ({
durationInFrames,
fps,
outputLocation,
+ chunkCodec,
}: {
outputLocation: string;
durationInFrames: number;
fps: number;
+ chunkCodec: Codec;
}): Promise<void> => {
const audioChannels = await getAudioChannels(outputLocation);
if (audioChannels > 0) {
@@ -19,6 +23,14 @@ export const addSilentAudioIfNecessary = async ({
const out = outputLocation + '-n';
+ const audioCodec = getAudioCodecName(chunkCodec);
+
+ const isVp8 = chunkCodec === 'vp8' || chunkCodec === 'vp9';
+
+ if (!audioCodec) {
+ throw new Error('expected audio codec');
+ }
+
await execa('ffmpeg', [
'-f',
'lavfi',
@@ -31,7 +43,7 @@ export const addSilentAudioIfNecessary = async ({
'-map',
'1:v:0',
'-c:a',
- 'pcm_s16le',
+ audioCodec,
'-c:v',
'copy',
'-ar',
@@ -40,7 +52,7 @@ export const addSilentAudioIfNecessary = async ({
'-t',
(durationInFrames / fps).toFixed(4),
'-f',
- 'matroska',
+ isVp8 ? 'webm' : 'matroska',
out,
]);
unlinkSync(outputLocation);
diff --git a/packages/renderer/src/combine-videos.ts b/packages/renderer/src/combine-videos.ts
index 97986e61a6..7f865a80fd 100644
--- a/packages/renderer/src/combine-videos.ts
+++ b/packages/renderer/src/combine-videos.ts
@@ -40,7 +40,7 @@ export const combineVideos = async ({
Internals.isAudioCodec(codec) ? null : '-c:v',
Internals.isAudioCodec(codec) ? null : 'copy',
'-c:a',
- Internals.isAudioCodec(codec) ? getAudioCodecName(codec) : 'aac',
+ getAudioCodecName(codec),
'-shortest',
'-y',
output,
diff --git a/packages/renderer/src/get-audio-codec-name.ts b/packages/renderer/src/get-audio-codec-name.ts
index caa8b878b6..8972f6092e 100644
--- a/packages/renderer/src/get-audio-codec-name.ts
+++ b/packages/renderer/src/get-audio-codec-name.ts
@@ -8,6 +8,10 @@ export const getAudioCodecName = (codec: Codec): string | null => {
return 'pcm_s16le';
}
+ if (codec === 'vp8' || codec === 'vp9') {
+ return 'libvorbis';
+ }
+
return 'aac';
}