From: James Almer <jamrial@gmail.com>
To: ffmpeg-devel@ffmpeg.org
Subject: [FFmpeg-devel] [PATCH] avcodec/extract_extradata: filter what Metadata OBUs are included in AV1 extradata
Date: Mon, 18 Sep 2023 14:18:26 -0300
Message-ID: <20230918171826.1479-1-jamrial@gmail.com> (raw)
Only those that are relevant for the entire coded stream should be included.
Signed-off-by: James Almer <jamrial@gmail.com>
---
| 27 +++++++++++++++++++++++++++
1 file changed, 27 insertions(+)
--git a/libavcodec/extract_extradata_bsf.c b/libavcodec/extract_extradata_bsf.c
index d5c81a2768..3bf225ee28 100644
--- a/libavcodec/extract_extradata_bsf.c
+++ b/libavcodec/extract_extradata_bsf.c
@@ -58,6 +58,23 @@ static int val_in_array(const int *arr, int len, int val)
return 0;
}
+static int add_metadata(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 extract_extradata_av1(AVBSFContext *ctx, AVPacket *pkt,
uint8_t **data, int *size)
{
@@ -77,6 +94,11 @@ 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->type == AV1_OBU_METADATA && !add_metadata(obu)) {
+ if (s->remove)
+ filtered_size += obu->raw_size;
+ continue;
+ }
extradata_size += obu->raw_size;
if (obu->type == AV1_OBU_SEQUENCE_HEADER)
has_seq = 1;
@@ -115,6 +137,11 @@ static int extract_extradata_av1(AVBSFContext *ctx, AVPacket *pkt,
AV1OBU *obu = &s->av1_pkt.obus[i];
if (val_in_array(extradata_obu_types, nb_extradata_obu_types,
obu->type)) {
+ if (obu->type == AV1_OBU_METADATA && !add_metadata(obu)) {
+ if (s->remove)
+ bytestream2_put_bufferu(&pb_filtered_data, obu->raw_data, obu->raw_size);
+ continue;
+ }
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);
--
2.42.0
_______________________________________________
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".
next reply other threads:[~2023-09-18 17:18 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-18 17:18 James Almer [this message]
2023-09-25 13:53 ` Derek Buitenhuis
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230918171826.1479-1-jamrial@gmail.com \
--to=jamrial@gmail.com \
--cc=ffmpeg-devel@ffmpeg.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
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