mediabunny 1.50.7 → 1.50.9

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.
@@ -4215,8 +4215,17 @@ var Mediabunny = (() => {
4215
4215
  ];
4216
4216
  var parseOpusTocByte = (packet) => {
4217
4217
  const config = packet[0] >> 3;
4218
+ const code = packet[0] & 3;
4219
+ let frameCount;
4220
+ if (code === 0) {
4221
+ frameCount = 1;
4222
+ } else if (code === 1 || code === 2) {
4223
+ frameCount = 2;
4224
+ } else {
4225
+ frameCount = packet[1] & 63;
4226
+ }
4218
4227
  return {
4219
- durationInSamples: OPUS_FRAME_DURATION_TABLE[config]
4228
+ durationInSamples: OPUS_FRAME_DURATION_TABLE[config] * frameCount
4220
4229
  };
4221
4230
  };
4222
4231
  var parseModesFromVorbisSetupPacket = (setupHeader) => {
@@ -12379,6 +12388,21 @@ var Mediabunny = (() => {
12379
12388
  if (formatTag === 7 /* MULAW */ || formatTag === 6 /* ALAW */) {
12380
12389
  bitsPerSample = 8;
12381
12390
  }
12391
+ if (formatTag !== 1 /* PCM */ && formatTag !== 3 /* IEEE_FLOAT */ && formatTag !== 6 /* ALAW */ && formatTag !== 7 /* MULAW */) {
12392
+ throw new Error(
12393
+ `Unsupported WAVE codec (format tag ${formatTag}). Only integer/float PCM, A-law, and \u03BC-law are supported.`
12394
+ );
12395
+ }
12396
+ if (formatTag === 1 /* PCM */ && ![8, 16, 24, 32].includes(bitsPerSample)) {
12397
+ throw new Error(
12398
+ `Unsupported WAVE PCM bit depth (${bitsPerSample}). Only 8, 16, 24, and 32 bits are supported.`
12399
+ );
12400
+ }
12401
+ if (formatTag === 3 /* IEEE_FLOAT */ && ![32, 64].includes(bitsPerSample)) {
12402
+ throw new Error(
12403
+ `Unsupported WAVE float bit depth (${bitsPerSample}). Only 32 and 64 bits are supported.`
12404
+ );
12405
+ }
12382
12406
  this.audioInfo = {
12383
12407
  format: formatTag,
12384
12408
  numberOfChannels: numChannels,
@@ -12527,9 +12551,11 @@ var Mediabunny = (() => {
12527
12551
  if (this.audioInfo.format === 3 /* IEEE_FLOAT */) {
12528
12552
  if (this.audioInfo.sampleSizeInBytes === 4) {
12529
12553
  return "pcm-f32";
12554
+ } else if (this.audioInfo.sampleSizeInBytes === 8) {
12555
+ return "pcm-f64";
12530
12556
  }
12531
12557
  }
12532
- return null;
12558
+ assert(false);
12533
12559
  }
12534
12560
  async getMimeType() {
12535
12561
  return "audio/wav";
@@ -28949,6 +28975,7 @@ var Mediabunny = (() => {
28949
28975
  this.isQuickTime = format instanceof MovOutputFormat;
28950
28976
  this.isCmaf = format instanceof CmafOutputFormat;
28951
28977
  this.minimumFragmentDuration = format._options.minimumFragmentDuration ?? (format instanceof CmafOutputFormat ? Infinity : 1);
28978
+ this.auxWriter.start();
28952
28979
  }
28953
28980
  async start() {
28954
28981
  const release = await this.mutex.acquire();
@@ -30750,7 +30777,8 @@ ${cue.notes ?? ""}`;
30750
30777
  view2.setUint8(0, 128 | trackData.track.id);
30751
30778
  view2.setInt16(1, relativeTimestamp, false);
30752
30779
  const msDuration = Math.round(1e3 * chunk.duration);
30753
- if (!chunk.additions) {
30780
+ const needsBlockGroup = !!chunk.additions || trackData.type === "subtitle";
30781
+ if (!needsBlockGroup) {
30754
30782
  view2.setUint8(3, Number(chunk.type === "key") << 7);
30755
30783
  const simpleBlock = { id: 163 /* SimpleBlock */, data: [
30756
30784
  prelude,
@@ -35907,7 +35935,7 @@ ${cue.notes ?? ""}`;
35907
35935
  getSupportedCodecs() {
35908
35936
  return [
35909
35937
  ...PCM_AUDIO_CODECS.filter(
35910
- (codec) => ["pcm-s16", "pcm-s24", "pcm-s32", "pcm-f32", "pcm-u8", "ulaw", "alaw"].includes(codec)
35938
+ (codec) => ["pcm-s16", "pcm-s24", "pcm-s32", "pcm-f32", "pcm-f64", "pcm-u8", "ulaw", "alaw"].includes(codec)
35911
35939
  )
35912
35940
  ];
35913
35941
  }
@@ -37423,32 +37451,39 @@ The @mediabunny/mp3-encoder extension package provides support for encoding MP3.
37423
37451
  assert(encodingConfig.transform);
37424
37452
  let needsRerender = width !== originalWidth || height !== originalHeight || totalRotation !== 0 && (!canUseRotationMetadata || trackOptions.process !== void 0) || !!crop || squarePixelWidth !== await track.getCodedWidth() || squarePixelHeight !== await track.getCodedHeight();
37425
37453
  if (!needsRerender) {
37426
- const tempOutput = new Output({
37427
- format: new Mp4OutputFormat(),
37428
- // Supports all video codecs
37429
- target: new NullTarget()
37430
- });
37431
- const tempSource = new VideoSampleSource(encodingConfig);
37432
- tempOutput.addVideoTrack(tempSource);
37433
- await tempOutput.start();
37434
- const sink = new VideoSampleSink(track);
37435
- const firstSample = await sink.getSample(firstTimestamp);
37436
- if (firstSample) {
37437
- try {
37438
- await tempSource.add(firstSample);
37439
- firstSample.close();
37440
- await tempOutput.finalize();
37441
- } catch (error) {
37442
- Logging._warn(
37443
- "An error occurred when probing encoder support. Falling back to rerender path.",
37444
- error
37445
- );
37446
- void tempOutput.cancel();
37447
- needsRerender = true;
37448
- encodingConfig.transform.force = true;
37454
+ var _stack = [];
37455
+ try {
37456
+ const tempOutput = new Output({
37457
+ format: new Mp4OutputFormat(),
37458
+ // Supports all video codecs
37459
+ target: new NullTarget()
37460
+ });
37461
+ const tempSource = new VideoSampleSource(encodingConfig);
37462
+ tempOutput.addVideoTrack(tempSource);
37463
+ await tempOutput.start();
37464
+ const sink = new VideoSampleSink(track);
37465
+ const firstSample = __using(_stack, await sink.getSample(firstTimestamp));
37466
+ if (firstSample) {
37467
+ try {
37468
+ await tempSource.add(firstSample);
37469
+ firstSample.close();
37470
+ await tempOutput.finalize();
37471
+ } catch (error) {
37472
+ Logging._warn(
37473
+ "An error occurred when probing encoder support. Falling back to rerender path.",
37474
+ error
37475
+ );
37476
+ void tempOutput.cancel();
37477
+ needsRerender = true;
37478
+ encodingConfig.transform.force = true;
37479
+ }
37480
+ } else {
37481
+ await tempOutput.cancel();
37449
37482
  }
37450
- } else {
37451
- await tempOutput.cancel();
37483
+ } catch (_) {
37484
+ var _error = _, _hasError = true;
37485
+ } finally {
37486
+ __callDispose(_stack, _error, _hasError);
37452
37487
  }
37453
37488
  }
37454
37489
  if (trackOptions.frameRate) {
@@ -37475,21 +37510,28 @@ The @mediabunny/mp3-encoder extension package provides support for encoding MP3.
37475
37510
  this._trackPromises.push((async () => {
37476
37511
  await this._started;
37477
37512
  const sink = new VideoSampleSink(track);
37478
- for await (const sample of sink.samples(this._startTimestamp, this._endTimestamp)) {
37479
- if (this._canceled) {
37513
+ for await (var _sample of sink.samples(this._startTimestamp, this._endTimestamp)) {
37514
+ var _stack2 = [];
37515
+ try {
37516
+ const sample = __using(_stack2, _sample);
37517
+ if (this._canceled) {
37518
+ return;
37519
+ }
37520
+ const adjustedSampleTimestamp = Math.max(sample.timestamp - this._startTimestamp, 0);
37521
+ sample.setTimestamp(adjustedSampleTimestamp);
37522
+ this._reportProgress(outputTrackId, sample.timestamp + sample.duration);
37523
+ await source.add(sample);
37480
37524
  sample.close();
37481
- return;
37482
- }
37483
- const adjustedSampleTimestamp = Math.max(sample.timestamp - this._startTimestamp, 0);
37484
- sample.setTimestamp(adjustedSampleTimestamp);
37485
- this._reportProgress(outputTrackId, sample.timestamp + sample.duration);
37486
- await source.add(sample);
37487
- if (lastSampleTimestamp !== null) {
37488
- if (this._synchronizer.shouldWait(outputTrackId, lastSampleTimestamp)) {
37489
- await this._synchronizer.wait(lastSampleTimestamp);
37525
+ if (lastSampleTimestamp !== null) {
37526
+ if (this._synchronizer.shouldWait(outputTrackId, lastSampleTimestamp)) {
37527
+ await this._synchronizer.wait(lastSampleTimestamp);
37528
+ }
37490
37529
  }
37530
+ } catch (_2) {
37531
+ var _error2 = _2, _hasError2 = true;
37532
+ } finally {
37533
+ __callDispose(_stack2, _error2, _hasError2);
37491
37534
  }
37492
- sample.close();
37493
37535
  }
37494
37536
  source.close();
37495
37537
  this._synchronizer.closeTrack(outputTrackId);
@@ -37630,50 +37672,75 @@ The @mediabunny/mp3-encoder extension package provides support for encoding MP3.
37630
37672
  this._trackPromises.push((async () => {
37631
37673
  await this._started;
37632
37674
  const sink = new AudioSampleSink(track);
37633
- for await (let sample of sink.samples(this._startTimestamp, this._endTimestamp)) {
37634
- if (this._canceled) {
37635
- sample.close();
37636
- return;
37637
- }
37638
- if (needsPadding) {
37639
- const paddingLength = firstTimestamp - this._startTimestamp;
37640
- const paddingLengthSamples = Math.round(paddingLength * originalSampleRate);
37641
- const bytesPerSample = getBytesPerSample(sample.format);
37642
- const data = new Uint8Array(bytesPerSample * paddingLengthSamples * originalNumberOfChannels);
37643
- if (sample.format === "u8" || sample.format === "u8-planar") {
37644
- data.fill(2 ** 7);
37645
- }
37646
- const silentSample = new AudioSample({
37647
- data,
37648
- // Use the same format the decoder is spitting out. This avoids feeding changing sample
37649
- // formats to the audio encoder.
37650
- format: sample.format,
37651
- numberOfChannels: originalNumberOfChannels,
37652
- sampleRate: originalSampleRate,
37653
- timestamp: 0
37654
- });
37655
- await this._registerAudioSample(silentSample, source, outputTrackId, () => lastSampleTimestamp);
37656
- needsPadding = false;
37657
- }
37658
- let startFrame = 0;
37659
- let endFrame = sample.numberOfFrames;
37660
- if (sample.timestamp < this._startTimestamp) {
37661
- startFrame = Math.round((this._startTimestamp - sample.timestamp) * sample.sampleRate);
37662
- }
37663
- if (sample.timestamp + sample.duration > this._endTimestamp) {
37664
- endFrame = Math.round((this._endTimestamp - sample.timestamp) * sample.sampleRate);
37665
- }
37666
- if (startFrame > 0 || endFrame < sample.numberOfFrames) {
37667
- const trimmedSample = sample.trim(startFrame, endFrame);
37668
- sample.close();
37669
- sample = trimmedSample;
37670
- if (sample.numberOfFrames === 0) {
37671
- sample.close();
37672
- continue;
37675
+ for await (var _sample of sink.samples(this._startTimestamp, this._endTimestamp)) {
37676
+ var _stack3 = [];
37677
+ try {
37678
+ const sample = __using(_stack3, _sample);
37679
+ var _stack2 = [];
37680
+ try {
37681
+ if (this._canceled) {
37682
+ return;
37683
+ }
37684
+ if (needsPadding) {
37685
+ var _stack = [];
37686
+ try {
37687
+ const paddingLength = firstTimestamp - this._startTimestamp;
37688
+ const paddingLengthSamples = Math.round(paddingLength * originalSampleRate);
37689
+ const bytesPerSample = getBytesPerSample(sample.format);
37690
+ const data = new Uint8Array(bytesPerSample * paddingLengthSamples * originalNumberOfChannels);
37691
+ if (sample.format === "u8" || sample.format === "u8-planar") {
37692
+ data.fill(2 ** 7);
37693
+ }
37694
+ const silentSample = __using(_stack, new AudioSample({
37695
+ data,
37696
+ // Use the same format the decoder is spitting out. This avoids feeding changing sample
37697
+ // formats to the audio encoder.
37698
+ format: sample.format,
37699
+ numberOfChannels: originalNumberOfChannels,
37700
+ sampleRate: originalSampleRate,
37701
+ timestamp: 0
37702
+ }));
37703
+ await this._registerAudioSample(silentSample, source, outputTrackId, () => lastSampleTimestamp);
37704
+ needsPadding = false;
37705
+ } catch (_) {
37706
+ var _error = _, _hasError = true;
37707
+ } finally {
37708
+ __callDispose(_stack, _error, _hasError);
37709
+ }
37710
+ }
37711
+ let startFrame = 0;
37712
+ let endFrame = sample.numberOfFrames;
37713
+ if (sample.timestamp < this._startTimestamp) {
37714
+ startFrame = Math.round((this._startTimestamp - sample.timestamp) * sample.sampleRate);
37715
+ }
37716
+ if (sample.timestamp + sample.duration > this._endTimestamp) {
37717
+ endFrame = Math.round((this._endTimestamp - sample.timestamp) * sample.sampleRate);
37718
+ }
37719
+ let finalSampleLet;
37720
+ if (startFrame > 0 || endFrame < sample.numberOfFrames) {
37721
+ const trimmedSample = sample.trim(startFrame, endFrame);
37722
+ sample.close();
37723
+ finalSampleLet = trimmedSample;
37724
+ if (trimmedSample.numberOfFrames === 0) {
37725
+ trimmedSample.close();
37726
+ continue;
37727
+ }
37728
+ } else {
37729
+ finalSampleLet = sample;
37730
+ }
37731
+ const finalSample = __using(_stack2, finalSampleLet);
37732
+ finalSample.setTimestamp(finalSample.timestamp - this._startTimestamp);
37733
+ await this._registerAudioSample(finalSample, source, outputTrackId, () => lastSampleTimestamp);
37734
+ } catch (_2) {
37735
+ var _error2 = _2, _hasError2 = true;
37736
+ } finally {
37737
+ __callDispose(_stack2, _error2, _hasError2);
37673
37738
  }
37739
+ } catch (_3) {
37740
+ var _error3 = _3, _hasError3 = true;
37741
+ } finally {
37742
+ __callDispose(_stack3, _error3, _hasError3);
37674
37743
  }
37675
- sample.setTimestamp(sample.timestamp - this._startTimestamp);
37676
- await this._registerAudioSample(sample, source, outputTrackId, () => lastSampleTimestamp);
37677
37744
  }
37678
37745
  source.close();
37679
37746
  this._synchronizer.closeTrack(outputTrackId);