1
0

avcodec/vaapi_encode_h26x: passthrough A53 CC data as H264/HEVC SEI

Signed-off-by: Aman Karmani <aman@tmm1.net>
This commit is contained in:
Aman Karmani 2023-01-09 18:40:24 +00:00 committed by Haihao Xiang
parent 7491545320
commit f5f1c1fd6b
3 changed files with 68 additions and 4 deletions

4
configure vendored
View File

@ -3181,7 +3181,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"
@ -3202,7 +3202,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"

View File

@ -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"
@ -41,6 +42,7 @@ enum {
SEI_TIMING = 0x01,
SEI_IDENTIFIER = 0x02,
SEI_RECOVERY_POINT = 0x04,
SEI_A53_CC = 0x08,
};
// Random (version 4) ISO 11578 UUID.
@ -99,6 +101,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;
@ -249,6 +253,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;
@ -675,6 +686,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,
@ -1220,6 +1247,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);
}
@ -1246,7 +1274,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 },
@ -1257,6 +1285,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,

View File

@ -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"
@ -41,6 +42,7 @@
enum {
SEI_MASTERING_DISPLAY = 0x08,
SEI_CONTENT_LIGHT_LEVEL = 0x10,
SEI_A53_CC = 0x20,
};
typedef struct VAAPIEncodeH265Picture {
@ -85,6 +87,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;
@ -227,6 +231,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;
@ -882,6 +893,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,
@ -1349,6 +1376,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);
}
@ -1407,7 +1435,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 "
@ -1415,6 +1443,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,