diff options
author | James Almer <jamrial@gmail.com> | 2023-09-18 12:21:49 -0300 |
---|---|---|
committer | James Almer <jamrial@gmail.com> | 2023-09-19 13:00:08 -0300 |
commit | ac64800edd341af80558b96a0213ce6d2d99cc2c (patch) | |
tree | 36500bc8e7a7374f9e2ef1cebf2e33124d92e1a4 | |
parent | abc346de735cae1b9316b7b853aa2d2661ab40fb (diff) | |
download | ffmpeg-ac64800edd341af80558b96a0213ce6d2d99cc2c.tar.gz |
avcodec/extract_extradata: filter what Metadata OBUs are included in AV1 extradata
Only those that are relevant for the entire coded stream should be included.
Signed-off-by: James Almer <jamrial@gmail.com>
-rw-r--r-- | libavcodec/extract_extradata_bsf.c | 40 |
1 files changed, 34 insertions, 6 deletions
diff --git a/libavcodec/extract_extradata_bsf.c b/libavcodec/extract_extradata_bsf.c index d5c81a2768..efc843736b 100644 --- a/libavcodec/extract_extradata_bsf.c +++ b/libavcodec/extract_extradata_bsf.c @@ -58,16 +58,45 @@ static int val_in_array(const int *arr, int len, int val) return 0; } -static int extract_extradata_av1(AVBSFContext *ctx, AVPacket *pkt, - uint8_t **data, int *size) +static int metadata_is_global(const AV1OBU *obu) +{ + static const int metadata_obu_types[] = { + AV1_METADATA_TYPE_HDR_CLL, AV1_METADATA_TYPE_HDR_MDCV, + }; + GetBitContext gb; + int metadata_type; + + if (init_get_bits(&gb, obu->data, obu->size_bits) < 0) + return 0; + + metadata_type = leb128(&gb); + + return val_in_array(metadata_obu_types, FF_ARRAY_ELEMS(metadata_obu_types), + metadata_type); +} + +static int obu_is_global(const AV1OBU *obu) { static const int extradata_obu_types[] = { AV1_OBU_SEQUENCE_HEADER, AV1_OBU_METADATA, }; + + if (!val_in_array(extradata_obu_types, FF_ARRAY_ELEMS(extradata_obu_types), + obu->type)) + return 0; + if (obu->type != AV1_OBU_METADATA) + return 1; + + return metadata_is_global(obu); +} + +static int extract_extradata_av1(AVBSFContext *ctx, AVPacket *pkt, + uint8_t **data, int *size) +{ + ExtractExtradataContext *s = ctx->priv_data; int extradata_size = 0, filtered_size = 0; - int nb_extradata_obu_types = FF_ARRAY_ELEMS(extradata_obu_types); int i, has_seq = 0, ret = 0; ret = ff_av1_packet_split(&s->av1_pkt, pkt->data, pkt->size, ctx); @@ -76,7 +105,7 @@ static int extract_extradata_av1(AVBSFContext *ctx, AVPacket *pkt, for (i = 0; i < s->av1_pkt.nb_obus; i++) { AV1OBU *obu = &s->av1_pkt.obus[i]; - if (val_in_array(extradata_obu_types, nb_extradata_obu_types, obu->type)) { + if (obu_is_global(obu)) { extradata_size += obu->raw_size; if (obu->type == AV1_OBU_SEQUENCE_HEADER) has_seq = 1; @@ -113,8 +142,7 @@ static int extract_extradata_av1(AVBSFContext *ctx, AVPacket *pkt, for (i = 0; i < s->av1_pkt.nb_obus; i++) { AV1OBU *obu = &s->av1_pkt.obus[i]; - if (val_in_array(extradata_obu_types, nb_extradata_obu_types, - obu->type)) { + if (obu_is_global(obu)) { bytestream2_put_bufferu(&pb_extradata, obu->raw_data, obu->raw_size); } else if (s->remove) { bytestream2_put_bufferu(&pb_filtered_data, obu->raw_data, obu->raw_size); |