Skip to content

[video_player] Fix washed-out HDR video playback on iOS#11569

Open
StefanGilligan wants to merge 1 commit intoflutter:mainfrom
StefanGilligan:video-player-hdr-fix
Open

[video_player] Fix washed-out HDR video playback on iOS#11569
StefanGilligan wants to merge 1 commit intoflutter:mainfrom
StefanGilligan:video-player-hdr-fix

Conversation

@StefanGilligan
Copy link
Copy Markdown

Declares BT.709 color properties on AVPlayerItemVideoOutput so AVFoundation tone-maps HDR sources (HLG, PQ, Dolby Vision) into the Flutter texture on the way into the pixel buffer.

Previously the output was constructed with only pixel buffer attributes, so HDR BT.2020 samples reached the Flutter texture unconverted, were sampled as sRGB, and produced washed-out highlights, raised blacks, and desaturated midtones. SDR (BT.709) sources are unaffected (BT.709 → BT.709 is a no-op).

The canonical fix per Apple is to construct the output with -initWithOutputSettings: and pass AVVideoColorPropertiesKey with a BT.709 triplet. AVVideoColorPropertiesKey placed under pixelBufferAttributes is silently ignored — this is the trap that has kept the underlying issue open for years.

Internal factory method renamed from videoOutputWithPixelBufferAttributes: to videoOutputWithOutputSettings: to reflect that the dictionary is now output settings (which may still include pixel buffer attribute keys).

References:

  • WWDC22 "Display HDR video in EDR with AVFoundation and Metal"
  • Apple Developer Forum thread 686044

Fixes

Tested on

Manual validation against an iPhone camera roll containing HLG and Dolby Vision clips, played inside a Flutter app using video_player. Before: preview washed out, highlights clipped grey, blacks raised. After: preview matches Photos.app for the same source clip. SDR BT.709 content renders identically to before.

A unit test (videoOutputIsConfiguredWithBT709ColorProperties) was added to assert the BT.709 triplet is present in the outputSettings dictionary passed to the factory — this locks in the fix against silent regression (since the old pixelBufferAttributes-only path produced no test failure and no runtime error, just visually wrong output).

Pre-Review Checklist

AVPlayerItemVideoOutput was being constructed with only pixel buffer
attributes and no AVVideoColorPropertiesKey. For HDR sources (HLG, PQ,
Dolby Vision) AVFoundation then hands the decoder's BT.2020 samples
through to the Flutter texture unconverted, which samples them as sRGB.
The result is washed-out highlights, raised blacks, and desaturated
midtones.

Switch to -initWithOutputSettings: and declare BT.709 color properties
on the output. AVFoundation's pixel transfer session now tone-maps and
gamut-converts HDR into BT.709 SDR on the way into the pixel buffer,
at no per-frame CPU cost. For SDR (BT.709) sources this is a no-op.

AVVideoColorPropertiesKey must live in the output settings dictionary
passed to -initWithOutputSettings:. Color keys placed under the pixel
buffer attributes dictionary are silently ignored by AVFoundation; this
is the trap that has kept the underlying issue unresolved. See WWDC22
"Display HDR video in EDR with AVFoundation and Metal" and Apple
Developer Forum thread 686044 for the prescribed approach.

Addresses flutter/flutter#91241 and flutter/flutter#143080.
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the video_player_avfoundation package to version 2.9.5. It addresses an issue where HDR video playback appeared washed out on iOS by configuring the AVPlayerItemVideoOutput with BT.709 color properties, forcing tone-mapping to SDR. The changes include updating the FVPAVFactory interface and implementation to support general output settings instead of just pixel buffer attributes, and adding a unit test to verify the configuration. I have no feedback to provide.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[video_player] Incorrect colors in HDR playback on iOS Video player iOS HDR videos look washed out

1 participant