From 1da96f6d694ae215b28754160c34ebe332a51625 Mon Sep 17 00:00:00 2001 From: Vanilagy <1696106+Vanilagy@users.noreply.github.com> Date: Thu, 19 Mar 2026 12:25:19 +0100 Subject: [PATCH] Add displayAspectWidth/displayAspectHeight only when they are necessary --- src/isobmff/isobmff-demuxer.ts | 14 +++++++++++--- src/matroska/matroska-demuxer.ts | 14 +++++++++++--- src/mpeg-ts/mpeg-ts-demuxer.ts | 10 ++++++++-- test/browser/par.test.ts | 4 ++-- 4 files changed, 32 insertions(+), 10 deletions(-) diff --git a/src/isobmff/isobmff-demuxer.ts b/src/isobmff/isobmff-demuxer.ts index e247193..d52e160 100644 --- a/src/isobmff/isobmff-demuxer.ts +++ b/src/isobmff/isobmff-demuxer.ts @@ -2947,15 +2947,23 @@ class IsobmffVideoTrackBacking extends IsobmffTrackBacking implements InputVideo this.internalTrack.info.av1CodecInfo = firstPacket && extractAv1CodecInfoFromPacket(firstPacket.data); } - return { + const config: VideoDecoderConfig = { codec: extractVideoCodecString(this.internalTrack.info), codedWidth: this.internalTrack.info.width, codedHeight: this.internalTrack.info.height, - displayAspectWidth: this.internalTrack.info.squarePixelWidth, - displayAspectHeight: this.internalTrack.info.squarePixelHeight, description: this.internalTrack.info.codecDescription ?? undefined, colorSpace: this.internalTrack.info.colorSpace ?? undefined, }; + + if ( + this.internalTrack.info.width !== this.internalTrack.info.squarePixelWidth + || this.internalTrack.info.height !== this.internalTrack.info.squarePixelHeight + ) { + config.displayAspectWidth = this.internalTrack.info.squarePixelWidth; + config.displayAspectHeight = this.internalTrack.info.squarePixelHeight; + } + + return config; })(); } } diff --git a/src/matroska/matroska-demuxer.ts b/src/matroska/matroska-demuxer.ts index 28106c9..37a601d 100644 --- a/src/matroska/matroska-demuxer.ts +++ b/src/matroska/matroska-demuxer.ts @@ -2430,7 +2430,7 @@ class MatroskaVideoTrackBacking extends MatroskaTrackBacking implements InputVid firstPacket = await this.getFirstPacket({}); } - return { + const config: VideoDecoderConfig = { codec: extractVideoCodecString({ width: this.internalTrack.info.width, height: this.internalTrack.info.height, @@ -2453,11 +2453,19 @@ class MatroskaVideoTrackBacking extends MatroskaTrackBacking implements InputVid }), codedWidth: this.internalTrack.info.width, codedHeight: this.internalTrack.info.height, - displayAspectWidth: this.internalTrack.info.squarePixelWidth, - displayAspectHeight: this.internalTrack.info.squarePixelHeight, description: this.internalTrack.info.codecDescription ?? undefined, colorSpace: this.internalTrack.info.colorSpace ?? undefined, }; + + if ( + this.internalTrack.info.width !== this.internalTrack.info.squarePixelWidth + || this.internalTrack.info.height !== this.internalTrack.info.squarePixelHeight + ) { + config.displayAspectWidth = this.internalTrack.info.squarePixelWidth; + config.displayAspectHeight = this.internalTrack.info.squarePixelHeight; + } + + return config; })(); } } diff --git a/src/mpeg-ts/mpeg-ts-demuxer.ts b/src/mpeg-ts/mpeg-ts-demuxer.ts index be61c08..42ee52e 100644 --- a/src/mpeg-ts/mpeg-ts-demuxer.ts +++ b/src/mpeg-ts/mpeg-ts-demuxer.ts @@ -1514,10 +1514,16 @@ class MpegTsVideoTrackBacking extends MpegTsTrackBacking implements InputVideoTr }), codedWidth: this.elementaryStream.info.width, codedHeight: this.elementaryStream.info.height, - displayAspectWidth: this.elementaryStream.info.squarePixelWidth, - displayAspectHeight: this.elementaryStream.info.squarePixelHeight, colorSpace: this.elementaryStream.info.colorSpace, }; + + if ( + this.elementaryStream.info.width !== this.elementaryStream.info.squarePixelWidth + || this.elementaryStream.info.height !== this.elementaryStream.info.squarePixelHeight + ) { + this.decoderConfig.displayAspectWidth = this.elementaryStream.info.squarePixelWidth; + this.decoderConfig.displayAspectHeight = this.elementaryStream.info.squarePixelHeight; + } } override getCodec(): VideoCodec { diff --git a/test/browser/par.test.ts b/test/browser/par.test.ts index 744999d..0f04c53 100644 --- a/test/browser/par.test.ts +++ b/test/browser/par.test.ts @@ -87,8 +87,8 @@ test('Pixel aspect ratio transcode conversion', async () => { expect(mp4.snapshot.squarePixelHeight).toBe(mp4.snapshot.codedHeight); expect(mp4.snapshot.displayWidth).toBe(mp4.snapshot.codedWidth); expect(mp4.snapshot.displayHeight).toBe(mp4.snapshot.codedHeight); - expect(mp4.snapshot.decoderDisplayAspectWidth).toBe(mp4.snapshot.codedWidth); - expect(mp4.snapshot.decoderDisplayAspectHeight).toBe(mp4.snapshot.codedHeight); + expect(mp4.snapshot.decoderDisplayAspectWidth).toBeUndefined(); + expect(mp4.snapshot.decoderDisplayAspectHeight).toBeUndefined(); expect(mp4.snapshot.codedWidth).toBe(source.squarePixelWidth); expect(mp4.snapshot.codedHeight).toBe(source.squarePixelHeight);