[FFmpeg-cvslog] avformat/mov: use av_display_rotation_get() for rotate metadata.

Clément Bœsch git at videolan.org
Fri May 23 23:30:30 CEST 2014


ffmpeg | branch: master | Clément Bœsch <u at pkh.me> | Tue May 20 19:51:27 2014 +0200| [e63a17bfdc99441ff25e188d2398bf1a8f1fbb7e] | committer: Clément Bœsch

avformat/mov: use av_display_rotation_get() for rotate metadata.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=e63a17bfdc99441ff25e188d2398bf1a8f1fbb7e
---

 libavformat/mov.c |   30 ++++++++++++++----------------
 1 file changed, 14 insertions(+), 16 deletions(-)

diff --git a/libavformat/mov.c b/libavformat/mov.c
index 7f72db9..7203d58 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -31,6 +31,7 @@
 
 #include "libavutil/attributes.h"
 #include "libavutil/channel_layout.h"
+#include "libavutil/display.h"
 #include "libavutil/intreadwrite.h"
 #include "libavutil/intfloat.h"
 #include "libavutil/mathematics.h"
@@ -2610,22 +2611,8 @@ static int mov_read_tkhd(MOVContext *c, AVIOContext *pb, MOVAtom atom)
     sc->width = width >> 16;
     sc->height = height >> 16;
 
-    //Assign clockwise rotate values based on transform matrix so that
-    //we can compensate for iPhone orientation during capture.
-
-    if (display_matrix[1][0] == -65536 && display_matrix[0][1] == 65536) {
-         av_dict_set(&st->metadata, "rotate", "90", 0);
-    }
-
-    if (display_matrix[0][0] == -65536 && display_matrix[1][1] == -65536) {
-         av_dict_set(&st->metadata, "rotate", "180", 0);
-    }
-
-    if (display_matrix[1][0] == 65536 && display_matrix[0][1] == -65536) {
-         av_dict_set(&st->metadata, "rotate", "270", 0);
-    }
-
-    // save the matrix when it is not the default identity
+    // save the matrix and add rotate metadata when it is not the default
+    // identity
     if (display_matrix[0][0] != (1 << 16) ||
         display_matrix[1][1] != (1 << 16) ||
         display_matrix[2][2] != (1 << 30) ||
@@ -2633,6 +2620,7 @@ static int mov_read_tkhd(MOVContext *c, AVIOContext *pb, MOVAtom atom)
         display_matrix[1][0] || display_matrix[1][2] ||
         display_matrix[2][0] || display_matrix[2][1]) {
         int i, j;
+        double rotate;
 
         av_freep(&sc->display_matrix);
         sc->display_matrix = av_malloc(sizeof(int32_t) * 9);
@@ -2642,6 +2630,16 @@ static int mov_read_tkhd(MOVContext *c, AVIOContext *pb, MOVAtom atom)
         for (i = 0; i < 3; i++)
             for (j = 0; j < 3; j++)
                 sc->display_matrix[i * 3 + j] = display_matrix[j][i];
+
+        rotate = av_display_rotation_get(sc->display_matrix);
+        if (!isnan(rotate)) {
+            char rotate_buf[64];
+            rotate = -rotate;
+            if (rotate < 0) // for backward compatibility
+                rotate += 360;
+            snprintf(rotate_buf, sizeof(rotate_buf), "%g", rotate);
+            av_dict_set(&st->metadata, "rotate", rotate_buf, 0);
+        }
     }
 
     // transform the display width/height according to the matrix



More information about the ffmpeg-cvslog mailing list