Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: Thilo Borgmann via ffmpeg-devel <ffmpeg-devel@ffmpeg.org>
To: ffmpeg-devel@ffmpeg.org
Cc: Thilo Borgmann <thilo.borgmann@mail.de>
Subject: [FFmpeg-devel] [PATCH v13 8/8] avcodec/webp: export XMP metadata
Date: Fri, 21 Jun 2024 12:43:23 +0200
Message-ID: <20240621104323.92453-9-thilo.borgmann@mail.de> (raw)
In-Reply-To: <20240621104323.92453-1-thilo.borgmann@mail.de>

From: Thilo Borgmann via ffmpeg-devel <ffmpeg-devel@ffmpeg.org>

---
 libavcodec/webp.c | 42 ++++++++++++++++++++++++++++++++++++------
 1 file changed, 36 insertions(+), 6 deletions(-)

diff --git a/libavcodec/webp.c b/libavcodec/webp.c
index bacf605ff2..c8be673060 100644
--- a/libavcodec/webp.c
+++ b/libavcodec/webp.c
@@ -38,8 +38,8 @@
  * @author Josef Zlomek, Pexeso Inc. <josef@pex.com>
  * Animation
  *
- * Unimplemented:
- *   - XMP metadata
+ * @author Thilo Borgmann <thilo.borgmann _at_ mail.de>
+ * XMP metadata
  */
 
 #include "libavutil/common.h"
@@ -220,6 +220,7 @@ typedef struct WebPContext {
     int has_exif;                       /* set after an EXIF chunk has been processed */
     int has_iccp;                       /* set after an ICCP chunk has been processed */
     int duration;                       /* frame duration in an animation */
+    int has_xmp;                        /* set after an XMP chunk has been processed */
     int width;                          /* image width */
     int height;                         /* image height */
     int vp8x_flags;                     /* global flags from VP8X chunk */
@@ -1469,6 +1470,7 @@ static int webp_decode_frame_common(AVCodecContext *avctx, uint8_t *data, int si
     // reset metadata bit for each packet
     s->has_exif      = 0;
     s->has_iccp      = 0;
+    s->has_xmp       = 0;
 
     while (bytestream2_get_bytes_left(&gb) > 8) {
         char chunk_str[5] = { 0 };
@@ -1500,6 +1502,7 @@ static int webp_decode_frame_common(AVCodecContext *avctx, uint8_t *data, int si
             s->canvas_height = 0;
             s->has_exif      = 0;
             s->has_iccp      = 0;
+            s->has_xmp       = 0;
             ff_progress_frame_unref(&s->canvas_frame);
             break;
         case MKTAG('V', 'P', '8', ' '):
@@ -1682,12 +1685,39 @@ exif_end:
             }
             s->vp8x_flags |= VP8X_FLAG_ANIMATION;
             break;
-        case MKTAG('X', 'M', 'P', ' '):
-            AV_WL32(chunk_str, chunk_type);
-            av_log(avctx, AV_LOG_WARNING, "skipping unsupported chunk: %s\n",
-                   chunk_str);
+        case MKTAG('X', 'M', 'P', ' '): {
+            GetByteContext xmp_gb;
+            AVDictionary **xmp_metadata = NULL;
+            uint8_t *buffer;
+            int xmp_offset = bytestream2_tell(&gb);
+
+            if (s->has_xmp) {
+                av_log(avctx, AV_LOG_VERBOSE, "Ignoring extra XMP chunk\n");
+                goto xmp_end;
+            }
+            if (!(s->vp8x_flags & VP8X_FLAG_XMP_METADATA))
+                av_log(avctx, AV_LOG_WARNING,
+                       "XMP chunk present, but XMP bit not set in the "
+                       "VP8X header\n");
+
+            // there are at least chunk_size bytes left to read
+            buffer = av_malloc(chunk_size + 1);
+            if (!buffer) {
+                return AVERROR(ENOMEM);
+            }
+
+            s->has_xmp = 1;
+            bytestream2_init(&xmp_gb, data + xmp_offset, size - xmp_offset);
+            bytestream2_get_buffer(&xmp_gb, buffer, chunk_size);
+            buffer[chunk_size] = '\0';
+
+            xmp_metadata = (s->vp8x_flags & VP8X_FLAG_ANIMATION) ? &p->metadata : &s->frame->metadata;
+            av_dict_set(xmp_metadata, "xmp", buffer, AV_DICT_DONT_STRDUP_VAL);
+
+xmp_end:
             bytestream2_skip(&gb, chunk_size);
             break;
+            }
         default:
             AV_WL32(chunk_str, chunk_type);
             av_log(avctx, AV_LOG_VERBOSE, "skipping unknown chunk: %s\n",
-- 
2.39.3 (Apple Git-146)

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

      parent reply	other threads:[~2024-06-21 10:44 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-21 10:43 [FFmpeg-devel] [PATCH v13 0/8] [WIP] webp: add support for animated WebP decoding Thilo Borgmann via ffmpeg-devel
2024-06-21 10:43 ` [FFmpeg-devel] [PATCH v13 1/8] avcodec/webp: remove unused definitions Thilo Borgmann via ffmpeg-devel
2024-06-21 10:43 ` [FFmpeg-devel] [PATCH v13 2/8] avcodec/webp: separate VP8 decoding Thilo Borgmann via ffmpeg-devel
2024-06-21 11:52   ` Anton Khirnov
2024-06-21 10:43 ` [FFmpeg-devel] [PATCH v13 3/8] avcodec/bsf: Add awebp2webp bitstream filter Thilo Borgmann via ffmpeg-devel
2024-06-21 10:43 ` [FFmpeg-devel] [PATCH v13 4/8] libavcodec/webp: add support for animated WebP Thilo Borgmann via ffmpeg-devel
2024-06-21 10:43 ` [FFmpeg-devel] [PATCH v13 5/8] avcodec/webp: make init_canvas_frame static Thilo Borgmann via ffmpeg-devel
2024-06-21 10:43 ` [FFmpeg-devel] [PATCH v13 6/8] libavformat/webp: add WebP demuxer Thilo Borgmann via ffmpeg-devel
2024-06-21 10:43 ` [FFmpeg-devel] [PATCH v13 7/8] fate: add test for animated WebP Thilo Borgmann via ffmpeg-devel
2024-06-21 10:43 ` Thilo Borgmann via ffmpeg-devel [this message]

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=20240621104323.92453-9-thilo.borgmann@mail.de \
    --to=ffmpeg-devel@ffmpeg.org \
    --cc=thilo.borgmann@mail.de \
    /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