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 846BF4132F for ; Mon, 28 Mar 2022 17:07:37 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 1F71468B214; Mon, 28 Mar 2022 20:07:36 +0300 (EEST) Received: from mail-yb1-f180.google.com (mail-yb1-f180.google.com [209.85.219.180]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 1805268B205 for ; Mon, 28 Mar 2022 20:07:30 +0300 (EEST) Received: by mail-yb1-f180.google.com with SMTP id o5so27188623ybe.2 for ; Mon, 28 Mar 2022 10:07:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=SF8oN1XF7h0F9oscAaLlGACkmyGIycJCj0tbYmtIB8I=; b=kt6QqykBz244A7F/Wg4BaJC2xhX7HTIUBXNKH98Ofmf1CBTnXqefDyqYfqHRjAKN8u KABsumfIiR0WTs1oHvnnkI+hRfimmMtwew7CJetMWjnSTGW0EpsWvIPDQCddHGVfNcZQ UvHgvNN8j+fJutL2AiG73SPUQRL1O2fWOWb274P9SSmgbLQfSCFSNNW1/Kwat8b1aul1 W6fFn0lOzMU/E3l9yd8x+tXwhxk9wChJT4CGLqsRhjZWohyFhjikfCUgaCEbeknXGfQR YwT2UQXb4L3akRJGXIBDIMVrulDYFEacsflVVQZMp+VddCftITrpO2a52CXu8M7KRgOD dBJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=SF8oN1XF7h0F9oscAaLlGACkmyGIycJCj0tbYmtIB8I=; b=sOHeoCEh3OSWFyGzqkNHY6x5RnKyqqapXVmS37yCbmy2kq7qIQobUmA/iGQhNJgADY 690uMpVMLGclvEbgrHM5VmOUKQsmphJeyztW738fU0CIyhvYfJRS6kvGk84hTYizS/5N xtBlMBRWVVht5D1p0bpqXVoou27YYGGU7QviZITnsVcVEqjF8Q/8pTMZKtPiq8KeF/Bm Jg3ZrpX72joDDYjVH6ba5V0BhBq6cBNvCY9xOsLPzoYsWWqerldTI2JUybRAEFedk1fU bTIv4wktSE+aip73dIePo7cpygcAAntD2bKC4qqJC6KArTlqFxCQadPQyY8NvQbs66uL QPdA== X-Gm-Message-State: AOAM530Bfz7EkAIAU7NIRZxwnCuZOYAK6zn0UKQSsdwnVXBEzae/Bb2N dtNMGFkbwLqzHGPkURddBLMBf1FflYiV0+atBKbly6CXwf4= X-Google-Smtp-Source: ABdhPJwR0Rx09Btjp4I8R+RCecP3ioxeQ1Uix4MysL9l3Pe2MEcENjnOOw7whCxvGE+CSBLY43EPNkfIMWrREv4x9Bg= X-Received: by 2002:a25:e78e:0:b0:633:9df1:9fff with SMTP id e136-20020a25e78e000000b006339df19fffmr23386098ybh.233.1648487247717; Mon, 28 Mar 2022 10:07:27 -0700 (PDT) MIME-Version: 1.0 References: <20220316170029.3954061-1-vigneshv@google.com> <20220316170218.3955336-1-vigneshv@google.com> In-Reply-To: From: Vignesh Venkatasubramanian Date: Mon, 28 Mar 2022 10:07:16 -0700 Message-ID: To: FFmpeg development discussions and patches Subject: Re: [FFmpeg-devel] [PATCH] avformat/mov: Add support for still image AVIF parsing 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: On Tue, Mar 22, 2022 at 2:56 PM Vignesh Venkatasubramanian wrote: > > On Wed, Mar 16, 2022 at 10:02 AM Vignesh Venkatasubramanian > wrote: > > > > Add support for parsing AVIF still images. This patches supports > > AVIF still images that have exactly 1 item (i.e.) no alpha channel. > > Essentially, we will have to parse the "iloc" box and populate > > the mov index. > > > > With this patch, we can decode still AVIF images like so: > > ffmpeg -i image.avif image.png > > > > Partially fixes trac ticket #7621 > > > > Signed-off-by: Vignesh Venkatasubramanian > > --- > > libavformat/isom.h | 1 + > > libavformat/mov.c | 142 +++++++++++++++++++++++++++++++++++++++++++++ > > 2 files changed, 143 insertions(+) > > > > diff --git a/libavformat/isom.h b/libavformat/isom.h > > index 5caf42b15d..02d681e3ae 100644 > > --- a/libavformat/isom.h > > +++ b/libavformat/isom.h > > @@ -315,6 +315,7 @@ typedef struct MOVContext { > > int have_read_mfra_size; > > uint32_t mfra_size; > > uint32_t max_stts_delta; > > + int is_still_picture_avif; > > } MOVContext; > > > > int ff_mp4_read_descr_len(AVIOContext *pb); > > diff --git a/libavformat/mov.c b/libavformat/mov.c > > index 6c847de164..3af49427b9 100644 > > --- a/libavformat/mov.c > > +++ b/libavformat/mov.c > > @@ -1136,6 +1136,7 @@ static int mov_read_ftyp(MOVContext *c, AVIOContext *pb, MOVAtom atom) > > c->isom = 1; > > av_log(c->fc, AV_LOG_DEBUG, "ISO: File Type Major Brand: %.4s\n",(char *)&type); > > av_dict_set(&c->fc->metadata, "major_brand", type, 0); > > + c->is_still_picture_avif = !strncmp(type, "avif", 4); > > minor_ver = avio_rb32(pb); /* minor version */ > > av_dict_set_int(&c->fc->metadata, "minor_version", minor_ver, 0); > > > > @@ -7430,6 +7431,146 @@ static int mov_read_SAND(MOVContext *c, AVIOContext *pb, MOVAtom atom) > > return 0; > > } > > > > +static int rb_size(AVIOContext *pb, uint64_t* value, int size) > > +{ > > + if (size == 0) { > > + *value = 0; > > + } else if (size == 1) { > > + *value = avio_r8(pb); > > + } else if (size == 2) { > > + *value = avio_rb16(pb); > > + } else if (size == 4) { > > + *value = avio_rb32(pb); > > + } else if (size == 8) { > > + *value = avio_rb64(pb); > > + } else { > > + return -1; > > + } > > + return size; > > +} > > + > > +static int mov_read_iloc(MOVContext *c, AVIOContext *pb, MOVAtom atom) > > +{ > > + int version, offset_size, length_size, base_offset_size, index_size; > > + int item_count, extent_count; > > + uint64_t base_offset, extent_offset, extent_length; > > + int i, j; > > + uint8_t value; > > + AVStream *st; > > + MOVStreamContext *sc; > > + > > + if (!c->is_still_picture_avif) { > > + // * For non-avif, we simply ignore the iloc box. > > + // * For animated avif, we don't care about the iloc box as all the > > + // necessary information can be found in the moov box. > > + return 0; > > + } > > + > > + if (c->fc->nb_streams) { > > + av_log(c->fc, AV_LOG_INFO, "Duplicate iloc box found\n"); > > + return 0; > > + } > > + > > + st = avformat_new_stream(c->fc, NULL); > > + if (!st) return AVERROR(ENOMEM); > > + st->id = c->fc->nb_streams; > > + sc = av_mallocz(sizeof(MOVStreamContext)); > > + if (!sc) return AVERROR(ENOMEM); > > + > > + st->priv_data = sc; > > + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; > > + st->codecpar->codec_id = AV_CODEC_ID_AV1; > > + sc->ffindex = st->index; > > + c->trak_index = st->index; > > + st->avg_frame_rate.num = st->avg_frame_rate.den = 1; > > + st->time_base.num = st->time_base.den = 1; > > + st->nb_frames = 1; > > + sc->time_scale = 1; > > + sc = st->priv_data; > > + sc->pb = c->fc->pb; > > + sc->pb_is_copied = 1; > > + > > + version = avio_r8(pb); > > + avio_rb24(pb); // flags. > > + > > + value = avio_r8(pb); > > + offset_size = (value >> 4) & 0xF; > > + length_size = value & 0xF; > > + value = avio_r8(pb); > > + base_offset_size = (value >> 4) & 0xF; > > + index_size = (version == 0) ? 0 : (value & 0xF); > > + if (index_size != 0) { > > + 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. > > + 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)); > > + 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)); > > + if (!sc->chunk_offsets) { > > + return AVERROR(ENOMEM); > > + } > > + sc->sample_count = item_count; > > + sc->sample_sizes = av_malloc_array(item_count, 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)); > > + if (!sc->stts_data) { > > + return AVERROR(ENOMEM); > > + } > > + sc->stts_data[0].count = 1; > > + sc->stts_data[0].duration = 0; // Not used for still images. But needed by mov_build_index. > > + > > + for (i = 0; i < item_count; ++i) { > > + (version < 2) ? avio_rb16(pb) : avio_rb32(pb); // item_id; > > + if (version > 0) { > > + avio_rb16(pb); // construction_method. > > + } > > + avio_rb16(pb); // data_reference_index. > > + if (rb_size(pb, &base_offset, base_offset_size) < 0) { > > + return AVERROR_INVALIDDATA; > > + } > > + extent_count = avio_rb16(pb); > > + if (extent_count > 1) { > > + // For still AVIF images, we only support one extent item. > > + return AVERROR_PATCHWELCOME; > > + } > > + for (j = 0; j < extent_count; ++j) { > > + 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; > > + } > > + } > > + > > + mov_build_index(c, st); > > + > > + // For still AVIF images, the iloc 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 that parsing can continue. > > + c->found_moov = 1; > > + > > + return atom.size; > > +} > > + > > static const MOVParseTableEntry mov_default_parse_table[] = { > > { MKTAG('A','C','L','R'), mov_read_aclr }, > > { MKTAG('A','P','R','G'), mov_read_avid }, > > @@ -7532,6 +7673,7 @@ static const MOVParseTableEntry mov_default_parse_table[] = { > > { MKTAG('k','i','n','d'), mov_read_kind }, > > { 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 }, > > { 0, NULL } > > }; > > > > -- > > 2.35.1.723.g4982287a31-goog > > > > Another ping on this? > > > -- > Vignesh If there are no more comments, can this be merged please? -- Vignesh _______________________________________________ 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".