From 87ed3a1934edc03f194fc727c3c187220199e966 Mon Sep 17 00:00:00 2001 From: Vanilagy <1696106+Vanilagy@users.noreply.github.com> Date: Thu, 12 Mar 2026 21:43:14 +0100 Subject: [PATCH] Fix faulty MPEG-2 detection (fixes #322) --- src/input-format.ts | 2 +- src/mpeg-ts/mpeg-ts-demuxer.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/input-format.ts b/src/input-format.ts index ed09428..5506af8 100644 --- a/src/input-format.ts +++ b/src/input-format.ts @@ -530,7 +530,7 @@ export class MpegTsInputFormat extends InputFormat { } else if (bytes[0] === 0x47 && bytes[TS_PACKET_SIZE + 16] === 0x47) { // MPEG-TS with Forward Error Correction return true; - } else if (bytes[4] === 0x47 && bytes[4 + TS_PACKET_SIZE] === 0x47) { + } else if (bytes[4] === 0x47 && bytes[4 + TS_PACKET_SIZE + 4] === 0x47) { // MPEG-2-TS (DVHS) return true; } diff --git a/src/mpeg-ts/mpeg-ts-demuxer.ts b/src/mpeg-ts/mpeg-ts-demuxer.ts index 253e8de..be61c08 100644 --- a/src/mpeg-ts/mpeg-ts-demuxer.ts +++ b/src/mpeg-ts/mpeg-ts-demuxer.ts @@ -161,10 +161,10 @@ export class MpegTsDemuxer extends Demuxer { // MPEG-TS with Forward Error Correction this.packetOffset = 0; this.packetStride = TS_PACKET_SIZE + 16; - } else if (startingBytes[4] === 0x47 && startingBytes[4 + TS_PACKET_SIZE] === 0x47) { + } else if (startingBytes[4] === 0x47 && startingBytes[4 + TS_PACKET_SIZE + 4] === 0x47) { // MPEG-2-TS (DVHS) this.packetOffset = 4; - this.packetStride = TS_PACKET_SIZE; + this.packetStride = TS_PACKET_SIZE + 4; } else { throw new Error('Unreachable.'); }