@remotion/webcodecs 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.
- package/dist/esm/index.mjs +15 -8
- package/dist/get-partial-audio-data.js +19 -8
- package/package.json +5 -5
package/dist/esm/index.mjs
CHANGED
|
@@ -5870,14 +5870,14 @@ var extractOverlappingAudioSamples = ({
|
|
|
5870
5870
|
const samplesPerChannel = sample.numberOfFrames;
|
|
5871
5871
|
let data;
|
|
5872
5872
|
if (numberOfChannels === 1) {
|
|
5873
|
-
data = new Float32Array(
|
|
5873
|
+
data = new Float32Array(samplesPerChannel);
|
|
5874
5874
|
sample.copyTo(data, { format: "f32", planeIndex: 0 });
|
|
5875
5875
|
} else {
|
|
5876
|
-
const
|
|
5877
|
-
sample.copyTo(
|
|
5876
|
+
const interleaved = new Float32Array(samplesPerChannel * numberOfChannels);
|
|
5877
|
+
sample.copyTo(interleaved, { format: "f32", planeIndex: 0 });
|
|
5878
5878
|
data = new Float32Array(samplesPerChannel);
|
|
5879
5879
|
for (let i = 0;i < samplesPerChannel; i++) {
|
|
5880
|
-
data[i] =
|
|
5880
|
+
data[i] = interleaved[i * numberOfChannels + channelIndex];
|
|
5881
5881
|
}
|
|
5882
5882
|
}
|
|
5883
5883
|
const startSampleInChunk = Math.floor((overlapStartSecond - chunkStartInSeconds) * sample.sampleRate);
|
|
@@ -5904,8 +5904,9 @@ var getPartialAudioData = async ({
|
|
|
5904
5904
|
};
|
|
5905
5905
|
signal.addEventListener("abort", onAbort, { once: true });
|
|
5906
5906
|
try {
|
|
5907
|
-
|
|
5908
|
-
|
|
5907
|
+
const seekFromSeconds = Math.max(0, fromSeconds - BUFFER_IN_SECONDS);
|
|
5908
|
+
if (seekFromSeconds > 0) {
|
|
5909
|
+
controller.seek(seekFromSeconds);
|
|
5909
5910
|
}
|
|
5910
5911
|
await parseMedia2({
|
|
5911
5912
|
acknowledgeRemotionLicense: true,
|
|
@@ -5948,8 +5949,8 @@ var getPartialAudioData = async ({
|
|
|
5948
5949
|
if (!audioDecoder) {
|
|
5949
5950
|
throw new Error("No audio decoder found");
|
|
5950
5951
|
}
|
|
5951
|
-
const fromSecondsWithBuffer =
|
|
5952
|
-
const toSecondsWithBuffer = toSeconds
|
|
5952
|
+
const fromSecondsWithBuffer = Math.max(0, fromSeconds - BUFFER_IN_SECONDS);
|
|
5953
|
+
const toSecondsWithBuffer = toSeconds + BUFFER_IN_SECONDS;
|
|
5953
5954
|
const time = sample.timestamp / track.timescale;
|
|
5954
5955
|
if (time < fromSecondsWithBuffer) {
|
|
5955
5956
|
return;
|
|
@@ -5964,6 +5965,12 @@ var getPartialAudioData = async ({
|
|
|
5964
5965
|
}
|
|
5965
5966
|
await audioDecoder.waitForQueueToBeLessThan(10);
|
|
5966
5967
|
audioDecoder.decode(sample);
|
|
5968
|
+
return () => {
|
|
5969
|
+
audioDecoder.flush().then(() => {
|
|
5970
|
+
audioDecoder.close();
|
|
5971
|
+
resolveAudioDecode();
|
|
5972
|
+
});
|
|
5973
|
+
};
|
|
5967
5974
|
};
|
|
5968
5975
|
}
|
|
5969
5976
|
});
|
|
@@ -23,17 +23,17 @@ const extractOverlappingAudioSamples = ({ sample, fromSeconds, toSeconds, channe
|
|
|
23
23
|
let data;
|
|
24
24
|
if (numberOfChannels === 1) {
|
|
25
25
|
// Mono audio
|
|
26
|
-
data = new Float32Array(
|
|
26
|
+
data = new Float32Array(samplesPerChannel);
|
|
27
27
|
sample.copyTo(data, { format: 'f32', planeIndex: 0 });
|
|
28
28
|
}
|
|
29
29
|
else {
|
|
30
30
|
// Multi-channel audio: extract specific channel
|
|
31
|
-
const
|
|
32
|
-
sample.copyTo(
|
|
31
|
+
const interleaved = new Float32Array(samplesPerChannel * numberOfChannels);
|
|
32
|
+
sample.copyTo(interleaved, { format: 'f32', planeIndex: 0 });
|
|
33
33
|
// Extract the specific channel (interleaved audio)
|
|
34
34
|
data = new Float32Array(samplesPerChannel);
|
|
35
35
|
for (let i = 0; i < samplesPerChannel; i++) {
|
|
36
|
-
data[i] =
|
|
36
|
+
data[i] = interleaved[i * numberOfChannels + channelIndex];
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
39
|
// Calculate which samples to keep from this chunk
|
|
@@ -62,8 +62,10 @@ const getPartialAudioData = async ({ src, fromSeconds, toSeconds, channelIndex,
|
|
|
62
62
|
};
|
|
63
63
|
signal.addEventListener('abort', onAbort, { once: true });
|
|
64
64
|
try {
|
|
65
|
-
|
|
66
|
-
|
|
65
|
+
// expand decode window slightly to avoid gaps at boundaries
|
|
66
|
+
const seekFromSeconds = Math.max(0, fromSeconds - BUFFER_IN_SECONDS);
|
|
67
|
+
if (seekFromSeconds > 0) {
|
|
68
|
+
controller.seek(seekFromSeconds);
|
|
67
69
|
}
|
|
68
70
|
await (0, media_parser_1.parseMedia)({
|
|
69
71
|
acknowledgeRemotionLicense: true,
|
|
@@ -106,8 +108,9 @@ const getPartialAudioData = async ({ src, fromSeconds, toSeconds, channelIndex,
|
|
|
106
108
|
if (!audioDecoder) {
|
|
107
109
|
throw new Error('No audio decoder found');
|
|
108
110
|
}
|
|
109
|
-
|
|
110
|
-
const
|
|
111
|
+
// decode a bit earlier and later than requested, trimming happens later
|
|
112
|
+
const fromSecondsWithBuffer = Math.max(0, fromSeconds - BUFFER_IN_SECONDS);
|
|
113
|
+
const toSecondsWithBuffer = toSeconds + BUFFER_IN_SECONDS;
|
|
111
114
|
// Convert timestamp using the track's timescale
|
|
112
115
|
const time = sample.timestamp / track.timescale;
|
|
113
116
|
// Skip samples that are before our requested start time (with buffer)
|
|
@@ -127,6 +130,14 @@ const getPartialAudioData = async ({ src, fromSeconds, toSeconds, channelIndex,
|
|
|
127
130
|
await audioDecoder.waitForQueueToBeLessThan(10);
|
|
128
131
|
// we're waiting for the queue above anyway, enqueue in sync mode
|
|
129
132
|
audioDecoder.decode(sample);
|
|
133
|
+
// this is called on the last sample of the track
|
|
134
|
+
// so if we have reached the end of the track, resolve the promise
|
|
135
|
+
return () => {
|
|
136
|
+
audioDecoder.flush().then(() => {
|
|
137
|
+
audioDecoder.close();
|
|
138
|
+
resolveAudioDecode();
|
|
139
|
+
});
|
|
140
|
+
};
|
|
130
141
|
};
|
|
131
142
|
},
|
|
132
143
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@remotion/webcodecs",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.384",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"module": "dist/esm/index.mjs",
|
|
@@ -27,14 +27,14 @@
|
|
|
27
27
|
"author": "Jonny Burger <jonny@remotion.dev>",
|
|
28
28
|
"license": "Remotion License (See https://remotion.dev/docs/webcodecs#license)",
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@remotion/media-parser": "4.0.
|
|
31
|
-
"@remotion/licensing": "4.0.
|
|
30
|
+
"@remotion/media-parser": "4.0.384",
|
|
31
|
+
"@remotion/licensing": "4.0.384"
|
|
32
32
|
},
|
|
33
33
|
"peerDependencies": {},
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"@types/dom-webcodecs": "0.1.11",
|
|
36
|
-
"@remotion/example-videos": "4.0.
|
|
37
|
-
"@remotion/eslint-config-internal": "4.0.
|
|
36
|
+
"@remotion/example-videos": "4.0.384",
|
|
37
|
+
"@remotion/eslint-config-internal": "4.0.384",
|
|
38
38
|
"playwright": "1.55.1",
|
|
39
39
|
"vite": "5.4.21",
|
|
40
40
|
"@playwright/test": "1.55.1",
|