diff mbox

[FFmpeg-devel,v2] avcodec/hevcdec: set the SEI parameters early on the AVCodecContext

Message ID 20190527140647.15404-1-robux4@ycbcr.xyz
State Accepted
Commit f2ad6238e4c0e99e2fc131ee14c586e87b045680
Headers show

Commit Message

Steve Lhomme May 27, 2019, 2:06 p.m. UTC
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.

Co-authored-by: James Almer <jamrial@gmail.com>
---
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.

Compared to previous version:
- no handling of the cpation flag
- pass the HEVCContext to export_stream_params()
---
 libavcodec/hevcdec.c | 21 +++++++++++----------
 1 file changed, 11 insertions(+), 10 deletions(-)

Comments

James Almer May 27, 2019, 2:58 p.m. UTC | #1
On 5/27/2019 11:06 AM, Steve Lhomme wrote:
> 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.
> 
> Co-authored-by: James Almer <jamrial@gmail.com>
> ---
> 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.

As i said, h264 should be a matter or moving the relevant code to
h264_init_ps().

Try https://0x0.st/zate.mkv, i created it using the patch i sent last
night that adds support for atc sei messages to cbs_h264, and
re-encoding a few frames from the LG HLG jazz sample.

> 
> Compared to previous version:
> - no handling of the cpation flag
> - pass the HEVCContext to export_stream_params()
> ---
>  libavcodec/hevcdec.c | 21 +++++++++++----------
>  1 file changed, 11 insertions(+), 10 deletions(-)
> 
> diff --git a/libavcodec/hevcdec.c b/libavcodec/hevcdec.c
> index 515b346535..f1934975d5 100644
> --- a/libavcodec/hevcdec.c
> +++ b/libavcodec/hevcdec.c
> @@ -310,9 +310,10 @@ static int decode_lt_rps(HEVCContext *s, LongTermRPS *rps, GetBitContext *gb)
>      return 0;
>  }
>  
> -static void export_stream_params(AVCodecContext *avctx, const HEVCParamSets *ps,
> -                                 const HEVCSPS *sps)
> +static void export_stream_params(HEVCContext *s, const HEVCSPS *sps)
>  {
> +    AVCodecContext *avctx = s->avctx;
> +    const HEVCParamSets *ps = &s->ps;
>      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,12 @@ 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.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)
> @@ -447,7 +454,7 @@ static int set_sps(HEVCContext *s, const HEVCSPS *sps,
>      if (ret < 0)
>          goto fail;
>  
> -    export_stream_params(s->avctx, &s->ps, sps);
> +    export_stream_params(s, sps);
>  
>      s->avctx->pix_fmt = pix_fmt;
>  
> @@ -2778,12 +2785,6 @@ static int set_side_data(HEVCContext *s)
>          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;
>  }
>  
> @@ -3179,7 +3180,7 @@ static int hevc_decode_extradata(HEVCContext *s, uint8_t *buf, int length, int f
>      for (i = 0; i < FF_ARRAY_ELEMS(s->ps.sps_list); i++) {
>          if (first && s->ps.sps_list[i]) {
>              const HEVCSPS *sps = (const HEVCSPS*)s->ps.sps_list[i]->data;
> -            export_stream_params(s->avctx, &s->ps, sps);
> +            export_stream_params(s, sps);
>              break;
>          }
>      }

LGTM.
diff mbox

Patch

diff --git a/libavcodec/hevcdec.c b/libavcodec/hevcdec.c
index 515b346535..f1934975d5 100644
--- a/libavcodec/hevcdec.c
+++ b/libavcodec/hevcdec.c
@@ -310,9 +310,10 @@  static int decode_lt_rps(HEVCContext *s, LongTermRPS *rps, GetBitContext *gb)
     return 0;
 }
 
-static void export_stream_params(AVCodecContext *avctx, const HEVCParamSets *ps,
-                                 const HEVCSPS *sps)
+static void export_stream_params(HEVCContext *s, const HEVCSPS *sps)
 {
+    AVCodecContext *avctx = s->avctx;
+    const HEVCParamSets *ps = &s->ps;
     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,12 @@  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.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)
@@ -447,7 +454,7 @@  static int set_sps(HEVCContext *s, const HEVCSPS *sps,
     if (ret < 0)
         goto fail;
 
-    export_stream_params(s->avctx, &s->ps, sps);
+    export_stream_params(s, sps);
 
     s->avctx->pix_fmt = pix_fmt;
 
@@ -2778,12 +2785,6 @@  static int set_side_data(HEVCContext *s)
         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;
 }
 
@@ -3179,7 +3180,7 @@  static int hevc_decode_extradata(HEVCContext *s, uint8_t *buf, int length, int f
     for (i = 0; i < FF_ARRAY_ELEMS(s->ps.sps_list); i++) {
         if (first && s->ps.sps_list[i]) {
             const HEVCSPS *sps = (const HEVCSPS*)s->ps.sps_list[i]->data;
-            export_stream_params(s->avctx, &s->ps, sps);
+            export_stream_params(s, sps);
             break;
         }
     }