Fix behavior with files with invalid pasp box (with num & den === 0) (fixes #362)

This commit is contained in:
Vanilagy
2026-05-02 14:27:25 +02:00
parent 62dfc5dd1c
commit 9ed21bf9c6
6 changed files with 70 additions and 26 deletions
+16 -12
View File
@@ -474,18 +474,22 @@ export class MpegTsDemuxer extends Demuxer {
elementaryStream.info.width = spsInfo.displayWidth;
elementaryStream.info.height = spsInfo.displayHeight;
if (spsInfo.pixelAspectRatio.num > spsInfo.pixelAspectRatio.den) {
elementaryStream.info.squarePixelWidth = Math.round(
elementaryStream.info.width
* spsInfo.pixelAspectRatio.num / spsInfo.pixelAspectRatio.den,
);
elementaryStream.info.squarePixelHeight = elementaryStream.info.height;
} else {
elementaryStream.info.squarePixelWidth = elementaryStream.info.width;
elementaryStream.info.squarePixelHeight = Math.round(
elementaryStream.info.height
* spsInfo.pixelAspectRatio.den / spsInfo.pixelAspectRatio.num,
);
const num = spsInfo.pixelAspectRatio.num;
const den = spsInfo.pixelAspectRatio.den;
if (num > 0 && den > 0) {
if (num > den) {
elementaryStream.info.squarePixelWidth = Math.round(
elementaryStream.info.width * num / den,
);
elementaryStream.info.squarePixelHeight = elementaryStream.info.height;
} else {
elementaryStream.info.squarePixelWidth = elementaryStream.info.width;
elementaryStream.info.squarePixelHeight = Math.round(
elementaryStream.info.height * den / num,
);
}
}
elementaryStream.info.colorSpace = {