summaryrefslogtreecommitdiff
path: root/libavformat/movenc.c
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2013-08-23 13:43:05 +0200
committerMichael Niedermayer <michaelni@gmx.at>2013-08-23 13:49:24 +0200
commit800ea20cadce7c5ec06e7821dc83dedb6e20209e (patch)
treed3400c82660ae2fa6f78776db2fec73aa1bd6ab2 /libavformat/movenc.c
parentc6f4a3a70837cf259466a7aab440dc0682b08c72 (diff)
parent30ce289074e88f528965cb57720674a675639737 (diff)
Merge remote-tracking branch 'qatar/master'
* qatar/master: movenc: Make tkhd "enabled" flag QuickTime compatible Conflicts: libavformat/movenc.c tests/ref/acodec/alac tests/ref/acodec/pcm-s16be tests/ref/acodec/pcm-s24be tests/ref/acodec/pcm-s32be tests/ref/acodec/pcm-s8 tests/ref/lavf/mov tests/ref/vsynth/vsynth1-dnxhd-1080i tests/ref/vsynth/vsynth1-mpeg4 tests/ref/vsynth/vsynth1-prores tests/ref/vsynth/vsynth1-qtrle tests/ref/vsynth/vsynth1-svq1 tests/ref/vsynth/vsynth2-dnxhd-1080i tests/ref/vsynth/vsynth2-mpeg4 tests/ref/vsynth/vsynth2-prores tests/ref/vsynth/vsynth2-qtrle tests/ref/vsynth/vsynth2-svq1 Merged-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavformat/movenc.c')
-rw-r--r--libavformat/movenc.c64
1 files changed, 55 insertions, 9 deletions
diff --git a/libavformat/movenc.c b/libavformat/movenc.c
index ecf57a5fb6..f65c2bd3cb 100644
--- a/libavformat/movenc.c
+++ b/libavformat/movenc.c
@@ -1600,7 +1600,9 @@ static int mov_write_tkhd_tag(AVIOContext *pb, MOVTrack *track, AVStream *st)
(version == 1) ? avio_wb32(pb, 104) : avio_wb32(pb, 92); /* size */
ffio_wfourcc(pb, "tkhd");
avio_w8(pb, version);
- avio_wb24(pb, track->secondary ? 0x2 : 0xf); /* flags (first track enabled) */
+ avio_wb24(pb, (track->flags & MOV_TRACK_ENABLED) ?
+ MOV_TKHD_FLAG_ENABLED | MOV_TKHD_FLAG_IN_MOVIE :
+ MOV_TKHD_FLAG_IN_MOVIE);
if (version == 1) {
avio_wb64(pb, track->time);
avio_wb64(pb, track->time);
@@ -2331,7 +2333,6 @@ static int mov_write_moov_tag(AVIOContext *pb, MOVMuxContext *mov,
{
int i;
int64_t pos = avio_tell(pb);
- int not_first[AVMEDIA_TYPE_NB]={0};
avio_wb32(pb, 0); /* size placeholder*/
ffio_wfourcc(pb, "moov");
@@ -2372,13 +2373,6 @@ static int mov_write_moov_tag(AVIOContext *pb, MOVMuxContext *mov,
mov_write_iods_tag(pb, mov);
for (i = 0; i < mov->nb_streams; i++) {
if (mov->tracks[i].entry > 0 || mov->flags & FF_MOV_FLAG_FRAGMENT) {
- if (i < s->nb_streams){
- int codec_type= s->streams[i]->codec->codec_type;
- if (codec_type==AVMEDIA_TYPE_AUDIO || codec_type==AVMEDIA_TYPE_SUBTITLE){
- mov->tracks[i].secondary= not_first[codec_type];
- not_first[codec_type]= 1;
- }
- }
mov_write_trak_tag(pb, mov, &(mov->tracks[i]), i < s->nb_streams ? s->streams[i] : NULL);
}
}
@@ -3510,6 +3504,56 @@ static int mov_create_timecode_track(AVFormatContext *s, int index, int src_inde
return ret;
}
+/*
+ * st->disposition controls the "enabled" flag in the tkhd tag.
+ * QuickTime will not play a track if it is not enabled. So make sure
+ * that one track of each type (audio, video, subtitle) is enabled.
+ *
+ * Subtitles are special. For audio and video, setting "enabled" also
+ * makes the track "default" (i.e. it is rendered when played). For
+ * subtitles, an "enabled" subtitle is not rendered by default, but
+ * if no subtitle is enabled, the subtitle menu in QuickTime will be
+ * empty!
+ */
+static void enable_tracks(AVFormatContext *s)
+{
+ MOVMuxContext *mov = s->priv_data;
+ int i;
+ uint8_t enabled[AVMEDIA_TYPE_NB];
+ int first[AVMEDIA_TYPE_NB];
+
+ for (i = 0; i < AVMEDIA_TYPE_NB; i++) {
+ enabled[i] = 0;
+ first[i] = -1;
+ }
+
+ for (i = 0; i < s->nb_streams; i++) {
+ AVStream *st = s->streams[i];
+
+ if (st->codec->codec_type <= AVMEDIA_TYPE_UNKNOWN ||
+ st->codec->codec_type >= AVMEDIA_TYPE_NB)
+ continue;
+
+ if (first[st->codec->codec_type] < 0)
+ 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;
+ }
+ }
+
+ for (i = 0; i < AVMEDIA_TYPE_NB; i++) {
+ switch (i) {
+ case AVMEDIA_TYPE_VIDEO:
+ case AVMEDIA_TYPE_AUDIO:
+ case AVMEDIA_TYPE_SUBTITLE:
+ if (!enabled[i] && first[i] >= 0)
+ mov->tracks[first[i]].flags |= MOV_TRACK_ENABLED;
+ break;
+ }
+ }
+}
+
static int mov_write_header(AVFormatContext *s)
{
AVIOContext *pb = s->pb;
@@ -3720,6 +3764,8 @@ static int mov_write_header(AVFormatContext *s)
}
}
+ enable_tracks(s);
+
if (mov->mode == MODE_ISM) {
/* If no fragmentation options have been set, set a default. */
if (!(mov->flags & (FF_MOV_FLAG_FRAG_KEYFRAME |