@remotion/media 4.0.511 → 4.0.513
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.
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type LogLevel } from 'remotion';
|
|
2
2
|
import type { MediaCache } from '../caches';
|
|
3
|
-
import type
|
|
3
|
+
import { type PcmS16AudioData } from '../convert-audiodata/convert-audiodata';
|
|
4
4
|
import type { MediaRequestInit } from '../request-init';
|
|
5
5
|
type ExtractAudioParams = {
|
|
6
6
|
src: string;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
export declare const combineAudioDataAndClosePrevious: (audioDataArray:
|
|
1
|
+
import { type UnresampledPcmS16AudioData } from './convert-audiodata';
|
|
2
|
+
export declare const combineAudioDataAndClosePrevious: (audioDataArray: UnresampledPcmS16AudioData[]) => UnresampledPcmS16AudioData;
|
|
@@ -12,5 +12,15 @@ export type PcmS16AudioData = {
|
|
|
12
12
|
timestamp: number;
|
|
13
13
|
durationInMicroSeconds: number;
|
|
14
14
|
};
|
|
15
|
+
export type UnresampledPcmS16AudioData = PcmS16AudioData & {
|
|
16
|
+
numberOfChannels: number;
|
|
17
|
+
sampleRate: number;
|
|
18
|
+
};
|
|
15
19
|
export declare const fixFloatingPoint: (value: number) => number;
|
|
16
|
-
export declare const
|
|
20
|
+
export declare const convertAudioDataToS16: ({ audioData, trimStartInSeconds, trimEndInSeconds, audioDataTimestamp, isLast, }: Omit<ConvertAudioDataOptions, "playbackRate">) => UnresampledPcmS16AudioData;
|
|
21
|
+
export declare const resamplePcmS16AudioData: ({ audioData, playbackRate, isLast, }: {
|
|
22
|
+
audioData: UnresampledPcmS16AudioData;
|
|
23
|
+
playbackRate: number;
|
|
24
|
+
isLast: boolean;
|
|
25
|
+
}) => PcmS16AudioData;
|
|
26
|
+
export declare const convertAudioData: (options: ConvertAudioDataOptions) => PcmS16AudioData;
|
package/dist/esm/index.mjs
CHANGED
|
@@ -2146,9 +2146,11 @@ class MediaPlayer {
|
|
|
2146
2146
|
}
|
|
2147
2147
|
setIsPremounting(isPremounting) {
|
|
2148
2148
|
this.premountAwareDelayPlayback.setIsPremounting(isPremounting);
|
|
2149
|
+
processNext();
|
|
2149
2150
|
}
|
|
2150
2151
|
setIsPostmounting(isPostmounting) {
|
|
2151
2152
|
this.premountAwareDelayPlayback.setIsPostmounting(isPostmounting);
|
|
2153
|
+
processNext();
|
|
2152
2154
|
}
|
|
2153
2155
|
async setLoop(loop, unloopedTimeInSeconds) {
|
|
2154
2156
|
const previousLoop = this.loop;
|
|
@@ -4196,11 +4198,10 @@ var ceilButNotIfFloatingPointIssue = (value) => {
|
|
|
4196
4198
|
const fixed = fixFloatingPoint2(value);
|
|
4197
4199
|
return Math.ceil(fixed);
|
|
4198
4200
|
};
|
|
4199
|
-
var
|
|
4201
|
+
var convertAudioDataToS16 = ({
|
|
4200
4202
|
audioData,
|
|
4201
4203
|
trimStartInSeconds,
|
|
4202
4204
|
trimEndInSeconds,
|
|
4203
|
-
playbackRate,
|
|
4204
4205
|
audioDataTimestamp,
|
|
4205
4206
|
isLast
|
|
4206
4207
|
}) => {
|
|
@@ -4209,14 +4210,9 @@ var convertAudioData = ({
|
|
|
4209
4210
|
sampleRate: currentSampleRate,
|
|
4210
4211
|
numberOfFrames
|
|
4211
4212
|
} = audioData;
|
|
4212
|
-
const ratio = currentSampleRate / getTargetSampleRate();
|
|
4213
4213
|
const frameOffset = Math.floor(fixFloatingPoint2(trimStartInSeconds * audioData.sampleRate));
|
|
4214
4214
|
const unroundedFrameCount = numberOfFrames - trimEndInSeconds * audioData.sampleRate - frameOffset;
|
|
4215
4215
|
const frameCount = isLast ? ceilButNotIfFloatingPointIssue(unroundedFrameCount) : Math.round(unroundedFrameCount);
|
|
4216
|
-
const newNumberOfFrames = isLast ? ceilButNotIfFloatingPointIssue(unroundedFrameCount / ratio / playbackRate) : Math.round(unroundedFrameCount / ratio / playbackRate);
|
|
4217
|
-
if (newNumberOfFrames === 0) {
|
|
4218
|
-
throw new Error("Cannot resample - the given sample rate would result in less than 1 sample");
|
|
4219
|
-
}
|
|
4220
4216
|
const srcChannels = new Int16Array(srcNumberOfChannels * frameCount);
|
|
4221
4217
|
const isF32 = audioData.format === "f32" || audioData.format === "f32-planar";
|
|
4222
4218
|
if (isF32) {
|
|
@@ -4248,20 +4244,39 @@ var convertAudioData = ({
|
|
|
4248
4244
|
frameCount
|
|
4249
4245
|
});
|
|
4250
4246
|
}
|
|
4251
|
-
const data = new Int16Array(newNumberOfFrames * TARGET_NUMBER_OF_CHANNELS);
|
|
4252
|
-
const chunkSize = frameCount / newNumberOfFrames;
|
|
4253
4247
|
const timestampOffsetMicroseconds = frameOffset / audioData.sampleRate * 1e6;
|
|
4254
|
-
|
|
4248
|
+
return {
|
|
4249
|
+
data: srcChannels,
|
|
4250
|
+
numberOfChannels: srcNumberOfChannels,
|
|
4251
|
+
numberOfFrames: frameCount,
|
|
4252
|
+
sampleRate: currentSampleRate,
|
|
4253
|
+
timestamp: audioDataTimestamp * 1e6 + fixFloatingPoint2(timestampOffsetMicroseconds),
|
|
4254
|
+
durationInMicroSeconds: fixFloatingPoint2(frameCount / currentSampleRate * 1e6)
|
|
4255
|
+
};
|
|
4256
|
+
};
|
|
4257
|
+
var resamplePcmS16AudioData = ({
|
|
4258
|
+
audioData,
|
|
4259
|
+
playbackRate,
|
|
4260
|
+
isLast
|
|
4261
|
+
}) => {
|
|
4262
|
+
const ratio = audioData.sampleRate / getTargetSampleRate();
|
|
4263
|
+
const newNumberOfFrames = isLast ? ceilButNotIfFloatingPointIssue(audioData.numberOfFrames / ratio / playbackRate) : Math.round(audioData.numberOfFrames / ratio / playbackRate);
|
|
4264
|
+
if (newNumberOfFrames === 0) {
|
|
4265
|
+
throw new Error("Cannot resample - the given sample rate would result in less than 1 sample");
|
|
4266
|
+
}
|
|
4267
|
+
if (newNumberOfFrames === audioData.numberOfFrames && TARGET_NUMBER_OF_CHANNELS === audioData.numberOfChannels && playbackRate === 1) {
|
|
4255
4268
|
return {
|
|
4256
|
-
data:
|
|
4269
|
+
data: audioData.data,
|
|
4257
4270
|
numberOfFrames: newNumberOfFrames,
|
|
4258
|
-
timestamp:
|
|
4271
|
+
timestamp: audioData.timestamp,
|
|
4259
4272
|
durationInMicroSeconds: fixFloatingPoint2(newNumberOfFrames / getTargetSampleRate() * 1e6)
|
|
4260
4273
|
};
|
|
4261
4274
|
}
|
|
4275
|
+
const data = new Int16Array(newNumberOfFrames * TARGET_NUMBER_OF_CHANNELS);
|
|
4276
|
+
const chunkSize = audioData.numberOfFrames / newNumberOfFrames;
|
|
4262
4277
|
resampleAudioData({
|
|
4263
|
-
srcNumberOfChannels,
|
|
4264
|
-
sourceChannels:
|
|
4278
|
+
srcNumberOfChannels: audioData.numberOfChannels,
|
|
4279
|
+
sourceChannels: audioData.data,
|
|
4265
4280
|
destination: data,
|
|
4266
4281
|
targetFrames: newNumberOfFrames,
|
|
4267
4282
|
chunkSize
|
|
@@ -4269,7 +4284,7 @@ var convertAudioData = ({
|
|
|
4269
4284
|
const newAudioData = {
|
|
4270
4285
|
data,
|
|
4271
4286
|
numberOfFrames: newNumberOfFrames,
|
|
4272
|
-
timestamp:
|
|
4287
|
+
timestamp: audioData.timestamp,
|
|
4273
4288
|
durationInMicroSeconds: fixFloatingPoint2(newNumberOfFrames / getTargetSampleRate() * 1e6)
|
|
4274
4289
|
};
|
|
4275
4290
|
return newAudioData;
|
|
@@ -4279,12 +4294,15 @@ var convertAudioData = ({
|
|
|
4279
4294
|
var combineAudioDataAndClosePrevious = (audioDataArray) => {
|
|
4280
4295
|
let numberOfFrames = 0;
|
|
4281
4296
|
let durationInMicroSeconds = 0;
|
|
4282
|
-
const { timestamp } = audioDataArray[0];
|
|
4297
|
+
const { numberOfChannels, sampleRate, timestamp } = audioDataArray[0];
|
|
4283
4298
|
for (const audioData of audioDataArray) {
|
|
4299
|
+
if (audioData.numberOfChannels !== numberOfChannels || audioData.sampleRate !== sampleRate) {
|
|
4300
|
+
throw new Error("Cannot combine audio data with different formats");
|
|
4301
|
+
}
|
|
4284
4302
|
numberOfFrames += audioData.numberOfFrames;
|
|
4285
4303
|
durationInMicroSeconds += audioData.durationInMicroSeconds;
|
|
4286
4304
|
}
|
|
4287
|
-
const arr = new Int16Array(numberOfFrames *
|
|
4305
|
+
const arr = new Int16Array(numberOfFrames * numberOfChannels);
|
|
4288
4306
|
let offset = 0;
|
|
4289
4307
|
for (const audioData of audioDataArray) {
|
|
4290
4308
|
arr.set(audioData.data, offset);
|
|
@@ -4292,7 +4310,9 @@ var combineAudioDataAndClosePrevious = (audioDataArray) => {
|
|
|
4292
4310
|
}
|
|
4293
4311
|
return {
|
|
4294
4312
|
data: arr,
|
|
4313
|
+
numberOfChannels,
|
|
4295
4314
|
numberOfFrames,
|
|
4315
|
+
sampleRate,
|
|
4296
4316
|
timestamp: fixFloatingPoint2(timestamp),
|
|
4297
4317
|
durationInMicroSeconds: fixFloatingPoint2(durationInMicroSeconds)
|
|
4298
4318
|
};
|
|
@@ -4378,12 +4398,14 @@ var extractAudioInternal = async ({
|
|
|
4378
4398
|
if (isFirstSample) {
|
|
4379
4399
|
trimStartInSeconds = fixFloatingPoint2(timeInSeconds - sample.timestamp);
|
|
4380
4400
|
if (trimStartInSeconds < 0) {
|
|
4381
|
-
const silenceFrames = Math.ceil(fixFloatingPoint2(-trimStartInSeconds *
|
|
4401
|
+
const silenceFrames = Math.ceil(fixFloatingPoint2(-trimStartInSeconds * audioDataRaw.sampleRate));
|
|
4382
4402
|
leadingSilence = {
|
|
4383
|
-
data: new Int16Array(silenceFrames *
|
|
4403
|
+
data: new Int16Array(silenceFrames * audioDataRaw.numberOfChannels),
|
|
4404
|
+
numberOfChannels: audioDataRaw.numberOfChannels,
|
|
4384
4405
|
numberOfFrames: silenceFrames,
|
|
4406
|
+
sampleRate: audioDataRaw.sampleRate,
|
|
4385
4407
|
timestamp: timeInSeconds * 1e6,
|
|
4386
|
-
durationInMicroSeconds: silenceFrames /
|
|
4408
|
+
durationInMicroSeconds: silenceFrames / audioDataRaw.sampleRate * 1e6
|
|
4387
4409
|
};
|
|
4388
4410
|
trimStartInSeconds = 0;
|
|
4389
4411
|
}
|
|
@@ -4391,11 +4413,10 @@ var extractAudioInternal = async ({
|
|
|
4391
4413
|
if (isLastSample) {
|
|
4392
4414
|
trimEndInSeconds = Math.max(0, sample.timestamp + sample.duration - (timeInSeconds + durationInSeconds));
|
|
4393
4415
|
}
|
|
4394
|
-
const audioData =
|
|
4416
|
+
const audioData = convertAudioDataToS16({
|
|
4395
4417
|
audioData: audioDataRaw,
|
|
4396
4418
|
trimStartInSeconds,
|
|
4397
4419
|
trimEndInSeconds,
|
|
4398
|
-
playbackRate,
|
|
4399
4420
|
audioDataTimestamp: sample.timestamp,
|
|
4400
4421
|
isLast: isLastSample
|
|
4401
4422
|
});
|
|
@@ -4412,7 +4433,12 @@ var extractAudioInternal = async ({
|
|
|
4412
4433
|
return { data: null, durationInSeconds: mediaDurationInSeconds };
|
|
4413
4434
|
}
|
|
4414
4435
|
const combined = combineAudioDataAndClosePrevious(audioDataArray);
|
|
4415
|
-
|
|
4436
|
+
const resampled = resamplePcmS16AudioData({
|
|
4437
|
+
audioData: combined,
|
|
4438
|
+
playbackRate,
|
|
4439
|
+
isLast: true
|
|
4440
|
+
});
|
|
4441
|
+
return { data: resampled, durationInSeconds: mediaDurationInSeconds };
|
|
4416
4442
|
} catch (err) {
|
|
4417
4443
|
const error = err;
|
|
4418
4444
|
if (isNetworkError(error)) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@remotion/media",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.513",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"module": "dist/esm/index.mjs",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"mediabunny": "1.50.8",
|
|
26
|
-
"remotion": "4.0.
|
|
26
|
+
"remotion": "4.0.513",
|
|
27
27
|
"zod": "4.4.3"
|
|
28
28
|
},
|
|
29
29
|
"peerDependencies": {
|
|
@@ -31,8 +31,8 @@
|
|
|
31
31
|
"react-dom": ">=16.8.0"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
|
-
"@remotion/eslint-config-internal": "4.0.
|
|
35
|
-
"@remotion/player": "4.0.
|
|
34
|
+
"@remotion/eslint-config-internal": "4.0.513",
|
|
35
|
+
"@remotion/player": "4.0.513",
|
|
36
36
|
"@vitest/browser-webdriverio": "4.0.9",
|
|
37
37
|
"eslint": "9.19.0",
|
|
38
38
|
"react": "19.2.3",
|