From 95c7b7fc2bb9c3a937fa96245a3522164ea63140 Mon Sep 17 00:00:00 2001 From: Marc Diaz Date: Mon, 20 Apr 2026 23:11:58 -0400 Subject: [PATCH] fix: add webm inflated duration and fix --- src/lib/exporter/streamingDecoder.ts | 12 ++++++++---- tests/fixtures/sample-inflated-duration.webm | Bin 0 -> 1252 bytes 2 files changed, 8 insertions(+), 4 deletions(-) create mode 100644 tests/fixtures/sample-inflated-duration.webm diff --git a/src/lib/exporter/streamingDecoder.ts b/src/lib/exporter/streamingDecoder.ts index 24b9844..c9a9597 100644 --- a/src/lib/exporter/streamingDecoder.ts +++ b/src/lib/exporter/streamingDecoder.ts @@ -246,14 +246,13 @@ export class StreamingVideoDecoder { const hintedDurationSec = Math.max(containerDurationSec, streamDurationSec, 0); const scanEndSec = hintedDurationSec > 0 ? hintedDurationSec + 0.5 : SCAN_UNBOUNDED_FALLBACK_SEC; - let maxPacketEndUs = 0; + let maxPacketTimestampUs = 0; const scanReader = this.demuxer.read("video", 0, scanEndSec).getReader(); try { while (true) { const { done, value } = await scanReader.read(); if (done || !value) break; - const endUs = value.timestamp + (value.duration ?? 0); - if (endUs > maxPacketEndUs) maxPacketEndUs = endUs; + if (value.timestamp > maxPacketTimestampUs) maxPacketTimestampUs = value.timestamp; } } finally { try { @@ -262,7 +261,12 @@ export class StreamingVideoDecoder { /* already closed */ } } - const scannedDuration = maxPacketEndUs / 1_000_000; + // Use last frame's timestamp + one frame duration. The `duration` field on the last + // packet in a WebM container is frequently inflated by the demuxer to match the + // container's declared end, causing validateDuration to see no divergence and + // propagate a duration that the decoder can never actually reach. + const typicalFrameDurationUs = Math.ceil(1_000_000 / frameRate); + const scannedDuration = (maxPacketTimestampUs + typicalFrameDurationUs) / 1_000_000; const validatedDuration = validateDuration(mediaInfo.duration, scannedDuration); this.metadata = { diff --git a/tests/fixtures/sample-inflated-duration.webm b/tests/fixtures/sample-inflated-duration.webm new file mode 100644 index 0000000000000000000000000000000000000000..6322840dba15e3d790d34e6e656c054f7e772bbf GIT binary patch literal 1252 zcmcK4O=uHA6ae72Nz_6Q{t+!wXt2dY#gJ55tf$E)QKP1MfTH5>`Vn_oy8H?!-(FI>vv7l ziE6aXoxdPQZ=A(Z`D}}OPH;_!xTb1Y?<&fNA>D(o)jDu;wcP*Ml&%WR3y;DZdEyjD zkM;)p+ggl!jb@YSxCMo_YY8%!SnWY+{$*b6jVw^kKcCpO-0&)w37G3sw|7`O zZT4?zqLc`m+;{T<84b>!Kr|G_4qe65eU7yBf0 z!2U^fYX-S)H*|(gMFCg6YNFifPF=EOBwlk!d${0 tW-el%XYNJ5p@z8u`w`}V{krO;yynV1GgiFugu?Tre4l*}ak)jR{R8OYZ`=R? literal 0 HcmV?d00001