[PR] avcodec/pngdec: preserve packet metadata (PR #24074)

qaq03101 via ffmpeg-devel <[email protected]>
Newsgroups gmane.comp.video.ffmpeg.devel
Message-ID <178643546266.59.3967605703884448499@29965ddac10e>
PR #24074 opened by qaq03101
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/24074
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/24074.patch

# Summary of changes

Preserve metadata copied from packet side data when decoding PNG images by merging PNG metadata into the output frame.

Fixes #23390.


>From 1817815d401023fc33b5e80c9f2e8ad2a0b4de6a Mon Sep 17 00:00:00 2001
From: qaq03101 <[email protected]>
Date: Tue, 11 Aug 2026 15:54:32 +0800
Subject: [PATCH] avcodec/pngdec: preserve packet metadata

Swapping metadata dictionaries drops entries already copied from
packet side data, including image2 source path metadata.

Copy PNG metadata into the output frame instead.

Reported-by: Icecream95
Fixes #23390.
Signed-off-by: qaq03101 <[email protected]>
---
 libavcodec/pngdec.c               | 6 +++++-
 tests/fate/image.mak              | 3 ++-
 tests/ref/fate/png-frame-metadata | 1 +
 3 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/libavcodec/pngdec.c b/libavcodec/pngdec.c
index 0030fa5615..3af36f47e1 100644
--- a/libavcodec/pngdec.c
+++ b/libavcodec/pngdec.c
@@ -1865,7 +1865,11 @@ static int output_frame(PNGDecContext *s, AVFrame *f)
         stereo3d->flags = s->stereo_mode ? 0 : AV_STEREO3D_FLAG_INVERT;
     }
 
-    FFSWAP(AVDictionary*, f->metadata, s->frame_metadata);
+    ret = av_dict_copy(&f->metadata, s->frame_metadata, 0);
+    if (ret < 0)
+        goto fail;
+
+    av_dict_free(&s->frame_metadata);
 
     return 0;
 fail:
diff --git a/tests/fate/image.mak b/tests/fate/image.mak
index e9fe059ead..e94a13f077 100644
--- a/tests/fate/image.mak
+++ b/tests/fate/image.mak
@@ -415,7 +415,8 @@ FATE_PNG += fate-png-int-rgb24
 fate-png-int-rgb24: CMD = framecrc -i $(TARGET_SAMPLES)/png1/lena-int_rgb24.png -sws_flags +accurate_rnd+bitexact
 
 FATE_PNG_PROBE += fate-png-frame-metadata
-fate-png-frame-metadata: CMD = run ffprobe$(PROGSSUF)$(EXESUF) -show_entries frame_tags \
+fate-png-frame-metadata: CMD = run ffprobe$(PROGSSUF)$(EXESUF) -f image2 \
+    -export_path_metadata 1 -show_entries frame_tags=gamma,Software,lavf.image2dec.source_basename \
     -i $(TARGET_SAMPLES)/filter/pixelart0.png
 
 FATE_PNG_PROBE += fate-png-side-data
diff --git a/tests/ref/fate/png-frame-metadata b/tests/ref/fate/png-frame-metadata
index 7c6d1916eb..faae1348f5 100644
--- a/tests/ref/fate/png-frame-metadata
+++ b/tests/ref/fate/png-frame-metadata
@@ -1,4 +1,5 @@
 [FRAME]
+TAG:lavf.image2dec.source_basename=pixelart0.png
 TAG:gamma=45455/100000
 TAG:Software=GLDPNG ver 3.4
 [/FRAME]
-- 
2.52.0

_______________________________________________
ffmpeg-devel mailing list -- [email protected]
To unsubscribe send an email to [email protected]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.