[FFmpeg-devel] [PATCH] libavcodec/libx265: add user data unregistered SEI encoding

Brad Hards bradh at frogmouth.net
Mon Jun 21 19:12:12 EEST 2021


On Monday, 14 June 2021 10:54:09 AM AEST Brad Hards wrote:
> On Saturday, 5 June 2021 8:20:28 PM AEST Brad Hards wrote:
> > ---
> > 
> >  libavcodec/libx265.c | 31 +++++++++++++++++++++++++++++++
> >  1 file changed, 31 insertions(+)
> > 
> > diff --git a/libavcodec/libx265.c b/libavcodec/libx265.c
> > index 90658d3d9e..35547a5a69 100644
> > --- a/libavcodec/libx265.c
> > +++ b/libavcodec/libx265.c
> > @@ -51,6 +51,9 @@ typedef struct libx265Context {
> > 
> >      char *profile;
> >      AVDictionary *x265_opts;
> > 
> > +    void *sei_data;
> > +    int sei_data_size;
> > +
> > 
> >      /**
> >      
> >       * If the encoder does not support ROI then warn the first time we
> >       * encounter a frame with ROI side data.
> > 
> > @@ -489,6 +492,8 @@ static int libx265_encode_frame(AVCodecContext *avctx,
> > AVPacket *pkt, ctx->api->picture_init(ctx->params, &x265pic);
> > 
> >      if (pic) {
> > 
> > +        x265_sei *sei = &(x265pic.userSEI);
> > +        sei->numPayloads = 0;
> > 
> >          for (i = 0; i < 3; i++) {
> >          
> >             x265pic.planes[i] = pic->data[i];
> >             x265pic.stride[i] = pic->linesize[i];
> > 
> > @@ -516,6 +521,32 @@ static int libx265_encode_frame(AVCodecContext
> > *avctx,
> > AVPacket *pkt,
> > 
> >              memcpy(x265pic.userData, &pic->reordered_opaque,
> > 
> > sizeof(pic->reordered_opaque)); }
> > +
> > +        for (i = 0; i < pic->nb_side_data; i++) {
> > +            AVFrameSideData *side_data = pic->side_data[i];
> > +            void *tmp;
> > +
> > +            if (side_data->type != AV_FRAME_DATA_SEI_UNREGISTERED)
> > +                continue;
> > +
> > +            tmp = av_fast_realloc(ctx->sei_data,
> > +                                  &ctx->sei_data_size,
> > +                                  (sei->numPayloads + 1) *
> > sizeof(x265_sei_payload)); +            if (!tmp) {
> > +                av_freep(&x265pic.userData);
> > +                av_freep(&x265pic.quantOffsets);
> > +                return AVERROR(ENOMEM);
> > +            } else {
> > +                x265_sei_payload *sei_payload;
> > +                ctx->sei_data = tmp;
> > +                sei->payloads = ctx->sei_data;
> > +                sei_payload = &(sei->payloads[sei->numPayloads]);
> > +                sei_payload->payload = side_data->data;
> > +                sei_payload->payloadSize = side_data->size;
> > +                sei_payload->payloadType = USER_DATA_UNREGISTERED;
> > +                sei->numPayloads++;
> > +            }
> > +        }
> > 
> >      }
> >      
> >      ret = ctx->api->encoder_encode(ctx->encoder, &nal, &nnal,
> 
> Ping on this patch.
Ping on this patch.

Brad






More information about the ffmpeg-devel mailing list