---
 libavformat/isom.h |  3 +++
 libavformat/mov.c  | 37 +++++++++++++++++++++++++++++++++++--
 2 files changed, 38 insertions(+), 2 deletions(-)

diff --git a/libavformat/isom.h b/libavformat/isom.h
index bf0792c..2dbdfd2 100644
--- a/libavformat/isom.h
+++ b/libavformat/isom.h
@@ -135,6 +135,9 @@ typedef struct MOVStreamContext {
     int64_t track_end;    ///< used for dts generation in fragmented movie 
files
     unsigned int rap_group_count;
     MOVSbgp *rap_group;
+
+    int matrix_present;
+    int display_matrix[3][3];
 } MOVStreamContext;
 
 typedef struct MOVContext {
diff --git a/libavformat/mov.c b/libavformat/mov.c
index 22ec01d..b0841b7 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -31,6 +31,7 @@
 #include "libavutil/avstring.h"
 #include "libavutil/channel_layout.h"
 #include "libavutil/dict.h"
+#include "libavutil/display.h"
 #include "libavutil/intfloat.h"
 #include "libavutil/intreadwrite.h"
 #include "libavutil/mathematics.h"
@@ -2460,7 +2461,7 @@ static int mov_read_tkhd(MOVContext *c, AVIOContext *pb, 
MOVAtom atom)
     int width;
     int height;
     int64_t disp_transform[2];
-    int display_matrix[3][2];
+    int display_matrix[3][3];
     AVStream *st;
     MOVStreamContext *sc;
     int version;
@@ -2502,7 +2503,7 @@ static int mov_read_tkhd(MOVContext *c, AVIOContext *pb, 
MOVAtom atom)
     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
-        avio_rb32(pb);           // 2.30 fixed point (not used)
+        display_matrix[i][2] = avio_rb32(pb);   //  2.30 fixed point (not used)
     }
 
     width  = avio_rb32(pb);  // 16.16 fixed point track width
@@ -2510,6 +2511,17 @@ static int mov_read_tkhd(MOVContext *c, AVIOContext *pb, 
MOVAtom atom)
     sc->width  = width >> 16;
     sc->height = height >> 16;
 
+    // save the matrix 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) ||
+        display_matrix[0][1] || display_matrix[0][2] ||
+        display_matrix[1][0] || display_matrix[1][2] ||
+        display_matrix[2][0] || display_matrix[2][1]) {
+        sc->matrix_present = 1;
+        memcpy(sc->display_matrix, display_matrix, sizeof(int) * 3 * 3);
+    }
+
     // transform the display width/height according to the matrix
     // skip this if the display matrix is the default identity matrix
     // or if it is rotating the picture, ex iPhone 3GS
@@ -3279,6 +3291,27 @@ retry:
                 sc->has_palette = 0;
             }
         }
+        if (sc->matrix_present) {
+            AVPacketSideData *sd, *tmp;
+
+            tmp = av_realloc_array(st->side_data,
+                                   st->nb_side_data + 1, sizeof(*tmp));
+            if (!tmp)
+                return AVERROR(ENOMEM);
+
+            st->side_data = tmp;
+            st->nb_side_data++;
+
+            sd = &st->side_data[st->nb_side_data - 1];
+            sd->type = AV_PKT_DATA_DISPLAYMATRIX;
+            sd->size = sizeof(int32_t) * 3 * 3;
+            sd->data = av_display_matrix_to_data(sc->display_matrix);
+
+            if (!sd->data)
+                return AVERROR(ENOMEM);
+
+            sc->matrix_present = 0;
+        }
 #if CONFIG_DV_DEMUXER
         if (mov->dv_demux && sc->dv_audio_container) {
             avpriv_dv_produce_packet(mov->dv_demux, pkt, pkt->data, pkt->size);
-- 
1.8.3.4 (Apple Git-47)

_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to