diff --git a/dev/demux.html b/dev/demux.html index 2bca413..d53045c 100644 --- a/dev/demux.html +++ b/dev/demux.html @@ -15,6 +15,31 @@ }); const videoTrack = await input.getPrimaryVideoTrack(); + const sink = new Mediabunny.EncodedPacketSink(videoTrack); + + for await (const packet of sink.packets()) { + console.log(packet.timestamp, packet.duration, packet.timestamp + packet.duration); + } + + /* + const sink = new Mediabunny.VideoSampleSink(videoTrack); + + for await (const sample of sink.samples()) { + console.log(sample.timestamp, sample.duration); + sample.close(); + } + */ + + /* + const sink = new Mediabunny.EncodedPacketSink(videoTrack); + + for await (const packet of sink.packets()) { + console.log(packet.timestamp, packet.timestamp + packet.duration); + } + */ + + + /* const sink = new Mediabunny.VideoSampleSink(videoTrack); console.log(await videoTrack.getDecoderConfig()) @@ -30,6 +55,7 @@ for await (const sample of sink.samples()) { console.log(sample); } + */ /* let total = 0; diff --git a/src/matroska/matroska-demuxer.ts b/src/matroska/matroska-demuxer.ts index c9655d5..79c84f4 100644 --- a/src/matroska/matroska-demuxer.ts +++ b/src/matroska/matroska-demuxer.ts @@ -1181,8 +1181,9 @@ export class MatroskaDemuxer extends Demuxer { case EBMLId.DefaultDuration: { if (!this.currentTrack) break; + // Floored to reduce chance of overlapping packets (https://github.com/Vanilagy/mediabunny/issues/170) this.currentTrack.defaultDuration - = this.currentTrack.segment.timestampFactor * readUnsignedInt(slice, size) / 1e9; + = Math.floor(this.currentTrack.segment.timestampFactor * readUnsignedInt(slice, size) / 1e9); }; break; case EBMLId.Name: {