Open Bug 2083754 Opened 1 month ago Updated 25 days ago

MSE rejects a fragmented MP4 init segment whose video track has tkhd width/height = 0 ("Failed to open media"). Chromium accepts it.

Categories

(Core :: Audio/Video: Playback, defect, P2)

Firefox 158
defect

Tracking

()

UNCONFIRMED

People

(Reporter: per+bugzilla, Unassigned, NeedInfo)

References

Details

(Keywords: regression)

Attachments

(2 files, 2 external files)

Product / Component: Core :: Audio/Video: Playback

Summary: MSE rejects a fragmented MP4 init segment whose video track has tkhd width/height = 0 ("Failed to open media"). Chromium accepts it.

Steps to reproduce:

  1. Open the attached mse-tkhd-testcase.html, a self-contained page that needs no network, login or DRM.
  2. The page creates a MediaSource and appends a real-world CMAF video init segment (video/mp4; codecs="avc1.64001E", CENC-encrypted, 1757 bytes, from a Danish streaming service, TV 2 Play) to a SourceBuffer. It does this unmodified and in a few patched variants.

Actual result (Firefox 158.0, Windows 11 x64):

OK   Audio: original (control)
FAIL Video: original (tkhd 0x0)                     - video error: 4 Failed to open media
OK   Video: tkhd set to 768x432
FAIL Video: btrt removed                            - video error: 4 Failed to open media
FAIL Video: pasp removed                            - video error: 4 Failed to open media
OK   Video: tkhd 768x432 + btrt and pasp removed

Firefox on Ubuntu 24.04 and Ubuntu 26.04 has the same error (and same work-around).

Expected result: The init segment is accepted, as it is in Chromium (Edge 155 / Chrome 155 accept all variants). The visual sample entry (encv → avc1, 768×432) and the SPS both carry valid dimensions.

Analysis:

  • The only difference between the failing and the passing segment is the 8 bytes holding tkhd width/height (16.16 fixed point). The original has both set to 0. Everything else (ftyp cmfc, mvex/trex, encv/avcC High@3.0 with chroma extension, pasp, btrt, sinf/schm cenc/tenc, two pssh) is unchanged.
  • MOZ_LOG (Media playback preset) for the real site shows the append being rejected right after demuxer creation:
    TrackBuffersManager::CreateDemuxerforMIMEType: mType.OriginalString=video/mp4; codecs="avc1.64001E"
    TrackBuffersManager::RejectAppend: rv=2147500037   (NS_ERROR_FAILURE)
    
    The site's player (THEOplayer) then calls MediaSource.endOfStream("decode"), and playback fails with a generic error.
  • It looks like the MP4 demuxer takes the display size from tkhd and treats 0×0 as invalid (for example via VideoInfo::IsValid()), instead of falling back to the sample entry / SPS dimensions.
  • ISO/IEC 14496-12 says tkhd width/height give the visual presentation size of a visual track. So the content is arguably non-conformant, and I have also reported it to the content provider. But Chromium (and presumably Safari) tolerate it, real-world packagers emit it (here an Edgeware JITP origin), and it breaks a major streaming service in Firefox on every machine.

Suggested fix: When tkhd width/height is 0 for a video track, fall back to the sample entry (or SPS) dimensions for the display size instead of failing the init segment.

Workaround (confirmed on the live site): A userscript that wraps SourceBuffer.prototype.appendBuffer and rewrites tkhd width/height from the stsd sample entry before init segments are appended makes the affected site (play.tv2.dk) play normally in Firefox 158. No other changes are needed (DRM/Widevine works once the init segment is accepted). This confirms the 0×0 tkhd is the only blocker.

AI The problem was solved with support from Claude. I have tested the work-around script and can vouch for the content of this bug report.

Flags: needinfo?(per+bugzilla)

Test file that can show problem/verify fix. Requires no credentials. I do not know how long this URL will be valid.

Flags: needinfo?(per+bugzilla)

Hmm. I probably should not have filled "needinfo". The usage was not clear, so I thought better add my email.

Thank you for the clear test case and the analysis.

Analysis

This is a regression from a recent change to the display size check in the MP4 demuxer.

  1. mp4parse takes the display size from tkhd. For this init segment, the display size is 0x0.
  2. MP4VideoInfo::Update in DecoderData.cpp rejects the track when IsValidVideoDisplaySize(mDisplay) fails. The check ignores the valid sample entry size (768x432).
  3. IsValidVideoDisplaySize in VideoUtils.cpp requires a width and a height above 0.
  4. The demuxer then drops the video track. TrackBuffersManager::OnDemuxerInitDone finds no track and calls RejectAppend(NS_ERROR_FAILURE) in TrackBuffersManager.cpp. This gives the rv=2147500037 in comment 0.

Fix direction

When the tkhd width or height is 0, use the sample entry size as the display size. Then run the current check. This keeps the current upper size limit. The init segment in the attached test case can become a gtest or a mochitest.

Alastor, could you please set the Regressed by field to the change that caused this, and confirm the fix direction?


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

Severity: -- → S2
Flags: needinfo?(alwu)
Keywords: regression
Priority: -- → P2
See Also: → 2084400

Some packagers (e.g. Edgeware JITP, used by TV 2 Play) write width/height 0 in tkhd. MP4VideoInfo::Update() rejected such tracks through IsValidVideoDisplaySize(), so MSE init segments failed with "Failed to open media". Chromium accepts them.

When either tkhd dimension is 0, use the sample entry dimensions as the display size, then apply the existing bounds check. H.264/HEVC still override the display size from the SPS later in MP4TrackDemuxer.

Some packagers (e.g. the Edgeware JITP origin used by TV 2 Play) write a video tkhd with width/height 0. MP4VideoInfo::Update copied that into mDisplay, so IsValidVideoDisplaySize failed and the track was rejected. For MSE this means RejectAppend(NS_ERROR_FAILURE) / "Failed to open media". Chromium accepts these files.

Now, when either tkhd dimension is 0, the visual sample entry size is used as the display size. The existing bounds check still runs on the result, so a track whose sample entry size is also 0 is still rejected.

Accidentally submitted this one twice to hackbot.

You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: