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)
Tracking
()
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:
- Open the attached
mse-tkhd-testcase.html, a self-contained page that needs no network, login or DRM. - The page creates a
MediaSourceand 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 aSourceBuffer. 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
tkhdwidth/height (16.16 fixed point). The original has both set to 0. Everything else (ftypcmfc, mvex/trex, encv/avcC High@3.0 with chroma extension, pasp, btrt, sinf/schmcenc/tenc, two pssh) is unchanged. - MOZ_LOG (Media playback preset) for the real site shows the append being rejected right after demuxer creation:
The site's player (THEOplayer) then callsTrackBuffersManager::CreateDemuxerforMIMEType: mType.OriginalString=video/mp4; codecs="avc1.64001E" TrackBuffersManager::RejectAppend: rv=2147500037 (NS_ERROR_FAILURE)MediaSource.endOfStream("decode"), and playback fails with a generic error. - It looks like the MP4 demuxer takes the display size from
tkhdand treats 0×0 as invalid (for example viaVideoInfo::IsValid()), instead of falling back to the sample entry / SPS dimensions. - ISO/IEC 14496-12 says
tkhdwidth/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.
| Reporter | ||
Comment 1•1 month ago
|
||
Test file that can show problem/verify fix. Requires no credentials. I do not know how long this URL will be valid.
| Reporter | ||
Comment 2•1 month ago
|
||
Hmm. I probably should not have filled "needinfo". The usage was not clear, so I thought better add my email.
Comment 3•1 month ago
|
||
| gecko-triage | ||
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.
- mp4parse takes the display size from
tkhd. For this init segment, the display size is 0x0. MP4VideoInfo::Updatein DecoderData.cpp rejects the track whenIsValidVideoDisplaySize(mDisplay)fails. The check ignores the valid sample entry size (768x432).IsValidVideoDisplaySizein VideoUtils.cpp requires a width and a height above 0.- The demuxer then drops the video track.
TrackBuffersManager::OnDemuxerInitDonefinds no track and callsRejectAppend(NS_ERROR_FAILURE)in TrackBuffersManager.cpp. This gives therv=2147500037in 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.
Comment 4•27 days ago
|
||
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.
Comment 5•27 days ago
|
||
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.
Comment 6•25 days ago
|
||
Accidentally submitted this one twice to hackbot.
Description
•