Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] [PATCH, v2] avformat/mov: get heif image rotation from irot box
@ 2024-05-27 15:22 Hacene Bouaroua
  2024-07-01 15:37 ` James Almer
  0 siblings, 1 reply; 2+ messages in thread
From: Hacene Bouaroua @ 2024-05-27 15:22 UTC (permalink / raw)
  To: ffmpeg-devel

parse irot box to get the transformative heif item rotation angle.

Signed-off-by: Hacene Bouaroua <hbouaroua@freebox.fr>
---
 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);
 
-- 
2.34.1

_______________________________________________
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".

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-07-01 15:37 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-05-27 15:22 [FFmpeg-devel] [PATCH, v2] avformat/mov: get heif image rotation from irot box Hacene Bouaroua
2024-07-01 15:37 ` James Almer

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git