summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClément Bœsch <u@pkh.me>2014-05-20 19:51:27 +0200
committerClément Bœsch <u@pkh.me>2014-05-23 23:30:21 +0200
commite63a17bfdc99441ff25e188d2398bf1a8f1fbb7e (patch)
treefd01f7bdbb467e6ad0f813a18ce401e9c6a39dff
parentfa972dcf1a36805de4aaa031331061a0a334996d (diff)
avformat/mov: use av_display_rotation_get() for rotate metadata.
-rw-r--r--libavformat/mov.c30
1 files changed, 14 insertions, 16 deletions
diff --git a/libavformat/mov.c b/libavformat/mov.c
index 7f72db973b..7203d586f9 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