From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id CE987489EF for ; Mon, 22 Jan 2024 21:12:44 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 4706668CBD9; Mon, 22 Jan 2024 23:12:42 +0200 (EET) Received: from mail-pf1-f173.google.com (mail-pf1-f173.google.com [209.85.210.173]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id AA25D68CACC for ; Mon, 22 Jan 2024 23:12:35 +0200 (EET) Received: by mail-pf1-f173.google.com with SMTP id d2e1a72fcca58-6dbcfef55dcso2125690b3a.1 for ; Mon, 22 Jan 2024 13:12:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1705957953; x=1706562753; darn=ffmpeg.org; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=rUL/27vTTM0BEsyorieeReL9My2RjK2h3iGTE2UgERU=; b=Tv5Pj8XeAUoh+NJxsfZFzJrhtpT3bGAVew+gHSHwQSOHIkQwJRAA0XgHRxToEB0oww w+LnnqPzJ74dUrOul84vLLK99U2V7XyAa7O8dDGqwy2p4XYo3ir3s8AjyuE7by5TLKwm LSewT5eAlGJd+0Rphky9Bh63xlXEUEHbM/XS7euEGRgijRZz/TgcWI346gBN3rwTH14a weTawHEGobZR4BmKmoNCQTuBDhq/xUXGPsClMawi4dRMSgZGrkM09wkeo7FTIH/Q/hAh owTzyayRKt34NsTnA6eBbZo7debwHdJcTMZ7tYfNKkx0afsmnI/QeaI7IFqHMfi8GzIz zq1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705957953; x=1706562753; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=rUL/27vTTM0BEsyorieeReL9My2RjK2h3iGTE2UgERU=; b=t1KTowDGSc/aGGuyJ3dItyneQjK+WYTa9opeqKmKu7YuHupm+ymw8ZIZz+qNyYtOms HDC4Mywywj0jHmUwOyNfaVwnqaJg1iz+cscUg2j8ipJ+64qncLzA2BKK3N08IMnlxpyg QZLal7vDQ1ORj++WV8qLpMiDxH9CSeDEnDHNttL6PVDmtS9EuGY8oGiZ0y/IwBK/j3Mu OAqhTQ4qbe/rII6HFHSVCLUaPMMbYMm6bv4MSi+3wVyW4OwCRYLr20h/HyNzfszT6crx Mp/6jV6H5CnYwr/t744/TRdC6cLxr3oBK7BnCLtENBg8XPb8Wm4e6RCgHswDv0JwPmOR RkxQ== X-Gm-Message-State: AOJu0YzzA87LufU/if8JgvFKJnQqzVxklCFZq+EmFioxd0QM2oI/5iFd mth9tRUj8CZLIDA5tZFyPRWhq4Nwibjma82TDvjRXY2o1/oNwUYeQrSlFgTT X-Google-Smtp-Source: AGHT+IGiU5zn0YO9GQLooPCJZyuFCvvstJO78lWvgA6xV28qAjPY0mZB1GxS5GR/05lSq5ScabaL9w== X-Received: by 2002:a05:6a00:1401:b0:6da:e246:5c2 with SMTP id l1-20020a056a00140100b006dae24605c2mr5434272pfu.55.1705957952469; Mon, 22 Jan 2024 13:12:32 -0800 (PST) Received: from localhost.localdomain (host197.190-225-105.telecom.net.ar. [190.225.105.197]) by smtp.gmail.com with ESMTPSA id l198-20020a633ecf000000b005cda4d88933sm8889073pga.43.2024.01.22.13.12.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jan 2024 13:12:31 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Mon, 22 Jan 2024 18:12:21 -0300 Message-ID: <20240122211221.8666-1-jamrial@gmail.com> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] avformat/mov: ignore item boxes for animated 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 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: Fixes a regression since d9fed9df2a, where the single animated stream would be exported twice as two independent streams. Signed-off-by: James Almer --- libavformat/isom.h | 1 + libavformat/mov.c | 141 +++++++++++++++++++++++++++++---------------- 2 files changed, 93 insertions(+), 49 deletions(-) diff --git a/libavformat/isom.h b/libavformat/isom.h index 2cf456fee1..21caaac256 100644 --- a/libavformat/isom.h +++ b/libavformat/isom.h @@ -280,6 +280,7 @@ typedef struct MOVContext { int64_t duration; ///< duration of the longest track int found_moov; ///< 'moov' atom has been found int found_iloc; ///< 'iloc' atom has been found + int found_iinf; ///< 'iinf' atom has been found int found_mdat; ///< 'mdat' atom has been found int found_hdlr_mdta; ///< 'hdlr' atom with type 'mdta' has been found int trak_index; ///< Index of the current 'trak' diff --git a/libavformat/mov.c b/libavformat/mov.c index 5cb907e120..72c3fff4a4 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -81,6 +81,7 @@ typedef struct MOVParseTableEntry { static int mov_read_default(MOVContext *c, AVIOContext *pb, MOVAtom atom); static int mov_read_mfra(MOVContext *c, AVIOContext *f); +static void mov_free_stream_context(AVFormatContext *s, AVStream *st); static int64_t add_ctts_entry(MOVCtts** ctts_data, unsigned int* ctts_count, unsigned int* allocated_size, int count, int duration); @@ -4639,6 +4640,17 @@ static int mov_read_trak(MOVContext *c, AVIOContext *pb, MOVAtom atom) MOVStreamContext *sc; int ret; + if (c->found_iinf) { + // * For animated heif, if the iinf box showed up before the moov + // box, we need to clear all the streams read in the former. + for (int i = c->fc->nb_streams - 1; i >= 0; i--) { + mov_free_stream_context(c->fc, c->fc->streams[i]); + ff_remove_stream(c->fc, c->fc->streams[i]); + } + av_freep(&c->heif_info); + c->heif_info_size = c->found_iinf = c->found_iloc = 0; + } + st = avformat_new_stream(c->fc, NULL); if (!st) return AVERROR(ENOMEM); st->id = -1; @@ -7768,8 +7780,9 @@ static int mov_read_iloc(MOVContext *c, AVIOContext *pb, MOVAtom atom) uint64_t base_offset, extent_offset, extent_length; uint8_t value; - if (c->found_iloc) { - av_log(c->fc, AV_LOG_INFO, "Duplicate iloc box found\n"); + if (c->found_moov) { + // * For animated heif, we don't care about the iloc box as all the + // necessary information can be found in the moov box. return 0; } @@ -7891,6 +7904,16 @@ static int mov_read_iinf(MOVContext *c, AVIOContext *pb, MOVAtom atom) int entry_count; int version, ret; + if (c->found_iinf) { + av_log(c->fc, AV_LOG_WARNING, "Duplicate iinf box found\n"); + return 0; + } + if (c->found_moov) { + // * For animated heif, we don't care about the iinf box as all the + // necessary information can be found in the moov box. + return 0; + } + version = avio_r8(pb); avio_rb24(pb); // flags. entry_count = version ? avio_rb32(pb) : avio_rb16(pb); @@ -7914,6 +7937,7 @@ static int mov_read_iinf(MOVContext *c, AVIOContext *pb, MOVAtom atom) return ret; } + c->found_iinf = 1; return 0; } @@ -7927,6 +7951,13 @@ static int mov_read_iref(MOVContext *c, AVIOContext *pb, MOVAtom atom) static int mov_read_ispe(MOVContext *c, AVIOContext *pb, MOVAtom atom) { uint32_t width, height; + + if (c->found_moov) { + // * For animated heif, we don't care about the ispe box as all the + // necessary information can be found in the moov box. + return 0; + } + avio_r8(pb); /* version */ avio_rb24(pb); /* flags */ width = avio_rb32(pb); @@ -7961,6 +7992,12 @@ static int mov_read_iprp(MOVContext *c, AVIOContext *pb, MOVAtom atom) int version, flags; int ret; + if (c->found_moov) { + // * For animated heif, we don't care about the iprp box as all the + // necessary information can be found in the moov box. + return 0; + } + a.size = avio_rb32(pb); a.type = avio_rl32(pb); @@ -8581,6 +8618,58 @@ static void mov_free_encryption_index(MOVEncryptionIndex **index) { av_freep(index); } +static void mov_free_stream_context(AVFormatContext *s, AVStream *st) +{ + MOVStreamContext *sc = st->priv_data; + + if (!sc) + return; + + av_freep(&sc->ctts_data); + for (int i = 0; i < sc->drefs_count; i++) { + av_freep(&sc->drefs[i].path); + av_freep(&sc->drefs[i].dir); + } + av_freep(&sc->drefs); + + sc->drefs_count = 0; + + if (!sc->pb_is_copied) + ff_format_io_close(s, &sc->pb); + + sc->pb = NULL; + av_freep(&sc->chunk_offsets); + av_freep(&sc->stsc_data); + av_freep(&sc->sample_sizes); + av_freep(&sc->keyframes); + av_freep(&sc->stts_data); + av_freep(&sc->sdtp_data); + av_freep(&sc->stps_data); + av_freep(&sc->elst_data); + av_freep(&sc->rap_group); + av_freep(&sc->sync_group); + av_freep(&sc->sgpd_sync); + av_freep(&sc->sample_offsets); + av_freep(&sc->open_key_samples); + av_freep(&sc->display_matrix); + av_freep(&sc->index_ranges); + + if (sc->extradata) + for (int i = 0; i < sc->stsd_count; i++) + av_free(sc->extradata[i]); + av_freep(&sc->extradata); + av_freep(&sc->extradata_size); + + mov_free_encryption_index(&sc->cenc.encryption_index); + av_encryption_info_free(sc->cenc.default_encrypted_sample); + av_aes_ctr_free(sc->cenc.aes_ctr); + + av_freep(&sc->stereo3d); + av_freep(&sc->spherical); + av_freep(&sc->mastering); + av_freep(&sc->coll); +} + static int mov_read_close(AVFormatContext *s) { MOVContext *mov = s->priv_data; @@ -8588,54 +8677,8 @@ static int mov_read_close(AVFormatContext *s) for (i = 0; i < s->nb_streams; i++) { AVStream *st = s->streams[i]; - MOVStreamContext *sc = st->priv_data; - - if (!sc) - continue; - av_freep(&sc->ctts_data); - for (j = 0; j < sc->drefs_count; j++) { - av_freep(&sc->drefs[j].path); - av_freep(&sc->drefs[j].dir); - } - av_freep(&sc->drefs); - - sc->drefs_count = 0; - - if (!sc->pb_is_copied) - ff_format_io_close(s, &sc->pb); - - sc->pb = NULL; - av_freep(&sc->chunk_offsets); - av_freep(&sc->stsc_data); - av_freep(&sc->sample_sizes); - av_freep(&sc->keyframes); - av_freep(&sc->stts_data); - av_freep(&sc->sdtp_data); - av_freep(&sc->stps_data); - av_freep(&sc->elst_data); - av_freep(&sc->rap_group); - av_freep(&sc->sync_group); - av_freep(&sc->sgpd_sync); - av_freep(&sc->sample_offsets); - av_freep(&sc->open_key_samples); - av_freep(&sc->display_matrix); - av_freep(&sc->index_ranges); - - if (sc->extradata) - for (j = 0; j < sc->stsd_count; j++) - av_free(sc->extradata[j]); - av_freep(&sc->extradata); - av_freep(&sc->extradata_size); - - mov_free_encryption_index(&sc->cenc.encryption_index); - av_encryption_info_free(sc->cenc.default_encrypted_sample); - av_aes_ctr_free(sc->cenc.aes_ctr); - - av_freep(&sc->stereo3d); - av_freep(&sc->spherical); - av_freep(&sc->mastering); - av_freep(&sc->coll); + mov_free_stream_context(s, st); } av_freep(&mov->dv_demux); -- 2.43.0 _______________________________________________ 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".