[vlc-devel] [PATCH] contrib: ffmpeg: use the SEI early in HEVC

Steve Lhomme robux4 at ycbcr.xyz
Fri May 24 09:14:47 CEST 2019


It fixes the alternate HLG transfer function being lost because we don't use
the one from the AVFrame once our picture pool is set (or we don't reconfigure
the display module dynamically if it changes).
---
 ...set-the-SEI-parameters-early-on-the-.patch | 63 +++++++++++++++++++
 contrib/src/ffmpeg/rules.mak                  |  1 +
 2 files changed, 64 insertions(+)
 create mode 100644 contrib/src/ffmpeg/0001-avcodec-hevcdec-set-the-SEI-parameters-early-on-the-.patch

diff --git a/contrib/src/ffmpeg/0001-avcodec-hevcdec-set-the-SEI-parameters-early-on-the-.patch b/contrib/src/ffmpeg/0001-avcodec-hevcdec-set-the-SEI-parameters-early-on-the-.patch
new file mode 100644
index 0000000000..0e8c71832e
--- /dev/null
+++ b/contrib/src/ffmpeg/0001-avcodec-hevcdec-set-the-SEI-parameters-early-on-the-.patch
@@ -0,0 +1,63 @@
+From c97e3d92bec19867eb8a2b1b2267fa0b28ead1ce Mon Sep 17 00:00:00 2001
+From: Steve Lhomme <robux4 at ycbcr.xyz>
+Date: Fri, 24 May 2019 08:58:00 +0200
+Subject: [PATCH] avcodec/hevcdec: set the SEI parameters early on the
+ AVCodecContext
+
+It's better to do it before the buffers are actually created. At least in VLC
+we currently don't support changing some parameters dynamically easily so we
+don't use the information if it comes after the buffer are created.
+
+---
+The same problem may exist with H264 alternative_transfer but I don't have a
+sample to test with and the code seems a bit different.
+---
+ libavcodec/hevcdec.c | 18 +++++++++++-------
+ 1 file changed, 11 insertions(+), 7 deletions(-)
+
+diff --git a/libavcodec/hevcdec.c b/libavcodec/hevcdec.c
+index 515b346535..f54f46aa5d 100644
+--- a/libavcodec/hevcdec.c
++++ b/libavcodec/hevcdec.c
+@@ -313,6 +313,7 @@ static int decode_lt_rps(HEVCContext *s, LongTermRPS *rps, GetBitContext *gb)
+ static void export_stream_params(AVCodecContext *avctx, const HEVCParamSets *ps,
+                                  const HEVCSPS *sps)
+ {
++    const HEVCContext *s = avctx->priv_data;
+     const HEVCVPS *vps = (const HEVCVPS*)ps->vps_list[sps->vps_id]->data;
+     const HEVCWindow *ow = &sps->output_window;
+     unsigned int num = 0, den = 0;
+@@ -355,6 +356,16 @@ static void export_stream_params(AVCodecContext *avctx, const HEVCParamSets *ps,
+     if (num != 0 && den != 0)
+         av_reduce(&avctx->framerate.den, &avctx->framerate.num,
+                   num, den, 1 << 30);
++
++    if (s->sei.a53_caption.a53_caption) {
++        avctx->properties |= FF_CODEC_PROPERTY_CLOSED_CAPTIONS;
++    }
++
++    if (s->sei.alternative_transfer.present &&
++        av_color_transfer_name(s->sei.alternative_transfer.preferred_transfer_characteristics) &&
++        s->sei.alternative_transfer.preferred_transfer_characteristics != AVCOL_TRC_UNSPECIFIED) {
++        avctx->color_trc = s->sei.alternative_transfer.preferred_transfer_characteristics;
++    }
+ }
+ 
+ static enum AVPixelFormat get_format(HEVCContext *s, const HEVCSPS *sps)
+@@ -2775,13 +2786,6 @@ static int set_side_data(HEVCContext *s)
+             memcpy(sd->data, s->sei.a53_caption.a53_caption, s->sei.a53_caption.a53_caption_size);
+         av_freep(&s->sei.a53_caption.a53_caption);
+         s->sei.a53_caption.a53_caption_size = 0;
+-        s->avctx->properties |= FF_CODEC_PROPERTY_CLOSED_CAPTIONS;
+-    }
+-
+-    if (s->sei.alternative_transfer.present &&
+-        av_color_transfer_name(s->sei.alternative_transfer.preferred_transfer_characteristics) &&
+-        s->sei.alternative_transfer.preferred_transfer_characteristics != AVCOL_TRC_UNSPECIFIED) {
+-        s->avctx->color_trc = out->color_trc = s->sei.alternative_transfer.preferred_transfer_characteristics;
+     }
+ 
+     return 0;
+-- 
+2.19.1.windows.1
+
diff --git a/contrib/src/ffmpeg/rules.mak b/contrib/src/ffmpeg/rules.mak
index 2eeee961a5..1a5dfa7243 100644
--- a/contrib/src/ffmpeg/rules.mak
+++ b/contrib/src/ffmpeg/rules.mak
@@ -244,6 +244,7 @@ ifdef USE_FFMPEG
 	$(APPLY) $(SRC)/ffmpeg/armv7_fixup.patch
 	$(APPLY) $(SRC)/ffmpeg/dxva_vc1_crash.patch
 	$(APPLY) $(SRC)/ffmpeg/h264_early_SAR.patch
+	$(APPLY) $(SRC)/ffmpeg/0001-avcodec-hevcdec-set-the-SEI-parameters-early-on-the-.patch
 endif
 ifdef USE_LIBAV
 	$(APPLY) $(SRC)/ffmpeg/libav_gsm.patch
-- 
2.17.1



More information about the vlc-devel mailing list