@remotion/web-renderer 4.0.383 → 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.
- package/dist/add-sample.d.ts +3 -0
- package/dist/add-sample.js +20 -0
- package/dist/artifact.d.ts +4 -5
- package/dist/artifact.js +12 -15
- package/dist/audio.d.ts +2 -0
- package/dist/audio.js +45 -0
- package/dist/esm/index.mjs +1275 -54
- package/dist/get-audio-encoding-config.d.ts +2 -0
- package/dist/get-audio-encoding-config.js +18 -0
- package/dist/render-media-on-web.js +30 -8
- package/dist/render-still-on-web.js +5 -5
- package/package.json +6 -6
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { AudioSampleSource, VideoSampleSource } from 'mediabunny';
|
|
2
|
+
export declare const addVideoSampleAndCloseFrame: (frameToEncode: VideoFrame, videoSampleSource: VideoSampleSource) => Promise<void>;
|
|
3
|
+
export declare const addAudioSample: (audio: AudioData, audioSampleSource: AudioSampleSource) => Promise<void>;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { AudioSample, VideoSample } from 'mediabunny';
|
|
2
|
+
export const addVideoSampleAndCloseFrame = async (frameToEncode, videoSampleSource) => {
|
|
3
|
+
const sample = new VideoSample(frameToEncode);
|
|
4
|
+
try {
|
|
5
|
+
await videoSampleSource.add(sample);
|
|
6
|
+
}
|
|
7
|
+
finally {
|
|
8
|
+
sample.close();
|
|
9
|
+
frameToEncode.close();
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
export const addAudioSample = async (audio, audioSampleSource) => {
|
|
13
|
+
const sample = new AudioSample(audio);
|
|
14
|
+
try {
|
|
15
|
+
await audioSampleSource.add(sample);
|
|
16
|
+
}
|
|
17
|
+
finally {
|
|
18
|
+
sample.close();
|
|
19
|
+
}
|
|
20
|
+
};
|
package/dist/artifact.d.ts
CHANGED
|
@@ -13,12 +13,11 @@ export type OnArtifact = (asset: EmittedArtifact) => void;
|
|
|
13
13
|
export type ArtifactsRef = React.RefObject<{
|
|
14
14
|
collectAssets: () => TRenderAsset[];
|
|
15
15
|
} | null>;
|
|
16
|
-
export declare const handleArtifacts: (
|
|
17
|
-
|
|
18
|
-
onArtifact: OnArtifact | null;
|
|
19
|
-
}) => {
|
|
20
|
-
handle: ({ imageData, frame, }: {
|
|
16
|
+
export declare const handleArtifacts: () => {
|
|
17
|
+
handle: ({ imageData, frame, assets: artifactAssets, onArtifact, }: {
|
|
21
18
|
imageData: Blob | OffscreenCanvas | null;
|
|
22
19
|
frame: number;
|
|
20
|
+
assets: TRenderAsset[];
|
|
21
|
+
onArtifact: OnArtifact;
|
|
23
22
|
}) => Promise<void>;
|
|
24
23
|
};
|
package/dist/artifact.js
CHANGED
|
@@ -36,23 +36,20 @@ export const onlyArtifact = async ({ assets, frameBuffer, }) => {
|
|
|
36
36
|
}
|
|
37
37
|
return result.filter(NoReactInternals.truthy);
|
|
38
38
|
};
|
|
39
|
-
export const handleArtifacts = (
|
|
39
|
+
export const handleArtifacts = () => {
|
|
40
40
|
const previousArtifacts = [];
|
|
41
|
-
const handle = async ({ imageData, frame, }) => {
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
if (previousArtifact) {
|
|
51
|
-
throw new Error(`An artifact with output "${artifact.filename}" was already registered at frame ${previousArtifact.frame}, but now registered again at frame ${frame}. Artifacts must have unique names. https://remotion.dev/docs/artifacts`);
|
|
52
|
-
}
|
|
53
|
-
onArtifact(artifact);
|
|
54
|
-
previousArtifacts.push({ frame, filename: artifact.filename });
|
|
41
|
+
const handle = async ({ imageData, frame, assets: artifactAssets, onArtifact, }) => {
|
|
42
|
+
const artifacts = await onlyArtifact({
|
|
43
|
+
assets: artifactAssets,
|
|
44
|
+
frameBuffer: imageData,
|
|
45
|
+
});
|
|
46
|
+
for (const artifact of artifacts) {
|
|
47
|
+
const previousArtifact = previousArtifacts.find((a) => a.filename === artifact.filename);
|
|
48
|
+
if (previousArtifact) {
|
|
49
|
+
throw new Error(`An artifact with output "${artifact.filename}" was already registered at frame ${previousArtifact.frame}, but now registered again at frame ${frame}. Artifacts must have unique names. https://remotion.dev/docs/artifacts`);
|
|
55
50
|
}
|
|
51
|
+
onArtifact(artifact);
|
|
52
|
+
previousArtifacts.push({ frame, filename: artifact.filename });
|
|
56
53
|
}
|
|
57
54
|
};
|
|
58
55
|
return { handle };
|
package/dist/audio.d.ts
ADDED
package/dist/audio.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
const TARGET_NUMBER_OF_CHANNELS = 2;
|
|
2
|
+
const TARGET_SAMPLE_RATE = 48000;
|
|
3
|
+
function mixAudio(waves, length) {
|
|
4
|
+
if (waves.length === 1) {
|
|
5
|
+
return waves[0];
|
|
6
|
+
}
|
|
7
|
+
const mixed = new Int16Array(length);
|
|
8
|
+
for (let i = 0; i < length; i++) {
|
|
9
|
+
const sum = waves.reduce((acc, wave) => acc + wave[i], 0);
|
|
10
|
+
// Clamp to Int16 range
|
|
11
|
+
mixed[i] = Math.max(-32768, Math.min(32767, sum));
|
|
12
|
+
}
|
|
13
|
+
return mixed;
|
|
14
|
+
}
|
|
15
|
+
export const onlyInlineAudio = (assets) => {
|
|
16
|
+
const inlineAudio = assets.filter((asset) => asset.type === 'inline-audio');
|
|
17
|
+
let length = null;
|
|
18
|
+
for (const asset of inlineAudio) {
|
|
19
|
+
if (asset.toneFrequency !== 1) {
|
|
20
|
+
throw new Error('Setting the toneFrequency is not supported yet in web rendering.');
|
|
21
|
+
}
|
|
22
|
+
if (length === null) {
|
|
23
|
+
length = asset.audio.length;
|
|
24
|
+
// 1 frame offset may happen due to rounding, it is safe to truncate the last sample
|
|
25
|
+
}
|
|
26
|
+
else if (Math.abs(length - asset.audio.length) > TARGET_NUMBER_OF_CHANNELS) {
|
|
27
|
+
throw new Error('All inline audio must have the same length');
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
length = Math.min(length, asset.audio.length);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
if (length === null) {
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
const mixedAudio = mixAudio(inlineAudio.map((asset) => asset.audio), length);
|
|
37
|
+
return new AudioData({
|
|
38
|
+
data: mixedAudio,
|
|
39
|
+
format: 's16',
|
|
40
|
+
numberOfChannels: TARGET_NUMBER_OF_CHANNELS,
|
|
41
|
+
numberOfFrames: length / TARGET_NUMBER_OF_CHANNELS,
|
|
42
|
+
sampleRate: TARGET_SAMPLE_RATE,
|
|
43
|
+
timestamp: inlineAudio[0].timestamp,
|
|
44
|
+
});
|
|
45
|
+
};
|