diff mbox

[FFmpeg-devel,v3,07/25] avformat/mov: mov_read_tkhd stores alternate group to AV_PKT_DATA_TRACK_ALTERNATE_GROUP

Message ID 1474291548-17810-8-git-send-email-erkki.seppala.ext@nokia.com
State New
Headers show

Commit Message

erkki.seppala.ext@nokia.com Sept. 19, 2016, 1:25 p.m. UTC
This is done only if the option read_alternate_group is set as to
not change the behavior when copying tracks.

FFmpeg automatically assigns track groups (when no
AV_PKT_DATA_TRACK_ALTERNATE_GROUP side data is not available) by the
track indices, so if the track indices would be changed, reusing the
original alternate group from the track would likely by unwanted,
because the reassignment of alternate group would be skipped.

Signed-off-by: Erkki Seppälä <erkki.seppala.ext@nokia.com>
Signed-off-by: OZOPlayer <OZOPL@nokia.com>
---
 libavformat/isom.h |  1 +
 libavformat/mov.c  | 16 +++++++++++++++-
 2 files changed, 16 insertions(+), 1 deletion(-)
diff mbox

Patch

diff --git a/libavformat/isom.h b/libavformat/isom.h
index 609b7b7..7b521d8 100644
--- a/libavformat/isom.h
+++ b/libavformat/isom.h
@@ -242,6 +242,7 @@  typedef struct MOVContext {
     uint8_t *decryption_key;
     int decryption_key_len;
     int enable_drefs;
+    int read_alternate_group;
 } MOVContext;
 
 int ff_mp4_read_descr_len(AVIOContext *pb);
diff --git a/libavformat/mov.c b/libavformat/mov.c
index ff4c91c..82450e9 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -3539,6 +3539,7 @@  static int mov_read_tkhd(MOVContext *c, AVIOContext *pb, MOVAtom atom)
     MOVStreamContext *sc;
     int version;
     int flags;
+    int alternate_group;
 
     if (c->fc->nb_streams < 1)
         return 0;
@@ -3565,7 +3566,7 @@  static int mov_read_tkhd(MOVContext *c, AVIOContext *pb, MOVAtom atom)
     avio_rb32(pb); /* reserved */
 
     avio_rb16(pb); /* layer */
-    avio_rb16(pb); /* alternate group */
+    alternate_group = avio_rb16(pb);
     avio_rb16(pb); /* volume */
     avio_rb16(pb); /* reserved */
 
@@ -3630,6 +3631,17 @@  static int mov_read_tkhd(MOVContext *c, AVIOContext *pb, MOVAtom atom)
                 disp_transform[0] / disp_transform[1],
                 INT_MAX);
     }
+
+    if (c->read_alternate_group) {
+        int *alternate_group_side =
+            (int*) av_stream_new_side_data(st, AV_PKT_DATA_TRACK_ALTERNATE_GROUP,
+                                           sizeof(int));
+        if (!alternate_group_side)
+            return AVERROR(ENOMEM);
+
+        *alternate_group_side = alternate_group;
+    }
+
     return 0;
 }
 
@@ -5682,6 +5694,8 @@  static const AVOption mov_options[] = {
     { "decryption_key", "The media decryption key (hex)", OFFSET(decryption_key), AV_OPT_TYPE_BINARY, .flags = AV_OPT_FLAG_DECODING_PARAM },
     { "enable_drefs", "Enable external track support.", OFFSET(enable_drefs), AV_OPT_TYPE_BOOL,
         {.i64 = 0}, 0, 1, FLAGS },
+    {"read_alternate_group", "", OFFSET(read_alternate_group), AV_OPT_TYPE_BOOL, {.i64 = 0},
+        0, 1, FLAGS},
 
     { NULL },
 };