From patchwork Sun Apr 24 18:35:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vignesh Venkat X-Patchwork-Id: 35432 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:3b9e:b0:7d:cfb5:dc7c with SMTP id b30csp1513778pzh; Sun, 24 Apr 2022 11:35:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyMfjuskEI9y2lT/90hspU+hcbnE5ufB9aPcPiMuzlJE6qtxH89UQwTYMuFQnFVtBsVJibA X-Received: by 2002:a17:906:5d07:b0:6ef:f147:caee with SMTP id g7-20020a1709065d0700b006eff147caeemr13434188ejt.292.1650825338542; Sun, 24 Apr 2022 11:35:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650825338; cv=none; d=google.com; s=arc-20160816; b=GhfiPvb1M8zbwpBhdu/X0yHwZQSWc/QNn2blE5oHUh4fyYgrIc3Qscpa4QVTw1y7Zj E1jpGMqyG7Uwv3hdpD9kHYDb3/pAurS3M6lcegmfvLg48+cue8eSJCwIz9lSRfltMV6l OIam796XAHWLBcTEpaUAF0ewIBw4GR4mOHflJe1s88rWMStkIjnWc3xZJ9izEmnq5omG RTNR18p3tve5LN920rFbLQ0FAy3CRUm6fVGZxG8I+onYCGTZst2Y3xbzMa/OSCahFNMr SItE5/h0+LIrJKUPOfY0J1Y7a2OUm9qQxqDnhkq5+C8gGzMLrZraxB5HC4TMff3tkbos zTpQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:to:from:mime-version:message-id:date :dkim-signature:delivered-to; bh=yLirJ6q5xLBj3vvIN6p7PJTMjldyAXgvxKoMFnkCQV4=; b=a+npYhZNVi8kBeBs1B/SLF/Cs2D/EGLNQysTGbUyHXgztwAAT/CJJZBVD2n6+VWe0p VdjJOv3k3VnvEBmrKkG3OXH1z3UYda8Wgd9zJ56lKIuXRI7cM0ZVSZgS7WBzBkBkP7bA lFC507ouxhdxNhfHZh+HefgLZoGWEaohCyALdy18qAxIWnbKpUE6/HBAuW0lUmtM1QVq oSxcO1ienQDrKtSKlUw9BcDqHQcEbQNQZ/2xuBBwAPloTHkHhDNxlM4nMclI9hq/iuJx KHJFt+hihhEAhDhhz934q2SL2vqPQCzaTylwJUe5mFNPIdnziTtrBhOaMK5YQQe/YT2W x16g== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@google.com header.s=20210112 header.b=PRHIw3Hq; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id z20-20020a05640235d400b00425e25ad716si1748878edc.34.2022.04.24.11.35.37; Sun, 24 Apr 2022 11:35:38 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@google.com header.s=20210112 header.b=PRHIw3Hq; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 103E168B1D4; Sun, 24 Apr 2022 21:35:34 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 8801568AF91 for ; Sun, 24 Apr 2022 21:35:27 +0300 (EEST) Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-2f7c5767f0fso33149647b3.4 for ; Sun, 24 Apr 2022 11:35:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:message-id:mime-version:subject:from:to:cc; bh=FA6Q5Rt/k6nn2uEbYefPq8xn/lPlHb3Icv8yWtRdsGY=; b=PRHIw3HqxtbBs3sBCvwLhIHNcTfb1+aKTZMPFdlnqt57dmpZLpr5U8F8OLKHPEBrLU bZIgvpTDB8TglceE3ipmxg88ACZekxZSPUKGGwq0huV1pi5MrOWz6kAUbP6dx5/8/vtr Q973GJOCd6kJN+9L9Ocsdy/hDmzWMN7O1/zI6uKetwHrYgzYmR7t4qngCfq21iSyohH/ VqgRFQzWXaFJzNL8yUqD9RbLAEFc8mdNGjZnWod3s+yknIM9K+BaZpcnTzBqNEXxr6H8 FfoffyYH9PCAM3gh4rMwXYXchvmzbMR51+nhBD/y9iYzfKNLJce1zXw30AVIl1MBaJOw 9aEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=FA6Q5Rt/k6nn2uEbYefPq8xn/lPlHb3Icv8yWtRdsGY=; b=a0mewQjmLvG0caljznxL4A89Xq2wCOWWE8nhL73CVmItBbd3FxUpQXpLv6IkC6/n5/ b1RUplmjkYRF0uezlXti23fZY8WMpuBgt/mzoj5Nbld+v1wtXPwdqxP3xPxY0Ip7i7GS UfJwX8KlgWqasljZ2uP8JPbqA8WI2IBcrSp48eHC0KBN536fa2cdVAAOnX83cEJ7V9HP Vc2FbwYYzmBG/oLnHbbo0vNTAa3TwRIBDF3bfw0/t45cteqiGcsnl5oRjS/81VOR/rn1 HJr/7r6WIcupciKa1ppjvTa6fbtzrSpeILpmuA7VHx7AcKgzseQZGpiT/aPgJw8ejeWw 1WAw== X-Gm-Message-State: AOAM530gPib8JQWOOXNiK8e6CRdalsumFv2DanFtZ/wfd1feSZSXV9Z6 lTap1hYmZxiGDc3ZiDXrtm7peEIDKkeoUL4WYsOuB4vwrdZicch1PEmWXzw/fRLnwslZDbsAkRD RUynfb+PVVloe8RxyvCaPkbLLbQYVibFQ7WNVRSYZV/iiMazKt8PNO/0aDYru8gsG8lJn X-Received: from vigneshv3.mtv.corp.google.com ([2620:0:1000:2511:4d80:f2e2:d20:17c0]) (user=vigneshv job=sendgmr) by 2002:a81:5b42:0:b0:2f7:d55d:69b0 with SMTP id p63-20020a815b42000000b002f7d55d69b0mr4434526ywb.65.1650825326016; Sun, 24 Apr 2022 11:35:26 -0700 (PDT) Date: Sun, 24 Apr 2022 11:35:14 -0700 Message-Id: <20220424183514.986374-1-vigneshv@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.36.0.rc2.479.g8af0fa9b8e-goog From: Vignesh Venkatasubramanian To: ffmpeg-devel@ffmpeg.org Subject: [FFmpeg-devel] [PATCH] avformat/mov: Only read the primary item for AVIF 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: Vignesh Venkatasubramanian Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: aP32qzwLixBJ Update the still AVIF parser to only read the primary item. With this patch, AVIF still images with exif/icc/alpha channel will no longer fail to parse. For example, this patch enables parsing of files in: https://github.com/AOMediaCodec/av1-avif/tree/master/testFiles/Microsoft Partially fixes trac ticket #7621 Signed-off-by: Vignesh Venkatasubramanian --- libavformat/isom.h | 1 + libavformat/mov.c | 41 +++++++++++++++++++++-------------------- 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/libavformat/isom.h b/libavformat/isom.h index cf36f04d5b..f05c2d9c28 100644 --- a/libavformat/isom.h +++ b/libavformat/isom.h @@ -317,6 +317,7 @@ typedef struct MOVContext { uint32_t mfra_size; uint32_t max_stts_delta; int is_still_picture_avif; + int primary_item_id; } MOVContext; int ff_mp4_read_descr_len(AVIOContext *pb); diff --git a/libavformat/mov.c b/libavformat/mov.c index 3e83e54a77..6be0f317ca 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -7449,6 +7449,13 @@ static int rb_size(AVIOContext *pb, uint64_t* value, int size) return size; } +static int mov_read_pitm(MOVContext *c, AVIOContext *pb, MOVAtom atom) +{ + avio_rb32(pb); // version & flags. + c->primary_item_id = avio_rb16(pb); + return atom.size; +} + static int mov_read_iloc(MOVContext *c, AVIOContext *pb, MOVAtom atom) { int version, offset_size, length_size, base_offset_size, index_size; @@ -7505,34 +7512,25 @@ static int mov_read_iloc(MOVContext *c, AVIOContext *pb, MOVAtom atom) return AVERROR_PATCHWELCOME; } item_count = (version < 2) ? avio_rb16(pb) : avio_rb32(pb); - if (item_count > 1) { - // For still AVIF images, we only support one item. Second item will - // generally be found for AVIF images with alpha channel. We don't - // support them as of now. - av_log(c->fc, AV_LOG_ERROR, "iloc: item_count > 1 not supported.\n"); - return AVERROR_PATCHWELCOME; - } // Populate the necessary fields used by mov_build_index. - sc->stsc_count = item_count; - sc->stsc_data = av_malloc_array(item_count, sizeof(*sc->stsc_data)); + sc->stsc_count = 1; + sc->stsc_data = av_malloc_array(1, sizeof(*sc->stsc_data)); if (!sc->stsc_data) return AVERROR(ENOMEM); sc->stsc_data[0].first = 1; sc->stsc_data[0].count = 1; sc->stsc_data[0].id = 1; - sc->chunk_count = item_count; - sc->chunk_offsets = - av_malloc_array(item_count, sizeof(*sc->chunk_offsets)); + sc->chunk_count = 1; + sc->chunk_offsets = av_malloc_array(1, sizeof(*sc->chunk_offsets)); if (!sc->chunk_offsets) return AVERROR(ENOMEM); - sc->sample_count = item_count; - sc->sample_sizes = - av_malloc_array(item_count, sizeof(*sc->sample_sizes)); + sc->sample_count = 1; + sc->sample_sizes = av_malloc_array(1, sizeof(*sc->sample_sizes)); if (!sc->sample_sizes) return AVERROR(ENOMEM); - sc->stts_count = item_count; - sc->stts_data = av_malloc_array(item_count, sizeof(*sc->stts_data)); + sc->stts_count = 1; + sc->stts_data = av_malloc_array(1, sizeof(*sc->stts_data)); if (!sc->stts_data) return AVERROR(ENOMEM); sc->stts_data[0].count = 1; @@ -7540,7 +7538,7 @@ static int mov_read_iloc(MOVContext *c, AVIOContext *pb, MOVAtom atom) sc->stts_data[0].duration = 0; for (int i = 0; i < item_count; i++) { - (version < 2) ? avio_rb16(pb) : avio_rb32(pb); // item_id; + int item_id = (version < 2) ? avio_rb16(pb) : avio_rb32(pb); if (version > 0) avio_rb16(pb); // construction_method. avio_rb16(pb); // data_reference_index. @@ -7556,8 +7554,10 @@ static int mov_read_iloc(MOVContext *c, AVIOContext *pb, MOVAtom atom) if (rb_size(pb, &extent_offset, offset_size) < 0 || rb_size(pb, &extent_length, length_size) < 0) return AVERROR_INVALIDDATA; - sc->sample_sizes[0] = extent_length; - sc->chunk_offsets[0] = base_offset + extent_offset; + if (item_id == c->primary_item_id) { + sc->sample_sizes[0] = extent_length; + sc->chunk_offsets[0] = base_offset + extent_offset; + } } } @@ -7674,6 +7674,7 @@ static const MOVParseTableEntry mov_default_parse_table[] = { { MKTAG('S','A','3','D'), mov_read_SA3D }, /* ambisonic audio box */ { MKTAG('S','A','N','D'), mov_read_SAND }, /* non diegetic audio box */ { MKTAG('i','l','o','c'), mov_read_iloc }, +{ MKTAG('p','i','t','m'), mov_read_pitm }, { 0, NULL } };