diff mbox series

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

Message ID 20210806091633.2083-1-bradh@frogmouth.net
State Accepted
Commit 7c08cad280a16b346c0a5e0efdfd8333ec54f095
Headers show
Series [FFmpeg-devel] libavcodec/libx264: add user data unregistered SEI encoding | expand

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished
andriy/PPC64_make success Make finished
andriy/PPC64_make_fate success Make fate finished

Commit Message

Brad Hards Aug. 6, 2021, 9:16 a.m. UTC
MISB ST 0604 and ST 2101 require user data unregistered SEI messages
(precision timestamps and sensor identifiers) to be included. That
currently isn't supported for libx264. This patch adds support
for user data unregistered SEI messages in accordance with ISO/IEC
14496-10:2020(E) section D.1.7 (syntax) and D.2.7 (semantics).

This code is based on a similar change for libx265 (commit
1f58503013720700a5adfd72c708e6275aefc165).
---
 libavcodec/libx264.c | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)

Comments

Brad Hards Aug. 13, 2021, 11:51 p.m. UTC | #1
On Friday, 6 August 2021 7:16:33 PM AEST Brad Hards wrote:
> MISB ST 0604 and ST 2101 require user data unregistered SEI messages
> (precision timestamps and sensor identifiers) to be included. That
> currently isn't supported for libx264. This patch adds support
> for user data unregistered SEI messages in accordance with ISO/IEC
> 14496-10:2020(E) section D.1.7 (syntax) and D.2.7 (semantics).
> 
> This code is based on a similar change for libx265 (commit
> 1f58503013720700a5adfd72c708e6275aefc165).
> ---
>  libavcodec/libx264.c | 30 ++++++++++++++++++++++++++++++
>  1 file changed, 30 insertions(+)
> 
> diff --git a/libavcodec/libx264.c b/libavcodec/libx264.c
> index 9afaf19547..e9bbe8d494 100644
> --- a/libavcodec/libx264.c
> +++ b/libavcodec/libx264.c
> @@ -32,6 +32,7 @@
>  #include "internal.h"
>  #include "packet_internal.h"
>  #include "atsc_a53.h"
> +#include "sei.h"
>  
>  #if defined(_MSC_VER)
>  #define X264_API_IMPORTS 1
> @@ -114,6 +115,9 @@ typedef struct X264Context {
>       * encounter a frame with ROI side data.
>       */
>      int roi_warned;
> +
> +    void *sei_data;
> +    int sei_data_size;
>  } X264Context;
>  
>  static void X264_log(void *p, int level, const char *fmt, va_list args)
> @@ -317,6 +321,9 @@ static int X264_frame(AVCodecContext *ctx, AVPacket *pkt, const AVFrame *frame,
>      x4->pic.img.i_plane = avfmt2_num_planes(ctx->pix_fmt);
>  
>      if (frame) {
> +        x264_sei_t *sei = &x4->pic.extra_sei;
> +        sei->num_payloads = 0;
> +
>          for (i = 0; i < x4->pic.img.i_plane; i++) {
>              x4->pic.img.plane[i]    = frame->data[i];
>              x4->pic.img.i_stride[i] = frame->linesize[i];
> @@ -439,6 +446,27 @@ static int X264_frame(AVCodecContext *ctx, AVPacket *pkt, const AVFrame *frame,
>                  }
>              }
>          }
> +
> +        for (int j = 0; j < frame->nb_side_data; j++) {
> +            AVFrameSideData *side_data = frame->side_data[j];
> +            void *tmp;
> +            x264_sei_payload_t *sei_payload;
> +            if (side_data->type != AV_FRAME_DATA_SEI_UNREGISTERED)
> +                continue;
> +            tmp = av_fast_realloc(x4->sei_data, &x4->sei_data_size, (sei->num_payloads + 1) * sizeof(*sei_payload));
> +            if (!tmp) {
> +                av_freep(&x4->pic.extra_sei.payloads);
> +                av_freep(&x4->pic.prop.quant_offsets);
> +                return AVERROR(ENOMEM);
> +            }
> +            x4->sei_data = tmp;
> +            sei->payloads = x4->sei_data;
> +            sei_payload = &sei->payloads[sei->num_payloads];
> +            sei_payload->payload = side_data->data;
> +            sei_payload->payload_size = side_data->size;
> +            sei_payload->payload_type = SEI_TYPE_USER_DATA_UNREGISTERED;
> +            sei->num_payloads++;
> +        }
>      }
>  
>      do {
> @@ -505,6 +533,8 @@ static av_cold int X264_close(AVCodecContext *avctx)
>      x264_param_cleanup(&x4->params);
>  #endif
>  
> +    av_freep(&x4->sei_data);
> +
>      if (x4->enc) {
>          x264_encoder_close(x4->enc);
>          x4->enc = NULL;
> 
Ping on this patch.

Brad
Brad Hards Aug. 22, 2021, 9:25 a.m. UTC | #2
On Saturday, 14 August 2021 9:51:03 AM AEST Brad Hards wrote:
> On Friday, 6 August 2021 7:16:33 PM AEST Brad Hards wrote:
> > MISB ST 0604 and ST 2101 require user data unregistered SEI messages
> > (precision timestamps and sensor identifiers) to be included. That
> > currently isn't supported for libx264. This patch adds support
> > for user data unregistered SEI messages in accordance with ISO/IEC
> > 14496-10:2020(E) section D.1.7 (syntax) and D.2.7 (semantics).
> > 
> > This code is based on a similar change for libx265 (commit
> > 1f58503013720700a5adfd72c708e6275aefc165).
> > ---
> > 
> >  libavcodec/libx264.c | 30 ++++++++++++++++++++++++++++++
> >  1 file changed, 30 insertions(+)
> > 
> > diff --git a/libavcodec/libx264.c b/libavcodec/libx264.c
> > index 9afaf19547..e9bbe8d494 100644
> > --- a/libavcodec/libx264.c
> > +++ b/libavcodec/libx264.c
> > @@ -32,6 +32,7 @@
> > 
> >  #include "internal.h"
> >  #include "packet_internal.h"
> >  #include "atsc_a53.h"
> > 
> > +#include "sei.h"
> > 
> >  #if defined(_MSC_VER)
> >  #define X264_API_IMPORTS 1
> > 
> > @@ -114,6 +115,9 @@ typedef struct X264Context {
> > 
> >       * encounter a frame with ROI side data.
> >       */
> >      
> >      int roi_warned;
> > 
> > +
> > +    void *sei_data;
> > +    int sei_data_size;
> > 
> >  } X264Context;
> >  
> >  static void X264_log(void *p, int level, const char *fmt, va_list args)
> > 
> > @@ -317,6 +321,9 @@ static int X264_frame(AVCodecContext *ctx, AVPacket
> > *pkt, const AVFrame *frame,> 
> >      x4->pic.img.i_plane = avfmt2_num_planes(ctx->pix_fmt);
> >      
> >      if (frame) {
> > 
> > +        x264_sei_t *sei = &x4->pic.extra_sei;
> > +        sei->num_payloads = 0;
> > +
> > 
> >          for (i = 0; i < x4->pic.img.i_plane; i++) {
> >          
> >              x4->pic.img.plane[i]    = frame->data[i];
> >              x4->pic.img.i_stride[i] = frame->linesize[i];
> > 
> > @@ -439,6 +446,27 @@ static int X264_frame(AVCodecContext *ctx, AVPacket
> > *pkt, const AVFrame *frame,> 
> >                  }
> >              
> >              }
> >          
> >          }
> > 
> > +
> > +        for (int j = 0; j < frame->nb_side_data; j++) {
> > +            AVFrameSideData *side_data = frame->side_data[j];
> > +            void *tmp;
> > +            x264_sei_payload_t *sei_payload;
> > +            if (side_data->type != AV_FRAME_DATA_SEI_UNREGISTERED)
> > +                continue;
> > +            tmp = av_fast_realloc(x4->sei_data, &x4->sei_data_size,
> > (sei->num_payloads + 1) * sizeof(*sei_payload)); +            if (!tmp) {
> > +                av_freep(&x4->pic.extra_sei.payloads);
> > +                av_freep(&x4->pic.prop.quant_offsets);
> > +                return AVERROR(ENOMEM);
> > +            }
> > +            x4->sei_data = tmp;
> > +            sei->payloads = x4->sei_data;
> > +            sei_payload = &sei->payloads[sei->num_payloads];
> > +            sei_payload->payload = side_data->data;
> > +            sei_payload->payload_size = side_data->size;
> > +            sei_payload->payload_type = SEI_TYPE_USER_DATA_UNREGISTERED;
> > +            sei->num_payloads++;
> > +        }
> > 
> >      }
> >      
> >      do {
> > 
> > @@ -505,6 +533,8 @@ static av_cold int X264_close(AVCodecContext *avctx)
> > 
> >      x264_param_cleanup(&x4->params);
> >  
> >  #endif
> > 
> > +    av_freep(&x4->sei_data);
> > +
> > 
> >      if (x4->enc) {
> >      
> >          x264_encoder_close(x4->enc);
> >          x4->enc = NULL;
> 
> Ping on this patch.
Ping on this patch.

Brad
Brad Hards Sept. 6, 2021, 12:17 a.m. UTC | #3
On Sunday, 22 August 2021 7:25:25 PM AEST Brad Hards wrote:
> On Saturday, 14 August 2021 9:51:03 AM AEST Brad Hards wrote:
> > On Friday, 6 August 2021 7:16:33 PM AEST Brad Hards wrote:
> > > MISB ST 0604 and ST 2101 require user data unregistered SEI messages
> > > (precision timestamps and sensor identifiers) to be included. That
> > > currently isn't supported for libx264. This patch adds support
> > > for user data unregistered SEI messages in accordance with ISO/IEC
> > > 14496-10:2020(E) section D.1.7 (syntax) and D.2.7 (semantics).
> > > 
> > > This code is based on a similar change for libx265 (commit
> > > 1f58503013720700a5adfd72c708e6275aefc165).
> > > ---
> > > 
> > >  libavcodec/libx264.c | 30 ++++++++++++++++++++++++++++++
> > >  1 file changed, 30 insertions(+)
> > > 
> > > diff --git a/libavcodec/libx264.c b/libavcodec/libx264.c
> > > index 9afaf19547..e9bbe8d494 100644
> > > --- a/libavcodec/libx264.c
> > > +++ b/libavcodec/libx264.c
> > > @@ -32,6 +32,7 @@
> > > 
> > >  #include "internal.h"
> > >  #include "packet_internal.h"
> > >  #include "atsc_a53.h"
> > > 
> > > +#include "sei.h"
> > > 
> > >  #if defined(_MSC_VER)
> > >  #define X264_API_IMPORTS 1
> > > 
> > > @@ -114,6 +115,9 @@ typedef struct X264Context {
> > > 
> > >       * encounter a frame with ROI side data.
> > >       */
> > >      
> > >      int roi_warned;
> > > 
> > > +
> > > +    void *sei_data;
> > > +    int sei_data_size;
> > > 
> > >  } X264Context;
> > >  
> > >  static void X264_log(void *p, int level, const char *fmt, va_list args)
> > > 
> > > @@ -317,6 +321,9 @@ static int X264_frame(AVCodecContext *ctx, AVPacket
> > > *pkt, const AVFrame *frame,>
> > > 
> > >      x4->pic.img.i_plane = avfmt2_num_planes(ctx->pix_fmt);
> > >      
> > >      if (frame) {
> > > 
> > > +        x264_sei_t *sei = &x4->pic.extra_sei;
> > > +        sei->num_payloads = 0;
> > > +
> > > 
> > >          for (i = 0; i < x4->pic.img.i_plane; i++) {
> > >          
> > >              x4->pic.img.plane[i]    = frame->data[i];
> > >              x4->pic.img.i_stride[i] = frame->linesize[i];
> > > 
> > > @@ -439,6 +446,27 @@ static int X264_frame(AVCodecContext *ctx, AVPacket
> > > *pkt, const AVFrame *frame,>
> > > 
> > >                  }
> > >              
> > >              }
> > >          
> > >          }
> > > 
> > > +
> > > +        for (int j = 0; j < frame->nb_side_data; j++) {
> > > +            AVFrameSideData *side_data = frame->side_data[j];
> > > +            void *tmp;
> > > +            x264_sei_payload_t *sei_payload;
> > > +            if (side_data->type != AV_FRAME_DATA_SEI_UNREGISTERED)
> > > +                continue;
> > > +            tmp = av_fast_realloc(x4->sei_data, &x4->sei_data_size,
> > > (sei->num_payloads + 1) * sizeof(*sei_payload)); +            if (!tmp)
> > > {
> > > +                av_freep(&x4->pic.extra_sei.payloads);
> > > +                av_freep(&x4->pic.prop.quant_offsets);
> > > +                return AVERROR(ENOMEM);
> > > +            }
> > > +            x4->sei_data = tmp;
> > > +            sei->payloads = x4->sei_data;
> > > +            sei_payload = &sei->payloads[sei->num_payloads];
> > > +            sei_payload->payload = side_data->data;
> > > +            sei_payload->payload_size = side_data->size;
> > > +            sei_payload->payload_type =
> > > SEI_TYPE_USER_DATA_UNREGISTERED;
> > > +            sei->num_payloads++;
> > > +        }
> > > 
> > >      }
> > >      
> > >      do {
> > > 
> > > @@ -505,6 +533,8 @@ static av_cold int X264_close(AVCodecContext *avctx)
> > > 
> > >      x264_param_cleanup(&x4->params);
> > >  
> > >  #endif
> > > 
> > > +    av_freep(&x4->sei_data);
> > > +
> > > 
> > >      if (x4->enc) {
> > >      
> > >          x264_encoder_close(x4->enc);
> > >          x4->enc = NULL;
> > 
> > Ping on this patch.
> 
> Ping on this patch.
Ping on this patch.

Brad
Brad Hards Sept. 20, 2021, 11:06 p.m. UTC | #4
On Monday, 6 September 2021 10:17:14 AM AEST Brad Hards wrote:
> On Sunday, 22 August 2021 7:25:25 PM AEST Brad Hards wrote:
> > On Saturday, 14 August 2021 9:51:03 AM AEST Brad Hards wrote:
> > > On Friday, 6 August 2021 7:16:33 PM AEST Brad Hards wrote:
> > > > MISB ST 0604 and ST 2101 require user data unregistered SEI messages
> > > > (precision timestamps and sensor identifiers) to be included. That
> > > > currently isn't supported for libx264. This patch adds support
> > > > for user data unregistered SEI messages in accordance with ISO/IEC
> > > > 14496-10:2020(E) section D.1.7 (syntax) and D.2.7 (semantics).
> > > > 
> > > > This code is based on a similar change for libx265 (commit
> > > > 1f58503013720700a5adfd72c708e6275aefc165).
> > > > ---
> > > > 
> > > >  libavcodec/libx264.c | 30 ++++++++++++++++++++++++++++++
> > > >  1 file changed, 30 insertions(+)
> > > > 
> > > > diff --git a/libavcodec/libx264.c b/libavcodec/libx264.c
> > > > index 9afaf19547..e9bbe8d494 100644
> > > > --- a/libavcodec/libx264.c
> > > > +++ b/libavcodec/libx264.c
> > > > @@ -32,6 +32,7 @@
> > > > 
> > > >  #include "internal.h"
> > > >  #include "packet_internal.h"
> > > >  #include "atsc_a53.h"
> > > > 
> > > > +#include "sei.h"
> > > > 
> > > >  #if defined(_MSC_VER)
> > > >  #define X264_API_IMPORTS 1
> > > > 
> > > > @@ -114,6 +115,9 @@ typedef struct X264Context {
> > > > 
> > > >       * encounter a frame with ROI side data.
> > > >       */
> > > >      
> > > >      int roi_warned;
> > > > 
> > > > +
> > > > +    void *sei_data;
> > > > +    int sei_data_size;
> > > > 
> > > >  } X264Context;
> > > >  
> > > >  static void X264_log(void *p, int level, const char *fmt, va_list
> > > >  args)
> > > > 
> > > > @@ -317,6 +321,9 @@ static int X264_frame(AVCodecContext *ctx,
> > > > AVPacket
> > > > *pkt, const AVFrame *frame,>
> > > > 
> > > >      x4->pic.img.i_plane = avfmt2_num_planes(ctx->pix_fmt);
> > > >      
> > > >      if (frame) {
> > > > 
> > > > +        x264_sei_t *sei = &x4->pic.extra_sei;
> > > > +        sei->num_payloads = 0;
> > > > +
> > > > 
> > > >          for (i = 0; i < x4->pic.img.i_plane; i++) {
> > > >          
> > > >              x4->pic.img.plane[i]    = frame->data[i];
> > > >              x4->pic.img.i_stride[i] = frame->linesize[i];
> > > > 
> > > > @@ -439,6 +446,27 @@ static int X264_frame(AVCodecContext *ctx,
> > > > AVPacket
> > > > *pkt, const AVFrame *frame,>
> > > > 
> > > >                  }
> > > >              
> > > >              }
> > > >          
> > > >          }
> > > > 
> > > > +
> > > > +        for (int j = 0; j < frame->nb_side_data; j++) {
> > > > +            AVFrameSideData *side_data = frame->side_data[j];
> > > > +            void *tmp;
> > > > +            x264_sei_payload_t *sei_payload;
> > > > +            if (side_data->type != AV_FRAME_DATA_SEI_UNREGISTERED)
> > > > +                continue;
> > > > +            tmp = av_fast_realloc(x4->sei_data, &x4->sei_data_size,
> > > > (sei->num_payloads + 1) * sizeof(*sei_payload)); +            if
> > > > (!tmp)
> > > > {
> > > > +                av_freep(&x4->pic.extra_sei.payloads);
> > > > +                av_freep(&x4->pic.prop.quant_offsets);
> > > > +                return AVERROR(ENOMEM);
> > > > +            }
> > > > +            x4->sei_data = tmp;
> > > > +            sei->payloads = x4->sei_data;
> > > > +            sei_payload = &sei->payloads[sei->num_payloads];
> > > > +            sei_payload->payload = side_data->data;
> > > > +            sei_payload->payload_size = side_data->size;
> > > > +            sei_payload->payload_type =
> > > > SEI_TYPE_USER_DATA_UNREGISTERED;
> > > > +            sei->num_payloads++;
> > > > +        }
> > > > 
> > > >      }
> > > >      
> > > >      do {
> > > > 
> > > > @@ -505,6 +533,8 @@ static av_cold int X264_close(AVCodecContext
> > > > *avctx)
> > > > 
> > > >      x264_param_cleanup(&x4->params);
> > > >  
> > > >  #endif
> > > > 
> > > > +    av_freep(&x4->sei_data);
> > > > +
> > > > 
> > > >      if (x4->enc) {
> > > >      
> > > >          x264_encoder_close(x4->enc);
> > > >          x4->enc = NULL;
> > > 
> > > Ping on this patch.
> > 
> > Ping on this patch.
> 
> Ping on this patch.
> 
Ping on this patch.

Brad
Derek Buitenhuis Oct. 18, 2021, 12:08 p.m. UTC | #5
On 8/6/2021 10:16 AM, Brad Hards wrote:
> MISB ST 0604 and ST 2101 require user data unregistered SEI messages
> (precision timestamps and sensor identifiers) to be included. That
> currently isn't supported for libx264. This patch adds support
> for user data unregistered SEI messages in accordance with ISO/IEC
> 14496-10:2020(E) section D.1.7 (syntax) and D.2.7 (semantics).
> 
> This code is based on a similar change for libx265 (commit
> 1f58503013720700a5adfd72c708e6275aefc165).
> ---
>  libavcodec/libx264.c | 30 ++++++++++++++++++++++++++++++
>  1 file changed, 30 insertions(+)

LGTM.

Will apply.

- Derek
diff mbox series

Patch

diff --git a/libavcodec/libx264.c b/libavcodec/libx264.c
index 9afaf19547..e9bbe8d494 100644
--- a/libavcodec/libx264.c
+++ b/libavcodec/libx264.c
@@ -32,6 +32,7 @@ 
 #include "internal.h"
 #include "packet_internal.h"
 #include "atsc_a53.h"
+#include "sei.h"
 
 #if defined(_MSC_VER)
 #define X264_API_IMPORTS 1
@@ -114,6 +115,9 @@  typedef struct X264Context {
      * encounter a frame with ROI side data.
      */
     int roi_warned;
+
+    void *sei_data;
+    int sei_data_size;
 } X264Context;
 
 static void X264_log(void *p, int level, const char *fmt, va_list args)
@@ -317,6 +321,9 @@  static int X264_frame(AVCodecContext *ctx, AVPacket *pkt, const AVFrame *frame,
     x4->pic.img.i_plane = avfmt2_num_planes(ctx->pix_fmt);
 
     if (frame) {
+        x264_sei_t *sei = &x4->pic.extra_sei;
+        sei->num_payloads = 0;
+
         for (i = 0; i < x4->pic.img.i_plane; i++) {
             x4->pic.img.plane[i]    = frame->data[i];
             x4->pic.img.i_stride[i] = frame->linesize[i];
@@ -439,6 +446,27 @@  static int X264_frame(AVCodecContext *ctx, AVPacket *pkt, const AVFrame *frame,
                 }
             }
         }
+
+        for (int j = 0; j < frame->nb_side_data; j++) {
+            AVFrameSideData *side_data = frame->side_data[j];
+            void *tmp;
+            x264_sei_payload_t *sei_payload;
+            if (side_data->type != AV_FRAME_DATA_SEI_UNREGISTERED)
+                continue;
+            tmp = av_fast_realloc(x4->sei_data, &x4->sei_data_size, (sei->num_payloads + 1) * sizeof(*sei_payload));
+            if (!tmp) {
+                av_freep(&x4->pic.extra_sei.payloads);
+                av_freep(&x4->pic.prop.quant_offsets);
+                return AVERROR(ENOMEM);
+            }
+            x4->sei_data = tmp;
+            sei->payloads = x4->sei_data;
+            sei_payload = &sei->payloads[sei->num_payloads];
+            sei_payload->payload = side_data->data;
+            sei_payload->payload_size = side_data->size;
+            sei_payload->payload_type = SEI_TYPE_USER_DATA_UNREGISTERED;
+            sei->num_payloads++;
+        }
     }
 
     do {
@@ -505,6 +533,8 @@  static av_cold int X264_close(AVCodecContext *avctx)
     x264_param_cleanup(&x4->params);
 #endif
 
+    av_freep(&x4->sei_data);
+
     if (x4->enc) {
         x264_encoder_close(x4->enc);
         x4->enc = NULL;