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 1227E407BC for ; Thu, 30 Jun 2022 21:05:03 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 443A868B75F; Fri, 1 Jul 2022 00:04:56 +0300 (EEST) Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 1A6EA68B73F for ; Fri, 1 Jul 2022 00:04:50 +0300 (EEST) Received: by mail-yb1-f202.google.com with SMTP id d132-20020a251d8a000000b0066c8dfb35f4so280892ybd.12 for ; Thu, 30 Jun 2022 14:04:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=7MTU060BMGaiWXGDRhJFaolWf0Cpc0UHRCj+OeTMdgg=; b=VOUucuj/DNC0RmZUkxs21rFgAF4c0vI1tuYa0HLlYcHvxOSxNIZFYq4eOX2GEl7gwn iaMXRkZsc3/P02GNuqzU8v+OuatwFqONTtaxU/D9MzpXx2jmFwTIIrAWSzF9QcB9mVQr aMFRJdxx+fHzPCwf54K1sdMb7OyNfHvBNq2D/XnPj+D5ASUgSzwAjh0gFrO106dhv620 kufnvTDw/NauquyL4XfiPMG4gTc79l+w/sTczNtmhriMWy2uA+anVJM7ifQbZ21lqmRL GCHyS0uLze5HNR0PxFy63SgHMO+IvuwYxy6ZjwhdpEXbctkJ+fjHKviPwDTtkDB9Zw22 23Eg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=7MTU060BMGaiWXGDRhJFaolWf0Cpc0UHRCj+OeTMdgg=; b=mRxdrzhr9/GRObxrNkNfOeX+nmdH6575ECNHXheUGyBwzZ+BtzKNmV3vqRI8VSrAqw 8DypkZcQ60802gaucoyZLhaHUVrgUcKSqLWDYTMWDlWnBeABOWhzXRT1y+QzLeZtJgqH H/YpCkLsmDntb2lIMIq83w2QTYDM8u46ihwuGpZVIcyF4ypbkrrFwMZx2RALS0f7I4rL s9vj5IZ11wMFcMM6oKzDUlDVpv5QOOcZElDeahMinxC5EZa1I8uZFRROnHQqjvIhftz3 6ZDTXBMtDW68tRGc4h6u2cXPHHxOqAxBvrX3nFvtWfYrWPKrosCy38FNmuJIPoOrgMrA qQJw== X-Gm-Message-State: AJIora/Ldgchig391KjuBEy7lsDVyiWrrRo5n/1SN4fTGnUw6NbKv/lL BawrPvPkgyF5nn+Lc3yiPQOa3p7UqAR2M8laPj82gh+7zksrWR7tqMYslYktIviGTxugoErKoCi +mOHebQ1zQ8IIC/G7TOLCdvPwmGSkjJ3NN5bElG4Mrx7UKz2iYE5hPEHChd3li02ez7y1 X-Google-Smtp-Source: AGRyM1veAVyqeDNTLCNx+XN+JQVwZgRRCVblb8kwc5hH+wXH25lGFtx0oTorCy96nk7x0TtPhgEPN1wJp3AHVg== X-Received: from vigneshv3.mtv.corp.google.com ([2620:0:1000:2511:f6b5:b6ce:7578:e219]) (user=vigneshv job=sendgmr) by 2002:a05:6902:1389:b0:668:39b3:63bc with SMTP id x9-20020a056902138900b0066839b363bcmr10725685ybu.577.1656623088840; Thu, 30 Jun 2022 14:04:48 -0700 (PDT) Date: Thu, 30 Jun 2022 14:04:34 -0700 In-Reply-To: <20220630210434.1551769-1-vigneshv@google.com> Message-Id: <20220630210434.1551769-2-vigneshv@google.com> Mime-Version: 1.0 References: <20220630210434.1551769-1-vigneshv@google.com> X-Mailer: git-send-email 2.37.0.rc0.161.g10f37bed90-goog From: Vignesh Venkatasubramanian To: ffmpeg-devel@ffmpeg.org Subject: [FFmpeg-devel] [PATCH 2/2] avformat/mov: Support parsing of still AVIF Alpha Channel 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 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: Parse the alpha channel for still AVIF images and expose it as a separate track. This is the simplest way of supporting AVIF alpha channel in a codec independent manner (similar to how ffmpeg supports animated AVIF with alpha channel). One can use the alphamerge filter to get a transparent image with a single command. For example: ffmpeg -i image_with_alpha.avif -filter_complex alphamerge image_with_alpha.png Signed-off-by: Vignesh Venkatasubramanian --- libavformat/isom.h | 1 + libavformat/mov.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+) diff --git a/libavformat/isom.h b/libavformat/isom.h index d8b262e915..62b95b40ff 100644 --- a/libavformat/isom.h +++ b/libavformat/isom.h @@ -318,6 +318,7 @@ typedef struct MOVContext { uint32_t max_stts_delta; int is_still_picture_avif; int primary_item_id; + int alpha_item_id; int *avif_item_ids; int avif_item_ids_size; int *avif_extent_lengths; diff --git a/libavformat/mov.c b/libavformat/mov.c index 9df5055d4e..72b17b618d 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -4758,6 +4758,7 @@ static int mov_read_meta(MOVContext *c, AVIOContext *pb, MOVAtom atom) int ret; avio_seek(pb, -8, SEEK_CUR); atom.size += 8; + c->alpha_item_id = -1; ret = mov_read_default(c, pb, atom); if (ret < 0) return ret; @@ -4767,6 +4768,12 @@ static int mov_read_meta(MOVContext *c, AVIOContext *pb, MOVAtom atom) ret = avif_add_stream(c, c->primary_item_id); if (ret) return ret; + if (c->alpha_item_id != -1) { + // Add a stream for the Alpha plane. + ret = avif_add_stream(c, c->alpha_item_id); + if (ret) + return ret; + } // For still AVIF images, the meta box contains all the // necessary information that would generally be provided by the // moov box. So simply mark that we have found the moov box so @@ -7556,6 +7563,64 @@ static int mov_read_pitm(MOVContext *c, AVIOContext *pb, MOVAtom atom) return atom.size; } +static int mov_read_iprp(MOVContext *c, AVIOContext *pb, MOVAtom atom) +{ + int entry_count, size, version, flags; + int index = 0, auxC_alpha_index = -1; + size = avio_rb32(pb); + if (avio_rl32(pb) != MKTAG('i','p','c','o')) + return AVERROR_INVALIDDATA; + size -= 8; + while (size > 0) { + int sub_size, sub_type; + sub_size = avio_rb32(pb); + sub_type = avio_rl32(pb); + sub_size -= 8; + size -= sub_size + 8; + index++; + if (sub_type == MKTAG('a','u','x','C')) { + const char *expected_alpha_urn = "urn:mpeg:mpegB:cicp:systems:auxiliary:alpha"; + avio_rb32(pb); // version & flags. + sub_size -= 4; + if (sub_size >= strlen(expected_alpha_urn) + 1) { + char alpha_urn[44]; + avio_read(pb, alpha_urn, 44); + sub_size -= 44; + if (!strncmp(alpha_urn, expected_alpha_urn, 44)) { + auxC_alpha_index = index; + } + } + } + avio_skip(pb, sub_size); + } + if (auxC_alpha_index == -1) + return atom.size; + + // ipma. + size = avio_rb32(pb); + if (avio_rl32(pb) != MKTAG('i','p','m','a')) + return AVERROR_INVALIDDATA; + version = avio_r8(pb); + flags = avio_rb24(pb); + entry_count = avio_rb32(pb); + for (int i = 0; i < entry_count; i++) { + int item_id, association_count; + item_id = (version < 1) ? avio_rb16(pb) : avio_rb32(pb); + association_count = avio_r8(pb); + for (int j = 0; j < association_count; j++) { + int property_index; + if (flags & 1) + property_index = avio_rb16(pb) & 0x7fff; + else + property_index = avio_r8(pb) & 0x7f; + if (property_index == auxC_alpha_index) { + c->alpha_item_id = item_id; + } + } + } + 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; @@ -7732,6 +7797,7 @@ static const MOVParseTableEntry mov_default_parse_table[] = { { MKTAG('i','l','o','c'), mov_read_iloc }, { MKTAG('p','c','m','C'), mov_read_pcmc }, /* PCM configuration box */ { MKTAG('p','i','t','m'), mov_read_pitm }, +{ MKTAG('i','p','r','p'), mov_read_iprp }, { 0, NULL } }; -- 2.37.0.rc0.161.g10f37bed90-goog _______________________________________________ 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".