mirror of
https://github.com/arcodange-org/mediabunny.git
synced 2026-09-28 11:23:45 +02:00
Fix behavior with files with invalid pasp box (with num & den === 0) (fixes #362)
This commit is contained in:
@@ -784,6 +784,37 @@ export const validateVideoChunkMetadata = (metadata: EncodedVideoChunkMetadata |
|
||||
'Video chunk metadata decoder configuration must specify a valid codedHeight (positive integer).',
|
||||
);
|
||||
}
|
||||
if (
|
||||
metadata.decoderConfig.displayAspectWidth !== undefined
|
||||
&& (
|
||||
!Number.isInteger(metadata.decoderConfig.displayAspectWidth)
|
||||
|| metadata.decoderConfig.displayAspectWidth <= 0
|
||||
)
|
||||
) {
|
||||
throw new TypeError(
|
||||
'Video chunk metadata decoder configuration displayAspectWidth, when defined, must be a positive integer.',
|
||||
);
|
||||
}
|
||||
if (
|
||||
metadata.decoderConfig.displayAspectHeight !== undefined
|
||||
&& (
|
||||
!Number.isInteger(metadata.decoderConfig.displayAspectHeight)
|
||||
|| metadata.decoderConfig.displayAspectHeight <= 0
|
||||
)
|
||||
) {
|
||||
throw new TypeError(
|
||||
'Video chunk metadata decoder configuration displayAspectHeight, when defined, must be a positive integer.',
|
||||
);
|
||||
}
|
||||
if (
|
||||
(metadata.decoderConfig.displayAspectWidth !== undefined)
|
||||
!== (metadata.decoderConfig.displayAspectHeight !== undefined)
|
||||
) {
|
||||
throw new TypeError(
|
||||
'Video chunk metadata decoder configuration must specify both displayAspectWidth and displayAspectHeight,'
|
||||
+ ' or neither.',
|
||||
);
|
||||
}
|
||||
if (metadata.decoderConfig.description !== undefined) {
|
||||
if (!isAllowSharedBufferSource(metadata.decoderConfig.description)) {
|
||||
throw new TypeError(
|
||||
|
||||
@@ -1475,10 +1475,13 @@ export class IsobmffDemuxer extends Demuxer {
|
||||
const num = readU32Be(slice);
|
||||
const den = readU32Be(slice);
|
||||
|
||||
if (num > den) {
|
||||
track.info.squarePixelWidth = Math.round(track.info.width * num / den);
|
||||
} else {
|
||||
track.info.squarePixelHeight = Math.round(track.info.height * den / num);
|
||||
// https://github.com/Vanilagy/mediabunny/issues/362
|
||||
if (num > 0 && den > 0) {
|
||||
if (num > den) {
|
||||
track.info.squarePixelWidth = Math.round(track.info.width * num / den);
|
||||
} else {
|
||||
track.info.squarePixelHeight = Math.round(track.info.height * den / num);
|
||||
}
|
||||
}
|
||||
}; break;
|
||||
|
||||
|
||||
@@ -1051,14 +1051,16 @@ export class MatroskaDemuxer extends Demuxer {
|
||||
const num = this.currentTrack.info.displayWidth * this.currentTrack.info.height;
|
||||
const den = this.currentTrack.info.displayHeight * this.currentTrack.info.width;
|
||||
|
||||
if (num > den) {
|
||||
this.currentTrack.info.squarePixelWidth = Math.round(
|
||||
this.currentTrack.info.width * num / den,
|
||||
);
|
||||
} else {
|
||||
this.currentTrack.info.squarePixelHeight = Math.round(
|
||||
this.currentTrack.info.height * den / num,
|
||||
);
|
||||
if (num > 0 && den > 0) {
|
||||
if (num > den) {
|
||||
this.currentTrack.info.squarePixelWidth = Math.round(
|
||||
this.currentTrack.info.width * num / den,
|
||||
);
|
||||
} else {
|
||||
this.currentTrack.info.squarePixelHeight = Math.round(
|
||||
this.currentTrack.info.height * den / num,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -938,6 +938,8 @@ export type Rational = {
|
||||
};
|
||||
|
||||
export const simplifyRational = (rational: Rational): Rational => {
|
||||
assert(Number.isInteger(rational.num));
|
||||
assert(Number.isInteger(rational.den));
|
||||
assert(rational.den !== 0);
|
||||
|
||||
let a = Math.abs(rational.num);
|
||||
|
||||
@@ -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 = {
|
||||
|
||||
Reference in New Issue
Block a user