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

Andreas Rheinhardt andreas.rheinhardt at outlook.com
Wed Jun 16 03:18:35 EEST 2021


Mohammad Izadi:
> 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 | 91 ++++++++++++++++++++++++++++++++++++++++++
>  libavcodec/packet.h    |  8 ++++
>  libavcodec/version.h   |  4 +-
>  6 files changed, 105 insertions(+), 2 deletions(-)
> 
> @@ -1620,6 +1692,25 @@ static int vpx_encode(AVCodecContext *avctx, AVPacket *pkt,
>                  vp9_encode_set_roi(avctx, frame->width, frame->height, sd);
>              }
>          }
> +
> +        if (!ctx->discard_hdr10_plus) {
> +            AVFrameSideData *hdr10_plus_metadata;
> +            // Add HDR10+ metadata to queue.
> +            hdr10_plus_metadata = av_frame_get_side_data(frame, AV_FRAME_DATA_DYNAMIC_HDR_PLUS);
> +            if (hdr10_plus_metadata) {
> +                int err;
> +                struct FrameHDR10Plus data;
> +                data.pts = frame->pts;
> +                data.hdr10_plus = av_buffer_ref(hdr10_plus_metadata->buf);
> +                if (!data.hdr10_plus)
> +                    return AVERROR(ENOMEM);
> +                err = add_hdr10_plus(ctx->hdr10_plus_fifo, &data);
> +                if (err < 0) {
> +                    av_freep(&data.hdr10_plus);

This is not how you free an AVBufferRef.

> +                    return err;
> +                }
> +            }
> +        }
>      }
>  
>      // this is for encoding with preset temporal layering patterns defined in


More information about the ffmpeg-devel mailing list