Fix HLS muxer audio segmentation bug, fix conversion tests failing in CI

This commit is contained in:
Vanilagy
2026-04-14 21:40:07 +02:00
parent 6410ea9f42
commit a3767af141
4 changed files with 90 additions and 28 deletions
+7 -5
View File
@@ -691,6 +691,7 @@ export class HlsMuxer extends Muxer {
let audioEndIndex = 0;
if (videoTrack && (!videoTrack.closed || videoTrack.packets.length > 0)) {
// A video track is active (and maybe an audio track too)
const allBelow = videoTrack.packets.every(x => x.timestamp < currentSegmentEndTimestamp);
let bestKeyPacket: EncodedPacket | null = null;
@@ -773,21 +774,22 @@ export class HlsMuxer extends Muxer {
}
}
} else if (audioTrack && (!audioTrack.closed || audioTrack.packets.length > 0)) {
// There's only an audio track active
const allBelow = audioTrack.packets.every(x => x.timestamp < currentSegmentEndTimestamp);
if (allBelow) {
if (audioTrack.closed) {
// We can write all packets since they're all below
audioEndIndex = audioTrack.packets.length;
} else {
// We don't know enough packets yet
return;
}
} else {
// Aim to make the segment at most as long as desired
const index = findLastIndex(audioTrack.packets, x => x.timestamp <= currentSegmentEndTimestamp);
if (index !== -1) {
audioEndIndex = index;
} else {
audioEndIndex = 1;
}
audioEndIndex = Math.max(index, 1); // Always include at least the first packet
}
}
+1 -1
View File
@@ -72,7 +72,7 @@ export abstract class Target extends EventEmitter<TargetEvents> {
this._emit('write', { start, end });
}
/**
/**
* Returns a new {@link RangedTarget} that writes data to this target using the given offset.
*
* Useful for writing a file into a section of a larger file.