Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: Eric Joyner <erj@erj.cc>
To: ffmpeg-devel@ffmpeg.org
Cc: Eric Joyner <erj@erj.cc>
Subject: [FFmpeg-devel] [PATCH 1/2] libavformat: Support multiple thumbnails in HEIF
Date: Wed, 16 Jul 2025 19:30:01 -0700
Message-ID: <20250717023057.678-2-erj@erj.cc> (raw)
In-Reply-To: <20250717023057.678-1-erj@erj.cc>

Prevents ffmpeg/ffprobe from erroring out when reading an HEIF that
contains multiple hvcC thumbnails (e.g. from a Nikon Z6III camera).

Before, move_read_iref_thmb() would always override the stored
thmb_item_id in the MOVContext with each new read thumbnail, causing a
stream and item_id mismatch later in mov_parse_heif_items(), resulting
in the "HEIF thumbnail doesn't reference a stream" error message.

To solve this,

- Turn thmb_item_id into an array of IDs because multiple thumbnails can
  exist
- Change check in mov_parse_heif_items() to compare against all stored
  thumbnail IDs to see if any item missing a stream is in the list of
  thumbnail IDs.

Signed-off-by: Eric Joyner <erj@erj.cc>
---
 libavformat/isom.h |  3 ++-
 libavformat/mov.c  | 24 +++++++++++++++++-------
 2 files changed, 19 insertions(+), 8 deletions(-)

diff --git a/libavformat/isom.h b/libavformat/isom.h
index 10f882806e..94c9c65989 100644
--- a/libavformat/isom.h
+++ b/libavformat/isom.h
@@ -376,7 +376,8 @@ typedef struct MOVContext {
     int nb_heif_item;
     HEIFGrid *heif_grid;
     int nb_heif_grid;
-    int thmb_item_id;
+    int* thmb_item_id;
+    int nb_thmb_item;
     int64_t idat_offset;
     int interleaved_read;
 } MOVContext;
diff --git a/libavformat/mov.c b/libavformat/mov.c
index c935bbf0bf..7010e13b50 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -8972,6 +8972,7 @@ static int mov_read_iref_dimg(MOVContext *c, AVIOContext *pb, int version)
 
 static int mov_read_iref_thmb(MOVContext *c, AVIOContext *pb, int version)
 {
+    int *thmb_item_id;
     int entries;
     int to_item_id, from_item_id = version ? avio_rb32(pb) : avio_rb16(pb);
 
@@ -8986,10 +8987,15 @@ static int mov_read_iref_thmb(MOVContext *c, AVIOContext *pb, int version)
     if (to_item_id != c->primary_item_id)
         return 0;
 
-    c->thmb_item_id = from_item_id;
+    /* Put thumnbail IDs into an array */
+    thmb_item_id = av_dynarray2_add((void **)&c->thmb_item_id, &c->nb_thmb_item,
+                                    sizeof(*c->thmb_item_id),
+                                    (const void *)&from_item_id);
+    if (!thmb_item_id)
+        return AVERROR(ENOMEM);
 
-    av_log(c->fc, AV_LOG_TRACE, "thmb: from_item_id %d, entries %d\n",
-           from_item_id, entries);
+    av_log(c->fc, AV_LOG_TRACE, "thmb: from_item_id %d, entries %d, nb_thmb: %d\n",
+           from_item_id, entries, c->nb_thmb_item);
 
     return 0;
 }
@@ -9859,6 +9865,7 @@ static int mov_read_close(AVFormatContext *s)
         av_freep(&mov->heif_grid[i].tile_item_list);
     }
     av_freep(&mov->heif_grid);
+    av_freep(&mov->thmb_item_id);
 
     return 0;
 }
@@ -10323,9 +10330,12 @@ static int mov_parse_heif_items(AVFormatContext *s)
         if (!item)
             continue;
         if (!item->st) {
-            if (item->item_id == mov->thmb_item_id) {
-                av_log(s, AV_LOG_ERROR, "HEIF thumbnail doesn't reference a stream\n");
-                return AVERROR_INVALIDDATA;
+            for (int i = 0; i < mov->nb_thmb_item; i++) {
+                if (item->item_id == mov->thmb_item_id[i]) {
+                    av_log(s, AV_LOG_ERROR, "HEIF thumbnail ID %d doesn't reference a stream\n",
+                           item->item_id);
+                    return AVERROR_INVALIDDATA;
+                }
             }
             continue;
         }
@@ -10476,7 +10486,7 @@ static int mov_read_header(AVFormatContext *s)
 
     mov->fc = s;
     mov->trak_index = -1;
-    mov->thmb_item_id = -1;
+    mov->thmb_item_id = NULL;
     mov->primary_item_id = -1;
     mov->cur_item_id = -1;
     /* .mov and .mp4 aren't streamable anyway (only progressive download if moov is before mdat) */
-- 
2.49.0.windows.1

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

  reply	other threads:[~2025-07-17  2:31 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-07-17  2:30 [FFmpeg-devel] [PATCH 0/2] Fix Nikon HEIF decoding error Eric Joyner
2025-07-17  2:30 ` Eric Joyner [this message]
2025-07-17  2:30 ` [FFmpeg-devel] [PATCH 2/2] libavformat: Enable jpeg streams in HEIF MOVContext Eric Joyner
2025-07-17 11:54   ` Lynne
2025-07-17 15:54 ` [FFmpeg-devel] [PATCH 0/2] Fix Nikon HEIF decoding error compn

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=20250717023057.678-2-erj@erj.cc \
    --to=erj@erj.cc \
    --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