HEVC video on macOS stays frozen after background video decode suspension (scrolled off-screen or in a hidden tab for 30 seconds or more)
Categories
(Core :: Audio/Video: Playback, defect, P2)
Tracking
()
People
(Reporter: j.thomperoo, Unassigned)
References
Details
Attachments
(4 files)
User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:160.0) Gecko/20100101 Firefox/160.0
Steps to reproduce
- Serve the attached files locally:
python3 -m http.server 8000in the folder, then open http://localhost:8000/. The page playshevc.mp4muted and looped, with a status box showingcurrentTimeand getVideoPlaybackQuality().totalVideoFrames. - Let it play for about five seconds.
- Scroll to the bottom of the page so the video is off-screen, and wait 30 seconds. Alternatively, open a new tab, wait 30 seconds, then close it.
- Scroll back to the top, or return to the tab.
Actual results
The video stays frozen on one frame. paused remains false and currentTime keeps advancing, including through loops, but totalVideoFrames never increases again. No error or other media event fires. It does not recover on its own.
Expected results
Playback resumes, as it does for H.264 and AV1.
| Reporter | ||
Comment 1•3 days ago
|
||
| Reporter | ||
Comment 2•3 days ago
|
||
| Reporter | ||
Comment 3•3 days ago
|
||
Additional information:
- The same clip encoded as H.264 (?src=h264.mp4) recovers normally, and so do AV1 encodes of our own footage.
- Setting media.suspend-background-video.enabled to false prevents the freeze, so the trigger appears to be resuming after background video decode suspension.
- An absence of 15 seconds did not trigger it. 30 seconds triggers it reliably.
- Setting video.currentTime = video.currentTime restores playback. pause() followed by play() does not.
- The synthetic clip is x265, Main profile, 1280x720 at 25fps, 520kbps, keyint 50, open GOP, B-frames. A static test pattern encoded the same way did not reproduce it. Content with real motion did.
- Found on a production site, where looping background hero videos froze for Firefox visitors on Apple Silicon.
- Possibly related: bug 2034130 (HEVC on Windows drops frames after the decoder is recreated on resume).
Comment 4•3 days ago
|
||
The Bugbug bot thinks this bug should belong to the 'Core::Audio/Video: Playback' component, and is moving the bug to that component. Please correct in case you think the bot is wrong.
Comment 5•3 days ago
|
||
| gecko-triage | ||
Thanks for the samples and the clear steps.
Analysis
The attached hevc.mp4 has only one IDR frame, at t=0. The other sync samples are CRA frames with leading RASL pictures, every 2 seconds. The attached h264.mp4 has an IDR frame at every sync sample.
On macOS, the MP4 demuxer accepts only IDR frames as HEVC keyframes (MP4Demuxer.cpp). The reason is that VideoToolbox can reject a CRA frame as the first sample after a seek. Bug 2049615 added this rule in Firefox 154. So with this clip, every seek on macOS restarts the decoder at t=0.
After media.suspend-background-video.delay-ms (10 seconds), Firefox shuts down the video decoder. On resume, a clip with no audio track runs VideoOnlySeekingState (MediaDecoderStateMachine.cpp). This seek targets the live clock, which keeps moving. When the playhead is late in the 18-second loop, the new decoder must decode from t=0 to catch the clock. It then skips to the end of the stream and shows no frame. This probably explains why 15 seconds away works and 30 seconds fails: the trigger is probably the playhead position, not the time away.
This also explains why a seek recovers and pause() plus play() does not. This is a probable cause from code reading. It does not explain why playback never recovers at the next loop. A media log can show what repeats on each loop.
Next steps
Jamie, could you please capture a profile with the attached page and hevc.mp4, on the same Mac?
Please capture a profile:
- Open
about:logging. - Under Log module selection, choose "Media playback" in the Logging preset: drop-down.
- Under Logging output, select "Logging to the Firefox Profiler".
- Click Start Logging.
- Reload the page. Then do the steps that show the problem.
- Click Stop Logging. The profile opens in the Firefox Profiler.
- Click Upload Local Profile. This is the share button.
- Copy the share URL. Add it to this bug.
The instruction video shows these steps.
Jamie, could you please also attach the text of about:support to this bug?
If you'd like to provide feedback on this comment, please use the 👍 or 👎 reaction.
Comment 6•3 days ago
|
||
Bug 2065822 might help, which will treat HEVC CRA as a random access point.
| Reporter | ||
Comment 7•3 days ago
|
||
| Reporter | ||
Comment 8•3 days ago
|
||
(In reply to media-triaging-bot from comment #5)
Thanks for the samples and the clear steps.
Analysis
The attached
hevc.mp4has only one IDR frame, at t=0. The other sync samples are CRA frames with leading RASL pictures, every 2 seconds. The attachedh264.mp4has an IDR frame at every sync sample.On macOS, the MP4 demuxer accepts only IDR frames as HEVC keyframes (MP4Demuxer.cpp). The reason is that VideoToolbox can reject a CRA frame as the first sample after a seek. Bug 2049615 added this rule in Firefox 154. So with this clip, every seek on macOS restarts the decoder at t=0.
After
media.suspend-background-video.delay-ms(10 seconds), Firefox shuts down the video decoder. On resume, a clip with no audio track runsVideoOnlySeekingState(MediaDecoderStateMachine.cpp). This seek targets the live clock, which keeps moving. When the playhead is late in the 18-second loop, the new decoder must decode from t=0 to catch the clock. It then skips to the end of the stream and shows no frame. This probably explains why 15 seconds away works and 30 seconds fails: the trigger is probably the playhead position, not the time away.This also explains why a seek recovers and
pause()plusplay()does not. This is a probable cause from code reading. It does not explain why playback never recovers at the next loop. A media log can show what repeats on each loop.Next steps
Jamie, could you please capture a profile with the attached page and
hevc.mp4, on the same Mac?Please capture a profile:
- Open
about:logging.- Under Log module selection, choose "Media playback" in the Logging preset: drop-down.
- Under Logging output, select "Logging to the Firefox Profiler".
- Click Start Logging.
- Reload the page. Then do the steps that show the problem.
- Click Stop Logging. The profile opens in the Firefox Profiler.
- Click Upload Local Profile. This is the share button.
- Copy the share URL. Add it to this bug.
The instruction video shows these steps.
Jamie, could you please also attach the text of
about:supportto this bug?
If you'd like to provide feedback on this comment, please use the 👍 or 👎 reaction.
Profiles as requested, both on the attached page and hevc.mp4, same Mac:
- Scrolled off-screen for about 30 seconds, then back: https://share.firefox.dev/4kr55RQ
- Switched to another tab for about 30 seconds, then back: https://share.firefox.dev/3WPsenj
about:support text attached.
A correction to comment 0: it does recover on its own. In both of these runs the video stayed frozen after returning, then resumed when the loop started again. Earlier I had only watched for 20 to 25 seconds after returning. It is also intermittent: in some runs the frame count kept rising while the video was hidden, so the decoder does not seem to have been suspended, and those runs never froze.
Comment 9•2 days ago
|
||
| gecko-triage | ||
Thanks for the two profiles and about:support. They show the full chain, and they correct the analysis in comment 5.
Analysis
Both profiles show the same sequence. The decoder is VideoToolbox hardware decoding in the RDD process. While the video is hidden, a blank decoder replaces it.
- On resume, the clip has no audio track, so Firefox does a video-only seek to the playback position. In the tab case the target is 5.57 s. The log shows
Video seeked to 0, because on macOS the MP4 demuxer accepts only the IDR frame at t=0 as an HEVC keyframe. - The "next keyframe" lookup reads the sync flags of the file, so it reports the CRA frame at about 2 s. That frame is behind the target, so
ShouldSkipstarts a skip to a keyframe after the target (MediaFormatReader.cpp). - The demuxer finds no keyframe after the target. The log shows
Skipping failed, skipped 451 framesand thenNS_ERROR_DOM_MEDIA_END_OF_STREAM(MediaFormatReader.cpp). - The looping state takes this false end of stream as the end of a loop. It adds the track duration to the video queue offset (MediaDecoderStateMachine.cpp). In the tab case, the offset becomes 54.24 s while the clock is at 41.60 s.
- The new frames from t=0 are thus about 12.6 s ahead of the clock. No frame renders until the clock catches up, which looks like recovery at the next loop. In the scroll case the gap is about 6.6 s.
This explains the other facts too. H.264 has an IDR frame at each sync sample, so the two keyframe answers agree and no skip occurs. A seek such as currentTime = currentTime resets the queue offset, and pause() plus play() does not. The freeze needs a real decoder suspension and a resume position after the first CRA frame. This fits the intermittent result in comment 8. It does not explain why the static test pattern did not show the problem.
Probable cause and fix direction
The probable cause is bug 2049615 (Firefox 154). It made the macOS demuxer accept only IDR frames as HEVC keyframes, but the next keyframe lookup still uses the sync flags of the file. This comes from code reading and the logs. No bisection confirms it.
Two changes can fix it:
- Make the next keyframe lookup agree with the keyframe check of the demuxer. Bug 2065822 (in progress) keeps CRA frames as keyframes, so it probably covers this MP4 path, as comment 6 says. In the current tree, bug 2080453 (Firefox 162) changed
GetNextKeyframeTimeto use a keyframe map (SampleIterator.cpp). This can remove the trigger, but nobody tested it on this clip. - When a skip finds no keyframe after the threshold, do not leave the demuxer at the end of the stream. Any looping clip that has this skip failure can freeze in the same way.
The attached page and hevc.mp4 reproduce the problem, with resume more than 2 s into the loop. A Nightly 162 run with the same steps can show if bug 2080453 removes the skip: the log then has no Skipping up to line. Bug 2091293 is a related report of HEVC CRA keyframe handling on macOS, in Matroska.
If you'd like to provide feedback on this comment, please use the 👍 or 👎 reaction.
Description
•