fix: pass explicit range to packet scan read

Some containers are truncated when read() has no end bound.
Use container/stream duration + buffer as scan range, matching
the same pattern used in decodeAll().
This commit is contained in:
Enriquefft
2026-04-12 18:06:01 -05:00
parent 5e62ad3215
commit 337838294d
+3 -1
View File
@@ -230,9 +230,11 @@ export class StreamingVideoDecoder {
// Scan video packets to find the true content boundary.
// MediaRecorder (especially on Linux) writes unreliable container durations.
// Packet timestamps are ground truth — no decode needed, just timestamp reads.
// Pass explicit range because some containers are truncated without one.
const scanEndSec = Math.max(mediaInfo.duration, videoStream?.duration ?? 0, 0) + 0.5;
let maxPacketEndUs = 0;
const scanReader = (
this.demuxer.read("video") as ReadableStream<EncodedVideoChunk>
this.demuxer.read("video", 0, scanEndSec) as ReadableStream<EncodedVideoChunk>
).getReader();
try {
while (true) {