From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.ffmpeg.org (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTPS id 0CE3549ACD for ; Thu, 17 Jul 2025 02:31:29 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTP id 068D668EEC2; Thu, 17 Jul 2025 05:31:18 +0300 (EEST) Received: from mail-pg1-f171.google.com (mail-pg1-f171.google.com [209.85.215.171]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTPS id A557F68EC2B for ; Thu, 17 Jul 2025 05:31:09 +0300 (EEST) Received: by mail-pg1-f171.google.com with SMTP id 41be03b00d2f7-af51596da56so366014a12.0 for ; Wed, 16 Jul 2025 19:31:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=erj.cc; s=google; t=1752719467; x=1753324267; darn=ffmpeg.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=P7YleNXURmOZ7uJuhIa0UhcLZw5eV+8E98/m+a1W/ZA=; b=T5flu7EcqyF2oQpiXJwx+GtyqjdTZQxlyAbkvVW8b23KC6mMY7ewGInTkQcKWqVcZ/ NuMZQNe5aZ9jQnzguKCsX0kjXS6tYi+emhxW0OXbXAf/U9oGzHQiDGVifgdEo1UpRizb udegMwKJ3N0raJeOkmOsCar2R38x30CmMl6PIgib0HHTfOM6DeMAZD+6Dwfs7MP4nSaq Ij4glhFGYrop0KS8tzhyOIf7OAJEHtYRvCMDb4HRcgB6c27knpJN3tiVEmV9G5Nwx076 bG6ckcQUA6/kkIZJRQMaGoO2/vNLZ8NV77anl0C/6yWqU4lsBVX/Hhl4/mZ9+Z5KsGMg 04lw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752719467; x=1753324267; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=P7YleNXURmOZ7uJuhIa0UhcLZw5eV+8E98/m+a1W/ZA=; b=FFRmz88TA2NG8RXBSc9x8z9+lOVZAA2nyFe70Nl45mdMZiToHoiicPgbTVV8/U/YvT fHpi5vCFDm0hPsiYHJWq+CQ3i440mEyszXCwuY8+7TcYONvR3oczVIUW9oBpY3BHtjpt lmQywomoq2SgzrsEX6zK83yjbvHsngQjS4WP0afPa5VxLZh3wr19TlOCo7x3PyzSdHyD 6yIyeHFaid3zP3xDD16MR/lT1YU9JybZe22wmunm9JnOTNDMqikQFaqHxRXGHdLPhgwn r/pwtAiLiRXt1GRG6vgf7X8wp0hD/2agrSOmvcaZValHuMjHfWg7RDVEs1FTgXHFp2t8 GY/w== X-Gm-Message-State: AOJu0YxjZ9Nk10KkbGtdqzEQZ9Oi1U0B/No6jNf2erbAnWyFqBAGqGWl +1XGs5t7s4H/udblFU9s5+h/Bkw1uOWnMNWWe9zVL1MIgdv7Hw1luTx7Fk9vH2t4n8S76ydKxbK XYNAu X-Gm-Gg: ASbGnctXvb3fBnygD7RIx6VkBgUC1VMPbEpg4IMQM1H1xSSEo1n4KW80ZfAvcuOIkVz MhSnENKzQoYU+rOyXWeujNUSqmuGwpew1xh9BLHUENMvoQO0R67hLs4Zst8NZNaYPkPFnjsSv9b 1PWPxZ7XLtsbfnnIIwy/uNAp1d9jlMDGpqMUU7wzFDOKnam3lxp8BDJEYjU8duOB3x1cXfrj6B+ STFs5TUbEzH3qfTA7uiCMl4Vlkp1fV5RhgoyHEn/iFORi+itiZ66thvslXDboM0BwL1gZJ6eBAb yduXch9B41PPV210VPSP6KAWwHrdSClej9eyQAe5chI7x55Q9S8lsfSvJPDLEhVVpvI6OZLV97O //I+Fn6NDNALFWLLLo4AnLIxBG8JhaiJHhw== X-Google-Smtp-Source: AGHT+IHxqnmeSv9x11G/8BUFtcGWNfu8CMzAwMZupBY58xpI85Ec1+BwCYbs1+JRdQN3Mi2QEukVnA== X-Received: by 2002:a17:902:ce05:b0:234:c549:d9f1 with SMTP id d9443c01a7336-23e25770c34mr61887225ad.47.1752719467166; Wed, 16 Jul 2025 19:31:07 -0700 (PDT) Received: from localhost.localdomain ([50.53.68.99]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-23de4333b39sm139240575ad.161.2025.07.16.19.31.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Jul 2025 19:31:06 -0700 (PDT) From: Eric Joyner To: ffmpeg-devel@ffmpeg.org Date: Wed, 16 Jul 2025 19:30:01 -0700 Message-ID: <20250717023057.678-2-erj@erj.cc> X-Mailer: git-send-email 2.49.0.windows.1 In-Reply-To: <20250717023057.678-1-erj@erj.cc> References: <20250717023057.678-1-erj@erj.cc> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/2] libavformat: Support multiple thumbnails in HEIF X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Eric Joyner Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: 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 --- 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".