[FFmpeg-devel] [PATCH 2/3] avformat/mov: use av_display_rotation_get() for rotate metadata.

Clément Bœsch u at pkh.me
Tue May 20 19:59:06 CEST 2014


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

diff --git a/libavformat/mov.c b/libavformat/mov.c
index 26fb0ed..8c0f5ca 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"
@@ -2561,10 +2562,12 @@ static int mov_read_tkhd(MOVContext *c, AVIOContext *pb, MOVAtom atom)
     int height;
     int64_t disp_transform[2];
     int display_matrix[3][3];
+    int display_matrix_flat[3*3];
     AVStream *st;
     MOVStreamContext *sc;
     int version;
     int flags;
+    double rotate;
 
     if (c->fc->nb_streams < 1)
         return 0;
@@ -2600,9 +2603,9 @@ static int mov_read_tkhd(MOVContext *c, AVIOContext *pb, MOVAtom atom)
     // save u,v,z to store the whole matrix in the AV_PKT_DATA_DISPLAYMATRIX
     // side data, but the scale factor is not needed to calculate aspect ratio
     for (i = 0; i < 3; i++) {
-        display_matrix[i][0] = avio_rb32(pb);   // 16.16 fixed point
-        display_matrix[i][1] = avio_rb32(pb);   // 16.16 fixed point
-        display_matrix[i][2] = avio_rb32(pb);   //  2.30 fixed point
+        display_matrix_flat[i*3 + 0] = display_matrix[i][0] = avio_rb32(pb);   // 16.16 fixed point
+        display_matrix_flat[i*3 + 1] = display_matrix[i][1] = avio_rb32(pb);   // 16.16 fixed point
+        display_matrix_flat[i*3 + 2] = display_matrix[i][2] = avio_rb32(pb);   //  2.30 fixed point
     }
 
     width = avio_rb32(pb);       // 16.16 fixed point track width
@@ -2610,19 +2613,13 @@ 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);
+    rotate = av_display_rotation_get(display_matrix_flat);
+    if (rotate && rotate != NAN) {
+        char rotate_buf[64];
+        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);
     }
 
     // save the matrix when it is not the default identity
-- 
1.9.2



More information about the ffmpeg-devel mailing list