mirror of
https://github.com/arcodange-org/mediabunny.git
synced 2026-10-03 05:43:50 +02:00
Remove packet iteration upper bound for mediaSamplesInRange (fixes #269)
This commit is contained in:
+7
-17
@@ -480,23 +480,13 @@ export abstract class BaseMediaSampleSink<
|
|||||||
|
|
||||||
let currentPacket: EncodedPacket | null = keyPacket;
|
let currentPacket: EncodedPacket | null = keyPacket;
|
||||||
|
|
||||||
let endPacket: EncodedPacket | undefined = undefined;
|
// B-frames make it exceedingly difficult to properly define an upper bound for packet iteration if an end
|
||||||
if (endTimestamp < Infinity) {
|
// timestamp is set, so we just don't do it. The case that makes it especially tricky is when the frames
|
||||||
// When an end timestamp is set, we cannot simply use that for the packet iterator due to out-of-order
|
// following a key frame have a lower timestamp than the keyframe; something that quite frequently happens
|
||||||
// frames (B-frames). Instead, we'll need to keep decoding packets until we get a frame that exceeds
|
// in HEVC streams. The price to pay for not upper-bounding the packet iterator is a slight increase in
|
||||||
// this end time. However, we can still put a bound on it: Since key frames are by definition never
|
// decoder work at the end of the range, but the added correctness and reliability makes this tradeoff worth
|
||||||
// out of order, we can stop at the first key frame after the end timestamp.
|
// it.
|
||||||
const packet = await packetSink.getPacket(endTimestamp);
|
const endPacket = undefined;
|
||||||
const keyPacket = !packet
|
|
||||||
? null
|
|
||||||
: packet.type === 'key' && packet.timestamp === endTimestamp
|
|
||||||
? packet
|
|
||||||
: await packetSink.getNextKeyPacket(packet, { verifyKeyPackets: true });
|
|
||||||
|
|
||||||
if (keyPacket) {
|
|
||||||
endPacket = keyPacket;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const packets = packetSink.packets(keyPacket ?? undefined, endPacket);
|
const packets = packetSink.packets(keyPacket ?? undefined, endPacket);
|
||||||
await packets.next(); // Skip the start packet as we already have it
|
await packets.next(); // Skip the start packet as we already have it
|
||||||
|
|||||||
Reference in New Issue
Block a user