[FFmpeg-cvslog] mov: Do not group tracks if more than one is enabled per type

Luca Barbato git at videolan.org
Fri Jul 11 13:06:08 CEST 2014


ffmpeg | branch: master | Luca Barbato <lu_zero at gentoo.org> | Fri Jul  4 16:26:06 2014 +0200| [f90729699db9ede2bef2b28000f1795dab1b8996] | committer: Luca Barbato

mov: Do not group tracks if more than one is enabled per type

The specification requires at most 1 track enabled per alternate group.

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

 libavformat/movenc.c |   21 ++++++++++++++++-----
 libavformat/movenc.h |    2 ++
 2 files changed, 18 insertions(+), 5 deletions(-)

diff --git a/libavformat/movenc.c b/libavformat/movenc.c
index f5c36fc..b0c380e 100644
--- a/libavformat/movenc.c
+++ b/libavformat/movenc.c
@@ -1459,11 +1459,20 @@ static int mov_write_mdia_tag(AVIOContext *pb, MOVTrack *track)
     return update_size(pb, pos);
 }
 
-static int mov_write_tkhd_tag(AVIOContext *pb, MOVTrack *track, AVStream *st)
+static int mov_write_tkhd_tag(AVIOContext *pb, MOVMuxContext *mov,
+                              MOVTrack *track, AVStream *st)
 {
     int64_t duration = av_rescale_rnd(track->track_duration, MOV_TIMESCALE,
                                       track->timescale, AV_ROUND_UP);
     int version = duration < INT32_MAX ? 0 : 1;
+    int group   = 0;
+
+    if (st) {
+        if (mov->per_stream_grouping)
+            group = st->index;
+        else
+            group = st->codec->codec_type;
+    }
 
     if (track->mode == MODE_ISM)
         version = 1;
@@ -1491,7 +1500,7 @@ static int mov_write_tkhd_tag(AVIOContext *pb, MOVTrack *track, AVStream *st)
     avio_wb32(pb, 0); /* reserved */
     avio_wb32(pb, 0); /* reserved */
     avio_wb16(pb, 0); /* layer */
-    avio_wb16(pb, st ? st->codec->codec_type : 0); /* alternate group) */
+    avio_wb16(pb, group); /* alternate group) */
     /* Volume, only for audio */
     if (track->enc->codec_type == AVMEDIA_TYPE_AUDIO)
         avio_wb16(pb, 0x0100);
@@ -1665,7 +1674,7 @@ static int mov_write_trak_tag(AVIOContext *pb, MOVMuxContext *mov,
     int64_t pos = avio_tell(pb);
     avio_wb32(pb, 0); /* size */
     ffio_wfourcc(pb, "trak");
-    mov_write_tkhd_tag(pb, track, st);
+    mov_write_tkhd_tag(pb, mov, track, st);
     if (track->mode == MODE_PSP || track->flags & MOV_TRACK_CTTS ||
         (track->entry && track->cluster[0].dts) ||
         is_clcp_track(track)) {
@@ -3164,7 +3173,7 @@ static void enable_tracks(AVFormatContext *s)
 {
     MOVMuxContext *mov = s->priv_data;
     int i;
-    uint8_t enabled[AVMEDIA_TYPE_NB];
+    int enabled[AVMEDIA_TYPE_NB];
     int first[AVMEDIA_TYPE_NB];
 
     for (i = 0; i < AVMEDIA_TYPE_NB; i++) {
@@ -3183,7 +3192,7 @@ static void enable_tracks(AVFormatContext *s)
             first[st->codec->codec_type] = i;
         if (st->disposition & AV_DISPOSITION_DEFAULT) {
             mov->tracks[i].flags |= MOV_TRACK_ENABLED;
-            enabled[st->codec->codec_type] = 1;
+            enabled[st->codec->codec_type]++;
         }
     }
 
@@ -3192,6 +3201,8 @@ static void enable_tracks(AVFormatContext *s)
         case AVMEDIA_TYPE_VIDEO:
         case AVMEDIA_TYPE_AUDIO:
         case AVMEDIA_TYPE_SUBTITLE:
+            if (enabled[i] > 1)
+                mov->per_stream_grouping = 1;
             if (!enabled[i] && first[i] >= 0)
                 mov->tracks[first[i]].flags |= MOV_TRACK_ENABLED;
             break;
diff --git a/libavformat/movenc.h b/libavformat/movenc.h
index 3410080..35be781 100644
--- a/libavformat/movenc.h
+++ b/libavformat/movenc.h
@@ -162,6 +162,8 @@ typedef struct MOVMuxContext {
     int64_t reserved_moov_pos;
 
     char *major_brand;
+
+    int per_stream_grouping;
 } MOVMuxContext;
 
 #define FF_MOV_FLAG_RTP_HINT 1



More information about the ffmpeg-cvslog mailing list