mediabunny 1.57.0 → 1.58.0

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.
@@ -17709,7 +17709,7 @@ var Mediabunny = (() => {
17709
17709
  this.rootPath = response.url;
17710
17710
  }
17711
17711
  outer:
17712
- if (this._orchestrator.fileSize === null && (response.status === 206 || response.type === "basic" && !response.headers.has("Content-Encoding"))) {
17712
+ if (this._orchestrator.fileSize === null && !response.headers.has("Content-Encoding") && (response.status === 206 || response.type === "basic")) {
17713
17713
  const contentRange = response.headers.get("Content-Range");
17714
17714
  if (contentRange) {
17715
17715
  const match = /\/(\d+)/.exec(contentRange);
@@ -39984,6 +39984,9 @@ ${cue.notes ?? ""}`;
39984
39984
  "options.copy.boundaryPolicy, when provided, must be 'expand' or 'shrink'."
39985
39985
  );
39986
39986
  }
39987
+ if (options.copy.boundaryTolerance !== void 0 && (!isNumber(options.copy.boundaryTolerance) || options.copy.boundaryTolerance < 0)) {
39988
+ throw new TypeError("options.copy.boundaryTolerance, when provided, must be a non-negative number.");
39989
+ }
39987
39990
  }
39988
39991
  const composable = options.composable ?? false;
39989
39992
  if (!composable) {
@@ -40045,6 +40048,7 @@ ${cue.notes ?? ""}`;
40045
40048
  this._copyMode = options.copy === false ? false : options.copy?.mode ?? "preferred";
40046
40049
  this._copyTimestampShiftTolerance = options.copy === false ? 0 : options.copy?.shiftTolerance ?? 0;
40047
40050
  this._copyBoundaryPolicy = options.copy === false ? "expand" : options.copy?.boundaryPolicy ?? "expand";
40051
+ this._copyBoundaryTolerance = options.copy === false ? Infinity : options.copy?.boundaryTolerance ?? Infinity;
40048
40052
  this._composable = composable;
40049
40053
  this.input = options.input;
40050
40054
  this.output = options.output;
@@ -40514,7 +40518,10 @@ The @mediabunny/mp3-encoder extension package provides support for encoding MP3.
40514
40518
  copyStartPacket = startPacket;
40515
40519
  if (startPacket) {
40516
40520
  const effectiveStartTimestamp = this._copyBoundaryPolicy === "shrink" ? Math.max(startPacket.timestamp, this._startTimestamp) : startPacket.timestamp;
40517
- if (!this.output.format.supportsTimestampedMediaData) {
40521
+ const boundaryDeviation = this._copyBoundaryPolicy === "shrink" ? effectiveStartTimestamp - this._startTimestamp : Math.max(this._startTimestamp - effectiveStartTimestamp, 0);
40522
+ if (boundaryDeviation > this._copyBoundaryTolerance) {
40523
+ needsTranscode = true;
40524
+ } else if (!this.output.format.supportsTimestampedMediaData) {
40518
40525
  if (this._timestampOffsetAdjusted) {
40519
40526
  const isValid = effectiveStartTimestamp + this._timestampOffset === 0;
40520
40527
  if (!isValid) {
@@ -40565,6 +40572,7 @@ The @mediabunny/mp3-encoder extension package provides support for encoding MP3.
40565
40572
  const sink = new EncodedPacketSink(track);
40566
40573
  const decoderConfig = await track.getDecoderConfig();
40567
40574
  const meta = { decoderConfig: decoderConfig ?? void 0 };
40575
+ let maxTimestamp = null;
40568
40576
  if (copyStartPacket) for await (const packet of sink.packets(
40569
40577
  copyStartPacket,
40570
40578
  void 0,
@@ -40605,10 +40613,16 @@ The @mediabunny/mp3-encoder extension package provides support for encoding MP3.
40605
40613
  }
40606
40614
  packetStartTimestamp += this._timestampOffset;
40607
40615
  packetEndTimestamp += this._timestampOffset;
40616
+ let packetType = packet.type;
40617
+ if (packetType === "key" && maxTimestamp !== null && packetStartTimestamp < maxTimestamp) {
40618
+ packetType = "delta";
40619
+ }
40620
+ maxTimestamp = Math.max(maxTimestamp ?? -Infinity, packetStartTimestamp);
40608
40621
  const modifiedPacket = packet.clone({
40609
40622
  timestamp: packetStartTimestamp,
40610
40623
  duration: packetEndTimestamp - packetStartTimestamp,
40611
- sideData: alpha === "discard" ? {} : packet.sideData
40624
+ sideData: alpha === "discard" ? {} : packet.sideData,
40625
+ type: packetType
40612
40626
  });
40613
40627
  this._reportProgress(outputTrackId, modifiedPacket.timestamp + modifiedPacket.duration);
40614
40628
  await source.add(modifiedPacket, meta);
@@ -40815,7 +40829,10 @@ The @mediabunny/mp3-encoder extension package provides support for encoding MP3.
40815
40829
  }
40816
40830
  copyStartPacket = startPacket;
40817
40831
  if (startPacket) {
40818
- if (!this.output.format.supportsTimestampedMediaData) {
40832
+ const boundaryDeviation = this._copyBoundaryPolicy === "shrink" ? Math.max(startPacket.timestamp - this._startTimestamp, 0) : Math.max(this._startTimestamp - startPacket.timestamp, 0);
40833
+ if (boundaryDeviation > this._copyBoundaryTolerance) {
40834
+ needsTranscode = true;
40835
+ } else if (!this.output.format.supportsTimestampedMediaData) {
40819
40836
  if (this._timestampOffsetAdjusted) {
40820
40837
  const isValid = startPacket.timestamp + this._timestampOffset === 0;
40821
40838
  if (!isValid) {