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 04F324AD37 for ; Fri, 18 Jul 2025 17:49:08 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTP id 2C69F68DD4F; Fri, 18 Jul 2025 20:49:06 +0300 (EEST) Received: from vidala.pars.ee (vidala.pars.ee [116.203.72.101]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTPS id 0253068DC7C for ; Fri, 18 Jul 2025 20:48:59 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; s=202405r; d=lynne.ee; c=relaxed/relaxed; h=From:To:Subject:Date:Message-ID; t=1752860939; bh=DdelUQBUaZoTYgF1UFxVKkf QfYQU2O5aNmeoxDBbX/8=; b=RWTkrzukuEoiSRqUV0fbAMzdA+ACkrIonKKCH3KT0covitSnT3 r59Mzx8XPrTRpXJORSlGVv9FPHY67hqMC8D+91MJAKH6CCrrYA25ycDuyKs3x4e91MOlYxA+PZ3 U44lIoyzpUENc6HG9NL73Wsbv4aZeoZ0jw1ExpphXfly57sevsqkAOxIVbJPDFRUMoJtWdK+Ajg /jb6oQ3rooWSjaFpw1qdw/odc4v402aTgT/RusMKnbqKGF6JKVvmvDpHwUzqt/zBTf5siQEQI2y f/Du4oeS7Rmika4tzNpcl8VVpyvm4mn6Njv3y5TbV3T/rph96FwJhhtoz3Um2nJSAtw==; DKIM-Signature: v=1; a=ed25519-sha256; s=202405e; d=lynne.ee; c=relaxed/relaxed; h=From:To:Subject:Date:Message-ID; t=1752860939; bh=DdelUQBUaZoTYgF1UFxVKkf QfYQU2O5aNmeoxDBbX/8=; b=HpNFDGnU07DgB9lTDmp3oyCARpraO+E9v1k15Hp09ZI6YLIiV3 oz7k458wXDOgNHMjCQJpsytFUvfV2HnQsqDg==; Message-ID: <705b6cc1-6ea5-4550-a1e7-366e69a6ab84@lynne.ee> Date: Sat, 19 Jul 2025 02:48:56 +0900 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird To: ffmpeg-devel@ffmpeg.org References: <20250718005518.1462-1-jamrial@gmail.com> Content-Language: en-US From: Lynne In-Reply-To: <20250718005518.1462-1-jamrial@gmail.com> Subject: Re: [FFmpeg-devel] [PATCH] avformat/mov: don't assume iloc and iinf entries for each item_id will be in the same order 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 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: On 18/07/2025 09:55, James Almer wrote: > Nothing forbids them to be in any order the muxer desires. > > Fixes demuxing heif samples generated by S1II. > > Signed-off-by: James Almer > --- > libavformat/mov.c | 41 ++++++++++++++++++++++++++--------------- > 1 file changed, 26 insertions(+), 15 deletions(-) > > diff --git a/libavformat/mov.c b/libavformat/mov.c > index 836bdfb4e1..ccaa988e4b 100644 > --- a/libavformat/mov.c > +++ b/libavformat/mov.c > @@ -8739,7 +8739,7 @@ static int mov_read_iloc(MOVContext *c, AVIOContext *pb, MOVAtom atom) > > av_log(c->fc, AV_LOG_TRACE, "iloc: item_count %d\n", item_count); > for (int i = 0; i < item_count; i++) { > - HEIFItem *item = c->heif_item[i]; > + HEIFItem *item = NULL; > int item_id = (version < 2) ? avio_rb16(pb) : avio_rb32(pb); > int offset_type = (version > 0) ? avio_rb16(pb) & 0xf : 0; > > @@ -8765,8 +8765,14 @@ static int mov_read_iloc(MOVContext *c, AVIOContext *pb, MOVAtom atom) > base_offset > INT64_MAX - extent_offset) > return AVERROR_INVALIDDATA; > > - if (!item) > - item = c->heif_item[i] = av_mallocz(sizeof(*item)); > + for (int j = 0; j < c->nb_heif_item; j++) { > + item = c->heif_item[j]; > + if (!item) > + item = c->heif_item[j] = av_mallocz(sizeof(*item)); > + else if (item->item_id != item_id) > + continue; > + break; > + } > if (!item) > return AVERROR(ENOMEM); > > @@ -8776,18 +8782,18 @@ static int mov_read_iloc(MOVContext *c, AVIOContext *pb, MOVAtom atom) > item->is_idat_relative = 1; > item->extent_length = extent_length; > item->extent_offset = base_offset + extent_offset; > - av_log(c->fc, AV_LOG_TRACE, "iloc: item_idx %d, offset_type %d, " > + av_log(c->fc, AV_LOG_TRACE, "iloc: item_idx %d, item->item_id %d, offset_type %d, " > "extent_offset %"PRId64", extent_length %"PRId64"\n", > - i, offset_type, item->extent_offset, item->extent_length); > + i, item->item_id, offset_type, item->extent_offset, item->extent_length); > } > > c->found_iloc = 1; > return atom.size; > } > > -static int mov_read_infe(MOVContext *c, AVIOContext *pb, MOVAtom atom, int idx) > +static int mov_read_infe(MOVContext *c, AVIOContext *pb, MOVAtom atom) > { > - HEIFItem *item; > + HEIFItem *item = NULL; > AVBPrint item_name; > int64_t size = atom.size; > uint32_t item_type; > @@ -8827,22 +8833,27 @@ static int mov_read_infe(MOVContext *c, AVIOContext *pb, MOVAtom atom, int idx) > if (size > 0) > avio_skip(pb, size); > > - item = c->heif_item[idx]; > - if (!item) > - item = c->heif_item[idx] = av_mallocz(sizeof(*item)); > + for (int i = 0; i < c->nb_heif_item; i++) { > + item = c->heif_item[i]; > + if (!item) > + item = c->heif_item[i] = av_mallocz(sizeof(*item)); > + else if (item->item_id != item_id) > + continue; > + break; > + } > if (!item) > return AVERROR(ENOMEM); > > if (ret) > - av_bprint_finalize(&item_name, &c->heif_item[idx]->name); > - c->heif_item[idx]->item_id = item_id; > - c->heif_item[idx]->type = item_type; > + av_bprint_finalize(&item_name, &item->name); > + item->item_id = item_id; > + item->type = item_type; > > switch (item_type) { > case MKTAG('a','v','0','1'): > case MKTAG('j','p','e','g'): > case MKTAG('h','v','c','1'): > - ret = heif_add_stream(c, c->heif_item[idx]); > + ret = heif_add_stream(c, item); > if (ret < 0) > return ret; > break; > @@ -8884,7 +8895,7 @@ static int mov_read_iinf(MOVContext *c, AVIOContext *pb, MOVAtom atom) > ret = AVERROR_INVALIDDATA; > goto fail; > } > - ret = mov_read_infe(c, pb, infe, i); > + ret = mov_read_infe(c, pb, infe); > if (ret < 0) > goto fail; > if (!ret) Thanks, works perfectly when combined with the other 2 patches, all thumbnails and streams are demuxed properly. _______________________________________________ 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".