mirror of
https://github.com/arcodange-org/mediabunny.git
synced 2026-10-02 05:13:50 +02:00
Fix HLS muxer audio segmentation bug, fix conversion tests failing in CI
This commit is contained in:
@@ -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
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user