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/extract_extradata: filter what Metadata OBUs are included in AV1 extradata
@ 2023-09-18 17:18 James Almer
  2023-09-25 13:53 ` Derek Buitenhuis
  0 siblings, 1 reply; 2+ messages in thread
From: James Almer @ 2023-09-18 17:18 UTC (permalink / raw)
  To: ffmpeg-devel

Only those that are relevant for the entire coded stream should be included.

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/extract_extradata_bsf.c | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)

diff --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".

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

end of thread, other threads:[~2023-09-25 13:53 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-18 17:18 [FFmpeg-devel] [PATCH] avcodec/extract_extradata: filter what Metadata OBUs are included in AV1 extradata James Almer
2023-09-25 13:53 ` Derek Buitenhuis

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