mediabunny 1.44.0 → 1.44.1

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.
Files changed (35) hide show
  1. package/dist/bundles/mediabunny.cjs +38 -45
  2. package/dist/bundles/mediabunny.min.cjs +4 -4
  3. package/dist/bundles/mediabunny.min.mjs +4 -4
  4. package/dist/bundles/mediabunny.mjs +38 -45
  5. package/dist/bundles/mediabunny.node.cjs +38 -45
  6. package/dist/modules/src/adts/adts-muxer.js +1 -1
  7. package/dist/modules/src/flac/flac-muxer.js +1 -1
  8. package/dist/modules/src/hls/hls-muxer.d.ts.map +1 -1
  9. package/dist/modules/src/hls/hls-muxer.js +8 -10
  10. package/dist/modules/src/isobmff/isobmff-muxer.d.ts.map +1 -1
  11. package/dist/modules/src/isobmff/isobmff-muxer.js +5 -4
  12. package/dist/modules/src/matroska/matroska-muxer.d.ts.map +1 -1
  13. package/dist/modules/src/matroska/matroska-muxer.js +7 -6
  14. package/dist/modules/src/media-source.d.ts.map +1 -1
  15. package/dist/modules/src/media-source.js +8 -17
  16. package/dist/modules/src/mp3/mp3-muxer.js +1 -1
  17. package/dist/modules/src/mpeg-ts/mpeg-ts-muxer.js +4 -4
  18. package/dist/modules/src/muxer.d.ts +1 -1
  19. package/dist/modules/src/muxer.d.ts.map +1 -1
  20. package/dist/modules/src/muxer.js +1 -3
  21. package/dist/modules/src/ogg/ogg-muxer.js +1 -1
  22. package/dist/modules/src/tsconfig.tsbuildinfo +1 -1
  23. package/dist/modules/src/wave/wave-muxer.js +1 -1
  24. package/package.json +1 -1
  25. package/src/adts/adts-muxer.ts +1 -1
  26. package/src/flac/flac-muxer.ts +1 -1
  27. package/src/hls/hls-muxer.ts +8 -12
  28. package/src/isobmff/isobmff-muxer.ts +6 -4
  29. package/src/matroska/matroska-muxer.ts +8 -6
  30. package/src/media-source.ts +8 -17
  31. package/src/mp3/mp3-muxer.ts +1 -1
  32. package/src/mpeg-ts/mpeg-ts-muxer.ts +4 -4
  33. package/src/muxer.ts +1 -5
  34. package/src/ogg/ogg-muxer.ts +1 -1
  35. package/src/wave/wave-muxer.ts +1 -1
@@ -24890,8 +24890,7 @@ var Mediabunny = (() => {
24890
24890
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
24891
24891
  onTrackClose(track) {
24892
24892
  }
24893
- validateAndNormalizeTimestamp(track, timestampInSeconds, isKeyPacket) {
24894
- timestampInSeconds += track.source._timestampOffset;
24893
+ validateTimestamp(track, timestampInSeconds, isKeyPacket) {
24895
24894
  if (timestampInSeconds < 0) {
24896
24895
  throw new Error(`Timestamps must be non-negative (got ${timestampInSeconds}s).`);
24897
24896
  }
@@ -24916,7 +24915,6 @@ var Mediabunny = (() => {
24916
24915
  }
24917
24916
  timestampInfo.maxTimestamp = Math.max(timestampInfo.maxTimestamp, timestampInSeconds);
24918
24917
  }
24919
- return timestampInSeconds;
24920
24918
  }
24921
24919
  };
24922
24920
 
@@ -24947,7 +24945,7 @@ var Mediabunny = (() => {
24947
24945
  async addEncodedAudioPacket(track, packet, meta) {
24948
24946
  const release = await this.mutex.acquire();
24949
24947
  try {
24950
- this.validateAndNormalizeTimestamp(track, packet.timestamp, packet.type === "key");
24948
+ this.validateTimestamp(track, packet.timestamp, packet.type === "key");
24951
24949
  if (this.inputIsAdts === null) {
24952
24950
  validateAudioChunkMetadata(meta);
24953
24951
  const description = meta?.decoderConfig?.description;
@@ -25112,7 +25110,7 @@ var Mediabunny = (() => {
25112
25110
  async addEncodedAudioPacket(track, packet, meta) {
25113
25111
  const release = await this.mutex.acquire();
25114
25112
  try {
25115
- this.validateAndNormalizeTimestamp(
25113
+ this.validateTimestamp(
25116
25114
  track,
25117
25115
  packet.timestamp,
25118
25116
  packet.type === "key"
@@ -27973,7 +27971,7 @@ var Mediabunny = (() => {
27973
27971
  }
27974
27972
  packetData = concatNalUnitsInLengthPrefixed(nalUnits, 4);
27975
27973
  }
27976
- const timestamp = this.validateAndNormalizeTimestamp(
27974
+ this.validateTimestamp(
27977
27975
  trackData.track,
27978
27976
  packet.timestamp,
27979
27977
  packet.type === "key"
@@ -27981,7 +27979,7 @@ var Mediabunny = (() => {
27981
27979
  const internalSample = this.createSampleForTrack(
27982
27980
  trackData,
27983
27981
  packetData,
27984
- timestamp,
27982
+ packet.timestamp,
27985
27983
  packet.duration,
27986
27984
  packet.type
27987
27985
  );
@@ -28003,11 +28001,12 @@ var Mediabunny = (() => {
28003
28001
  const headerLength = adtsFrame.crcCheck === null ? MIN_ADTS_FRAME_HEADER_SIZE : MAX_ADTS_FRAME_HEADER_SIZE;
28004
28002
  packetData = packetData.subarray(headerLength);
28005
28003
  }
28006
- let timestamp = this.validateAndNormalizeTimestamp(
28004
+ this.validateTimestamp(
28007
28005
  trackData.track,
28008
28006
  packet.timestamp,
28009
28007
  packet.type === "key"
28010
28008
  );
28009
+ let timestamp = packet.timestamp;
28011
28010
  let duration = packet.duration;
28012
28011
  if (trackData.info.requiresPcmTransformation) {
28013
28012
  const pcmInfo = parsePcmCodec(
@@ -28066,7 +28065,7 @@ var Mediabunny = (() => {
28066
28065
  const release = await this.mutex.acquire();
28067
28066
  try {
28068
28067
  const trackData = this.getSubtitleTrackData(track, meta);
28069
- this.validateAndNormalizeTimestamp(trackData.track, cue.timestamp, true);
28068
+ this.validateTimestamp(trackData.track, cue.timestamp, true);
28070
28069
  if (track.source._codec === "webvtt") {
28071
28070
  trackData.cueQueue.push(cue);
28072
28071
  await this.processWebVTTCues(trackData, cue.timestamp);
@@ -29296,7 +29295,8 @@ var Mediabunny = (() => {
29296
29295
  try {
29297
29296
  const trackData = this.getVideoTrackData(track, packet, meta);
29298
29297
  const isKeyFrame = packet.type === "key";
29299
- let timestamp = this.validateAndNormalizeTimestamp(trackData.track, packet.timestamp, isKeyFrame);
29298
+ this.validateTimestamp(trackData.track, packet.timestamp, isKeyFrame);
29299
+ let timestamp = packet.timestamp;
29300
29300
  let duration = packet.duration;
29301
29301
  if (track.metadata.frameRate !== void 0) {
29302
29302
  timestamp = roundToDivisor(timestamp, track.metadata.frameRate);
@@ -29325,8 +29325,8 @@ var Mediabunny = (() => {
29325
29325
  packetData = packetData.subarray(headerLength);
29326
29326
  }
29327
29327
  const isKeyFrame = packet.type === "key";
29328
- const timestamp = this.validateAndNormalizeTimestamp(trackData.track, packet.timestamp, isKeyFrame);
29329
- const audioChunk = this.createInternalChunk(packetData, timestamp, packet.duration, packet.type);
29328
+ this.validateTimestamp(trackData.track, packet.timestamp, isKeyFrame);
29329
+ const audioChunk = this.createInternalChunk(packetData, packet.timestamp, packet.duration, packet.type);
29330
29330
  trackData.chunkQueue.push(audioChunk);
29331
29331
  await this.interleaveChunks();
29332
29332
  } finally {
@@ -29337,9 +29337,9 @@ var Mediabunny = (() => {
29337
29337
  const release = await this.mutex.acquire();
29338
29338
  try {
29339
29339
  const trackData = this.getSubtitleTrackData(track, meta);
29340
- const timestamp = this.validateAndNormalizeTimestamp(trackData.track, cue.timestamp, true);
29340
+ this.validateTimestamp(trackData.track, cue.timestamp, true);
29341
29341
  let bodyText = cue.text;
29342
- const timestampMs = Math.round(timestamp * 1e3);
29342
+ const timestampMs = Math.round(cue.timestamp * 1e3);
29343
29343
  inlineTimestampRegex.lastIndex = 0;
29344
29344
  bodyText = bodyText.replace(inlineTimestampRegex, (match) => {
29345
29345
  const time = parseSubtitleTimestamp(match.slice(1, -1));
@@ -29352,7 +29352,7 @@ ${cue.identifier ?? ""}
29352
29352
  ${cue.notes ?? ""}`;
29353
29353
  const subtitleChunk = this.createInternalChunk(
29354
29354
  body,
29355
- timestamp,
29355
+ cue.timestamp,
29356
29356
  cue.duration,
29357
29357
  "key",
29358
29358
  additions.trim() ? textEncoder.encode(additions) : null
@@ -29746,7 +29746,7 @@ ${cue.notes ?? ""}`;
29746
29746
  this.mp3Writer.writeXingFrame(this.xingFrameData);
29747
29747
  this.frameCount++;
29748
29748
  }
29749
- this.validateAndNormalizeTimestamp(track, packet.timestamp, packet.type === "key");
29749
+ this.validateTimestamp(track, packet.timestamp, packet.type === "key");
29750
29750
  if (writeXingHeader) {
29751
29751
  this.framePositions.push(this.writer.getPos());
29752
29752
  }
@@ -29953,7 +29953,7 @@ ${cue.notes ?? ""}`;
29953
29953
  const release = await this.mutex.acquire();
29954
29954
  try {
29955
29955
  const trackData = this.getTrackData(track, meta);
29956
- this.validateAndNormalizeTimestamp(trackData.track, packet.timestamp, packet.type === "key");
29956
+ this.validateTimestamp(trackData.track, packet.timestamp, packet.type === "key");
29957
29957
  const currentTimestampInSamples = trackData.currentTimestampInSamples;
29958
29958
  const { durationInSamples, vorbisBlockSize } = extractSampleMetadata(
29959
29959
  packet.data,
@@ -30276,7 +30276,7 @@ ${cue.notes ?? ""}`;
30276
30276
  const release = await this.mutex.acquire();
30277
30277
  try {
30278
30278
  const trackData = this.getVideoTrackData(track, meta);
30279
- const timestamp = this.validateAndNormalizeTimestamp(
30279
+ this.validateTimestamp(
30280
30280
  trackData.track,
30281
30281
  packet.timestamp,
30282
30282
  packet.type === "key"
@@ -30287,7 +30287,7 @@ ${cue.notes ?? ""}`;
30287
30287
  }
30288
30288
  trackData.timestampProcessingQueue.push({
30289
30289
  data: preparedData,
30290
- presentationTimestamp: timestamp,
30290
+ presentationTimestamp: packet.timestamp,
30291
30291
  decodeTimestamp: null,
30292
30292
  isKeyframe: packet.type === "key"
30293
30293
  });
@@ -30299,7 +30299,7 @@ ${cue.notes ?? ""}`;
30299
30299
  const release = await this.mutex.acquire();
30300
30300
  try {
30301
30301
  const trackData = this.getAudioTrackData(track, meta);
30302
- const timestamp = this.validateAndNormalizeTimestamp(
30302
+ this.validateTimestamp(
30303
30303
  trackData.track,
30304
30304
  packet.timestamp,
30305
30305
  packet.type === "key"
@@ -30310,7 +30310,7 @@ ${cue.notes ?? ""}`;
30310
30310
  }
30311
30311
  trackData.timestampProcessingQueue.push({
30312
30312
  data: preparedData,
30313
- presentationTimestamp: timestamp,
30313
+ presentationTimestamp: packet.timestamp,
30314
30314
  decodeTimestamp: null,
30315
30315
  isKeyframe: packet.type === "key"
30316
30316
  });
@@ -30783,7 +30783,7 @@ ${cue.notes ?? ""}`;
30783
30783
  this.sampleRate = meta.decoderConfig.sampleRate;
30784
30784
  this.headerWritten = true;
30785
30785
  }
30786
- this.validateAndNormalizeTimestamp(track, packet.timestamp, packet.type === "key");
30786
+ this.validateTimestamp(track, packet.timestamp, packet.type === "key");
30787
30787
  if (!this.isRf64 && this.writer.getPos() + packet.data.byteLength >= 2 ** 32) {
30788
30788
  throw new Error(
30789
30789
  "Adding more audio data would exceed the maximum RIFF size of 4 GiB. To write larger files, use RF64 by setting `large: true` in the WavOutputFormatOptions."
@@ -31209,11 +31209,6 @@ ${cue.notes ?? ""}`;
31209
31209
  this._closingPromise = null;
31210
31210
  /** @internal */
31211
31211
  this._closed = false;
31212
- /**
31213
- * @internal
31214
- * A time offset in seconds that is added to all timestamps generated by this source.
31215
- */
31216
- this._timestampOffset = 0;
31217
31212
  }
31218
31213
  /** @internal */
31219
31214
  _ensureValidAdd() {
@@ -32212,7 +32207,7 @@ ${cue.notes ?? ""}`;
32212
32207
  let frameCount = 0;
32213
32208
  let errored = false;
32214
32209
  let lastSampleTimestamp = null;
32215
- let pauseOffset = 0;
32210
+ let timestampOffset = 0;
32216
32211
  const tick = () => {
32217
32212
  assert(frameRate !== null);
32218
32213
  if (!this._lastVideoFrame) {
@@ -32262,7 +32257,7 @@ ${cue.notes ?? ""}`;
32262
32257
  if (frameSeen) {
32263
32258
  if (lastSampleTimestamp !== null && this._options.timestampBase !== "unix") {
32264
32259
  const timeDelta = currentTimestamp - lastSampleTimestamp;
32265
- pauseOffset -= timeDelta;
32260
+ timestampOffset -= timeDelta;
32266
32261
  }
32267
32262
  lastSampleTimestamp = currentTimestamp;
32268
32263
  }
@@ -32286,7 +32281,7 @@ ${cue.notes ?? ""}`;
32286
32281
  target = now / 1e3 - output._firstMediaStreamTimestamp;
32287
32282
  }
32288
32283
  }
32289
- this._timestampOffset = target - firstVideoFrameTimestamp;
32284
+ timestampOffset = target - firstVideoFrameTimestamp;
32290
32285
  }
32291
32286
  lastSampleTimestamp = currentTimestamp;
32292
32287
  if (this._encoder.getQueueSize() >= 8) {
@@ -32294,7 +32289,7 @@ ${cue.notes ?? ""}`;
32294
32289
  return;
32295
32290
  }
32296
32291
  const sample = new VideoSample(videoFrame, {
32297
- timestamp: currentTimestamp + pauseOffset
32292
+ timestamp: currentTimestamp + timestampOffset
32298
32293
  });
32299
32294
  void this._encoder.add(sample, true).catch((error) => {
32300
32295
  errored = true;
@@ -33022,7 +33017,7 @@ ${cue.notes ?? ""}`;
33022
33017
  let firstAudioDataTimestamp = null;
33023
33018
  let errored = false;
33024
33019
  let lastSampleTimestamp = null;
33025
- let pauseOffset = 0;
33020
+ let timestampOffset = 0;
33026
33021
  const onAudioSample = (audioSample) => {
33027
33022
  if (errored) {
33028
33023
  audioSample.close();
@@ -33034,7 +33029,7 @@ ${cue.notes ?? ""}`;
33034
33029
  if (dataSeen) {
33035
33030
  if (lastSampleTimestamp !== null && this._options.timestampBase !== "unix") {
33036
33031
  const timeDelta = currentTimestamp - lastSampleTimestamp;
33037
- pauseOffset -= timeDelta;
33032
+ timestampOffset -= timeDelta;
33038
33033
  }
33039
33034
  lastSampleTimestamp = currentTimestamp;
33040
33035
  }
@@ -33058,14 +33053,14 @@ ${cue.notes ?? ""}`;
33058
33053
  target = performance.now() / 1e3 - output._firstMediaStreamTimestamp;
33059
33054
  }
33060
33055
  }
33061
- this._timestampOffset = target - firstAudioDataTimestamp;
33056
+ timestampOffset = target - firstAudioDataTimestamp;
33062
33057
  }
33063
33058
  lastSampleTimestamp = currentTimestamp;
33064
33059
  if (this._encoder.getQueueSize() >= 8) {
33065
33060
  audioSample.close();
33066
33061
  return;
33067
33062
  }
33068
- audioSample.setTimestamp(currentTimestamp + pauseOffset);
33063
+ audioSample.setTimestamp(currentTimestamp + timestampOffset);
33069
33064
  void this._encoder.add(audioSample, true).catch((error) => {
33070
33065
  errored = true;
33071
33066
  this._abortController?.abort();
@@ -33667,15 +33662,14 @@ ${cue.notes ?? ""}`;
33667
33662
  const playlist = trackData.playlist;
33668
33663
  const release = await playlist.mutex.acquire();
33669
33664
  try {
33670
- const timestamp = this.validateAndNormalizeTimestamp(track, packet.timestamp, packet.type === "key");
33671
- const adjustedPacket = packet.clone({ timestamp });
33672
- trackData.packets.push(adjustedPacket);
33665
+ this.validateTimestamp(track, packet.timestamp, packet.type === "key");
33666
+ trackData.packets.push(packet);
33673
33667
  if (playlist.currentSegmentStartTimestamp === null) {
33674
- playlist.currentSegmentStartTimestamp = adjustedPacket.timestamp;
33668
+ playlist.currentSegmentStartTimestamp = packet.timestamp;
33675
33669
  } else if (!playlist.currentSegmentStartTimestampIsFixed) {
33676
33670
  playlist.currentSegmentStartTimestamp = Math.min(
33677
33671
  playlist.currentSegmentStartTimestamp,
33678
- adjustedPacket.timestamp
33672
+ packet.timestamp
33679
33673
  );
33680
33674
  }
33681
33675
  await this.advancePlaylist(playlist);
@@ -33688,15 +33682,14 @@ ${cue.notes ?? ""}`;
33688
33682
  const playlist = trackData.playlist;
33689
33683
  const release = await playlist.mutex.acquire();
33690
33684
  try {
33691
- const timestamp = this.validateAndNormalizeTimestamp(track, packet.timestamp, packet.type === "key");
33692
- const adjustedPacket = packet.clone({ timestamp });
33693
- trackData.packets.push(adjustedPacket);
33685
+ this.validateTimestamp(track, packet.timestamp, packet.type === "key");
33686
+ trackData.packets.push(packet);
33694
33687
  if (playlist.currentSegmentStartTimestamp === null) {
33695
- playlist.currentSegmentStartTimestamp = adjustedPacket.timestamp;
33688
+ playlist.currentSegmentStartTimestamp = packet.timestamp;
33696
33689
  } else if (!playlist.currentSegmentStartTimestampIsFixed) {
33697
33690
  playlist.currentSegmentStartTimestamp = Math.min(
33698
33691
  playlist.currentSegmentStartTimestamp,
33699
- adjustedPacket.timestamp
33692
+ packet.timestamp
33700
33693
  );
33701
33694
  }
33702
33695
  await this.advancePlaylist(playlist);