[FFmpeg-devel] [PATCH] avcodec: Pass the HDR10+ metadata to the packet side data in VP9 encoder

Lynne dev at lynne.ee
Thu May 27 00:42:42 EEST 2021


May 26, 2021, 20:43 by izadi-at-google.com at ffmpeg.org:

> HDR10+ metadata is stored in the bit stream for HEVC. The story is different for VP9 and cannot store the metadata in the bit stream. HDR10+ should be passed to packet side data an stored in the container (mkv) for VP9.
>
> This CL is taking HDR10+ from AVFrame side data in libvpxenc and is passing it to the AVPacket side data.
> ---
>  doc/APIchanges         |  2 +
>  libavcodec/avpacket.c  |  1 +
>  libavcodec/decode.c    |  1 +
>  libavcodec/libvpxenc.c | 89 +++++++++++++++++++++++++++++++++++++++++-
>  libavcodec/packet.h    |  8 ++++
>  libavcodec/version.h   |  2 +-
>  6 files changed, 100 insertions(+), 3 deletions(-)
>
> diff --git a/doc/APIchanges b/doc/APIchanges
> index c46f4d5304..60995579e5 100644
> --- a/doc/APIchanges
> +++ b/doc/APIchanges
> @@ -13,6 +13,8 @@ libavutil:     2021-04-27
>  
>  
>  API changes, most recent first:
> +2021-05-25 - 8c88a66d3c - lavc 59.2.100 - packet.h
> +  Add AV_PKT_DATA_DYNAMIC_HDR10_PLUS
>  
>  2021-04-27 - cb3ac722f4 - lavc 59.0.100 - avcodec.h
>  Constified AVCodecParserContext.parser.
> diff --git a/libavcodec/avpacket.c b/libavcodec/avpacket.c
> index 7383d12d3e..800bee3489 100644
> --- a/libavcodec/avpacket.c
> +++ b/libavcodec/avpacket.c
> @@ -289,6 +289,7 @@ const char *av_packet_side_data_name(enum AVPacketSideDataType type)
>  case AV_PKT_DATA_ICC_PROFILE:                return "ICC Profile";
>  case AV_PKT_DATA_DOVI_CONF:                  return "DOVI configuration record";
>  case AV_PKT_DATA_S12M_TIMECODE:              return "SMPTE ST 12-1:2014 timecode";
> +    case AV_PKT_DATA_DYNAMIC_HDR10_PLUS:         return "HDR10+ Dynamic Metadata (SMPTE 2094-40)";
>  }
>  return NULL;
>  }
> diff --git a/libavcodec/decode.c b/libavcodec/decode.c
> index 75bc7ad98e..40f688e40c 100644
> --- a/libavcodec/decode.c
> +++ b/libavcodec/decode.c
> @@ -1488,6 +1488,7 @@ int ff_decode_frame_props(AVCodecContext *avctx, AVFrame *frame)
>  { AV_PKT_DATA_A53_CC,                     AV_FRAME_DATA_A53_CC },
>  { AV_PKT_DATA_ICC_PROFILE,                AV_FRAME_DATA_ICC_PROFILE },
>  { AV_PKT_DATA_S12M_TIMECODE,              AV_FRAME_DATA_S12M_TIMECODE },
> +        { AV_PKT_DATA_DYNAMIC_HDR10_PLUS,         AV_FRAME_DATA_DYNAMIC_HDR_PLUS },
>  };
>  
>  if (IS_EMPTY(pkt) && av_fifo_size(avctx->internal->pkt_props) >= sizeof(*pkt))
> diff --git a/libavcodec/libvpxenc.c b/libavcodec/libvpxenc.c
> index 66bad444d0..44ac90cafe 100644
> --- a/libavcodec/libvpxenc.c
> +++ b/libavcodec/libvpxenc.c
> @@ -64,6 +64,11 @@ struct FrameListData {
>  struct FrameListData *next;
>  };
>  
> +typedef struct FrameHDR10Plus {
> +    int64_t pts;
> +    AVBufferRef *hdr10_plus;
> +} FrameHDR10Plus;
> +
>  typedef struct VPxEncoderContext {
>  AVClass *class;
>  struct vpx_codec_ctx encoder;
> @@ -121,6 +126,8 @@ typedef struct VPxEncoderContext {
>  int tune_content;
>  int corpus_complexity;
>  int tpl_model;
> +    int discard_hdr10_plus;
> +    AVFifoBuffer *hdr10_plus_fifo;
>  /**
>  * If the driver does not support ROI then warn the first time we
>  * encounter a frame with ROI side data.
> @@ -316,6 +323,49 @@ static av_cold void free_frame_list(struct FrameListData *list)
>  }
>  }
>  
> +static void add_hdr10_plus(AVFifoBuffer *fifo, struct FrameHDR10Plus *data)
> +{
> +    av_fifo_grow(fifo, sizeof(FrameHDR10Plus));
> +    av_fifo_generic_write(fifo, data, sizeof(FrameHDR10Plus), NULL);
> +}
> +
> +static av_cold void free_hdr10_plus(struct FrameHDR10Plus *p)
> +{
> +    if (!p) return;
>

Put the returns on a newline.


> +    av_buffer_unref(&p->hdr10_plus);
> +    av_free(p);
> +}
> +
> +static av_cold void free_hdr10_plus_fifo(AVFifoBuffer **fifo)
> +{
> +    FrameHDR10Plus *frame_hdr10_plus = NULL;
> +    while (av_fifo_generic_read(*fifo, frame_hdr10_plus, sizeof(*frame_hdr10_plus), NULL) > 0) {
> +        free_hdr10_plus(frame_hdr10_plus);
> +    }
>

No brackets around one-line expressions.
Fix the coding style nits and it looks good to me.



More information about the ffmpeg-devel mailing list