PR #24990 opened by smp79
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/24990
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/24990.patch
### Problem
The alternative transfer characteristics SEI is parsed into
`sei.common.alternative_transfer`, and `export_stream_params_from_sei()`
applies it to `avctx->color_trc` at every frame start. `ff_h2645_sei_reset()`
does not clear that state, so once one such SEI has been seen it keeps
overriding `color_trc` for the rest of the decode.
When the active SPS later changes to one without a colour description,
`export_stream_params()` resets primaries, transfer and matrix to unspecified.
The stale SEI then restores the old transfer characteristics on the next frame,
leaving `color_trc=arib-std-b67` with unspecified primaries and matrix.
### Reproduction
A DVB stream that alternates between an HLG section (with this SEI) and an SDR
section (new SPS, no colour description):
ffprobe -show_frames -select_streams v:0 \
-show_entries frame=pts_time,color_transfer,color_primaries,color_space
\
input.ts
Before: frames in the SDR section still report `arib-std-b67`, with unknown
primaries and colour space.
After: they report unspecified transfer, like the rest of the SDR section.
This breaks players that follow the decoder-reported colour properties. Kodi,
for example, never leaves HDR output after the first HLG section.
### Fix
Clear the SEI once it has been applied. `avctx->color_trc` keeps the value for
the rest of the sequence, and frame threads copy it from one to the next in
`update_context_from_thread()`, so nothing depends on the flag being re-applied.
### Testing
- Reproduced and verified on the stream above with VAAPI hardware decoding.
- Checked with `-threads 1` and `-threads 8` on the repro stream.
>From 3a9d1be2c0d90edf039665641b6392191e5072af Mon Sep 17 00:00:00 2001
From: smp79 <[email protected]>
Date: Sat, 10 Oct 2026 02:57:46 +0300
Subject: [PATCH] avcodec/hevc/hevcdec: don't re-apply a stale alternative
transfer SEI
The alternative transfer characteristics SEI is parsed into
sei.common.alternative_transfer, and export_stream_params_from_sei()
applies it to avctx->color_trc at every frame start. However
ff_h2645_sei_reset() never clears that state, so once a single such
SEI has been seen it keeps overriding color_trc for the rest of the
decode.
When the active SPS later changes to one without a colour
description, export_stream_params() resets primaries, transfer and
matrix to unspecified, and the stale SEI then restores the old
transfer characteristics, leaving color_trc=arib-std-b67 with
unspecified primaries and matrix.
Clear the SEI once it has been applied.
---
libavcodec/hevc/hevcdec.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/libavcodec/hevc/hevcdec.c b/libavcodec/hevc/hevcdec.c
index a36ea57bc2..b77c61850d 100644
--- a/libavcodec/hevc/hevcdec.c
+++ b/libavcodec/hevc/hevcdec.c
@@ -395,6 +395,8 @@ static int export_stream_params_from_sei(HEVCContext *s)
avctx->color_trc =
s->sei.common.alternative_transfer.preferred_transfer_characteristics;
}
+ s->sei.common.alternative_transfer.present = 0;
+
return 0;
}
--
2.52.0
_______________________________________________
ffmpeg-devel mailing list -- [email protected]
To unsubscribe send an email to [email protected]