Open Bug 2084400 Opened 1 month ago Updated 1 month ago

videoWidth/videoHeight keep the MP4 tkhd size for AV1 instead of the decoded size

Categories

(Core :: Audio/Video, defect, P3)

defect

Tracking

()

People

(Reporter: zcorpan, Unassigned)

References

(Blocks 1 open bug)

Details

For an AV1 MP4 whose tkhd declares 160x120 for a 320x240 stream, videoWidth/videoHeight stay 160x120 after frames are decoded, both with src and with MSE. requestVideoFrameCallback metadata reports 320x240.

Firefox is inconsistent across codecs here: with VP9 in MP4 (and WebM DisplayWidth/DisplayHeight), it reports 160x120 at loadedmetadata but switches to 320x240 after the first frame, and with H.264 it reports 320x240 throughout. Chrome and Safari report 320x240 once frames are decoded.

Tests: https://github.com/web-platform-tests/wpt/pull/63960

  • html/semantics/embedded-content/the-video-element/video-container-presentation-size.tentative.html: "MP4 tkhd, AV1"
  • media-source/mediasource-container-presentation-size.tentative.html: "MP4 tkhd, AV1" (after frames are presented)

ISO BMFF defines tkhd width/height as the presentation size and HTML defers to the format, so the AV1 behavior follows the spec as written. https://github.com/whatwg/html/issues/13106 proposes using the declared size only for aspect ratio, matching the other codecs and browsers.

Thanks for the tests and the spec issue.

Analysis

The MP4 demuxer copies the tkhd size into VideoInfo::mDisplay for every video codec (DecoderData.cpp). The H.264 and VP9 paths later replace that value, but each path does it differently. The AV1 path never replaces it.

  • H.264 and HEVC: the demuxer replaces mDisplay with the SPS size before loadedmetadata (MP4Demuxer.cpp). This is why H.264 reports 320x240 throughout.
  • VP9: VPXChangeMonitor keeps a pixel aspect ratio from mImage and mDisplay, which is 1.0 for this file. On the first keyframe that the monitor handles, it applies that ratio to the coded size (MediaChangeMonitor.cpp). The result is 320x240. For VP9 in MP4, this path runs only when the monitor creates a new decoder, so the switch looks like a side effect.
  • AV1: AV1ChangeMonitor::UpdateConfig changes mDisplay only when the coded size changes (MediaChangeMonitor.cpp). The av1C box and the sequence header both give 320x240, which equals mImage. Thus mDisplay stays at 160x120.

The rest of the pipeline only carries mDisplay to videoWidth/videoHeight. requestVideoFrameCallback reports the decoded image size, so it shows 320x240. This is not a regression: the aspect ratio logic in both monitors is from bug 1764425.

Next steps

The decision in whatwg/html issue 13106 sets the correct behavior here. If the spec uses the declared size only for the aspect ratio, one rule in the MP4 demuxer for all codecs is the cleaner fix. That rule turns the tkhd size into an aspect ratio and applies it to the coded size. A smaller option is to make AV1ChangeMonitor apply mPixelAspectRatio on the first sequence header too. The VP9 path must then not depend on a new decoder. The tentative tests in WPT PR 63960 can land with the fix.

This bug now blocks bug 1452683 (AV1 playback support). Bug 2083754 is related: it is about a tkhd size of 0 in MSE.


To give feedback on this comment, add a thumbs-up or thumbs-down reaction.

Blocks: AV1
Severity: -- → S3
Priority: -- → P3
See Also: → 2083754
You need to log in before you can comment on or make changes to this bug.