@remotion/web-renderer 4.0.382 → 4.0.384

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,2 @@
1
+ import { type AudioEncodingConfig } from 'mediabunny';
2
+ export declare const getDefaultAudioEncodingConfig: () => Promise<AudioEncodingConfig | null>;
@@ -0,0 +1,18 @@
1
+ import { canEncodeAudio, QUALITY_MEDIUM, } from 'mediabunny';
2
+ export const getDefaultAudioEncodingConfig = async () => {
3
+ const preferredDefaultAudioEncodingConfig = {
4
+ codec: 'aac',
5
+ bitrate: QUALITY_MEDIUM,
6
+ };
7
+ if (await canEncodeAudio(preferredDefaultAudioEncodingConfig.codec, preferredDefaultAudioEncodingConfig)) {
8
+ return preferredDefaultAudioEncodingConfig;
9
+ }
10
+ const backupDefaultAudioEncodingConfig = {
11
+ codec: 'opus',
12
+ bitrate: QUALITY_MEDIUM,
13
+ };
14
+ if (await canEncodeAudio(backupDefaultAudioEncodingConfig.codec, backupDefaultAudioEncodingConfig)) {
15
+ return backupDefaultAudioEncodingConfig;
16
+ }
17
+ return null;
18
+ };
@@ -1,8 +1,11 @@
1
- import { BufferTarget, Output, VideoSample, VideoSampleSource } from 'mediabunny';
1
+ import { AudioSampleSource, BufferTarget, Output, VideoSampleSource, } from 'mediabunny';
2
2
  import { Internals } from 'remotion';
3
+ import { addAudioSample, addVideoSampleAndCloseFrame } from './add-sample';
3
4
  import { handleArtifacts } from './artifact';
5
+ import { onlyInlineAudio } from './audio';
4
6
  import { createScaffold } from './create-scaffold';
5
7
  import { getRealFrameRange } from './frame-range';
8
+ import { getDefaultAudioEncodingConfig } from './get-audio-encoding-config';
6
9
  import { codecToMediabunnyCodec, containerToMediabunnyContainer, getDefaultVideoCodecForContainer, getQualityForWebRendererQuality, } from './mediabunny-mappings';
7
10
  import { createFrame } from './take-screenshot';
8
11
  import { createThrottledProgressCallback } from './throttle-progress';
@@ -55,10 +58,7 @@ const internalRenderMediaOnWeb = async ({ composition, inputProps, delayRenderTi
55
58
  defaultCodec: resolved.defaultCodec,
56
59
  defaultOutName: resolved.defaultOutName,
57
60
  });
58
- const artifactsHandler = handleArtifacts({
59
- ref: collectAssets,
60
- onArtifact,
61
- });
61
+ const artifactsHandler = handleArtifacts();
62
62
  cleanupFns.push(() => {
63
63
  cleanupScaffold();
64
64
  });
@@ -100,6 +100,16 @@ const internalRenderMediaOnWeb = async ({ composition, inputProps, delayRenderTi
100
100
  videoSampleSource.close();
101
101
  });
102
102
  output.addVideoTrack(videoSampleSource);
103
+ // TODO: Should be able to customize
104
+ const defaultAudioEncodingConfig = await getDefaultAudioEncodingConfig();
105
+ if (!defaultAudioEncodingConfig) {
106
+ return Promise.reject(new Error('No default audio encoding config found'));
107
+ }
108
+ const audioSampleSource = new AudioSampleSource(defaultAudioEncodingConfig);
109
+ cleanupFns.push(() => {
110
+ audioSampleSource.close();
111
+ });
112
+ output.addAudioTrack(audioSampleSource);
103
113
  await output.start();
104
114
  if (signal === null || signal === void 0 ? void 0 : signal.aborted) {
105
115
  throw new Error('renderMediaOnWeb() was cancelled');
@@ -125,7 +135,16 @@ const internalRenderMediaOnWeb = async ({ composition, inputProps, delayRenderTi
125
135
  width: resolved.width,
126
136
  height: resolved.height,
127
137
  });
128
- await artifactsHandler.handle({ imageData, frame: i });
138
+ const assets = collectAssets.current.collectAssets();
139
+ if (onArtifact) {
140
+ await artifactsHandler.handle({
141
+ imageData,
142
+ frame: i,
143
+ assets,
144
+ onArtifact,
145
+ });
146
+ }
147
+ const audio = onlyInlineAudio(assets);
129
148
  if (signal === null || signal === void 0 ? void 0 : signal.aborted) {
130
149
  throw new Error('renderMediaOnWeb() was cancelled');
131
150
  }
@@ -147,10 +166,12 @@ const internalRenderMediaOnWeb = async ({ composition, inputProps, delayRenderTi
147
166
  expectedTimestamp: timestamp,
148
167
  });
149
168
  }
150
- await videoSampleSource.add(new VideoSample(frameToEncode));
169
+ await Promise.all([
170
+ addVideoSampleAndCloseFrame(frameToEncode, videoSampleSource),
171
+ audio ? addAudioSample(audio, audioSampleSource) : Promise.resolve(),
172
+ ]);
151
173
  progress.encodedFrames++;
152
174
  throttledOnProgress === null || throttledOnProgress === void 0 ? void 0 : throttledOnProgress({ ...progress });
153
- frameToEncode.close();
154
175
  if (signal === null || signal === void 0 ? void 0 : signal.aborted) {
155
176
  throw new Error('renderMediaOnWeb() was cancelled');
156
177
  }
@@ -158,6 +179,7 @@ const internalRenderMediaOnWeb = async ({ composition, inputProps, delayRenderTi
158
179
  // Call progress one final time to ensure final state is reported
159
180
  onProgress === null || onProgress === void 0 ? void 0 : onProgress({ ...progress });
160
181
  videoSampleSource.close();
182
+ audioSampleSource.close();
161
183
  await output.finalize();
162
184
  return output.target.buffer;
163
185
  }
@@ -37,10 +37,7 @@ async function internalRenderStillOnWeb({ frame, delayRenderTimeoutInMillisecond
37
37
  defaultCodec: resolved.defaultCodec,
38
38
  defaultOutName: resolved.defaultOutName,
39
39
  });
40
- const artifactsHandler = handleArtifacts({
41
- ref: collectAssets,
42
- onArtifact,
43
- });
40
+ const artifactsHandler = handleArtifacts();
44
41
  try {
45
42
  if (signal === null || signal === void 0 ? void 0 : signal.aborted) {
46
43
  throw new Error('renderStillOnWeb() was cancelled');
@@ -60,7 +57,10 @@ async function internalRenderStillOnWeb({ frame, delayRenderTimeoutInMillisecond
60
57
  height: resolved.height,
61
58
  imageFormat,
62
59
  });
63
- await artifactsHandler.handle({ imageData, frame });
60
+ const assets = collectAssets.current.collectAssets();
61
+ if (onArtifact) {
62
+ await artifactsHandler.handle({ imageData, frame, assets, onArtifact });
63
+ }
64
64
  return imageData;
65
65
  }
66
66
  finally {
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "url": "https://github.com/remotion-dev/remotion/tree/main/packages/web-renderer"
4
4
  },
5
5
  "name": "@remotion/web-renderer",
6
- "version": "4.0.382",
6
+ "version": "4.0.384",
7
7
  "main": "dist/index.js",
8
8
  "sideEffects": false,
9
9
  "scripts": {
@@ -16,14 +16,14 @@
16
16
  "author": "Remotion <jonny@remotion.dev>",
17
17
  "license": "UNLICENSED",
18
18
  "dependencies": {
19
- "remotion": "4.0.382",
20
- "mediabunny": "1.25.3"
19
+ "remotion": "4.0.384",
20
+ "mediabunny": "1.25.8"
21
21
  },
22
22
  "devDependencies": {
23
- "@remotion/eslint-config-internal": "4.0.382",
24
- "@remotion/player": "4.0.382",
25
- "@remotion/media": "4.0.382",
26
- "@vitejs/plugin-react": "^5.1.0",
23
+ "@remotion/eslint-config-internal": "4.0.384",
24
+ "@remotion/player": "4.0.384",
25
+ "@remotion/media": "4.0.384",
26
+ "@vitejs/plugin-react": "4.1.0",
27
27
  "@vitest/browser-playwright": "4.0.9",
28
28
  "playwright": "1.55.1",
29
29
  "eslint": "9.19.0",