Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] [PATCH] avcodec/vaapi_encode_h26x: passthrough A53 CC data as H264/HEVC SEI
@ 2023-01-02 19:32 Aman Karmani
  2023-01-05  8:46 ` Xiang, Haihao
  2023-01-06 17:15 ` [FFmpeg-devel] [PATCH v2] " Aman Karmani
  0 siblings, 2 replies; 7+ messages in thread
From: Aman Karmani @ 2023-01-02 19:32 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Aman Karmani

From: Aman Karmani <aman@tmm1.net>

Signed-off-by: Aman Karmani <aman@tmm1.net>
---
    avcodec/vaapi_encode_h26x: passthrough A53 CC data as H264/HEVC SEI

Published-As: https://github.com/ffstaging/FFmpeg/releases/tag/pr-ffstaging-46%2Ftmm1%2Fvaapi-a53cc-v1
Fetch-It-Via: git fetch https://github.com/ffstaging/FFmpeg pr-ffstaging-46/tmm1/vaapi-a53cc-v1
Pull-Request: https://github.com/ffstaging/FFmpeg/pull/46

 libavcodec/vaapi_encode_h264.c | 27 ++++++++++++++++++++++++++-
 libavcodec/vaapi_encode_h265.c | 27 ++++++++++++++++++++++++++-
 2 files changed, 52 insertions(+), 2 deletions(-)

diff --git a/libavcodec/vaapi_encode_h264.c b/libavcodec/vaapi_encode_h264.c
index b1b503b2a6..d22b38ab38 100644
--- a/libavcodec/vaapi_encode_h264.c
+++ b/libavcodec/vaapi_encode_h264.c
@@ -26,6 +26,7 @@
 #include "libavutil/internal.h"
 #include "libavutil/opt.h"
 
+#include "atsc_a53.h"
 #include "avcodec.h"
 #include "cbs.h"
 #include "cbs_h264.h"
@@ -40,6 +41,7 @@ enum {
     SEI_TIMING         = 0x01,
     SEI_IDENTIFIER     = 0x02,
     SEI_RECOVERY_POINT = 0x04,
+    SEI_A53_CC         = 0x08,
 };
 
 // Random (version 4) ISO 11578 UUID.
@@ -98,6 +100,8 @@ typedef struct VAAPIEncodeH264Context {
     H264RawSEIRecoveryPoint        sei_recovery_point;
     SEIRawUserDataUnregistered     sei_identifier;
     char                          *sei_identifier_string;
+    SEIRawUserDataRegistered       sei_a53cc;
+    void                          *sei_a53cc_data;
 
     int aud_needed;
     int sei_needed;
@@ -248,6 +252,13 @@ static int vaapi_encode_h264_write_extra_header(AVCodecContext *avctx,
             if (err < 0)
                 goto fail;
         }
+        if (priv->sei_needed & SEI_A53_CC) {
+            err = ff_cbs_sei_add_message(priv->cbc, au, 1,
+                                         SEI_TYPE_USER_DATA_REGISTERED_ITU_T_T35,
+                                         &priv->sei_a53cc, NULL);
+            if (err < 0)
+                goto fail;
+        }
 
         priv->sei_needed = 0;
 
@@ -607,7 +618,8 @@ static int vaapi_encode_h264_init_picture_params(AVCodecContext *avctx,
     VAAPIEncodePicture              *prev = pic->prev;
     VAAPIEncodeH264Picture         *hprev = prev ? prev->priv_data : NULL;
     VAEncPictureParameterBufferH264 *vpic = pic->codec_picture_params;
-    int i;
+    int i, err;
+    size_t sei_a53cc_len;
 
     if (pic->type == PICTURE_TYPE_IDR) {
         av_assert0(pic->display_order == pic->encode_order);
@@ -681,6 +693,18 @@ static int vaapi_encode_h264_init_picture_params(AVCodecContext *avctx,
         priv->sei_needed |= SEI_RECOVERY_POINT;
     }
 
+    av_freep(&priv->sei_a53cc_data);
+    err = ff_alloc_a53_sei(pic->input_image, 0, &priv->sei_a53cc_data, &sei_a53cc_len);
+    if (err < 0)
+        return err;
+    if (priv->sei_a53cc_data != NULL) {
+        priv->sei_a53cc.itu_t_t35_country_code = 181;
+        priv->sei_a53cc.data = (uint8_t *)priv->sei_a53cc_data + 1;
+        priv->sei_a53cc.data_length = sei_a53cc_len - 1;
+
+        priv->sei_needed |= SEI_A53_CC;
+    }
+
     vpic->CurrPic = (VAPictureH264) {
         .picture_id          = pic->recon_surface,
         .frame_idx           = hpic->frame_num,
@@ -1226,6 +1250,7 @@ static av_cold int vaapi_encode_h264_close(AVCodecContext *avctx)
     ff_cbs_fragment_free(&priv->current_access_unit);
     ff_cbs_close(&priv->cbc);
     av_freep(&priv->sei_identifier_string);
+    av_freep(&priv->sei_a53cc_data);
 
     return ff_vaapi_encode_close(avctx);
 }
diff --git a/libavcodec/vaapi_encode_h265.c b/libavcodec/vaapi_encode_h265.c
index 94b56c6578..3611bd6147 100644
--- a/libavcodec/vaapi_encode_h265.c
+++ b/libavcodec/vaapi_encode_h265.c
@@ -27,6 +27,7 @@
 #include "libavutil/opt.h"
 #include "libavutil/mastering_display_metadata.h"
 
+#include "atsc_a53.h"
 #include "avcodec.h"
 #include "cbs.h"
 #include "cbs_h265.h"
@@ -40,6 +41,7 @@
 enum {
     SEI_MASTERING_DISPLAY       = 0x08,
     SEI_CONTENT_LIGHT_LEVEL     = 0x10,
+    SEI_A53_CC                  = 0x20,
 };
 
 typedef struct VAAPIEncodeH265Picture {
@@ -84,6 +86,8 @@ typedef struct VAAPIEncodeH265Context {
 
     SEIRawMasteringDisplayColourVolume sei_mastering_display;
     SEIRawContentLightLevelInfo        sei_content_light_level;
+    SEIRawUserDataRegistered           sei_a53cc;
+    void                              *sei_a53cc_data;
 
     CodedBitstreamContext *cbc;
     CodedBitstreamFragment current_access_unit;
@@ -226,6 +230,13 @@ static int vaapi_encode_h265_write_extra_header(AVCodecContext *avctx,
             if (err < 0)
                 goto fail;
         }
+        if (priv->sei_needed & SEI_A53_CC) {
+            err = ff_cbs_sei_add_message(priv->cbc, au, 1,
+                                         SEI_TYPE_USER_DATA_REGISTERED_ITU_T_T35,
+                                         &priv->sei_a53cc, NULL);
+            if (err < 0)
+                goto fail;
+        }
 
         priv->sei_needed = 0;
 
@@ -759,7 +770,8 @@ static int vaapi_encode_h265_init_picture_params(AVCodecContext *avctx,
     VAAPIEncodePicture              *prev = pic->prev;
     VAAPIEncodeH265Picture         *hprev = prev ? prev->priv_data : NULL;
     VAEncPictureParameterBufferHEVC *vpic = pic->codec_picture_params;
-    int i;
+    int i, err;
+    size_t sei_a53cc_len;
 
     if (pic->type == PICTURE_TYPE_IDR) {
         av_assert0(pic->display_order == pic->encode_order);
@@ -888,6 +900,18 @@ static int vaapi_encode_h265_init_picture_params(AVCodecContext *avctx,
         }
     }
 
+    av_freep(&priv->sei_a53cc_data);
+    err = ff_alloc_a53_sei(pic->input_image, 0, &priv->sei_a53cc_data, &sei_a53cc_len);
+    if (err < 0)
+        return err;
+    if (priv->sei_a53cc_data != NULL) {
+        priv->sei_a53cc.itu_t_t35_country_code = 181;
+        priv->sei_a53cc.data = (uint8_t *)priv->sei_a53cc_data + 1;
+        priv->sei_a53cc.data_length = sei_a53cc_len - 1;
+
+        priv->sei_needed |= SEI_A53_CC;
+    }
+
     vpic->decoded_curr_pic = (VAPictureHEVC) {
         .picture_id    = pic->recon_surface,
         .pic_order_cnt = hpic->pic_order_cnt,
@@ -1355,6 +1379,7 @@ static av_cold int vaapi_encode_h265_close(AVCodecContext *avctx)
 
     ff_cbs_fragment_free(&priv->current_access_unit);
     ff_cbs_close(&priv->cbc);
+    av_freep(&priv->sei_a53cc_data);
 
     return ff_vaapi_encode_close(avctx);
 }

base-commit: 3bcec58535d395945a390bdc7af4048a7abc60eb
-- 
ffmpeg-codebot
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [FFmpeg-devel] [PATCH] avcodec/vaapi_encode_h26x: passthrough A53 CC data as H264/HEVC SEI
  2023-01-02 19:32 [FFmpeg-devel] [PATCH] avcodec/vaapi_encode_h26x: passthrough A53 CC data as H264/HEVC SEI Aman Karmani
@ 2023-01-05  8:46 ` Xiang, Haihao
  2023-01-06 17:15 ` [FFmpeg-devel] [PATCH v2] " Aman Karmani
  1 sibling, 0 replies; 7+ messages in thread
From: Xiang, Haihao @ 2023-01-05  8:46 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: aman

On Ma, 2023-01-02 at 19:32 +0000, Aman Karmani wrote:
> From: Aman Karmani <aman@tmm1.net>
> 
> Signed-off-by: Aman Karmani <aman@tmm1.net>
> ---
>     avcodec/vaapi_encode_h26x: passthrough A53 CC data as H264/HEVC SEI
> 
> Published-As: 
> https://github.com/ffstaging/FFmpeg/releases/tag/pr-ffstaging-46%2Ftmm1%2Fvaapi-a53cc-v1
> Fetch-It-Via: git fetch https://github.com/ffstaging/FFmpeg pr-ffstaging-
> 46/tmm1/vaapi-a53cc-v1
> Pull-Request: https://github.com/ffstaging/FFmpeg/pull/46
> 
>  libavcodec/vaapi_encode_h264.c | 27 ++++++++++++++++++++++++++-
>  libavcodec/vaapi_encode_h265.c | 27 ++++++++++++++++++++++++++-
>  2 files changed, 52 insertions(+), 2 deletions(-)
> 
> diff --git a/libavcodec/vaapi_encode_h264.c b/libavcodec/vaapi_encode_h264.c
> index b1b503b2a6..d22b38ab38 100644
> --- a/libavcodec/vaapi_encode_h264.c
> +++ b/libavcodec/vaapi_encode_h264.c
> @@ -26,6 +26,7 @@
>  #include "libavutil/internal.h"
>  #include "libavutil/opt.h"
>  
> +#include "atsc_a53.h"
>  #include "avcodec.h"
>  #include "cbs.h"
>  #include "cbs_h264.h"
> @@ -40,6 +41,7 @@ enum {
>      SEI_TIMING         = 0x01,
>      SEI_IDENTIFIER     = 0x02,
>      SEI_RECOVERY_POINT = 0x04,
> +    SEI_A53_CC         = 0x08,
>  };
>  
>  // Random (version 4) ISO 11578 UUID.
> @@ -98,6 +100,8 @@ typedef struct VAAPIEncodeH264Context {
>      H264RawSEIRecoveryPoint        sei_recovery_point;
>      SEIRawUserDataUnregistered     sei_identifier;
>      char                          *sei_identifier_string;
> +    SEIRawUserDataRegistered       sei_a53cc;
> +    void                          *sei_a53cc_data;
>  
>      int aud_needed;
>      int sei_needed;
> @@ -248,6 +252,13 @@ static int
> vaapi_encode_h264_write_extra_header(AVCodecContext *avctx,
>              if (err < 0)
>                  goto fail;
>          }
> +        if (priv->sei_needed & SEI_A53_CC) {
> +            err = ff_cbs_sei_add_message(priv->cbc, au, 1,
> +                                         SEI_TYPE_USER_DATA_REGISTERED_ITU_T_
> T35,
> +                                         &priv->sei_a53cc, NULL);
> +            if (err < 0)
> +                goto fail;
> +        }
>  
>          priv->sei_needed = 0;
>  
> @@ -607,7 +618,8 @@ static int
> vaapi_encode_h264_init_picture_params(AVCodecContext *avctx,
>      VAAPIEncodePicture              *prev = pic->prev;
>      VAAPIEncodeH264Picture         *hprev = prev ? prev->priv_data : NULL;
>      VAEncPictureParameterBufferH264 *vpic = pic->codec_picture_params;
> -    int i;
> +    int i, err;
> +    size_t sei_a53cc_len;
>  
>      if (pic->type == PICTURE_TYPE_IDR) {
>          av_assert0(pic->display_order == pic->encode_order);
> @@ -681,6 +693,18 @@ static int
> vaapi_encode_h264_init_picture_params(AVCodecContext *avctx,
>          priv->sei_needed |= SEI_RECOVERY_POINT;
>      }
>  
> +    av_freep(&priv->sei_a53cc_data);
> +    err = ff_alloc_a53_sei(pic->input_image, 0, &priv->sei_a53cc_data,
> &sei_a53cc_len);
> +    if (err < 0)
> +        return err;
> +    if (priv->sei_a53cc_data != NULL) {
> +        priv->sei_a53cc.itu_t_t35_country_code = 181;
> +        priv->sei_a53cc.data = (uint8_t *)priv->sei_a53cc_data + 1;
> +        priv->sei_a53cc.data_length = sei_a53cc_len - 1;
> +
> +        priv->sei_needed |= SEI_A53_CC;
> +    }
> +
>      vpic->CurrPic = (VAPictureH264) {
>          .picture_id          = pic->recon_surface,
>          .frame_idx           = hpic->frame_num,
> @@ -1226,6 +1250,7 @@ static av_cold int
> vaapi_encode_h264_close(AVCodecContext *avctx)
>      ff_cbs_fragment_free(&priv->current_access_unit);
>      ff_cbs_close(&priv->cbc);
>      av_freep(&priv->sei_identifier_string);
> +    av_freep(&priv->sei_a53cc_data);
>  
>      return ff_vaapi_encode_close(avctx);
>  }
> diff --git a/libavcodec/vaapi_encode_h265.c b/libavcodec/vaapi_encode_h265.c
> index 94b56c6578..3611bd6147 100644
> --- a/libavcodec/vaapi_encode_h265.c
> +++ b/libavcodec/vaapi_encode_h265.c
> @@ -27,6 +27,7 @@
>  #include "libavutil/opt.h"
>  #include "libavutil/mastering_display_metadata.h"
>  
> +#include "atsc_a53.h"
>  #include "avcodec.h"
>  #include "cbs.h"
>  #include "cbs_h265.h"
> @@ -40,6 +41,7 @@
>  enum {
>      SEI_MASTERING_DISPLAY       = 0x08,
>      SEI_CONTENT_LIGHT_LEVEL     = 0x10,
> +    SEI_A53_CC                  = 0x20,
>  };
>  
>  typedef struct VAAPIEncodeH265Picture {
> @@ -84,6 +86,8 @@ typedef struct VAAPIEncodeH265Context {
>  
>      SEIRawMasteringDisplayColourVolume sei_mastering_display;
>      SEIRawContentLightLevelInfo        sei_content_light_level;
> +    SEIRawUserDataRegistered           sei_a53cc;
> +    void                              *sei_a53cc_data;
>  
>      CodedBitstreamContext *cbc;
>      CodedBitstreamFragment current_access_unit;
> @@ -226,6 +230,13 @@ static int
> vaapi_encode_h265_write_extra_header(AVCodecContext *avctx,
>              if (err < 0)
>                  goto fail;
>          }
> +        if (priv->sei_needed & SEI_A53_CC) {
> +            err = ff_cbs_sei_add_message(priv->cbc, au, 1,
> +                                         SEI_TYPE_USER_DATA_REGISTERED_ITU_T_
> T35,
> +                                         &priv->sei_a53cc, NULL);
> +            if (err < 0)
> +                goto fail;
> +        }
>  
>          priv->sei_needed = 0;
>  
> @@ -759,7 +770,8 @@ static int
> vaapi_encode_h265_init_picture_params(AVCodecContext *avctx,
>      VAAPIEncodePicture              *prev = pic->prev;
>      VAAPIEncodeH265Picture         *hprev = prev ? prev->priv_data : NULL;
>      VAEncPictureParameterBufferHEVC *vpic = pic->codec_picture_params;
> -    int i;
> +    int i, err;
> +    size_t sei_a53cc_len;
>  
>      if (pic->type == PICTURE_TYPE_IDR) {
>          av_assert0(pic->display_order == pic->encode_order);
> @@ -888,6 +900,18 @@ static int
> vaapi_encode_h265_init_picture_params(AVCodecContext *avctx,
>          }
>      }
>  
> +    av_freep(&priv->sei_a53cc_data);
> +    err = ff_alloc_a53_sei(pic->input_image, 0, &priv->sei_a53cc_data,
> &sei_a53cc_len);
> +    if (err < 0)
> +        return err;
> +    if (priv->sei_a53cc_data != NULL) {
> +        priv->sei_a53cc.itu_t_t35_country_code = 181;
> +        priv->sei_a53cc.data = (uint8_t *)priv->sei_a53cc_data + 1;
> +        priv->sei_a53cc.data_length = sei_a53cc_len - 1;
> +
> +        priv->sei_needed |= SEI_A53_CC;
> +    }
> +
>      vpic->decoded_curr_pic = (VAPictureHEVC) {
>          .picture_id    = pic->recon_surface,
>          .pic_order_cnt = hpic->pic_order_cnt,
> @@ -1355,6 +1379,7 @@ static av_cold int
> vaapi_encode_h265_close(AVCodecContext *avctx)
>  
>      ff_cbs_fragment_free(&priv->current_access_unit);
>      ff_cbs_close(&priv->cbc);
> +    av_freep(&priv->sei_a53cc_data);
>  
>      return ff_vaapi_encode_close(avctx);
>  }

May we use sei option to control whether a53 CC data is inserted into the coded
stream ? The default value of sei can be changed to SEI_IDENTIFIER | SEI_TIMING
| SEI_RECOVERY_POINT | SEI_A53_CC for h264 and SEI_MASTERING_DISPLAY |
SEI_CONTENT_LIGHT_LEVEL | SEI_A53_CC for h265. 

Thanks
Haihao



> 
> base-commit: 3bcec58535d395945a390bdc7af4048a7abc60eb
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [FFmpeg-devel] [PATCH v2] avcodec/vaapi_encode_h26x: passthrough A53 CC data as H264/HEVC SEI
  2023-01-02 19:32 [FFmpeg-devel] [PATCH] avcodec/vaapi_encode_h26x: passthrough A53 CC data as H264/HEVC SEI Aman Karmani
  2023-01-05  8:46 ` Xiang, Haihao
@ 2023-01-06 17:15 ` Aman Karmani
  2023-01-06 17:41   ` [FFmpeg-devel] [PATCH v3] " Aman Karmani
  1 sibling, 1 reply; 7+ messages in thread
From: Aman Karmani @ 2023-01-06 17:15 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Aman Karmani, Xiang, Haihao

From: Aman Karmani <aman@tmm1.net>

Signed-off-by: Aman Karmani <aman@tmm1.net>
---
    avcodec/vaapi_encode_h26x: passthrough A53 CC data as H264/HEVC SEI
    
    v2: control via sei parameter

Published-As: https://github.com/ffstaging/FFmpeg/releases/tag/pr-ffstaging-46%2Ftmm1%2Fvaapi-a53cc-v2
Fetch-It-Via: git fetch https://github.com/ffstaging/FFmpeg pr-ffstaging-46/tmm1/vaapi-a53cc-v2
Pull-Request: https://github.com/ffstaging/FFmpeg/pull/46

Range-diff vs v1:

 1:  a8eb71f061 ! 1:  9a2fee07a9 avcodec/vaapi_encode_h26x: passthrough A53 CC data as H264/HEVC SEI
     @@ libavcodec/vaapi_encode_h264.c: static int vaapi_encode_h264_write_extra_header(
       
               priv->sei_needed = 0;
       
     -@@ libavcodec/vaapi_encode_h264.c: static int vaapi_encode_h264_init_picture_params(AVCodecContext *avctx,
     -     VAAPIEncodePicture              *prev = pic->prev;
     -     VAAPIEncodeH264Picture         *hprev = prev ? prev->priv_data : NULL;
     -     VAEncPictureParameterBufferH264 *vpic = pic->codec_picture_params;
     --    int i;
     -+    int i, err;
     -+    size_t sei_a53cc_len;
     - 
     -     if (pic->type == PICTURE_TYPE_IDR) {
     -         av_assert0(pic->display_order == pic->encode_order);
      @@ libavcodec/vaapi_encode_h264.c: static int vaapi_encode_h264_init_picture_params(AVCodecContext *avctx,
               priv->sei_needed |= SEI_RECOVERY_POINT;
           }
       
     -+    av_freep(&priv->sei_a53cc_data);
     -+    err = ff_alloc_a53_sei(pic->input_image, 0, &priv->sei_a53cc_data, &sei_a53cc_len);
     -+    if (err < 0)
     -+        return err;
     -+    if (priv->sei_a53cc_data != NULL) {
     -+        priv->sei_a53cc.itu_t_t35_country_code = 181;
     -+        priv->sei_a53cc.data = (uint8_t *)priv->sei_a53cc_data + 1;
     -+        priv->sei_a53cc.data_length = sei_a53cc_len - 1;
     ++    if (priv->sei & SEI_A53_CC) {
     ++        int err;
     ++        size_t sei_a53cc_len;
     ++        av_freep(&priv->sei_a53cc_data);
     ++        err = ff_alloc_a53_sei(pic->input_image, 0, &priv->sei_a53cc_data, &sei_a53cc_len);
     ++        if (err < 0)
     ++            return err;
     ++        if (priv->sei_a53cc_data != NULL) {
     ++            priv->sei_a53cc.itu_t_t35_country_code = 181;
     ++            priv->sei_a53cc.data = (uint8_t *)priv->sei_a53cc_data + 1;
     ++            priv->sei_a53cc.data_length = sei_a53cc_len - 1;
      +
     -+        priv->sei_needed |= SEI_A53_CC;
     ++            priv->sei_needed |= SEI_A53_CC;
     ++        }
      +    }
      +
           vpic->CurrPic = (VAPictureH264) {
     @@ libavcodec/vaapi_encode_h264.c: static av_cold int vaapi_encode_h264_close(AVCod
       
           return ff_vaapi_encode_close(avctx);
       }
     +@@ libavcodec/vaapi_encode_h264.c: static const AVOption vaapi_encode_h264_options[] = {
     + 
     +     { "sei", "Set SEI to include",
     +       OFFSET(sei), AV_OPT_TYPE_FLAGS,
     +-      { .i64 = SEI_IDENTIFIER | SEI_TIMING | SEI_RECOVERY_POINT },
     ++      { .i64 = SEI_IDENTIFIER | SEI_TIMING | SEI_RECOVERY_POINT | SEI_A53_CC },
     +       0, INT_MAX, FLAGS, "sei" },
     +     { "identifier", "Include encoder version identifier",
     +       0, AV_OPT_TYPE_CONST, { .i64 = SEI_IDENTIFIER },
     +@@ libavcodec/vaapi_encode_h264.c: static const AVOption vaapi_encode_h264_options[] = {
     +     { "recovery_point", "Include recovery points where appropriate",
     +       0, AV_OPT_TYPE_CONST, { .i64 = SEI_RECOVERY_POINT },
     +       INT_MIN, INT_MAX, FLAGS, "sei" },
     ++    { "a53_cc", "Include A/53 caption data"
     ++      0, AV_OPT_TYPE_CONST, { .i64 = SEI_A53_CC },
     ++      INT_MIN, INT_MAX, FLAGS, "sei" },
     + 
     +     { "profile", "Set profile (profile_idc and constraint_set*_flag)",
     +       OFFSET(profile), AV_OPT_TYPE_INT,
      
       ## libavcodec/vaapi_encode_h265.c ##
      @@
     @@ libavcodec/vaapi_encode_h265.c: static int vaapi_encode_h265_write_extra_header(
       
               priv->sei_needed = 0;
       
     -@@ libavcodec/vaapi_encode_h265.c: static int vaapi_encode_h265_init_picture_params(AVCodecContext *avctx,
     -     VAAPIEncodePicture              *prev = pic->prev;
     -     VAAPIEncodeH265Picture         *hprev = prev ? prev->priv_data : NULL;
     -     VAEncPictureParameterBufferHEVC *vpic = pic->codec_picture_params;
     --    int i;
     -+    int i, err;
     -+    size_t sei_a53cc_len;
     - 
     -     if (pic->type == PICTURE_TYPE_IDR) {
     -         av_assert0(pic->display_order == pic->encode_order);
      @@ libavcodec/vaapi_encode_h265.c: static int vaapi_encode_h265_init_picture_params(AVCodecContext *avctx,
               }
           }
       
     -+    av_freep(&priv->sei_a53cc_data);
     -+    err = ff_alloc_a53_sei(pic->input_image, 0, &priv->sei_a53cc_data, &sei_a53cc_len);
     -+    if (err < 0)
     -+        return err;
     -+    if (priv->sei_a53cc_data != NULL) {
     -+        priv->sei_a53cc.itu_t_t35_country_code = 181;
     -+        priv->sei_a53cc.data = (uint8_t *)priv->sei_a53cc_data + 1;
     -+        priv->sei_a53cc.data_length = sei_a53cc_len - 1;
     ++    if (priv->sei & SEI_A53_CC) {
     ++        int err;
     ++        size_t sei_a53cc_len;
     ++        av_freep(&priv->sei_a53cc_data);
     ++        err = ff_alloc_a53_sei(pic->input_image, 0, &priv->sei_a53cc_data, &sei_a53cc_len);
     ++        if (err < 0)
     ++            return err;
     ++        if (priv->sei_a53cc_data != NULL) {
     ++            priv->sei_a53cc.itu_t_t35_country_code = 181;
     ++            priv->sei_a53cc.data = (uint8_t *)priv->sei_a53cc_data + 1;
     ++            priv->sei_a53cc.data_length = sei_a53cc_len - 1;
      +
     -+        priv->sei_needed |= SEI_A53_CC;
     ++            priv->sei_needed |= SEI_A53_CC;
     ++        }
      +    }
      +
           vpic->decoded_curr_pic = (VAPictureHEVC) {
     @@ libavcodec/vaapi_encode_h265.c: static av_cold int vaapi_encode_h265_close(AVCod
       
           return ff_vaapi_encode_close(avctx);
       }
     +@@ libavcodec/vaapi_encode_h265.c: static const AVOption vaapi_encode_h265_options[] = {
     + 
     +     { "sei", "Set SEI to include",
     +       OFFSET(sei), AV_OPT_TYPE_FLAGS,
     +-      { .i64 = SEI_MASTERING_DISPLAY | SEI_CONTENT_LIGHT_LEVEL },
     ++      { .i64 = SEI_MASTERING_DISPLAY | SEI_CONTENT_LIGHT_LEVEL | SEI_A53_CC },
     +       0, INT_MAX, FLAGS, "sei" },
     +     { "hdr",
     +       "Include HDR metadata for mastering display colour volume "
     +@@ libavcodec/vaapi_encode_h265.c: static const AVOption vaapi_encode_h265_options[] = {
     +       0, AV_OPT_TYPE_CONST,
     +       { .i64 = SEI_MASTERING_DISPLAY | SEI_CONTENT_LIGHT_LEVEL },
     +       INT_MIN, INT_MAX, FLAGS, "sei" },
     ++    { "a53_cc",
     ++      "Include A/53 caption data"
     ++      0, AV_OPT_TYPE_CONST,
     ++      { .i64 = SEI_A53_CC },
     ++      INT_MIN, INT_MAX, FLAGS, "sei" },
     + 
     +     { "tiles", "Tile columns x rows",
     +       OFFSET(common.tile_cols), AV_OPT_TYPE_IMAGE_SIZE,


 libavcodec/vaapi_encode_h264.c | 33 +++++++++++++++++++++++++++++++-
 libavcodec/vaapi_encode_h265.c | 35 +++++++++++++++++++++++++++++++++-
 2 files changed, 66 insertions(+), 2 deletions(-)

diff --git a/libavcodec/vaapi_encode_h264.c b/libavcodec/vaapi_encode_h264.c
index b1b503b2a6..06b0004a2c 100644
--- a/libavcodec/vaapi_encode_h264.c
+++ b/libavcodec/vaapi_encode_h264.c
@@ -26,6 +26,7 @@
 #include "libavutil/internal.h"
 #include "libavutil/opt.h"
 
+#include "atsc_a53.h"
 #include "avcodec.h"
 #include "cbs.h"
 #include "cbs_h264.h"
@@ -40,6 +41,7 @@ enum {
     SEI_TIMING         = 0x01,
     SEI_IDENTIFIER     = 0x02,
     SEI_RECOVERY_POINT = 0x04,
+    SEI_A53_CC         = 0x08,
 };
 
 // Random (version 4) ISO 11578 UUID.
@@ -98,6 +100,8 @@ typedef struct VAAPIEncodeH264Context {
     H264RawSEIRecoveryPoint        sei_recovery_point;
     SEIRawUserDataUnregistered     sei_identifier;
     char                          *sei_identifier_string;
+    SEIRawUserDataRegistered       sei_a53cc;
+    void                          *sei_a53cc_data;
 
     int aud_needed;
     int sei_needed;
@@ -248,6 +252,13 @@ static int vaapi_encode_h264_write_extra_header(AVCodecContext *avctx,
             if (err < 0)
                 goto fail;
         }
+        if (priv->sei_needed & SEI_A53_CC) {
+            err = ff_cbs_sei_add_message(priv->cbc, au, 1,
+                                         SEI_TYPE_USER_DATA_REGISTERED_ITU_T_T35,
+                                         &priv->sei_a53cc, NULL);
+            if (err < 0)
+                goto fail;
+        }
 
         priv->sei_needed = 0;
 
@@ -681,6 +692,22 @@ static int vaapi_encode_h264_init_picture_params(AVCodecContext *avctx,
         priv->sei_needed |= SEI_RECOVERY_POINT;
     }
 
+    if (priv->sei & SEI_A53_CC) {
+        int err;
+        size_t sei_a53cc_len;
+        av_freep(&priv->sei_a53cc_data);
+        err = ff_alloc_a53_sei(pic->input_image, 0, &priv->sei_a53cc_data, &sei_a53cc_len);
+        if (err < 0)
+            return err;
+        if (priv->sei_a53cc_data != NULL) {
+            priv->sei_a53cc.itu_t_t35_country_code = 181;
+            priv->sei_a53cc.data = (uint8_t *)priv->sei_a53cc_data + 1;
+            priv->sei_a53cc.data_length = sei_a53cc_len - 1;
+
+            priv->sei_needed |= SEI_A53_CC;
+        }
+    }
+
     vpic->CurrPic = (VAPictureH264) {
         .picture_id          = pic->recon_surface,
         .frame_idx           = hpic->frame_num,
@@ -1226,6 +1253,7 @@ static av_cold int vaapi_encode_h264_close(AVCodecContext *avctx)
     ff_cbs_fragment_free(&priv->current_access_unit);
     ff_cbs_close(&priv->cbc);
     av_freep(&priv->sei_identifier_string);
+    av_freep(&priv->sei_a53cc_data);
 
     return ff_vaapi_encode_close(avctx);
 }
@@ -1252,7 +1280,7 @@ static const AVOption vaapi_encode_h264_options[] = {
 
     { "sei", "Set SEI to include",
       OFFSET(sei), AV_OPT_TYPE_FLAGS,
-      { .i64 = SEI_IDENTIFIER | SEI_TIMING | SEI_RECOVERY_POINT },
+      { .i64 = SEI_IDENTIFIER | SEI_TIMING | SEI_RECOVERY_POINT | SEI_A53_CC },
       0, INT_MAX, FLAGS, "sei" },
     { "identifier", "Include encoder version identifier",
       0, AV_OPT_TYPE_CONST, { .i64 = SEI_IDENTIFIER },
@@ -1263,6 +1291,9 @@ static const AVOption vaapi_encode_h264_options[] = {
     { "recovery_point", "Include recovery points where appropriate",
       0, AV_OPT_TYPE_CONST, { .i64 = SEI_RECOVERY_POINT },
       INT_MIN, INT_MAX, FLAGS, "sei" },
+    { "a53_cc", "Include A/53 caption data"
+      0, AV_OPT_TYPE_CONST, { .i64 = SEI_A53_CC },
+      INT_MIN, INT_MAX, FLAGS, "sei" },
 
     { "profile", "Set profile (profile_idc and constraint_set*_flag)",
       OFFSET(profile), AV_OPT_TYPE_INT,
diff --git a/libavcodec/vaapi_encode_h265.c b/libavcodec/vaapi_encode_h265.c
index 94b56c6578..991d8a3aba 100644
--- a/libavcodec/vaapi_encode_h265.c
+++ b/libavcodec/vaapi_encode_h265.c
@@ -27,6 +27,7 @@
 #include "libavutil/opt.h"
 #include "libavutil/mastering_display_metadata.h"
 
+#include "atsc_a53.h"
 #include "avcodec.h"
 #include "cbs.h"
 #include "cbs_h265.h"
@@ -40,6 +41,7 @@
 enum {
     SEI_MASTERING_DISPLAY       = 0x08,
     SEI_CONTENT_LIGHT_LEVEL     = 0x10,
+    SEI_A53_CC                  = 0x20,
 };
 
 typedef struct VAAPIEncodeH265Picture {
@@ -84,6 +86,8 @@ typedef struct VAAPIEncodeH265Context {
 
     SEIRawMasteringDisplayColourVolume sei_mastering_display;
     SEIRawContentLightLevelInfo        sei_content_light_level;
+    SEIRawUserDataRegistered           sei_a53cc;
+    void                              *sei_a53cc_data;
 
     CodedBitstreamContext *cbc;
     CodedBitstreamFragment current_access_unit;
@@ -226,6 +230,13 @@ static int vaapi_encode_h265_write_extra_header(AVCodecContext *avctx,
             if (err < 0)
                 goto fail;
         }
+        if (priv->sei_needed & SEI_A53_CC) {
+            err = ff_cbs_sei_add_message(priv->cbc, au, 1,
+                                         SEI_TYPE_USER_DATA_REGISTERED_ITU_T_T35,
+                                         &priv->sei_a53cc, NULL);
+            if (err < 0)
+                goto fail;
+        }
 
         priv->sei_needed = 0;
 
@@ -888,6 +899,22 @@ static int vaapi_encode_h265_init_picture_params(AVCodecContext *avctx,
         }
     }
 
+    if (priv->sei & SEI_A53_CC) {
+        int err;
+        size_t sei_a53cc_len;
+        av_freep(&priv->sei_a53cc_data);
+        err = ff_alloc_a53_sei(pic->input_image, 0, &priv->sei_a53cc_data, &sei_a53cc_len);
+        if (err < 0)
+            return err;
+        if (priv->sei_a53cc_data != NULL) {
+            priv->sei_a53cc.itu_t_t35_country_code = 181;
+            priv->sei_a53cc.data = (uint8_t *)priv->sei_a53cc_data + 1;
+            priv->sei_a53cc.data_length = sei_a53cc_len - 1;
+
+            priv->sei_needed |= SEI_A53_CC;
+        }
+    }
+
     vpic->decoded_curr_pic = (VAPictureHEVC) {
         .picture_id    = pic->recon_surface,
         .pic_order_cnt = hpic->pic_order_cnt,
@@ -1355,6 +1382,7 @@ static av_cold int vaapi_encode_h265_close(AVCodecContext *avctx)
 
     ff_cbs_fragment_free(&priv->current_access_unit);
     ff_cbs_close(&priv->cbc);
+    av_freep(&priv->sei_a53cc_data);
 
     return ff_vaapi_encode_close(avctx);
 }
@@ -1413,7 +1441,7 @@ static const AVOption vaapi_encode_h265_options[] = {
 
     { "sei", "Set SEI to include",
       OFFSET(sei), AV_OPT_TYPE_FLAGS,
-      { .i64 = SEI_MASTERING_DISPLAY | SEI_CONTENT_LIGHT_LEVEL },
+      { .i64 = SEI_MASTERING_DISPLAY | SEI_CONTENT_LIGHT_LEVEL | SEI_A53_CC },
       0, INT_MAX, FLAGS, "sei" },
     { "hdr",
       "Include HDR metadata for mastering display colour volume "
@@ -1421,6 +1449,11 @@ static const AVOption vaapi_encode_h265_options[] = {
       0, AV_OPT_TYPE_CONST,
       { .i64 = SEI_MASTERING_DISPLAY | SEI_CONTENT_LIGHT_LEVEL },
       INT_MIN, INT_MAX, FLAGS, "sei" },
+    { "a53_cc",
+      "Include A/53 caption data"
+      0, AV_OPT_TYPE_CONST,
+      { .i64 = SEI_A53_CC },
+      INT_MIN, INT_MAX, FLAGS, "sei" },
 
     { "tiles", "Tile columns x rows",
       OFFSET(common.tile_cols), AV_OPT_TYPE_IMAGE_SIZE,

base-commit: 3bcec58535d395945a390bdc7af4048a7abc60eb
-- 
ffmpeg-codebot
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [FFmpeg-devel] [PATCH v3] avcodec/vaapi_encode_h26x: passthrough A53 CC data as H264/HEVC SEI
  2023-01-06 17:15 ` [FFmpeg-devel] [PATCH v2] " Aman Karmani
@ 2023-01-06 17:41   ` Aman Karmani
  2023-01-06 19:02     ` Andreas Rheinhardt
  2023-01-09 18:40     ` [FFmpeg-devel] [PATCH v4] " Aman Karmani
  0 siblings, 2 replies; 7+ messages in thread
From: Aman Karmani @ 2023-01-06 17:41 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Aman Karmani, Xiang, Haihao

From: Aman Karmani <aman@tmm1.net>

Signed-off-by: Aman Karmani <aman@tmm1.net>
---
    avcodec/vaapi_encode_h26x: passthrough A53 CC data as H264/HEVC SEI
    
    v3: fix build failure v2: add control via sei parameter

Published-As: https://github.com/ffstaging/FFmpeg/releases/tag/pr-ffstaging-46%2Ftmm1%2Fvaapi-a53cc-v3
Fetch-It-Via: git fetch https://github.com/ffstaging/FFmpeg pr-ffstaging-46/tmm1/vaapi-a53cc-v3
Pull-Request: https://github.com/ffstaging/FFmpeg/pull/46

Range-diff vs v2:

 1:  9a2fee07a9 ! 1:  149fa8e61c avcodec/vaapi_encode_h26x: passthrough A53 CC data as H264/HEVC SEI
     @@ libavcodec/vaapi_encode_h264.c: static const AVOption vaapi_encode_h264_options[
           { "recovery_point", "Include recovery points where appropriate",
             0, AV_OPT_TYPE_CONST, { .i64 = SEI_RECOVERY_POINT },
             INT_MIN, INT_MAX, FLAGS, "sei" },
     -+    { "a53_cc", "Include A/53 caption data"
     ++    { "a53_cc", "Include A/53 caption data",
      +      0, AV_OPT_TYPE_CONST, { .i64 = SEI_A53_CC },
      +      INT_MIN, INT_MAX, FLAGS, "sei" },
       
     @@ libavcodec/vaapi_encode_h265.c: static const AVOption vaapi_encode_h265_options[
             { .i64 = SEI_MASTERING_DISPLAY | SEI_CONTENT_LIGHT_LEVEL },
             INT_MIN, INT_MAX, FLAGS, "sei" },
      +    { "a53_cc",
     -+      "Include A/53 caption data"
     ++      "Include A/53 caption data",
      +      0, AV_OPT_TYPE_CONST,
      +      { .i64 = SEI_A53_CC },
      +      INT_MIN, INT_MAX, FLAGS, "sei" },


 libavcodec/vaapi_encode_h264.c | 33 +++++++++++++++++++++++++++++++-
 libavcodec/vaapi_encode_h265.c | 35 +++++++++++++++++++++++++++++++++-
 2 files changed, 66 insertions(+), 2 deletions(-)

diff --git a/libavcodec/vaapi_encode_h264.c b/libavcodec/vaapi_encode_h264.c
index b1b503b2a6..9f9d77a0e9 100644
--- a/libavcodec/vaapi_encode_h264.c
+++ b/libavcodec/vaapi_encode_h264.c
@@ -26,6 +26,7 @@
 #include "libavutil/internal.h"
 #include "libavutil/opt.h"
 
+#include "atsc_a53.h"
 #include "avcodec.h"
 #include "cbs.h"
 #include "cbs_h264.h"
@@ -40,6 +41,7 @@ enum {
     SEI_TIMING         = 0x01,
     SEI_IDENTIFIER     = 0x02,
     SEI_RECOVERY_POINT = 0x04,
+    SEI_A53_CC         = 0x08,
 };
 
 // Random (version 4) ISO 11578 UUID.
@@ -98,6 +100,8 @@ typedef struct VAAPIEncodeH264Context {
     H264RawSEIRecoveryPoint        sei_recovery_point;
     SEIRawUserDataUnregistered     sei_identifier;
     char                          *sei_identifier_string;
+    SEIRawUserDataRegistered       sei_a53cc;
+    void                          *sei_a53cc_data;
 
     int aud_needed;
     int sei_needed;
@@ -248,6 +252,13 @@ static int vaapi_encode_h264_write_extra_header(AVCodecContext *avctx,
             if (err < 0)
                 goto fail;
         }
+        if (priv->sei_needed & SEI_A53_CC) {
+            err = ff_cbs_sei_add_message(priv->cbc, au, 1,
+                                         SEI_TYPE_USER_DATA_REGISTERED_ITU_T_T35,
+                                         &priv->sei_a53cc, NULL);
+            if (err < 0)
+                goto fail;
+        }
 
         priv->sei_needed = 0;
 
@@ -681,6 +692,22 @@ static int vaapi_encode_h264_init_picture_params(AVCodecContext *avctx,
         priv->sei_needed |= SEI_RECOVERY_POINT;
     }
 
+    if (priv->sei & SEI_A53_CC) {
+        int err;
+        size_t sei_a53cc_len;
+        av_freep(&priv->sei_a53cc_data);
+        err = ff_alloc_a53_sei(pic->input_image, 0, &priv->sei_a53cc_data, &sei_a53cc_len);
+        if (err < 0)
+            return err;
+        if (priv->sei_a53cc_data != NULL) {
+            priv->sei_a53cc.itu_t_t35_country_code = 181;
+            priv->sei_a53cc.data = (uint8_t *)priv->sei_a53cc_data + 1;
+            priv->sei_a53cc.data_length = sei_a53cc_len - 1;
+
+            priv->sei_needed |= SEI_A53_CC;
+        }
+    }
+
     vpic->CurrPic = (VAPictureH264) {
         .picture_id          = pic->recon_surface,
         .frame_idx           = hpic->frame_num,
@@ -1226,6 +1253,7 @@ static av_cold int vaapi_encode_h264_close(AVCodecContext *avctx)
     ff_cbs_fragment_free(&priv->current_access_unit);
     ff_cbs_close(&priv->cbc);
     av_freep(&priv->sei_identifier_string);
+    av_freep(&priv->sei_a53cc_data);
 
     return ff_vaapi_encode_close(avctx);
 }
@@ -1252,7 +1280,7 @@ static const AVOption vaapi_encode_h264_options[] = {
 
     { "sei", "Set SEI to include",
       OFFSET(sei), AV_OPT_TYPE_FLAGS,
-      { .i64 = SEI_IDENTIFIER | SEI_TIMING | SEI_RECOVERY_POINT },
+      { .i64 = SEI_IDENTIFIER | SEI_TIMING | SEI_RECOVERY_POINT | SEI_A53_CC },
       0, INT_MAX, FLAGS, "sei" },
     { "identifier", "Include encoder version identifier",
       0, AV_OPT_TYPE_CONST, { .i64 = SEI_IDENTIFIER },
@@ -1263,6 +1291,9 @@ static const AVOption vaapi_encode_h264_options[] = {
     { "recovery_point", "Include recovery points where appropriate",
       0, AV_OPT_TYPE_CONST, { .i64 = SEI_RECOVERY_POINT },
       INT_MIN, INT_MAX, FLAGS, "sei" },
+    { "a53_cc", "Include A/53 caption data",
+      0, AV_OPT_TYPE_CONST, { .i64 = SEI_A53_CC },
+      INT_MIN, INT_MAX, FLAGS, "sei" },
 
     { "profile", "Set profile (profile_idc and constraint_set*_flag)",
       OFFSET(profile), AV_OPT_TYPE_INT,
diff --git a/libavcodec/vaapi_encode_h265.c b/libavcodec/vaapi_encode_h265.c
index 94b56c6578..f5b85cef6f 100644
--- a/libavcodec/vaapi_encode_h265.c
+++ b/libavcodec/vaapi_encode_h265.c
@@ -27,6 +27,7 @@
 #include "libavutil/opt.h"
 #include "libavutil/mastering_display_metadata.h"
 
+#include "atsc_a53.h"
 #include "avcodec.h"
 #include "cbs.h"
 #include "cbs_h265.h"
@@ -40,6 +41,7 @@
 enum {
     SEI_MASTERING_DISPLAY       = 0x08,
     SEI_CONTENT_LIGHT_LEVEL     = 0x10,
+    SEI_A53_CC                  = 0x20,
 };
 
 typedef struct VAAPIEncodeH265Picture {
@@ -84,6 +86,8 @@ typedef struct VAAPIEncodeH265Context {
 
     SEIRawMasteringDisplayColourVolume sei_mastering_display;
     SEIRawContentLightLevelInfo        sei_content_light_level;
+    SEIRawUserDataRegistered           sei_a53cc;
+    void                              *sei_a53cc_data;
 
     CodedBitstreamContext *cbc;
     CodedBitstreamFragment current_access_unit;
@@ -226,6 +230,13 @@ static int vaapi_encode_h265_write_extra_header(AVCodecContext *avctx,
             if (err < 0)
                 goto fail;
         }
+        if (priv->sei_needed & SEI_A53_CC) {
+            err = ff_cbs_sei_add_message(priv->cbc, au, 1,
+                                         SEI_TYPE_USER_DATA_REGISTERED_ITU_T_T35,
+                                         &priv->sei_a53cc, NULL);
+            if (err < 0)
+                goto fail;
+        }
 
         priv->sei_needed = 0;
 
@@ -888,6 +899,22 @@ static int vaapi_encode_h265_init_picture_params(AVCodecContext *avctx,
         }
     }
 
+    if (priv->sei & SEI_A53_CC) {
+        int err;
+        size_t sei_a53cc_len;
+        av_freep(&priv->sei_a53cc_data);
+        err = ff_alloc_a53_sei(pic->input_image, 0, &priv->sei_a53cc_data, &sei_a53cc_len);
+        if (err < 0)
+            return err;
+        if (priv->sei_a53cc_data != NULL) {
+            priv->sei_a53cc.itu_t_t35_country_code = 181;
+            priv->sei_a53cc.data = (uint8_t *)priv->sei_a53cc_data + 1;
+            priv->sei_a53cc.data_length = sei_a53cc_len - 1;
+
+            priv->sei_needed |= SEI_A53_CC;
+        }
+    }
+
     vpic->decoded_curr_pic = (VAPictureHEVC) {
         .picture_id    = pic->recon_surface,
         .pic_order_cnt = hpic->pic_order_cnt,
@@ -1355,6 +1382,7 @@ static av_cold int vaapi_encode_h265_close(AVCodecContext *avctx)
 
     ff_cbs_fragment_free(&priv->current_access_unit);
     ff_cbs_close(&priv->cbc);
+    av_freep(&priv->sei_a53cc_data);
 
     return ff_vaapi_encode_close(avctx);
 }
@@ -1413,7 +1441,7 @@ static const AVOption vaapi_encode_h265_options[] = {
 
     { "sei", "Set SEI to include",
       OFFSET(sei), AV_OPT_TYPE_FLAGS,
-      { .i64 = SEI_MASTERING_DISPLAY | SEI_CONTENT_LIGHT_LEVEL },
+      { .i64 = SEI_MASTERING_DISPLAY | SEI_CONTENT_LIGHT_LEVEL | SEI_A53_CC },
       0, INT_MAX, FLAGS, "sei" },
     { "hdr",
       "Include HDR metadata for mastering display colour volume "
@@ -1421,6 +1449,11 @@ static const AVOption vaapi_encode_h265_options[] = {
       0, AV_OPT_TYPE_CONST,
       { .i64 = SEI_MASTERING_DISPLAY | SEI_CONTENT_LIGHT_LEVEL },
       INT_MIN, INT_MAX, FLAGS, "sei" },
+    { "a53_cc",
+      "Include A/53 caption data",
+      0, AV_OPT_TYPE_CONST,
+      { .i64 = SEI_A53_CC },
+      INT_MIN, INT_MAX, FLAGS, "sei" },
 
     { "tiles", "Tile columns x rows",
       OFFSET(common.tile_cols), AV_OPT_TYPE_IMAGE_SIZE,

base-commit: 3bcec58535d395945a390bdc7af4048a7abc60eb
-- 
ffmpeg-codebot
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [FFmpeg-devel] [PATCH v3] avcodec/vaapi_encode_h26x: passthrough A53 CC data as H264/HEVC SEI
  2023-01-06 17:41   ` [FFmpeg-devel] [PATCH v3] " Aman Karmani
@ 2023-01-06 19:02     ` Andreas Rheinhardt
  2023-01-09 18:40     ` [FFmpeg-devel] [PATCH v4] " Aman Karmani
  1 sibling, 0 replies; 7+ messages in thread
From: Andreas Rheinhardt @ 2023-01-06 19:02 UTC (permalink / raw)
  To: ffmpeg-devel

Aman Karmani:
> From: Aman Karmani <aman@tmm1.net>
> 
> Signed-off-by: Aman Karmani <aman@tmm1.net>
> ---
>     avcodec/vaapi_encode_h26x: passthrough A53 CC data as H264/HEVC SEI
>     
>     v3: fix build failure v2: add control via sei parameter
> 
> Published-As: https://github.com/ffstaging/FFmpeg/releases/tag/pr-ffstaging-46%2Ftmm1%2Fvaapi-a53cc-v3
> Fetch-It-Via: git fetch https://github.com/ffstaging/FFmpeg pr-ffstaging-46/tmm1/vaapi-a53cc-v3
> Pull-Request: https://github.com/ffstaging/FFmpeg/pull/46
> 
> Range-diff vs v2:
> 
>  1:  9a2fee07a9 ! 1:  149fa8e61c avcodec/vaapi_encode_h26x: passthrough A53 CC data as H264/HEVC SEI
>      @@ libavcodec/vaapi_encode_h264.c: static const AVOption vaapi_encode_h264_options[
>            { "recovery_point", "Include recovery points where appropriate",
>              0, AV_OPT_TYPE_CONST, { .i64 = SEI_RECOVERY_POINT },
>              INT_MIN, INT_MAX, FLAGS, "sei" },
>      -+    { "a53_cc", "Include A/53 caption data"
>      ++    { "a53_cc", "Include A/53 caption data",
>       +      0, AV_OPT_TYPE_CONST, { .i64 = SEI_A53_CC },
>       +      INT_MIN, INT_MAX, FLAGS, "sei" },
>        
>      @@ libavcodec/vaapi_encode_h265.c: static const AVOption vaapi_encode_h265_options[
>              { .i64 = SEI_MASTERING_DISPLAY | SEI_CONTENT_LIGHT_LEVEL },
>              INT_MIN, INT_MAX, FLAGS, "sei" },
>       +    { "a53_cc",
>      -+      "Include A/53 caption data"
>      ++      "Include A/53 caption data",
>       +      0, AV_OPT_TYPE_CONST,
>       +      { .i64 = SEI_A53_CC },
>       +      INT_MIN, INT_MAX, FLAGS, "sei" },
> 
> 
>  libavcodec/vaapi_encode_h264.c | 33 +++++++++++++++++++++++++++++++-
>  libavcodec/vaapi_encode_h265.c | 35 +++++++++++++++++++++++++++++++++-
>  2 files changed, 66 insertions(+), 2 deletions(-)
> 
> diff --git a/libavcodec/vaapi_encode_h264.c b/libavcodec/vaapi_encode_h264.c
> index b1b503b2a6..9f9d77a0e9 100644
> --- a/libavcodec/vaapi_encode_h264.c
> +++ b/libavcodec/vaapi_encode_h264.c
> @@ -26,6 +26,7 @@
>  #include "libavutil/internal.h"
>  #include "libavutil/opt.h"
>  
> +#include "atsc_a53.h"
>  #include "avcodec.h"
>  #include "cbs.h"
>  #include "cbs_h264.h"
> @@ -40,6 +41,7 @@ enum {
>      SEI_TIMING         = 0x01,
>      SEI_IDENTIFIER     = 0x02,
>      SEI_RECOVERY_POINT = 0x04,
> +    SEI_A53_CC         = 0x08,
>  };
>  
>  // Random (version 4) ISO 11578 UUID.
> @@ -98,6 +100,8 @@ typedef struct VAAPIEncodeH264Context {
>      H264RawSEIRecoveryPoint        sei_recovery_point;
>      SEIRawUserDataUnregistered     sei_identifier;
>      char                          *sei_identifier_string;
> +    SEIRawUserDataRegistered       sei_a53cc;
> +    void                          *sei_a53cc_data;
>  
>      int aud_needed;
>      int sei_needed;
> @@ -248,6 +252,13 @@ static int vaapi_encode_h264_write_extra_header(AVCodecContext *avctx,
>              if (err < 0)
>                  goto fail;
>          }
> +        if (priv->sei_needed & SEI_A53_CC) {
> +            err = ff_cbs_sei_add_message(priv->cbc, au, 1,
> +                                         SEI_TYPE_USER_DATA_REGISTERED_ITU_T_T35,
> +                                         &priv->sei_a53cc, NULL);
> +            if (err < 0)
> +                goto fail;
> +        }
>  
>          priv->sei_needed = 0;
>  
> @@ -681,6 +692,22 @@ static int vaapi_encode_h264_init_picture_params(AVCodecContext *avctx,
>          priv->sei_needed |= SEI_RECOVERY_POINT;
>      }
>  
> +    if (priv->sei & SEI_A53_CC) {
> +        int err;
> +        size_t sei_a53cc_len;
> +        av_freep(&priv->sei_a53cc_data);
> +        err = ff_alloc_a53_sei(pic->input_image, 0, &priv->sei_a53cc_data, &sei_a53cc_len);
> +        if (err < 0)
> +            return err;
> +        if (priv->sei_a53cc_data != NULL) {
> +            priv->sei_a53cc.itu_t_t35_country_code = 181;
> +            priv->sei_a53cc.data = (uint8_t *)priv->sei_a53cc_data + 1;
> +            priv->sei_a53cc.data_length = sei_a53cc_len - 1;
> +
> +            priv->sei_needed |= SEI_A53_CC;
> +        }
> +    }
> +
>      vpic->CurrPic = (VAPictureH264) {
>          .picture_id          = pic->recon_surface,
>          .frame_idx           = hpic->frame_num,
> @@ -1226,6 +1253,7 @@ static av_cold int vaapi_encode_h264_close(AVCodecContext *avctx)
>      ff_cbs_fragment_free(&priv->current_access_unit);
>      ff_cbs_close(&priv->cbc);
>      av_freep(&priv->sei_identifier_string);
> +    av_freep(&priv->sei_a53cc_data);
>  
>      return ff_vaapi_encode_close(avctx);
>  }
> @@ -1252,7 +1280,7 @@ static const AVOption vaapi_encode_h264_options[] = {
>  
>      { "sei", "Set SEI to include",
>        OFFSET(sei), AV_OPT_TYPE_FLAGS,
> -      { .i64 = SEI_IDENTIFIER | SEI_TIMING | SEI_RECOVERY_POINT },
> +      { .i64 = SEI_IDENTIFIER | SEI_TIMING | SEI_RECOVERY_POINT | SEI_A53_CC },
>        0, INT_MAX, FLAGS, "sei" },
>      { "identifier", "Include encoder version identifier",
>        0, AV_OPT_TYPE_CONST, { .i64 = SEI_IDENTIFIER },
> @@ -1263,6 +1291,9 @@ static const AVOption vaapi_encode_h264_options[] = {
>      { "recovery_point", "Include recovery points where appropriate",
>        0, AV_OPT_TYPE_CONST, { .i64 = SEI_RECOVERY_POINT },
>        INT_MIN, INT_MAX, FLAGS, "sei" },
> +    { "a53_cc", "Include A/53 caption data",
> +      0, AV_OPT_TYPE_CONST, { .i64 = SEI_A53_CC },
> +      INT_MIN, INT_MAX, FLAGS, "sei" },
>  
>      { "profile", "Set profile (profile_idc and constraint_set*_flag)",
>        OFFSET(profile), AV_OPT_TYPE_INT,
> diff --git a/libavcodec/vaapi_encode_h265.c b/libavcodec/vaapi_encode_h265.c
> index 94b56c6578..f5b85cef6f 100644
> --- a/libavcodec/vaapi_encode_h265.c
> +++ b/libavcodec/vaapi_encode_h265.c
> @@ -27,6 +27,7 @@
>  #include "libavutil/opt.h"
>  #include "libavutil/mastering_display_metadata.h"
>  
> +#include "atsc_a53.h"
>  #include "avcodec.h"
>  #include "cbs.h"
>  #include "cbs_h265.h"
> @@ -40,6 +41,7 @@
>  enum {
>      SEI_MASTERING_DISPLAY       = 0x08,
>      SEI_CONTENT_LIGHT_LEVEL     = 0x10,
> +    SEI_A53_CC                  = 0x20,
>  };
>  
>  typedef struct VAAPIEncodeH265Picture {
> @@ -84,6 +86,8 @@ typedef struct VAAPIEncodeH265Context {
>  
>      SEIRawMasteringDisplayColourVolume sei_mastering_display;
>      SEIRawContentLightLevelInfo        sei_content_light_level;
> +    SEIRawUserDataRegistered           sei_a53cc;
> +    void                              *sei_a53cc_data;
>  
>      CodedBitstreamContext *cbc;
>      CodedBitstreamFragment current_access_unit;
> @@ -226,6 +230,13 @@ static int vaapi_encode_h265_write_extra_header(AVCodecContext *avctx,
>              if (err < 0)
>                  goto fail;
>          }
> +        if (priv->sei_needed & SEI_A53_CC) {
> +            err = ff_cbs_sei_add_message(priv->cbc, au, 1,
> +                                         SEI_TYPE_USER_DATA_REGISTERED_ITU_T_T35,
> +                                         &priv->sei_a53cc, NULL);
> +            if (err < 0)
> +                goto fail;
> +        }
>  
>          priv->sei_needed = 0;
>  
> @@ -888,6 +899,22 @@ static int vaapi_encode_h265_init_picture_params(AVCodecContext *avctx,
>          }
>      }
>  
> +    if (priv->sei & SEI_A53_CC) {
> +        int err;
> +        size_t sei_a53cc_len;
> +        av_freep(&priv->sei_a53cc_data);
> +        err = ff_alloc_a53_sei(pic->input_image, 0, &priv->sei_a53cc_data, &sei_a53cc_len);
> +        if (err < 0)
> +            return err;
> +        if (priv->sei_a53cc_data != NULL) {
> +            priv->sei_a53cc.itu_t_t35_country_code = 181;
> +            priv->sei_a53cc.data = (uint8_t *)priv->sei_a53cc_data + 1;
> +            priv->sei_a53cc.data_length = sei_a53cc_len - 1;
> +
> +            priv->sei_needed |= SEI_A53_CC;
> +        }
> +    }
> +
>      vpic->decoded_curr_pic = (VAPictureHEVC) {
>          .picture_id    = pic->recon_surface,
>          .pic_order_cnt = hpic->pic_order_cnt,
> @@ -1355,6 +1382,7 @@ static av_cold int vaapi_encode_h265_close(AVCodecContext *avctx)
>  
>      ff_cbs_fragment_free(&priv->current_access_unit);
>      ff_cbs_close(&priv->cbc);
> +    av_freep(&priv->sei_a53cc_data);
>  
>      return ff_vaapi_encode_close(avctx);
>  }
> @@ -1413,7 +1441,7 @@ static const AVOption vaapi_encode_h265_options[] = {
>  
>      { "sei", "Set SEI to include",
>        OFFSET(sei), AV_OPT_TYPE_FLAGS,
> -      { .i64 = SEI_MASTERING_DISPLAY | SEI_CONTENT_LIGHT_LEVEL },
> +      { .i64 = SEI_MASTERING_DISPLAY | SEI_CONTENT_LIGHT_LEVEL | SEI_A53_CC },
>        0, INT_MAX, FLAGS, "sei" },
>      { "hdr",
>        "Include HDR metadata for mastering display colour volume "
> @@ -1421,6 +1449,11 @@ static const AVOption vaapi_encode_h265_options[] = {
>        0, AV_OPT_TYPE_CONST,
>        { .i64 = SEI_MASTERING_DISPLAY | SEI_CONTENT_LIGHT_LEVEL },
>        INT_MIN, INT_MAX, FLAGS, "sei" },
> +    { "a53_cc",
> +      "Include A/53 caption data",
> +      0, AV_OPT_TYPE_CONST,
> +      { .i64 = SEI_A53_CC },
> +      INT_MIN, INT_MAX, FLAGS, "sei" },
>  
>      { "tiles", "Tile columns x rows",
>        OFFSET(common.tile_cols), AV_OPT_TYPE_IMAGE_SIZE,
> 
> base-commit: 3bcec58535d395945a390bdc7af4048a7abc60eb

1. You are repeating yourself in this patch.
2. You forgot to add the necessary atsc_a53 configure dependencies.

- Andreas

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [FFmpeg-devel] [PATCH v4] avcodec/vaapi_encode_h26x: passthrough A53 CC data as H264/HEVC SEI
  2023-01-06 17:41   ` [FFmpeg-devel] [PATCH v3] " Aman Karmani
  2023-01-06 19:02     ` Andreas Rheinhardt
@ 2023-01-09 18:40     ` Aman Karmani
  2023-01-16  4:10       ` Xiang, Haihao
  1 sibling, 1 reply; 7+ messages in thread
From: Aman Karmani @ 2023-01-09 18:40 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Aman Karmani, Xiang, Haihao, Andreas Rheinhardt

From: Aman Karmani <aman@tmm1.net>

Signed-off-by: Aman Karmani <aman@tmm1.net>
---
    avcodec/vaapi_encode_h26x: passthrough A53 CC data as H264/HEVC SEI
    
    v4: updated deps in configure v3: fix build failure v2: add control via
    sei parameter

Published-As: https://github.com/ffstaging/FFmpeg/releases/tag/pr-ffstaging-46%2Ftmm1%2Fvaapi-a53cc-v4
Fetch-It-Via: git fetch https://github.com/ffstaging/FFmpeg pr-ffstaging-46/tmm1/vaapi-a53cc-v4
Pull-Request: https://github.com/ffstaging/FFmpeg/pull/46

Range-diff vs v3:

 1:  149fa8e61c ! 1:  367db524fb avcodec/vaapi_encode_h26x: passthrough A53 CC data as H264/HEVC SEI
     @@ Commit message
      
          Signed-off-by: Aman Karmani <aman@tmm1.net>
      
     + ## configure ##
     +@@ configure: h264_qsv_decoder_select="h264_mp4toannexb_bsf qsvdec"
     + h264_qsv_encoder_select="atsc_a53 qsvenc"
     + h264_rkmpp_decoder_deps="rkmpp"
     + h264_rkmpp_decoder_select="h264_mp4toannexb_bsf"
     +-h264_vaapi_encoder_select="cbs_h264 vaapi_encode"
     ++h264_vaapi_encoder_select="atsc_a53 cbs_h264 vaapi_encode"
     + h264_v4l2m2m_decoder_deps="v4l2_m2m h264_v4l2_m2m"
     + h264_v4l2m2m_decoder_select="h264_mp4toannexb_bsf"
     + h264_v4l2m2m_encoder_deps="v4l2_m2m h264_v4l2_m2m"
     +@@ configure: hevc_qsv_encoder_select="hevcparse qsvenc"
     + hevc_rkmpp_decoder_deps="rkmpp"
     + hevc_rkmpp_decoder_select="hevc_mp4toannexb_bsf"
     + hevc_vaapi_encoder_deps="VAEncPictureParameterBufferHEVC"
     +-hevc_vaapi_encoder_select="cbs_h265 vaapi_encode"
     ++hevc_vaapi_encoder_select="atsc_a53 cbs_h265 vaapi_encode"
     + hevc_v4l2m2m_decoder_deps="v4l2_m2m hevc_v4l2_m2m"
     + hevc_v4l2m2m_decoder_select="hevc_mp4toannexb_bsf"
     + hevc_v4l2m2m_encoder_deps="v4l2_m2m hevc_v4l2_m2m"
     +
       ## libavcodec/vaapi_encode_h264.c ##
      @@
       #include "libavutil/internal.h"


 configure                      |  4 ++--
 libavcodec/vaapi_encode_h264.c | 33 +++++++++++++++++++++++++++++++-
 libavcodec/vaapi_encode_h265.c | 35 +++++++++++++++++++++++++++++++++-
 3 files changed, 68 insertions(+), 4 deletions(-)

diff --git a/configure b/configure
index e54649fa48..5ba1395bea 100755
--- a/configure
+++ b/configure
@@ -3191,7 +3191,7 @@ h264_qsv_decoder_select="h264_mp4toannexb_bsf qsvdec"
 h264_qsv_encoder_select="atsc_a53 qsvenc"
 h264_rkmpp_decoder_deps="rkmpp"
 h264_rkmpp_decoder_select="h264_mp4toannexb_bsf"
-h264_vaapi_encoder_select="cbs_h264 vaapi_encode"
+h264_vaapi_encoder_select="atsc_a53 cbs_h264 vaapi_encode"
 h264_v4l2m2m_decoder_deps="v4l2_m2m h264_v4l2_m2m"
 h264_v4l2m2m_decoder_select="h264_mp4toannexb_bsf"
 h264_v4l2m2m_encoder_deps="v4l2_m2m h264_v4l2_m2m"
@@ -3208,7 +3208,7 @@ hevc_qsv_encoder_select="hevcparse qsvenc"
 hevc_rkmpp_decoder_deps="rkmpp"
 hevc_rkmpp_decoder_select="hevc_mp4toannexb_bsf"
 hevc_vaapi_encoder_deps="VAEncPictureParameterBufferHEVC"
-hevc_vaapi_encoder_select="cbs_h265 vaapi_encode"
+hevc_vaapi_encoder_select="atsc_a53 cbs_h265 vaapi_encode"
 hevc_v4l2m2m_decoder_deps="v4l2_m2m hevc_v4l2_m2m"
 hevc_v4l2m2m_decoder_select="hevc_mp4toannexb_bsf"
 hevc_v4l2m2m_encoder_deps="v4l2_m2m hevc_v4l2_m2m"
diff --git a/libavcodec/vaapi_encode_h264.c b/libavcodec/vaapi_encode_h264.c
index b1b503b2a6..9f9d77a0e9 100644
--- a/libavcodec/vaapi_encode_h264.c
+++ b/libavcodec/vaapi_encode_h264.c
@@ -26,6 +26,7 @@
 #include "libavutil/internal.h"
 #include "libavutil/opt.h"
 
+#include "atsc_a53.h"
 #include "avcodec.h"
 #include "cbs.h"
 #include "cbs_h264.h"
@@ -40,6 +41,7 @@ enum {
     SEI_TIMING         = 0x01,
     SEI_IDENTIFIER     = 0x02,
     SEI_RECOVERY_POINT = 0x04,
+    SEI_A53_CC         = 0x08,
 };
 
 // Random (version 4) ISO 11578 UUID.
@@ -98,6 +100,8 @@ typedef struct VAAPIEncodeH264Context {
     H264RawSEIRecoveryPoint        sei_recovery_point;
     SEIRawUserDataUnregistered     sei_identifier;
     char                          *sei_identifier_string;
+    SEIRawUserDataRegistered       sei_a53cc;
+    void                          *sei_a53cc_data;
 
     int aud_needed;
     int sei_needed;
@@ -248,6 +252,13 @@ static int vaapi_encode_h264_write_extra_header(AVCodecContext *avctx,
             if (err < 0)
                 goto fail;
         }
+        if (priv->sei_needed & SEI_A53_CC) {
+            err = ff_cbs_sei_add_message(priv->cbc, au, 1,
+                                         SEI_TYPE_USER_DATA_REGISTERED_ITU_T_T35,
+                                         &priv->sei_a53cc, NULL);
+            if (err < 0)
+                goto fail;
+        }
 
         priv->sei_needed = 0;
 
@@ -681,6 +692,22 @@ static int vaapi_encode_h264_init_picture_params(AVCodecContext *avctx,
         priv->sei_needed |= SEI_RECOVERY_POINT;
     }
 
+    if (priv->sei & SEI_A53_CC) {
+        int err;
+        size_t sei_a53cc_len;
+        av_freep(&priv->sei_a53cc_data);
+        err = ff_alloc_a53_sei(pic->input_image, 0, &priv->sei_a53cc_data, &sei_a53cc_len);
+        if (err < 0)
+            return err;
+        if (priv->sei_a53cc_data != NULL) {
+            priv->sei_a53cc.itu_t_t35_country_code = 181;
+            priv->sei_a53cc.data = (uint8_t *)priv->sei_a53cc_data + 1;
+            priv->sei_a53cc.data_length = sei_a53cc_len - 1;
+
+            priv->sei_needed |= SEI_A53_CC;
+        }
+    }
+
     vpic->CurrPic = (VAPictureH264) {
         .picture_id          = pic->recon_surface,
         .frame_idx           = hpic->frame_num,
@@ -1226,6 +1253,7 @@ static av_cold int vaapi_encode_h264_close(AVCodecContext *avctx)
     ff_cbs_fragment_free(&priv->current_access_unit);
     ff_cbs_close(&priv->cbc);
     av_freep(&priv->sei_identifier_string);
+    av_freep(&priv->sei_a53cc_data);
 
     return ff_vaapi_encode_close(avctx);
 }
@@ -1252,7 +1280,7 @@ static const AVOption vaapi_encode_h264_options[] = {
 
     { "sei", "Set SEI to include",
       OFFSET(sei), AV_OPT_TYPE_FLAGS,
-      { .i64 = SEI_IDENTIFIER | SEI_TIMING | SEI_RECOVERY_POINT },
+      { .i64 = SEI_IDENTIFIER | SEI_TIMING | SEI_RECOVERY_POINT | SEI_A53_CC },
       0, INT_MAX, FLAGS, "sei" },
     { "identifier", "Include encoder version identifier",
       0, AV_OPT_TYPE_CONST, { .i64 = SEI_IDENTIFIER },
@@ -1263,6 +1291,9 @@ static const AVOption vaapi_encode_h264_options[] = {
     { "recovery_point", "Include recovery points where appropriate",
       0, AV_OPT_TYPE_CONST, { .i64 = SEI_RECOVERY_POINT },
       INT_MIN, INT_MAX, FLAGS, "sei" },
+    { "a53_cc", "Include A/53 caption data",
+      0, AV_OPT_TYPE_CONST, { .i64 = SEI_A53_CC },
+      INT_MIN, INT_MAX, FLAGS, "sei" },
 
     { "profile", "Set profile (profile_idc and constraint_set*_flag)",
       OFFSET(profile), AV_OPT_TYPE_INT,
diff --git a/libavcodec/vaapi_encode_h265.c b/libavcodec/vaapi_encode_h265.c
index 94b56c6578..f5b85cef6f 100644
--- a/libavcodec/vaapi_encode_h265.c
+++ b/libavcodec/vaapi_encode_h265.c
@@ -27,6 +27,7 @@
 #include "libavutil/opt.h"
 #include "libavutil/mastering_display_metadata.h"
 
+#include "atsc_a53.h"
 #include "avcodec.h"
 #include "cbs.h"
 #include "cbs_h265.h"
@@ -40,6 +41,7 @@
 enum {
     SEI_MASTERING_DISPLAY       = 0x08,
     SEI_CONTENT_LIGHT_LEVEL     = 0x10,
+    SEI_A53_CC                  = 0x20,
 };
 
 typedef struct VAAPIEncodeH265Picture {
@@ -84,6 +86,8 @@ typedef struct VAAPIEncodeH265Context {
 
     SEIRawMasteringDisplayColourVolume sei_mastering_display;
     SEIRawContentLightLevelInfo        sei_content_light_level;
+    SEIRawUserDataRegistered           sei_a53cc;
+    void                              *sei_a53cc_data;
 
     CodedBitstreamContext *cbc;
     CodedBitstreamFragment current_access_unit;
@@ -226,6 +230,13 @@ static int vaapi_encode_h265_write_extra_header(AVCodecContext *avctx,
             if (err < 0)
                 goto fail;
         }
+        if (priv->sei_needed & SEI_A53_CC) {
+            err = ff_cbs_sei_add_message(priv->cbc, au, 1,
+                                         SEI_TYPE_USER_DATA_REGISTERED_ITU_T_T35,
+                                         &priv->sei_a53cc, NULL);
+            if (err < 0)
+                goto fail;
+        }
 
         priv->sei_needed = 0;
 
@@ -888,6 +899,22 @@ static int vaapi_encode_h265_init_picture_params(AVCodecContext *avctx,
         }
     }
 
+    if (priv->sei & SEI_A53_CC) {
+        int err;
+        size_t sei_a53cc_len;
+        av_freep(&priv->sei_a53cc_data);
+        err = ff_alloc_a53_sei(pic->input_image, 0, &priv->sei_a53cc_data, &sei_a53cc_len);
+        if (err < 0)
+            return err;
+        if (priv->sei_a53cc_data != NULL) {
+            priv->sei_a53cc.itu_t_t35_country_code = 181;
+            priv->sei_a53cc.data = (uint8_t *)priv->sei_a53cc_data + 1;
+            priv->sei_a53cc.data_length = sei_a53cc_len - 1;
+
+            priv->sei_needed |= SEI_A53_CC;
+        }
+    }
+
     vpic->decoded_curr_pic = (VAPictureHEVC) {
         .picture_id    = pic->recon_surface,
         .pic_order_cnt = hpic->pic_order_cnt,
@@ -1355,6 +1382,7 @@ static av_cold int vaapi_encode_h265_close(AVCodecContext *avctx)
 
     ff_cbs_fragment_free(&priv->current_access_unit);
     ff_cbs_close(&priv->cbc);
+    av_freep(&priv->sei_a53cc_data);
 
     return ff_vaapi_encode_close(avctx);
 }
@@ -1413,7 +1441,7 @@ static const AVOption vaapi_encode_h265_options[] = {
 
     { "sei", "Set SEI to include",
       OFFSET(sei), AV_OPT_TYPE_FLAGS,
-      { .i64 = SEI_MASTERING_DISPLAY | SEI_CONTENT_LIGHT_LEVEL },
+      { .i64 = SEI_MASTERING_DISPLAY | SEI_CONTENT_LIGHT_LEVEL | SEI_A53_CC },
       0, INT_MAX, FLAGS, "sei" },
     { "hdr",
       "Include HDR metadata for mastering display colour volume "
@@ -1421,6 +1449,11 @@ static const AVOption vaapi_encode_h265_options[] = {
       0, AV_OPT_TYPE_CONST,
       { .i64 = SEI_MASTERING_DISPLAY | SEI_CONTENT_LIGHT_LEVEL },
       INT_MIN, INT_MAX, FLAGS, "sei" },
+    { "a53_cc",
+      "Include A/53 caption data",
+      0, AV_OPT_TYPE_CONST,
+      { .i64 = SEI_A53_CC },
+      INT_MIN, INT_MAX, FLAGS, "sei" },
 
     { "tiles", "Tile columns x rows",
       OFFSET(common.tile_cols), AV_OPT_TYPE_IMAGE_SIZE,

base-commit: 3bcec58535d395945a390bdc7af4048a7abc60eb
-- 
ffmpeg-codebot
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [FFmpeg-devel] [PATCH v4] avcodec/vaapi_encode_h26x: passthrough A53 CC data as H264/HEVC SEI
  2023-01-09 18:40     ` [FFmpeg-devel] [PATCH v4] " Aman Karmani
@ 2023-01-16  4:10       ` Xiang, Haihao
  0 siblings, 0 replies; 7+ messages in thread
From: Xiang, Haihao @ 2023-01-16  4:10 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: haihao.xiang-at-intel.com, aman, andreas.rheinhardt

On Ma, 2023-01-09 at 18:40 +0000, Aman Karmani wrote:
> From: Aman Karmani <aman@tmm1.net>
> 
> Signed-off-by: Aman Karmani <aman@tmm1.net>
> ---
>     avcodec/vaapi_encode_h26x: passthrough A53 CC data as H264/HEVC SEI
>     
>     v4: updated deps in configure v3: fix build failure v2: add control via
>     sei parameter
> 
> Published-As: 
> https://github.com/ffstaging/FFmpeg/releases/tag/pr-ffstaging-46%2Ftmm1%2Fvaapi-a53cc-v4
> Fetch-It-Via: git fetch https://github.com/ffstaging/FFmpeg pr-ffstaging-
> 46/tmm1/vaapi-a53cc-v4
> Pull-Request: https://github.com/ffstaging/FFmpeg/pull/46
> 
> Range-diff vs v3:
> 
>  1:  149fa8e61c ! 1:  367db524fb avcodec/vaapi_encode_h26x: passthrough A53 CC
> data as H264/HEVC SEI
>      @@ Commit message
>       
>           Signed-off-by: Aman Karmani <aman@tmm1.net>
>       
>      + ## configure ##
>      +@@ configure: h264_qsv_decoder_select="h264_mp4toannexb_bsf qsvdec"
>      + h264_qsv_encoder_select="atsc_a53 qsvenc"
>      + h264_rkmpp_decoder_deps="rkmpp"
>      + h264_rkmpp_decoder_select="h264_mp4toannexb_bsf"
>      +-h264_vaapi_encoder_select="cbs_h264 vaapi_encode"
>      ++h264_vaapi_encoder_select="atsc_a53 cbs_h264 vaapi_encode"
>      + h264_v4l2m2m_decoder_deps="v4l2_m2m h264_v4l2_m2m"
>      + h264_v4l2m2m_decoder_select="h264_mp4toannexb_bsf"
>      + h264_v4l2m2m_encoder_deps="v4l2_m2m h264_v4l2_m2m"
>      +@@ configure: hevc_qsv_encoder_select="hevcparse qsvenc"
>      + hevc_rkmpp_decoder_deps="rkmpp"
>      + hevc_rkmpp_decoder_select="hevc_mp4toannexb_bsf"
>      + hevc_vaapi_encoder_deps="VAEncPictureParameterBufferHEVC"
>      +-hevc_vaapi_encoder_select="cbs_h265 vaapi_encode"
>      ++hevc_vaapi_encoder_select="atsc_a53 cbs_h265 vaapi_encode"
>      + hevc_v4l2m2m_decoder_deps="v4l2_m2m hevc_v4l2_m2m"
>      + hevc_v4l2m2m_decoder_select="hevc_mp4toannexb_bsf"
>      + hevc_v4l2m2m_encoder_deps="v4l2_m2m hevc_v4l2_m2m"
>      +
>        ## libavcodec/vaapi_encode_h264.c ##
>       @@
>        #include "libavutil/internal.h"
> 
> 
>  configure                      |  4 ++--
>  libavcodec/vaapi_encode_h264.c | 33 +++++++++++++++++++++++++++++++-
>  libavcodec/vaapi_encode_h265.c | 35 +++++++++++++++++++++++++++++++++-
>  3 files changed, 68 insertions(+), 4 deletions(-)
> 
> diff --git a/configure b/configure
> index e54649fa48..5ba1395bea 100755
> --- a/configure
> +++ b/configure
> @@ -3191,7 +3191,7 @@ h264_qsv_decoder_select="h264_mp4toannexb_bsf qsvdec"
>  h264_qsv_encoder_select="atsc_a53 qsvenc"
>  h264_rkmpp_decoder_deps="rkmpp"
>  h264_rkmpp_decoder_select="h264_mp4toannexb_bsf"
> -h264_vaapi_encoder_select="cbs_h264 vaapi_encode"
> +h264_vaapi_encoder_select="atsc_a53 cbs_h264 vaapi_encode"
>  h264_v4l2m2m_decoder_deps="v4l2_m2m h264_v4l2_m2m"
>  h264_v4l2m2m_decoder_select="h264_mp4toannexb_bsf"
>  h264_v4l2m2m_encoder_deps="v4l2_m2m h264_v4l2_m2m"
> @@ -3208,7 +3208,7 @@ hevc_qsv_encoder_select="hevcparse qsvenc"
>  hevc_rkmpp_decoder_deps="rkmpp"
>  hevc_rkmpp_decoder_select="hevc_mp4toannexb_bsf"
>  hevc_vaapi_encoder_deps="VAEncPictureParameterBufferHEVC"
> -hevc_vaapi_encoder_select="cbs_h265 vaapi_encode"
> +hevc_vaapi_encoder_select="atsc_a53 cbs_h265 vaapi_encode"
>  hevc_v4l2m2m_decoder_deps="v4l2_m2m hevc_v4l2_m2m"
>  hevc_v4l2m2m_decoder_select="hevc_mp4toannexb_bsf"
>  hevc_v4l2m2m_encoder_deps="v4l2_m2m hevc_v4l2_m2m"
> diff --git a/libavcodec/vaapi_encode_h264.c b/libavcodec/vaapi_encode_h264.c
> index b1b503b2a6..9f9d77a0e9 100644
> --- a/libavcodec/vaapi_encode_h264.c
> +++ b/libavcodec/vaapi_encode_h264.c
> @@ -26,6 +26,7 @@
>  #include "libavutil/internal.h"
>  #include "libavutil/opt.h"
>  
> +#include "atsc_a53.h"
>  #include "avcodec.h"
>  #include "cbs.h"
>  #include "cbs_h264.h"
> @@ -40,6 +41,7 @@ enum {
>      SEI_TIMING         = 0x01,
>      SEI_IDENTIFIER     = 0x02,
>      SEI_RECOVERY_POINT = 0x04,
> +    SEI_A53_CC         = 0x08,
>  };
>  
>  // Random (version 4) ISO 11578 UUID.
> @@ -98,6 +100,8 @@ typedef struct VAAPIEncodeH264Context {
>      H264RawSEIRecoveryPoint        sei_recovery_point;
>      SEIRawUserDataUnregistered     sei_identifier;
>      char                          *sei_identifier_string;
> +    SEIRawUserDataRegistered       sei_a53cc;
> +    void                          *sei_a53cc_data;
>  
>      int aud_needed;
>      int sei_needed;
> @@ -248,6 +252,13 @@ static int
> vaapi_encode_h264_write_extra_header(AVCodecContext *avctx,
>              if (err < 0)
>                  goto fail;
>          }
> +        if (priv->sei_needed & SEI_A53_CC) {
> +            err = ff_cbs_sei_add_message(priv->cbc, au, 1,
> +                                         SEI_TYPE_USER_DATA_REGISTERED_ITU_T_
> T35,
> +                                         &priv->sei_a53cc, NULL);
> +            if (err < 0)
> +                goto fail;
> +        }
>  
>          priv->sei_needed = 0;
>  
> @@ -681,6 +692,22 @@ static int
> vaapi_encode_h264_init_picture_params(AVCodecContext *avctx,
>          priv->sei_needed |= SEI_RECOVERY_POINT;
>      }
>  
> +    if (priv->sei & SEI_A53_CC) {
> +        int err;
> +        size_t sei_a53cc_len;
> +        av_freep(&priv->sei_a53cc_data);
> +        err = ff_alloc_a53_sei(pic->input_image, 0, &priv->sei_a53cc_data,
> &sei_a53cc_len);
> +        if (err < 0)
> +            return err;
> +        if (priv->sei_a53cc_data != NULL) {
> +            priv->sei_a53cc.itu_t_t35_country_code = 181;
> +            priv->sei_a53cc.data = (uint8_t *)priv->sei_a53cc_data + 1;
> +            priv->sei_a53cc.data_length = sei_a53cc_len - 1;
> +
> +            priv->sei_needed |= SEI_A53_CC;
> +        }
> +    }
> +
>      vpic->CurrPic = (VAPictureH264) {
>          .picture_id          = pic->recon_surface,
>          .frame_idx           = hpic->frame_num,
> @@ -1226,6 +1253,7 @@ static av_cold int
> vaapi_encode_h264_close(AVCodecContext *avctx)
>      ff_cbs_fragment_free(&priv->current_access_unit);
>      ff_cbs_close(&priv->cbc);
>      av_freep(&priv->sei_identifier_string);
> +    av_freep(&priv->sei_a53cc_data);
>  
>      return ff_vaapi_encode_close(avctx);
>  }
> @@ -1252,7 +1280,7 @@ static const AVOption vaapi_encode_h264_options[] = {
>  
>      { "sei", "Set SEI to include",
>        OFFSET(sei), AV_OPT_TYPE_FLAGS,
> -      { .i64 = SEI_IDENTIFIER | SEI_TIMING | SEI_RECOVERY_POINT },
> +      { .i64 = SEI_IDENTIFIER | SEI_TIMING | SEI_RECOVERY_POINT | SEI_A53_CC
> },
>        0, INT_MAX, FLAGS, "sei" },
>      { "identifier", "Include encoder version identifier",
>        0, AV_OPT_TYPE_CONST, { .i64 = SEI_IDENTIFIER },
> @@ -1263,6 +1291,9 @@ static const AVOption vaapi_encode_h264_options[] = {
>      { "recovery_point", "Include recovery points where appropriate",
>        0, AV_OPT_TYPE_CONST, { .i64 = SEI_RECOVERY_POINT },
>        INT_MIN, INT_MAX, FLAGS, "sei" },
> +    { "a53_cc", "Include A/53 caption data",
> +      0, AV_OPT_TYPE_CONST, { .i64 = SEI_A53_CC },
> +      INT_MIN, INT_MAX, FLAGS, "sei" },
>  
>      { "profile", "Set profile (profile_idc and constraint_set*_flag)",
>        OFFSET(profile), AV_OPT_TYPE_INT,
> diff --git a/libavcodec/vaapi_encode_h265.c b/libavcodec/vaapi_encode_h265.c
> index 94b56c6578..f5b85cef6f 100644
> --- a/libavcodec/vaapi_encode_h265.c
> +++ b/libavcodec/vaapi_encode_h265.c
> @@ -27,6 +27,7 @@
>  #include "libavutil/opt.h"
>  #include "libavutil/mastering_display_metadata.h"
>  
> +#include "atsc_a53.h"
>  #include "avcodec.h"
>  #include "cbs.h"
>  #include "cbs_h265.h"
> @@ -40,6 +41,7 @@
>  enum {
>      SEI_MASTERING_DISPLAY       = 0x08,
>      SEI_CONTENT_LIGHT_LEVEL     = 0x10,
> +    SEI_A53_CC                  = 0x20,
>  };
>  
>  typedef struct VAAPIEncodeH265Picture {
> @@ -84,6 +86,8 @@ typedef struct VAAPIEncodeH265Context {
>  
>      SEIRawMasteringDisplayColourVolume sei_mastering_display;
>      SEIRawContentLightLevelInfo        sei_content_light_level;
> +    SEIRawUserDataRegistered           sei_a53cc;
> +    void                              *sei_a53cc_data;
>  
>      CodedBitstreamContext *cbc;
>      CodedBitstreamFragment current_access_unit;
> @@ -226,6 +230,13 @@ static int
> vaapi_encode_h265_write_extra_header(AVCodecContext *avctx,
>              if (err < 0)
>                  goto fail;
>          }
> +        if (priv->sei_needed & SEI_A53_CC) {
> +            err = ff_cbs_sei_add_message(priv->cbc, au, 1,
> +                                         SEI_TYPE_USER_DATA_REGISTERED_ITU_T_
> T35,
> +                                         &priv->sei_a53cc, NULL);
> +            if (err < 0)
> +                goto fail;
> +        }
>  
>          priv->sei_needed = 0;
>  
> @@ -888,6 +899,22 @@ static int
> vaapi_encode_h265_init_picture_params(AVCodecContext *avctx,
>          }
>      }
>  
> +    if (priv->sei & SEI_A53_CC) {
> +        int err;
> +        size_t sei_a53cc_len;
> +        av_freep(&priv->sei_a53cc_data);
> +        err = ff_alloc_a53_sei(pic->input_image, 0, &priv->sei_a53cc_data,
> &sei_a53cc_len);
> +        if (err < 0)
> +            return err;
> +        if (priv->sei_a53cc_data != NULL) {
> +            priv->sei_a53cc.itu_t_t35_country_code = 181;
> +            priv->sei_a53cc.data = (uint8_t *)priv->sei_a53cc_data + 1;
> +            priv->sei_a53cc.data_length = sei_a53cc_len - 1;
> +
> +            priv->sei_needed |= SEI_A53_CC;
> +        }
> +    }
> +
>      vpic->decoded_curr_pic = (VAPictureHEVC) {
>          .picture_id    = pic->recon_surface,
>          .pic_order_cnt = hpic->pic_order_cnt,
> @@ -1355,6 +1382,7 @@ static av_cold int
> vaapi_encode_h265_close(AVCodecContext *avctx)
>  
>      ff_cbs_fragment_free(&priv->current_access_unit);
>      ff_cbs_close(&priv->cbc);
> +    av_freep(&priv->sei_a53cc_data);
>  
>      return ff_vaapi_encode_close(avctx);
>  }
> @@ -1413,7 +1441,7 @@ static const AVOption vaapi_encode_h265_options[] = {
>  
>      { "sei", "Set SEI to include",
>        OFFSET(sei), AV_OPT_TYPE_FLAGS,
> -      { .i64 = SEI_MASTERING_DISPLAY | SEI_CONTENT_LIGHT_LEVEL },
> +      { .i64 = SEI_MASTERING_DISPLAY | SEI_CONTENT_LIGHT_LEVEL | SEI_A53_CC
> },
>        0, INT_MAX, FLAGS, "sei" },
>      { "hdr",
>        "Include HDR metadata for mastering display colour volume "
> @@ -1421,6 +1449,11 @@ static const AVOption vaapi_encode_h265_options[] = {
>        0, AV_OPT_TYPE_CONST,
>        { .i64 = SEI_MASTERING_DISPLAY | SEI_CONTENT_LIGHT_LEVEL },
>        INT_MIN, INT_MAX, FLAGS, "sei" },
> +    { "a53_cc",
> +      "Include A/53 caption data",
> +      0, AV_OPT_TYPE_CONST,
> +      { .i64 = SEI_A53_CC },
> +      INT_MIN, INT_MAX, FLAGS, "sei" },
>  
>      { "tiles", "Tile columns x rows",
>        OFFSET(common.tile_cols), AV_OPT_TYPE_IMAGE_SIZE,
> 
> base-commit: 3bcec58535d395945a390bdc7af4048a7abc60eb


LGTM, will apply.

-Haihao

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2023-01-16  4:10 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-02 19:32 [FFmpeg-devel] [PATCH] avcodec/vaapi_encode_h26x: passthrough A53 CC data as H264/HEVC SEI Aman Karmani
2023-01-05  8:46 ` Xiang, Haihao
2023-01-06 17:15 ` [FFmpeg-devel] [PATCH v2] " Aman Karmani
2023-01-06 17:41   ` [FFmpeg-devel] [PATCH v3] " Aman Karmani
2023-01-06 19:02     ` Andreas Rheinhardt
2023-01-09 18:40     ` [FFmpeg-devel] [PATCH v4] " Aman Karmani
2023-01-16  4:10       ` Xiang, Haihao

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git