From patchwork Mon May 27 15:22:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hacene Bouaroua X-Patchwork-Id: 49296 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a59:542:0:b0:460:55fa:d5ed with SMTP id 63csp3337320vqf; Mon, 27 May 2024 08:22:18 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVaRIO3yT8htidAna0xnbeAYcvCPA5xXArBmOx+58ORZL1SqEzdA6smMAAWeDAxMBlwrNGaMMkdiMA1PwX1K6LpEJCz6A4OyRSx4w== X-Google-Smtp-Source: AGHT+IE/S1EpTtA+ZJBxjS4ghRNY+Uyp576YJwcJtenb/uIc09YI9JldakFs0S15aErQoNESP9ZR X-Received: by 2002:a19:6407:0:b0:51e:fc99:d6ef with SMTP id 2adb3069b0e04-529649c5d8cmr5504642e87.18.1716823337992; Mon, 27 May 2024 08:22:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1716823337; cv=none; d=google.com; s=arc-20160816; b=IRZJNBLDNVWRC7cayMnvqQNMKK7iFPmSdhbXh2NmqUbsEW01nvBoLIWnshj8o9zglG Lmo88cCQsvHp5B5kezXBTgSsSVypstA8WmetewG1scPDyvFRkjxst2MLt72K3GtUe1Fg 6PXKiYFGtvWIvzk+v1MYhBlTyyPG7bTYmWTAR7WY9Uq6ess09xu1lf1XZdHDax3EUQIo vpZ7B+btcSjMafrCdHE4oG9K3lEqV0WzbykNlZq8aUSOHwR67BGWWahmms96F1l7ZLI7 RiZM5HFsTrZZC0g1yEejb+FfyFhHS9ByVYryVJ5U5kcdEkUSk22TxuqVfvzPUj7YfAiF M4UQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:content-language:to:user-agent:mime-version:date :message-id:from:dkim-signature:delivered-to; bh=ni0Nx+URgBXnyEXG9yrFovlMrUsyHyT+TYDKGALNfN8=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=oPgsdhQIlvLuVsxPO/I0f8shxaMzv36eMxVU9lEBPy3g/UB1R7i4yYWNtOfc2xkvu/ XvVKfTz1EnVe3+qHM01hoRmVRpX84RUKSqbWTkqtZIzKlkf9God3uw7QD2CvwfFCtVjS aK8WSdXky9wevz1I3X/8Ib+4cXz6SyygxMkLBkgvfwf6oT9KDQSHPpSGmwc0LqDm/EdM fRA/E3qX+ySXwlwMfN9SohP8lEP6lOEPW301slXsMoI8JvFZSKbg3r2thdZalN22xRFT aj701SUKb+Vhg5z6YADsSeVMRj9hWY7eZEjgmp3m3BJfwZ9dWsME2hZUrDlm9ydHlNNC gt7w==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@freebox-fr.20230601.gappssmtp.com header.s=20230601 header.b=PAZnSvOQ; 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 a640c23a62f3a-a626cc363b4si401785866b.285.2024.05.27.08.22.17; Mon, 27 May 2024 08:22:17 -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=@freebox-fr.20230601.gappssmtp.com header.s=20230601 header.b=PAZnSvOQ; 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 6DC1368D4BC; Mon, 27 May 2024 18:22:15 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f47.google.com (mail-wm1-f47.google.com [209.85.128.47]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id E9B3568D084 for ; Mon, 27 May 2024 18:22:08 +0300 (EEST) Received: by mail-wm1-f47.google.com with SMTP id 5b1f17b1804b1-4210aa012e5so22335105e9.0 for ; Mon, 27 May 2024 08:22:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebox-fr.20230601.gappssmtp.com; s=20230601; t=1716823328; x=1717428128; darn=ffmpeg.org; h=content-transfer-encoding:content-language:to:subject:user-agent :mime-version:date:message-id:from:from:to:cc:subject:date :message-id:reply-to; bh=hR4XcqDXrRFaKq0ve0fgZVggGYJIgmY37qR7diBo4A4=; b=PAZnSvOQ61tx1gIXWock4MuHks9ZerWARUeLnQxPxCrxdprDx9vr7O0mLe69pdAg0m pyc8yG5K2tFK+UYWApKese65CTjg3BvBtcKCg76AiGnuQrkTE/fe9zh/Cb2m/uKIB6Sw 5bqodCX65cgwlEojJ3n5ldQ6MmFchOlP3j0jHQSZgpRNJHP8wdqfQaSAkVGtyeTpF11D 9HnHqQpuCzrvFhqrEDm3+dUzVdn+mMsH7CSd9+QQnPcoulMDepgv2qXIBqXZqhwPvlzT pdTDV7FE5eozj/lok/wsPW1j+vXTaNSbVX2u7O123JigEF91pACu6fAhMg8sVp4DrQ8r hqGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716823328; x=1717428128; h=content-transfer-encoding:content-language:to:subject:user-agent :mime-version:date:message-id:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=hR4XcqDXrRFaKq0ve0fgZVggGYJIgmY37qR7diBo4A4=; b=apLEkwpxCp3xvr2tMJV816KEFBPXIFT+Pi/LUxNnYeNCjaTl0TAcBdZwO/KG+sn9/u J6vJYc1eP4JatpNB412mexPcX2MgWkvKlt/Yi7Z6ALtlimsa1WEzsLn+sAuo3EvzJLbK 4m+wb86YnoZlMaQ7boWKfJo8mAjn08dvcyNnIGs5PQRpS1JbcSUaZ3tou3brJEi/KmH8 T362cq8/WECCSc8L6pN+vvs/X2kIFU2OxaQ3v4IsWlIV4czfCq2H02uCe2CNyVNuwerF qYLZSyJ6eF0zbWUFNU/8WEyfyWGN15XjyeEpKDinoAJSSKvUnrWDlj868xUvuJpz7KkI sCWA== X-Gm-Message-State: AOJu0YwTqdt3GrlFpSlKAc/G/DI27sAB7itD3RclddWeKNWiOU47sVLP fCnjZiyrNgss22G3q9Xm8RDn45D/3oyiuJJAg04XHfL+qWnlt9KzIIOTJCCh0RXLF5XI1UX66Q9 9c44= X-Received: by 2002:a05:600c:5593:b0:420:2b2e:f6e7 with SMTP id 5b1f17b1804b1-42108a79034mr78932555e9.17.1716823327919; Mon, 27 May 2024 08:22:07 -0700 (PDT) Received: from [192.168.108.115] (freebox.vlq16.iliad.fr. [213.36.7.13]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4210896676bsm113392725e9.4.2024.05.27.08.22.07 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 27 May 2024 08:22:07 -0700 (PDT) From: Hacene Bouaroua X-Google-Original-From: Hacene Bouaroua Message-ID: <1c939e57-2c6e-412e-b453-25f88ae29057@freebxo.fr> Date: Mon, 27 May 2024 17:22:07 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird To: ffmpeg-devel@ffmpeg.org Content-Language: en-US Subject: [FFmpeg-devel] [PATCH, v2] avformat/mov: get heif image rotation from irot box 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: 9/rE8xK+iND/ parse irot box to get the transformative heif item rotation angle. Signed-off-by: Hacene Bouaroua --- libavformat/avformat.h | 5 +++++ libavformat/isom.h | 1 + libavformat/mov.c | 25 +++++++++++++++++++++++++ 3 files changed, 31 insertions(+) diff --git a/libavformat/avformat.h b/libavformat/avformat.h index 8afdcd9fd0..615650ddcb 100644 --- a/libavformat/avformat.h +++ b/libavformat/avformat.h @@ -1077,6 +1077,11 @@ typedef struct AVStreamGroupTileGrid { * final image before presentation. */ int height; + /** + * the angle which the reconstructed image is initially rotated + * (in anti-clockwise direction) in units of degrees. + */ + int rotation; } AVStreamGroupTileGrid; enum AVStreamGroupParamsType { diff --git a/libavformat/isom.h b/libavformat/isom.h index c0a5788e08..757e3f8738 100644 --- a/libavformat/isom.h +++ b/libavformat/isom.h @@ -277,6 +277,7 @@ typedef struct HEIFItem { int64_t extent_offset; int width; int height; + int rotation; int type; int is_idat_relative; } HEIFItem; diff --git a/libavformat/mov.c b/libavformat/mov.c index 45eca74d1d..5f04e68f88 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -8398,6 +8398,27 @@ static int mov_read_ispe(MOVContext *c, AVIOContext *pb, MOVAtom atom) return 0; } +static int mov_read_irot(MOVContext *c, AVIOContext *pb, MOVAtom atom) +{ + uint32_t angle; + + angle = avio_r8(pb); + + av_log(c->fc, AV_LOG_TRACE, "irot: item_id %d, angle %u\n", + c->cur_item_id, angle); + + for (int i = 0; i < c->nb_heif_item; i++) { + if (c->heif_item[i].item_id == c->cur_item_id) { + // angle * 90 specifies the angle (in anti-clockwise direction) + // in units of degrees. + c->heif_item[i].rotation = angle * 90; + break; + } + } + + return 0; +} + static int mov_read_iprp(MOVContext *c, AVIOContext *pb, MOVAtom atom) { typedef struct MOVAtoms { @@ -8615,6 +8636,7 @@ static const MOVParseTableEntry mov_default_parse_table[] = { { MKTAG('i','d','a','t'), mov_read_idat }, { MKTAG('i','r','e','f'), mov_read_iref }, { MKTAG('i','s','p','e'), mov_read_ispe }, +{ MKTAG('i','r','o','t'), mov_read_irot }, { MKTAG('i','p','r','p'), mov_read_iprp }, { MKTAG('i','i','n','f'), mov_read_iinf }, { MKTAG('a','m','v','e'), mov_read_amve }, /* ambient viewing environment box */ @@ -9315,6 +9337,9 @@ static int read_image_grid(AVFormatContext *s, const HEIFGrid *grid, tile_grid->width = (flags & 1) ? avio_rb32(s->pb) : avio_rb16(s->pb); tile_grid->height = (flags & 1) ? avio_rb32(s->pb) : avio_rb16(s->pb); + /* rotation */ + tile_grid->rotation = item->rotation; + av_log(c->fc, AV_LOG_TRACE, "grid: grid_rows %d grid_cols %d output_width %d output_height %d\n", tile_rows, tile_cols, tile_grid->width, tile_grid->height);