Skip to content

🎥 Make videos programmatically with React

Merge branch 'v4' into rustinffmpeg

Jonny Burger4e80f9382827
diff --cc packages/cli/src/compositions.ts
index cb04570bda,f2b653f0ba..876050eecd
--- a/packages/cli/src/compositions.ts
+++ b/packages/cli/src/compositions.ts
@@@ -51,8 -55,12 +53,10 @@@ export const listCompositionsCommand =
publicDir,
});
+ registerCleanupJob(() => cleanupBundle());
+
const compositions = await getCompositions(bundled, {
browserExecutable,
- ffmpegExecutable,
- ffprobeExecutable,
chromiumOptions,
envVariables,
inputProps,
diff --cc packages/example/src/simulate-lambda.ts
index 5a9195500d,8cb5ee0901..2f89669236
--- a/packages/example/src/simulate-lambda.ts
+++ b/packages/example/src/simulate-lambda.ts
@@@ -47,8 -47,12 +47,10 @@@ const start = async () =>
onProgress: () => console.log('progress'),
output: 'out/combined.mp4',
numberOfGifLoops: null,
- ffmpegExecutable: null,
- remotionRoot: process.cwd(),
audioCodec: 'aac',
});
+
+ RenderInternals.deleteDirectory(bundled);
};
start();
diff --cc packages/example/src/test/stills.test.ts
index 012061ea0c,e4d29aef0f..6da6c7c6f3
--- a/packages/example/src/test/stills.test.ts
+++ b/packages/example/src/test/stills.test.ts
@@@ -33,7 -36,9 +36,7 @@@ test
onError: (err) => {
throw err;
},
- downloadMap: RenderInternals.makeDownloadMap(),
- ffmpegExecutable: null,
- ffprobeExecutable: null,
+ downloadMap,
remotionRoot: process.cwd(),
});
diff --cc packages/it-tests/src/ssr/render-frames.test.ts
index 3fd4171bec,8458cc6940..e37ab3f898
--- a/packages/it-tests/src/ssr/render-frames.test.ts
+++ b/packages/it-tests/src/ssr/render-frames.test.ts
@@@ -58,7 -58,12 +58,9 @@@ test("Legacy SSR way of rendering video
codec: "h264",
});
expect(fs.existsSync(outPath)).toBe(true);
- const probe = await execa(
- await RenderInternals.getExecutableBinary(null, process.cwd(), "ffprobe"),
- [outPath]
- );
+ const probe = await RenderInternals.callFf("ffprobe", [outPath]);
expect(probe.stderr).toMatch(/Video: h264/);
+
+ RenderInternals.deleteDirectory(framesDir);
await puppeteerInstance.close();
});
diff --cc packages/renderer/src/merge-audio-track.ts
index 068b0b53b0,01b78257ea..2fd8eedafe
--- a/packages/renderer/src/merge-audio-track.ts
+++ b/packages/renderer/src/merge-audio-track.ts
@@@ -46,29 -54,34 +46,32 @@@ const mergeAudioTrackUnlimited = async
const chunked = chunk(files, 10);
const tempPath = tmpDir('remotion-large-audio-mixing');
- const chunkNames = await Promise.all(
- chunked.map(async (chunkFiles, i) => {
- const chunkOutname = path.join(tempPath, `chunk-${i}.wav`);
- await mergeAudioTrack({
- files: chunkFiles,
- numberOfSeconds,
- outName: chunkOutname,
- downloadMap,
- remotionRoot,
- });
- return chunkOutname;
- })
- );
+ try {
+ const chunkNames = await Promise.all(
+ chunked.map(async (chunkFiles, i) => {
+ const chunkOutname = path.join(tempPath, `chunk-${i}.wav`);
+ await mergeAudioTrack({
- ffmpegExecutable,
+ files: chunkFiles,
+ numberOfSeconds,
+ outName: chunkOutname,
+ downloadMap,
+ remotionRoot,
+ });
+ return chunkOutname;
+ })
+ );
- await mergeAudioTrack({
- files: chunkNames,
- numberOfSeconds,
- outName,
- downloadMap,
- remotionRoot,
- });
- await deleteDirectory(tempPath);
- return;
+ await mergeAudioTrack({
- ffmpegExecutable,
+ files: chunkNames,
+ numberOfSeconds,
+ outName,
+ downloadMap,
+ remotionRoot,
+ });
+ return;
+ } finally {
+ deleteDirectory(tempPath);
+ }
}
const {complexFilterFlag: mergeFilter, cleanup} =
diff --cc packages/renderer/src/test/extract-frame-from-video.test.ts
index d1e2053c8d,66965ba5c3..06a0b3a9dc
--- a/packages/renderer/src/test/extract-frame-from-video.test.ts
+++ b/packages/renderer/src/test/extract-frame-from-video.test.ts
@@@ -14,7 -14,10 +14,8 @@@ const src = path.join
);
test('Should be able to extract a frame from a video', async () => {
+ const downloadMap = makeDownloadMap();
const str = await extractFrameFromVideo({
- ffmpegExecutable: null,
- ffprobeExecutable: null,
src,
time: 1,
imageFormat: 'jpeg',
@@@ -26,7 -31,11 +29,9 @@@
});
test('Should be able to extract a frame from a video as PNG', async () => {
+ const downloadMap = makeDownloadMap();
+
const str = await extractFrameFromVideo({
- ffmpegExecutable: null,
- ffprobeExecutable: null,
src,
time: 1,
imageFormat: 'png',
@@@ -38,7 -48,11 +44,9 @@@
});
test('Should get the last frame if out of range', async () => {
+ const downloadMap = makeDownloadMap();
+
const str = await extractFrameFromVideo({
- ffmpegExecutable: null,
- ffprobeExecutable: null,
src,
time: 100,
imageFormat: 'jpeg',
diff --cc packages/renderer/src/test/get-audio-channels.test.ts
index 71d45909ab,4883067766..9386ee0875
--- a/packages/renderer/src/test/get-audio-channels.test.ts
+++ b/packages/renderer/src/test/get-audio-channels.test.ts
@@@ -19,8 -19,11 +19,9 @@@ test('Get audio channels for video', as
expect(existsSync(videoWithoutAudio)).toEqual(true);
const channels = await getAudioChannelsAndDuration(
downloadMap,
- videoWithoutAudio,
- null,
- process.cwd()
+ videoWithoutAudio
);
+ cleanDownloadMap(downloadMap);
expect(channels).toEqual({channels: 2, duration: 10});
}, 90000);
@@@ -39,8 -42,12 +40,10 @@@ test('Get audio channels for video with
expect(existsSync(videoWithAudio)).toEqual(true);
const channels = await getAudioChannelsAndDuration(
downloadMap,
- videoWithAudio,
- null,
- process.cwd()
+ videoWithAudio
);
+ cleanDownloadMap(downloadMap);
+
expect(channels.channels).toEqual(0);
expect(channels.duration).toBeCloseTo(3.334, 2);
}, 90000);
@@@ -58,15 -65,23 +61,18 @@@ test('Get audio channels for video wit
'sound1.mp3'
);
expect(existsSync(audio)).toEqual(true);
- const channels = await getAudioChannelsAndDuration(
- downloadMap,
- audio,
- null,
- process.cwd()
- );
+ const channels = await getAudioChannelsAndDuration(downloadMap, audio);
+ cleanDownloadMap(downloadMap);
+
expect(channels).toEqual({channels: 2, duration: 56.529});
}, 90000);
test('Throw error if parsing a non video file', () => {
const downloadMap = makeDownloadMap();
- const tsFile = path.join(__dirname, '..', 'ffmpeg-flags.ts');
+ const tsFile = path.join(__dirname, '..', 'can-use-parallel-encoding.ts');
expect(existsSync(tsFile)).toEqual(true);
expect(() =>
- getAudioChannelsAndDuration(downloadMap, tsFile, null, process.cwd())
+ getAudioChannelsAndDuration(downloadMap, tsFile)
).rejects.toThrow(/Invalid data found when processing input/);
+ cleanDownloadMap(downloadMap);
});
diff --cc packages/renderer/src/test/get-last-frame-of-corrupted-video.test.ts
index 0264e3627d,8391a81c14..80841aff33
--- a/packages/renderer/src/test/get-last-frame-of-corrupted-video.test.ts
+++ b/packages/renderer/src/test/get-last-frame-of-corrupted-video.test.ts
@@@ -1,10 -1,14 +1,11 @@@
import path from 'path';
-import process from 'process';
import {test} from 'vitest';
- import {makeDownloadMap} from '../assets/download-map';
+ import {cleanDownloadMap, makeDownloadMap} from '../assets/download-map';
import {getLastFrameOfVideo} from '../extract-frame-from-video';
test('Get last frame of corrupted video', async () => {
+ const downloadMap = makeDownloadMap();
await getLastFrameOfVideo({
- ffmpegExecutable: null,
- ffprobeExecutable: null,
offset: 0,
src: path.join(
__dirname,
@@@ -18,6 -22,8 +19,7 @@@
imageFormat: 'png',
specialVCodecForTransparency: 'none',
needsResize: null,
- downloadMap: makeDownloadMap(),
+ downloadMap,
- remotionRoot: process.cwd(),
});
+ cleanDownloadMap(downloadMap);
}, 90000);
diff --cc packages/renderer/src/test/last-frame-video-cache.test.ts
index 8b9d9c7c3d,2f79cb5eae..aaa90066de
--- a/packages/renderer/src/test/last-frame-video-cache.test.ts
+++ b/packages/renderer/src/test/last-frame-video-cache.test.ts
@@@ -22,37 -29,41 +22,38 @@@ const makeKey = (id: string, downloadMa
test('Last frame video cache', () => {
const downloadMap = makeDownloadMap();
- expect(getLastFrameFromCache(makeKey('1', downloadMap, process.cwd()))).toBe(
- null
- );
+ expect(getLastFrameFromCache(makeKey('1', downloadMap))).toBe(null);
const buf = crypto.randomBytes(10 * 1024 * 1024);
- setLastFrameInCache(makeKey('1', downloadMap, process.cwd()), buf);
- expect(
- getLastFrameFromCache(makeKey('1', downloadMap, process.cwd()))?.byteLength
- ).toBe(10 * 1024 * 1024);
- setLastFrameInCache(makeKey('2', downloadMap, process.cwd()), buf);
- setLastFrameInCache(makeKey('3', downloadMap, process.cwd()), buf);
- setLastFrameInCache(makeKey('4', downloadMap, process.cwd()), buf);
- setLastFrameInCache(makeKey('5', downloadMap, process.cwd()), buf);
- setLastFrameInCache(makeKey('6', downloadMap, process.cwd()), buf);
+ setLastFrameInCache(makeKey('1', downloadMap), buf);
+ expect(getLastFrameFromCache(makeKey('1', downloadMap))?.byteLength).toBe(
+ 10 * 1024 * 1024
+ );
+ setLastFrameInCache(makeKey('2', downloadMap), buf);
+ setLastFrameInCache(makeKey('3', downloadMap), buf);
+ setLastFrameInCache(makeKey('4', downloadMap), buf);
+ setLastFrameInCache(makeKey('5', downloadMap), buf);
+ setLastFrameInCache(makeKey('6', downloadMap), buf);
expect(
- getLastFrameFromCache(makeKey('1', downloadMap, process.cwd()))
- ?.byteLength ?? 0
+ getLastFrameFromCache(makeKey('1', downloadMap))?.byteLength ?? 0
).toBe(0);
- expect(
- getLastFrameFromCache(makeKey('2', downloadMap, process.cwd()))?.byteLength
- ).toBe(10 * 1024 * 1024);
- expect(
- getLastFrameFromCache(makeKey('3', downloadMap, process.cwd()))?.byteLength
- ).toBe(10 * 1024 * 1024);
- expect(
- getLastFrameFromCache(makeKey('4', downloadMap, process.cwd()))?.byteLength
- ).toBe(10 * 1024 * 1024);
- expect(
- getLastFrameFromCache(makeKey('5', downloadMap, process.cwd()))?.byteLength
- ).toBe(10 * 1024 * 1024);
- expect(
- getLastFrameFromCache(makeKey('6', downloadMap, process.cwd()))?.byteLength
- ).toBe(10 * 1024 * 1024);
+ expect(getLastFrameFromCache(makeKey('2', downloadMap))?.byteLength).toBe(
+ 10 * 1024 * 1024
+ );
+ expect(getLastFrameFromCache(makeKey('3', downloadMap))?.byteLength).toBe(
+ 10 * 1024 * 1024
+ );
+ expect(getLastFrameFromCache(makeKey('4', downloadMap))?.byteLength).toBe(
+ 10 * 1024 * 1024
+ );
+ expect(getLastFrameFromCache(makeKey('5', downloadMap))?.byteLength).toBe(
+ 10 * 1024 * 1024
+ );
+ expect(getLastFrameFromCache(makeKey('6', downloadMap))?.byteLength).toBe(
+ 10 * 1024 * 1024
+ );
clearLastFileCache(downloadMap);
+ cleanDownloadMap(downloadMap);
});