Skip to content

🎥 Make videos programmatically with React

testing

Jonny Burger4acee6dfd526
diff --git a/bun.lock b/bun.lock
index 548cf97122..94d60e313c 100644
--- a/bun.lock
+++ b/bun.lock
@@ -950,12 +950,12 @@
"devDependencies": {
"@remotion/eslint-config-internal": "workspace:*",
"@typescript/native-preview": "catalog:",
- "@vitest/browser-webdriverio": "4.0.9",
+ "@vitest/browser-playwright": "catalog:",
"eslint": "catalog:",
+ "playwright": "catalog:",
"react": "catalog:",
"react-dom": "catalog:",
"vitest": "catalog:",
- "webdriverio": "9.19.2",
},
"peerDependencies": {
"react": ">=16.8.0",
@@ -4865,7 +4865,7 @@
"buffer": ["[email protected]", "", { "dependencies": { "base64-js": "1.5.1", "ieee754": "1.2.1" } }, "sha512-FTiCpNxtwiZZHEZbcbTIcZjERVICn9yq/pDFkTl95/AxzD1naBctN7YO68riM/gLSDY7sdrMby8hofADYuuqOA=="],
- "buffer-crc32": ["[email protected]", "", {}, "sha512-Db1SbgBS/fg/392AblrMJk97KggmvYhr4pB5ZIMTWtaivCPMWLkmb7m21cJvpvgK+J3nsU2CmmixNBZx4vFj/w=="],
+ "buffer-crc32": ["[email protected]", "", {}, "sha512-VO9Ht/+p3SN7SKWqcrgEzjGbRSJYTx+Q1pTQC0wrWqHx0vpJraQ6GtHx8tvcg1rlK1byhU5gccxgOgj7B0TDkQ=="],
"buffer-equal-constant-time": ["[email protected]", "", {}, "sha512-zRpUiDwd/xk6ADqPMATG8vc9VPrkck7T07OIx0gnjmJAnHnTVXNQG3vfvWNuiZIkwu9KrKdA1iJKfsfTVxE6NA=="],
@@ -6473,7 +6473,7 @@
"package-manager-detector": ["[email protected]", "", {}, "sha512-ZsEbbZORsyHuO00lY1kV3/t72yp6Ysay6Pd17ZAlNGuGwmWDLCJxFpRs0IzfXfj1o4icJOkUEioexFHzyPurSQ=="],
- "pako": ["[email protected]", "", {}, "sha512-4hLB8Py4zZce5s4yd9XzopqwVv/yGNhV1Bl8NTmCq1763HeK2+EwVTv+leGeL13Dnh2wfbqowVPXCIO0z4taYw=="],
+ "pako": ["[email protected]", "", {}, "sha512-NUcwaKxUxWrZLpDG+z/xZaCgQITkA/Dv4V/T6bw7VON6l1Xz/VnrBqrYjZQ12TamKHzITTfOEIYUj48y2KXImA=="],
"param-case": ["[email protected]", "", { "dependencies": { "dot-case": "3.0.4", "tslib": "2.8.1" } }, "sha512-RXlj7zCYokReqWpOPH9oYivUzLYZ5vAPIfEmCTNViosC78F8F0H9y7T7gG2M39ymgutxF5gcFEsyZQSph9Bp3A=="],
@@ -9379,6 +9379,8 @@
"anymatch/picomatch": ["[email protected]", "", {}, "sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA=="],
+ "archiver/buffer-crc32": ["[email protected]", "", {}, "sha512-Db1SbgBS/fg/392AblrMJk97KggmvYhr4pB5ZIMTWtaivCPMWLkmb7m21cJvpvgK+J3nsU2CmmixNBZx4vFj/w=="],
+
"archiver/readable-stream": ["[email protected]", "", { "dependencies": { "abort-controller": "3.0.0", "buffer": "6.0.3", "events": "3.3.0", "process": "0.11.10", "string_decoder": "1.3.0" } }, "sha512-oIGGmcpTLwPga8Bn6/Z75SVaH1z5dUut2ibSyAMVhmUggWpmDn2dapB0n7f8nwaSiRtepAsfJyfXIO5DCVAODg=="],
"archiver-utils/readable-stream": ["[email protected]", "", { "dependencies": { "abort-controller": "3.0.0", "buffer": "6.0.3", "events": "3.3.0", "process": "0.11.10", "string_decoder": "1.3.0" } }, "sha512-oIGGmcpTLwPga8Bn6/Z75SVaH1z5dUut2ibSyAMVhmUggWpmDn2dapB0n7f8nwaSiRtepAsfJyfXIO5DCVAODg=="],
@@ -9435,8 +9437,6 @@
"boxen/type-fest": ["[email protected]", "", {}, "sha512-yOGpmOAL7CkKe/91I5O3gPICmJNLJ1G4zFYVAsRHg7M64biSnPtRj0WNQt++bRkjYOqjWXrhnUw1utzmVErAdg=="],
- "browserify-zlib/pako": ["[email protected]", "", {}, "sha512-NUcwaKxUxWrZLpDG+z/xZaCgQITkA/Dv4V/T6bw7VON6l1Xz/VnrBqrYjZQ12TamKHzITTfOEIYUj48y2KXImA=="],
-
"cacache/fs-minipass": ["[email protected]", "", { "dependencies": { "minipass": "7.1.2" } }, "sha512-XUBA9XClHbnJWSfBzjkm6RvPsyg3sryZt06BEQoXcF7EK/xpGaQYJgQKDJSUH5SGZ76Y7pFx1QBnXz09rU5Fbw=="],
"cacache/lru-cache": ["[email protected]", "", {}, "sha512-jumlc0BIUrS3qJGgIkWZsyfAM7NCWiBcCDhnd+3NNM5KbBmLTgHVfWBcg6W+rLUsIpzpERPsvwUP7CckAQSOoA=="],
@@ -9777,6 +9777,8 @@
"jsdoc/marked": ["[email protected]", "", { "bin": { "marked": "bin/marked.js" } }, "sha512-PRsaiG84bK+AMvxziE/lCFss8juXjNaWzVbN5tXAm4XjeaS9NAHhop+PjQxz2A9h8Q4M/xGmzP8vqNwy6JeK0A=="],
+ "jszip/pako": ["[email protected]", "", {}, "sha512-4hLB8Py4zZce5s4yd9XzopqwVv/yGNhV1Bl8NTmCq1763HeK2+EwVTv+leGeL13Dnh2wfbqowVPXCIO0z4taYw=="],
+
"jszip/readable-stream": ["[email protected]", "", { "dependencies": { "core-util-is": "1.0.3", "inherits": "2.0.4", "isarray": "1.0.0", "process-nextick-args": "2.0.1", "safe-buffer": "5.1.2", "string_decoder": "1.1.1", "util-deprecate": "1.0.2" } }, "sha512-8p0AUk4XODgIewSi0l8Epjs+EVnWiK7NoDIEGU0HhE7+ZyY8D1IMY7odu5lRrFXGg71L15KG8QrPmum45RTtdA=="],
"lazystream/readable-stream": ["[email protected]", "", { "dependencies": { "core-util-is": "1.0.3", "inherits": "2.0.4", "isarray": "1.0.0", "process-nextick-args": "2.0.1", "safe-buffer": "5.1.2", "string_decoder": "1.1.1", "util-deprecate": "1.0.2" } }, "sha512-8p0AUk4XODgIewSi0l8Epjs+EVnWiK7NoDIEGU0HhE7+ZyY8D1IMY7odu5lRrFXGg71L15KG8QrPmum45RTtdA=="],
@@ -10553,8 +10555,6 @@
"typescript-eslint/@typescript-eslint/utils": ["@typescript-eslint/[email protected]", "", { "dependencies": { "@eslint-community/eslint-utils": "4.7.0", "@typescript-eslint/scope-manager": "8.21.0", "@typescript-eslint/types": "8.21.0", "@typescript-eslint/typescript-estree": "8.21.0" }, "peerDependencies": { "eslint": "9.19.0", "typescript": "5.7.3" } }, "sha512-xcXBfcq0Kaxgj7dwejMbFyq7IOHgpNMtVuDveK7w3ZGwG9owKzhALVwKpTF2yrZmEwl9SWdetf3fxNzJQaVuxw=="],
- "unicode-trie/pako": ["[email protected]", "", {}, "sha512-NUcwaKxUxWrZLpDG+z/xZaCgQITkA/Dv4V/T6bw7VON6l1Xz/VnrBqrYjZQ12TamKHzITTfOEIYUj48y2KXImA=="],
-
"unified/@types/unist": ["@types/[email protected]", "", {}, "sha512-dqId9J8K/vGi5Zr7oo212BGii5m3q5Hxlkwy3WpYuKPklmBEvsbMYYyLxAQpSffdLl/gdW0XUpKWFvYmyoWCoQ=="],
"unist-util-find-after/@types/unist": ["@types/[email protected]", "", {}, "sha512-dqId9J8K/vGi5Zr7oo212BGii5m3q5Hxlkwy3WpYuKPklmBEvsbMYYyLxAQpSffdLl/gdW0XUpKWFvYmyoWCoQ=="],
@@ -10703,8 +10703,6 @@
"yargs/yargs-parser": ["[email protected]", "", {}, "sha512-rwu/ClNdSMpkSrUb+d6BRsSkLUq1fmfsY6TOpYzTwvwkg1/NRG85KBy3kq++A8LKQwX6lsu+aWad+2khvuXrqw=="],
- "yauzl/buffer-crc32": ["[email protected]", "", {}, "sha512-VO9Ht/+p3SN7SKWqcrgEzjGbRSJYTx+Q1pTQC0wrWqHx0vpJraQ6GtHx8tvcg1rlK1byhU5gccxgOgj7B0TDkQ=="],
-
"zip-stream/readable-stream": ["[email protected]", "", { "dependencies": { "abort-controller": "3.0.0", "buffer": "6.0.3", "events": "3.3.0", "process": "0.11.10", "string_decoder": "1.3.0" } }, "sha512-oIGGmcpTLwPga8Bn6/Z75SVaH1z5dUut2ibSyAMVhmUggWpmDn2dapB0n7f8nwaSiRtepAsfJyfXIO5DCVAODg=="],
"zod-to-json-schema/zod": ["[email protected]", "", {}, "sha512-AvvthqfqrAhNH9dnfmrfKzX5upOdjUVJYFqNSlkmGf64gRaTzlPwz99IHYnVs28qYAybvAlBV+H7pn0saFY4Ig=="],
diff --git a/packages/example-videos/videos/sample-audio.mp3 b/packages/example-videos/videos/sample-audio.mp3
new file mode 100644
index 0000000000..bf02eb3c7b
Binary files /dev/null and b/packages/example-videos/videos/sample-audio.mp3 differ
diff --git a/packages/example/public/sample-audio.mp3 b/packages/example/public/sample-audio.mp3
new file mode 100644
index 0000000000..bf02eb3c7b
Binary files /dev/null and b/packages/example/public/sample-audio.mp3 differ
diff --git a/packages/example/src/NewVideo.tsx b/packages/example/src/NewVideo.tsx
index c736089588..30cea7679d 100644
--- a/packages/example/src/NewVideo.tsx
+++ b/packages/example/src/NewVideo.tsx
@@ -1,30 +1,26 @@
-import {Video} from '@remotion/media';
+import {Audio} from '@remotion/media';
import {CalculateMetadataFunction, Composition} from 'remotion';
// https://www.remotion.dev/docs/mediabunny/metadata
-import {visualControl} from '@remotion/studio';
+import {staticFile} from 'remotion';
import {getMediaMetadata} from './get-media-metadata';
-const src = visualControl('video', 'https://remotion.media/video-h265.mp4');
+const src = staticFile('sample-audio.mp3');
export const calculateMetadataFn: CalculateMetadataFunction<
Record<string, unknown>
> = async () => {
- const {durationInSeconds, dimensions, fps} = await getMediaMetadata(src);
+ const {durationInSeconds} = await getMediaMetadata(src);
return {
- durationInFrames: Math.round(durationInSeconds * fps!),
- fps: fps!,
- width: dimensions!.width,
- height: dimensions!.height,
+ durationInFrames: Math.round(durationInSeconds * 30),
+ fps: 30,
+ width: 1920,
+ height: 1080,
};
};
export const Component = () => {
- return (
- <Video
- src={visualControl('video', 'https://remotion.media/video-h265.mp4')}
- />
- );
+ return <Audio src={src} />;
};
export const NewVideoComp = () => {
diff --git a/packages/media/package.json b/packages/media/package.json
index b1da0998d2..3d0c60db44 100644
--- a/packages/media/package.json
+++ b/packages/media/package.json
@@ -31,12 +31,12 @@
},
"devDependencies": {
"@remotion/eslint-config-internal": "workspace:*",
- "@vitest/browser-webdriverio": "4.0.9",
+ "@vitest/browser-playwright": "catalog:",
"eslint": "catalog:",
+ "playwright": "catalog:",
"react": "catalog:",
"react-dom": "catalog:",
"vitest": "catalog:",
- "webdriverio": "9.19.2",
"@typescript/native-preview": "catalog:"
},
"keywords": [],
diff --git a/packages/media/src/convert-audiodata/convert-audiodata.ts b/packages/media/src/convert-audiodata/convert-audiodata.ts
index 46629d239f..9096aafa61 100644
--- a/packages/media/src/convert-audiodata/convert-audiodata.ts
+++ b/packages/media/src/convert-audiodata/convert-audiodata.ts
@@ -92,6 +92,8 @@ export const convertAudioData = ({
frameCount,
});
+ console.log('srcChannels', srcChannels);
+
const data = new Int16Array(newNumberOfFrames * TARGET_NUMBER_OF_CHANNELS);
const chunkSize = frameCount / newNumberOfFrames;
diff --git a/packages/media/src/test/__snapshots__/audio-encoding.test.ts.snap b/packages/media/src/test/__snapshots__/audio-encoding.test.ts.snap
new file mode 100644
index 0000000000..fe915407c0
--- /dev/null
+++ b/packages/media/src/test/__snapshots__/audio-encoding.test.ts.snap
@@ -0,0 +1,321 @@
+// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
+
+exports[`Audio samples from MP3 should produce identical s16 output on Chrome and Firefox > sample-0-first10 1`] = `
+[
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+]
+`;
+
+exports[`Audio samples from MP3 should produce identical s16 output on Chrome and Firefox > sample-0-last10 1`] = `
+[
+ -372,
+ -549,
+ -165,
+ -271,
+ 10,
+ -107,
+ 116,
+ -12,
+ 184,
+ 151,
+]
+`;
+
+exports[`Audio samples from MP3 should produce identical s16 output on Chrome and Firefox > sample-0-sum 1`] = `-37638`;
+
+exports[`Audio samples from MP3 should produce identical s16 output on Chrome and Firefox > sample-1-first10 1`] = `
+[
+ 219,
+ 280,
+ 175,
+ 242,
+ 129,
+ 216,
+ 178,
+ 302,
+ 233,
+ 317,
+]
+`;
+
+exports[`Audio samples from MP3 should produce identical s16 output on Chrome and Firefox > sample-1-last10 1`] = `
+[
+ -515,
+ -1100,
+ -795,
+ -1530,
+ -735,
+ -1520,
+ -639,
+ -1386,
+ -793,
+ -1558,
+]
+`;
+
+exports[`Audio samples from MP3 should produce identical s16 output on Chrome and Firefox > sample-1-sum 1`] = `184794`;
+
+exports[`Audio samples from MP3 should produce identical s16 output on Chrome and Firefox > sample-2-first10 1`] = `
+[
+ -1449,
+ -2252,
+ -2129,
+ -2852,
+ -2186,
+ -2803,
+ -1939,
+ -2629,
+ -1934,
+ -2760,
+]
+`;
+
+exports[`Audio samples from MP3 should produce identical s16 output on Chrome and Firefox > sample-2-last10 1`] = `
+[
+ 29,
+ 452,
+ 239,
+ 640,
+ 151,
+ 587,
+ -95,
+ 374,
+ -247,
+ 214,
+]
+`;
+
+exports[`Audio samples from MP3 should produce identical s16 output on Chrome and Firefox > sample-2-sum 1`] = `-4022`;
+
+exports[`Audio samples from MP3 should produce identical s16 output on Chrome and Firefox > sample-3-first10 1`] = `
+[
+ -402,
+ 68,
+ -419,
+ 58,
+ -412,
+ 35,
+ -911,
+ -460,
+ -1605,
+ -1107,
+]
+`;
+
+exports[`Audio samples from MP3 should produce identical s16 output on Chrome and Firefox > sample-3-last10 1`] = `
+[
+ 144,
+ -354,
+ 352,
+ -168,
+ 810,
+ 264,
+ 1096,
+ 505,
+ 877,
+ 242,
+]
+`;
+
+exports[`Audio samples from MP3 should produce identical s16 output on Chrome and Firefox > sample-3-sum 1`] = `-55271`;
+
+exports[`Audio samples from MP3 should produce identical s16 output on Chrome and Firefox > sample-4-first10 1`] = `
+[
+ -104,
+ -766,
+ -1564,
+ -2251,
+ -2308,
+ -3028,
+ -1853,
+ -2605,
+ -1386,
+ -2163,
+]
+`;
+
+exports[`Audio samples from MP3 should produce identical s16 output on Chrome and Firefox > sample-4-last10 1`] = `
+[
+ -808,
+ -660,
+ -1141,
+ -983,
+ -822,
+ -674,
+ -450,
+ -318,
+ -739,
+ -623,
+]
+`;
+
+exports[`Audio samples from MP3 should produce identical s16 output on Chrome and Firefox > sample-4-sum 1`] = `29618`;
+
+exports[`Audio samples from MP3 should produce identical s16 output on Chrome and Firefox > sample-5-first10 1`] = `
+[
+ -1351,
+ -1261,
+ -2024,
+ -1977,
+ -3314,
+ -3322,
+ -5005,
+ -5067,
+ -5783,
+ -5890,
+]
+`;
+
+exports[`Audio samples from MP3 should produce identical s16 output on Chrome and Firefox > sample-5-last10 1`] = `
+[
+ 14921,
+ 13311,
+ 13080,
+ 11552,
+ 12247,
+ 10809,
+ 12936,
+ 11575,
+ 13706,
+ 12422,
+]
+`;
+
+exports[`Audio samples from MP3 should produce identical s16 output on Chrome and Firefox > sample-5-sum 1`] = `-87014`;
+
+exports[`Audio samples from MP3 should produce identical s16 output on Chrome and Firefox > sample-6-first10 1`] = `
+[
+ 13593,
+ 12389,
+ 12470,
+ 11329,
+ 10323,
+ 9243,
+ 7674,
+ 6675,
+ 5618,
+ 4712,
+]
+`;
+
+exports[`Audio samples from MP3 should produce identical s16 output on Chrome and Firefox > sample-6-last10 1`] = `
+[
+ 10202,
+ 10087,
+ 8771,
+ 8704,
+ 6993,
+ 7010,
+ 7535,
+ 7649,
+ 9049,
+ 9227,
+]
+`;
+
+exports[`Audio samples from MP3 should produce identical s16 output on Chrome and Firefox > sample-6-sum 1`] = `140323`;
+
+exports[`Audio samples from MP3 should produce identical s16 output on Chrome and Firefox > sample-7-first10 1`] = `
+[
+ 8301,
+ 8528,
+ 4900,
+ 5210,
+ 2057,
+ 2449,
+ 1704,
+ 2090,
+ 1229,
+ 1520,
+]
+`;
+
+exports[`Audio samples from MP3 should produce identical s16 output on Chrome and Firefox > sample-7-last10 1`] = `
+[
+ 3407,
+ 3507,
+ 2608,
+ 2859,
+ 1579,
+ 2207,
+ 949,
+ 1995,
+ 703,
+ 1945,
+]
+`;
+
+exports[`Audio samples from MP3 should produce identical s16 output on Chrome and Firefox > sample-7-sum 1`] = `-104504`;
+
+exports[`Audio samples from MP3 should produce identical s16 output on Chrome and Firefox > sample-8-first10 1`] = `
+[
+ 763,
+ 1813,
+ 1299,
+ 1865,
+ 1900,
+ 1992,
+ 1928,
+ 1803,
+ 1667,
+ 1599,
+]
+`;
+
+exports[`Audio samples from MP3 should produce identical s16 output on Chrome and Firefox > sample-8-last10 1`] = `
+[
+ -5267,
+ -5582,
+ -4603,
+ -4819,
+ -3590,
+ -3835,
+ -2846,
+ -3244,
+ -2548,
+ -3094,
+]
+`;
+
+exports[`Audio samples from MP3 should produce identical s16 output on Chrome and Firefox > sample-8-sum 1`] = `32453`;
+
+exports[`Audio samples from MP3 should produce identical s16 output on Chrome and Firefox > sample-9-first10 1`] = `
+[
+ -2889,
+ -3455,
+ -3223,
+ -3719,
+ -2819,
+ -3262,
+ -2644,
+ -3079,
+ -3705,
+ -4128,
+]
+`;
+
+exports[`Audio samples from MP3 should produce identical s16 output on Chrome and Firefox > sample-9-last10 1`] = `
+[
+ -4728,
+ -6248,
+ -4051,
+ -5481,
+ -3687,
+ -4959,
+ -4434,
+ -5413,
+ -5342,
+ -5825,
+]
+`;
+
+exports[`Audio samples from MP3 should produce identical s16 output on Chrome and Firefox > sample-9-sum 1`] = `-378527`;
diff --git a/packages/media/src/test/audio-encoding.test.ts b/packages/media/src/test/audio-encoding.test.ts
new file mode 100644
index 0000000000..50fd8e3017
--- /dev/null
+++ b/packages/media/src/test/audio-encoding.test.ts
@@ -0,0 +1,65 @@
+import {ALL_FORMATS, AudioSampleSink, Input, UrlSource} from 'mediabunny';
+import {expect, test} from 'vitest';
+import {convertAudioData} from '../convert-audiodata/convert-audiodata';
+
+test('Audio samples from MP3 should produce identical s16 output on Chrome and Firefox', async () => {
+ const input = new Input({
+ source: new UrlSource('/sample-audio.mp3'),
+ formats: ALL_FORMATS,
+ });
+
+ const audioTrack = await input.getPrimaryAudioTrack();
+ if (!audioTrack) {
+ throw new Error('No audio track found');
+ }
+
+ const decodable = await audioTrack.canDecode();
+ expect(decodable).toBe(true);
+
+ const sink = new AudioSampleSink(audioTrack);
+
+ let sampleIndex = 0;
+
+ for await (const sample of sink.samples()) {
+ const audioData = sample.toAudioData();
+ const {numberOfChannels, numberOfFrames, format} = audioData;
+
+ expect(numberOfFrames).toBe(1152);
+ expect(numberOfChannels).toBe(2);
+ expect(format === 'f32' || format === 's16-planar').toBe(true);
+
+ const result = convertAudioData({
+ audioData,
+ trimStartInSeconds: 0,
+ trimEndInSeconds: 0,
+ playbackRate: 1,
+ audioDataTimestamp: audioData.timestamp / 1_000_000,
+ isLast: false,
+ });
+
+ expect(result.numberOfFrames).toBe(numberOfFrames);
+ expect(result.data.length).toBe(numberOfFrames * 2);
+
+ const {data} = result;
+ let sum = 0;
+ for (let i = 0; i < data.length; i++) {
+ sum += data[i];
+ }
+
+ const first10 = Array.from(data.slice(0, 10));
+ const last10 = Array.from(data.slice(-10));
+
+ expect(first10).toMatchSnapshot(`sample-${sampleIndex}-first10`);
+ expect(last10).toMatchSnapshot(`sample-${sampleIndex}-last10`);
+ expect(sum).toMatchSnapshot(`sample-${sampleIndex}-sum`);
+
+ audioData.close();
+ sampleIndex++;
+
+ if (sampleIndex >= 10) {
+ break;
+ }
+ }
+
+ expect(sampleIndex).toBe(10);
+});
diff --git a/packages/media/vitest.config.ts b/packages/media/vitest.config.ts
index be8d11bfbe..d78972ce5c 100644
--- a/packages/media/vitest.config.ts
+++ b/packages/media/vitest.config.ts
@@ -1,12 +1,24 @@
-import {webdriverio} from '@vitest/browser-webdriverio';
+import {playwright} from '@vitest/browser-playwright';
import path from 'node:path';
import {defineConfig} from 'vitest/config';
export default defineConfig({
test: {
browser: {
- provider: webdriverio(),
- instances: [{browser: 'chrome'}],
+ provider: playwright(),
+ instances: [
+ {
+ browser: 'chromium',
+ provider: playwright({
+ launchOptions: {
+ channel: 'chrome',
+ },
+ }),
+ },
+ {
+ browser: 'firefox',
+ },
+ ],
headless: true,
screenshotFailures: false,
},
diff --git a/packages/web-renderer/src/render-media-on-web.tsx b/packages/web-renderer/src/render-media-on-web.tsx
index a49ca77ad3..2b83bab51f 100644
--- a/packages/web-renderer/src/render-media-on-web.tsx
+++ b/packages/web-renderer/src/render-media-on-web.tsx
@@ -1,8 +1,8 @@
-import {BufferTarget, StreamTarget} from 'mediabunny';
+import {BufferTarget, StreamTarget, WavOutputFormat} from 'mediabunny';
import type {CalculateMetadataFunction} from 'remotion';
import {Internals, type LogLevel} from 'remotion';
import type {AnyZodObject, z} from 'zod';
-import {addAudioSample, addVideoSampleAndCloseFrame} from './add-sample';
+import {addAudioSample} from './add-sample';
import {handleArtifacts, type WebRendererOnArtifact} from './artifact';
import {onlyInlineAudio} from './audio';
import {createBackgroundKeepalive} from './background-keepalive';
@@ -12,21 +12,14 @@ import {checkForError, createScaffold} from './create-scaffold';
import {getRealFrameRange, type FrameRange} from './frame-range';
import type {InternalState} from './internal-state';
import {makeInternalState} from './internal-state';
-import {
- makeOutputWithCleanup,
- makeVideoSampleSourceCleanup,
-} from './mediabunny-cleanups';
+import {makeOutputWithCleanup} from './mediabunny-cleanups';
import type {
WebRendererAudioCodec,
WebRendererContainer,
WebRendererQuality,
} from './mediabunny-mappings';
import {
- audioCodecToMediabunnyAudioCodec,
- codecToMediabunnyCodec,
- containerToMediabunnyContainer,
getDefaultVideoCodecForContainer,
- getMimeType,
getQualityForWebRendererQuality,
type WebRendererVideoCodec,
} from './mediabunny-mappings';
@@ -149,17 +142,12 @@ const internalRenderMediaOnWeb = async <
logLevel,
mediaCacheSizeInBytes,
schema,
- videoCodec: codec,
audioCodec: unresolvedAudioCodec,
audioBitrate,
container,
signal,
onProgress,
- hardwareAcceleration,
- keyframeIntervalInSeconds,
- videoBitrate,
frameRange,
- transparent,
onArtifact,
onFrame,
outputTarget: userDesiredOutputTarget,
@@ -183,23 +171,25 @@ const internalRenderMediaOnWeb = async <
await cleanupStaleOpfsFiles();
}
- const format = containerToMediabunnyContainer(container);
+ // TEMPORARY: Always output .wav regardless of options
+ const format = new WavOutputFormat();
+ // const format = containerToMediabunnyContainer(container);
- if (
- codec &&
- !format.getSupportedCodecs().includes(codecToMediabunnyCodec(codec))
- ) {
- return Promise.reject(
- new Error(`Codec ${codec} is not supported for container ${container}`),
- );
- }
+ // TEMPORARY: Skip video codec check for .wav output
+ // if (
+ // codec &&
+ // !format.getSupportedCodecs().includes(codecToMediabunnyCodec(codec))
+ // ) {
+ // return Promise.reject(
+ // new Error(`Codec ${codec} is not supported for container ${container}`),
+ // );
+ // }
const resolvedAudioBitrate =
typeof audioBitrate === 'number'
? audioBitrate
: getQualityForWebRendererQuality(audioBitrate);
- let finalAudioCodec: WebRendererAudioCodec | null = null;
if (!muted) {
const audioResult = await resolveAudioCodec({
container,
@@ -220,8 +210,6 @@ const internalRenderMediaOnWeb = async <
issue.message,
);
}
-
- finalAudioCodec = audioResult.codec;
}
const resolved = await Internals.resolveVideoConfig({
@@ -313,28 +301,35 @@ const internalRenderMediaOnWeb = async <
throw new Error('renderMediaOnWeb() was cancelled');
}
- using videoSampleSource = makeVideoSampleSourceCleanup({
- codec: codecToMediabunnyCodec(codec),
- bitrate:
- typeof videoBitrate === 'number'
- ? videoBitrate
- : getQualityForWebRendererQuality(videoBitrate),
- sizeChangeBehavior: 'deny',
- hardwareAcceleration,
- latencyMode: 'quality',
- keyFrameInterval: keyframeIntervalInSeconds,
- alpha: transparent ? 'keep' : 'discard',
- });
-
- outputWithCleanup.output.addVideoTrack(videoSampleSource.videoSampleSource);
-
+ // TEMPORARY: Skip video track for .wav output
+ // using videoSampleSource = makeVideoSampleSourceCleanup({
+ // codec: codecToMediabunnyCodec(codec),
+ // bitrate:
+ // typeof videoBitrate === 'number'
+ // ? videoBitrate
+ // : getQualityForWebRendererQuality(videoBitrate),
+ // sizeChangeBehavior: 'deny',
+ // hardwareAcceleration,
+ // latencyMode: 'quality',
+ // keyFrameInterval: keyframeIntervalInSeconds,
+ // alpha: transparent ? 'keep' : 'discard',
+ // });
+ // outputWithCleanup.output.addVideoTrack(videoSampleSource.videoSampleSource);
+ const videoSampleSource = {videoSampleSource: {close: () => {}}};
+
+ // TEMPORARY: Use pcm-s16 for .wav output
using audioSampleSource = createAudioSampleSource({
muted,
- codec: finalAudioCodec
- ? audioCodecToMediabunnyAudioCodec(finalAudioCodec)
- : null,
+ codec: 'pcm-s16' as any,
bitrate: resolvedAudioBitrate,
});
+ // using audioSampleSource = createAudioSampleSource({
+ // muted,
+ // codec: finalAudioCodec
+ // ? audioCodecToMediabunnyAudioCodec(finalAudioCodec)
+ // : null,
+ // bitrate: resolvedAudioBitrate,
+ // });
if (audioSampleSource) {
outputWithCleanup.output.addAudioTrack(
@@ -342,6 +337,8 @@ const internalRenderMediaOnWeb = async <
);
}
+ console.log('frfrfrffr??');
+
await outputWithCleanup.output.start();
if (signal?.aborted) {
@@ -435,12 +432,16 @@ const internalRenderMediaOnWeb = async <
: onlyInlineAudio({assets, fps: resolved.fps, timestamp});
internalState.addAudioMixingTime(performance.now() - audioCombineStart);
+ console.log(audio?.numberOfFrames);
+
const addSampleStart = performance.now();
+ // TEMPORARY: Skip video sample for .wav output, close the frame
+ frameToEncode.close();
await Promise.all([
- addVideoSampleAndCloseFrame(
- frameToEncode,
- videoSampleSource.videoSampleSource,
- ),
+ // addVideoSampleAndCloseFrame(
+ // frameToEncode,
+ // videoSampleSource.videoSampleSource,
+ // ),
audio && audioSampleSource
? addAudioSample(audio, audioSampleSource.audioSampleSource)
: Promise.resolve(),
@@ -503,9 +504,8 @@ const internalRenderMediaOnWeb = async <
throw new Error('The resulting buffer is empty');
}
- return Promise.resolve(
- new Blob([target.buffer], {type: getMimeType(container)}),
- );
+ // TEMPORARY: Force audio/wav mime type
+ return Promise.resolve(new Blob([target.buffer], {type: 'audio/wav'}));
},
internalState,
};
diff --git a/packages/web-renderer/src/test/audio.test.tsx b/packages/web-renderer/src/test/audio.test.tsx
index 8d61c2c9d5..1b395022df 100644
--- a/packages/web-renderer/src/test/audio.test.tsx
+++ b/packages/web-renderer/src/test/audio.test.tsx
@@ -239,3 +239,38 @@ test('explicit Opus selection produces Opus in MP4 output', async () => {
const audioCodec = await getAudioCodecFromBlob(blob);
expect(audioCodec).toBe('opus');
});
+
+test.only('should render MP3 audio source', async (t) => {
+ if (t.task.file.projectName === 'webkit') {
+ t.skip();
+ return;
+ }
+
+ const Component: React.FC = () => {
+ return <Audio src={staticFile('sample-audio.mp3')} />;
+ };
+
+ const result = await renderMediaOnWeb({
+ licenseKey: 'free-license',
+ composition: {
+ component: Component,
+ id: 'mp3-encoding-test',
+ width: 100,
+ height: 100,
+ fps: 30,
+ durationInFrames: 300,
+ calculateMetadata: null,
+ },
+ container: 'mp4',
+ frameRange: [0, 299],
+ logLevel: 'verbose',
+ outputTarget: 'arraybuffer',
+ });
+
+ const blob = await result.getBlob();
+ expect(blob.size).toBeGreaterThan(0);
+ const audioCodec = await getAudioCodecFromBlob(blob);
+ expect(audioCodec).toBe(
+ t.task.file.projectName === 'firefox' ? 'opus' : 'aac',
+ );
+});