From patchwork Tue Sep 26 17:37:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vignesh Venkat X-Patchwork-Id: 43916 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:2a18:b0:15d:8365:d4b8 with SMTP id e24csp2064010pzh; Tue, 26 Sep 2023 10:38:07 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEtO8lgJy9jRvgO8PRBh0N2v379hefE8cjJeP00+r6/JVCyShZSh1LNNPs6hlJ8uanwiRa/ X-Received: by 2002:a17:906:292a:b0:9a5:874a:9745 with SMTP id v10-20020a170906292a00b009a5874a9745mr8513279ejd.26.1695749886832; Tue, 26 Sep 2023 10:38:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695749886; cv=none; d=google.com; s=arc-20160816; b=tazT/wfVCWPzDW6uTzuWlmyDl25v9aXa+v/K6GGpVK/nFbXbxQNKXn7DQv5AAhir15 Q7EcRijmdoNhA822UJej91/M4Sz/MKT5g7+JZ782ABhotZMeMohT6Ptx3Dwao77cz5ja am1e5k7VqQOkNCMSxXoTl2qOCX2xKXWimQedulGyop+74nQ+Fmf98LYRrASQjxxjeaBA x40F4zVZLAIK/H7SVxGEG6B1kTDGFsfiODa57Sa7pQuAnszudAlZicPs6xqUUzb1UMFY Vc5bEIDfJdYI99BvZk1rdJejrqzst+Il9qPoT9bD/BADmPTDtUD/XUsy2/L2MGM6CVqL m9KQ== 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:from :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:to:message-id:mime-version:date :delivered-to; bh=1ZOK2rj6Ery78c0wdSREeL7PhYDWQdwY9+ph2jG7oek=; fh=zLTX2kwa8L5gNw1IDWXMzP8nX5h2CbyibdEHyEbl1/E=; b=nOhYtOLiv+PI0G3zfwCh4Piw2TnNDcPt2Ke6IhX6iSPms5953SH9OlENg5+rTWEEvi czYyWArvExqLWStKGxb3m6HhwwB6HXt4rI0Rz5YGZ3YkNyk8+3lSu00FrW4cs9rnQDH/ k1p0vHNz66p1P0Kkz2euojI34HLwBvZ7TeuWj69JGa7rTdFHDYkaW9upbrS4GCFrnrD0 g9SHXZV4eRSwErSL/XyKxNusDA8sRCN2qWG6STCrctTESKHq5hFwE/w/wSpSZnA7fO38 S2rdiuoiSUZVApA6Wp21ytRM9AWr3TDpl3PLWN0uCFufXJcJXtz14cC/wIOf0OdXGs1T UBCQ== ARC-Authentication-Results: i=1; mx.google.com; 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 rs22-20020a170907037600b009adbab54df1si11685221ejb.98.2023.09.26.10.38.05; Tue, 26 Sep 2023 10:38:06 -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; 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 A457E68CA17; Tue, 26 Sep 2023 20:38:01 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org 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 7BFC968C870 for ; Tue, 26 Sep 2023 20:37:55 +0300 (EEST) Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-d81d85aae7cso18820851276.0 for ; Tue, 26 Sep 2023 10:37:55 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695749874; x=1696354674; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=LAdTdXNl6cW31ji7Za7ctw5pVnfvi9AtGJjkFlaPQZE=; b=jhWd9jNg00hCJL2yLhWtFUj4wAalJiMC2qZ+6+PV7kbLk6lLejufLlNVeQFLvNuTEa uOvOBNAbt+gZK4zSh1ErmhSwQjVaW/8GI8oBfqe9iZGZScSAStU2YYddN7GwZZHDsTaL 93jegiFjbSrHHlGjh/2Rw1HLhcnaI2QukT2x6N4UpBf/+FI3SiSuHFPd8OrHPOMzCG3K sYsTKHQwoqhH2WhtkwYrYXdEUAH226cp8TdDtzaHmW/0LXT/6zMCpL2dXDmt6j4GuFVM fOsCu45bL7rU8wbbZEqJvrX58ZdqF2mT1tpKegt7AC3lLJUhWpYMabcnom+gau6URy0k DVpA== X-Gm-Message-State: AOJu0YzAXO5rOmYglxTRE+0OWuFXOnMQVDCOhHBovixHVw5htIv0Oguy Pb7UmZA+J5Lp33nXLFAcGwm1Sbompjm6dgLh+q/wih1ds3XHDpiij4tFyx7JgXMac9dokKW7P+C GcVmGJqeHYtx42IJTqCqgdOnM4cVjuFXY7ZVVlsvsVWkbTPFK5qHNd+H6T5qQHc3MzoUq X-Received: from vigneshv3.mtv.corp.google.com ([2620:0:1000:2511:6bf7:6f80:c25:1e7d]) (user=vigneshv job=sendgmr) by 2002:a25:abe4:0:b0:d86:780e:a8dd with SMTP id v91-20020a25abe4000000b00d86780ea8ddmr55876ybi.4.1695749873645; Tue, 26 Sep 2023 10:37:53 -0700 (PDT) Date: Tue, 26 Sep 2023 10:37:36 -0700 Mime-Version: 1.0 X-Mailer: git-send-email 2.42.0.515.g380fc7ccd1-goog Message-ID: <20230926173742.2623244-1-vigneshv@google.com> To: ffmpeg-devel@ffmpeg.org Subject: [FFmpeg-devel] [PATCH] avformat/mov: Add support for demuxing still HEIC images 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: , X-Patchwork-Original-From: Vignesh Venkatasubramanian via ffmpeg-devel From: Vignesh Venkat Reply-To: FFmpeg development discussions and patches Cc: Vignesh Venkatasubramanian Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: cqLO7Q244fVc They are similar to AVIF images (both use the HEIF container). The only additional work needed is to parse the hvcC box and put it in the extradata. With this patch applied, ffmpeg (when built with an HEVC decoder) is able to decode the files in https://github.com/nokiatech/heif/tree/gh-pages/content/images Partially fixes trac ticket #6521. Signed-off-by: Vignesh Venkatasubramanian --- libavformat/isom.h | 2 ++ libavformat/mov.c | 38 +++++++++++++++++++++++++++++++++++++- 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/libavformat/isom.h b/libavformat/isom.h index 3d375d7a46..b30b9da65e 100644 --- a/libavformat/isom.h +++ b/libavformat/isom.h @@ -327,6 +327,8 @@ typedef struct MOVContext { int64_t extent_offset; } *avif_info; int avif_info_size; + int64_t hvcC_offset; + int hvcC_size; int interleaved_read; } MOVContext; diff --git a/libavformat/mov.c b/libavformat/mov.c index 1996e0028c..cec9cb5fe1 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -1218,7 +1218,8 @@ 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); + c->is_still_picture_avif = !strncmp(type, "avif", 4) || + !strncmp(type, "mif1", 4); minor_ver = avio_rb32(pb); /* minor version */ av_dict_set_int(&c->fc->metadata, "minor_version", minor_ver, 0); @@ -4911,6 +4912,16 @@ static int avif_add_stream(MOVContext *c, int item_id) st->priv_data = sc; st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; st->codecpar->codec_id = AV_CODEC_ID_AV1; + if (c->hvcC_offset >= 0) { + int ret; + int64_t pos = avio_tell(c->fc->pb); + st->codecpar->codec_id = AV_CODEC_ID_HEVC; + avio_seek(c->fc->pb, c->hvcC_offset, SEEK_SET); + ret = ff_get_extradata(c->fc, st->codecpar, c->fc->pb, c->hvcC_size); + if (ret < 0) + return ret; + avio_seek(c->fc->pb, pos, SEEK_SET); + } sc->ffindex = st->index; c->trak_index = st->index; st->avg_frame_rate.num = st->avg_frame_rate.den = 1; @@ -4953,6 +4964,8 @@ static int avif_add_stream(MOVContext *c, int item_id) static int mov_read_meta(MOVContext *c, AVIOContext *pb, MOVAtom atom) { + c->hvcC_offset = -1; + c->hvcC_size = 0; while (atom.size > 8) { uint32_t tag; if (avio_feof(pb)) @@ -7826,6 +7839,28 @@ static int mov_read_iloc(MOVContext *c, AVIOContext *pb, MOVAtom atom) return atom.size; } +static int mov_read_iprp(MOVContext *c, AVIOContext *pb, MOVAtom atom) +{ + int 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; + if (sub_type == MKTAG('h','v','c','C')) { + c->hvcC_offset = avio_tell(pb); + c->hvcC_size = sub_size; + break; + } + avio_skip(pb, sub_size); + } + 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 }, @@ -7933,6 +7968,7 @@ static const MOVParseTableEntry mov_default_parse_table[] = { { MKTAG('p','c','m','C'), mov_read_pcmc }, /* PCM configuration box */ { MKTAG('p','i','t','m'), mov_read_pitm }, { MKTAG('e','v','c','C'), mov_read_glbl }, +{ MKTAG('i','p','r','p'), mov_read_iprp }, { 0, NULL } };