Skip to content

Fix HDR videos losing their colors when sent - #31407

Open
meh7an wants to merge 2 commits into
telegramdesktop:devfrom
meh7an:fix/hdr-video-sending
Open

meh7an wants to merge 2 commits into
telegramdesktop:devfrom
meh7an:fix/hdr-video-sending

Conversation

@meh7an

@meh7an meh7an commented Oct 4, 2026

Copy link
Copy Markdown
Contributor

Based on #31406, which adds the tone mapping this uses; only the last commit is new here.

When an HDR video is sent, the send box preview and the uploaded thumbnail (the clip reader), the video timeline in the photo editor and the re-encode used for a reduced quality or trimmed video all convert frames with plain swscale. The preview and timeline are washed out, and the re-encoded file is written as 8-bit SDR samples while it keeps the PQ or HLG tags of the source, so it looks broken for everyone who receives it.

These paths now go through one helper, Streaming::ConvertFrameToARGB32(), which tone maps HDR frames the same way playback does and runs swscale for the rest. The re-encode tone maps HDR frames to SDR before encoding and tags the result with what it is: the BT.709 transfer, the SMPTE 170M matrix because swscale converts RGB to YUV with BT.601 coefficients, and BT.709 primaries, or the source primaries when they are not BT.2020, because only BT.2020 is converted.

Testing

Tested on macOS 27.0, in a Debug build, with an 8-bit HLG video recorded on an iPhone:

  • The send box preview and the video timeline in the photo editor show correct colors instead of washed out.
  • Sending it with reduced quality uploads a video that plays with correct colors.
  • Temporary code re-encoded HDR10 and HLG test videos at a smaller size: the output is tagged BT.709 with the SMPTE 170M matrix and decodes to the colors of the tone mapped source, 1 to 3 levels apart in the median.
@john-preston

Copy link
Copy Markdown
Member

It inherits #31406’s alpha loss and can permanently remove transparency from generated stickers.

@meh7an

meh7an commented Oct 22, 2026

Copy link
Copy Markdown
Contributor Author

It inherits #31406’s alpha loss and can permanently remove transparency from generated stickers.

Thanks, fixed in #31406's commit, so #31407 and #31408 get it too. HDR frames with an alpha plane are now tone mapped through YUVA420P10 instead of P010, and the alpha is copied back into the tone mapped image, so they keep their transparency like SDR frames do. Checked with an HDR-tagged VP9 webm with alpha: the send box preview and playback now show it with transparency, the same as the same file without the HDR tags.

@meh7an
meh7an force-pushed the fix/hdr-video-sending branch from 7044f5f to f803cc4 Compare October 22, 2026 21:05

This branch has not been deployed

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

Labels

None yet

2 participants