# this patch is meant to address trac ticket <https://trac.ffmpeg.org/ticket/3622>
# where more than one stream/track was being enabled for the same media type.
# this caused playback failures in Quicktime and especially Apple TVs when both
# stereo and surround streams were being written to the same container.
diff --git a/libavformat/movenc.c b/libavformat/movenc.c
index 01bc3c9..a11378f 100644
|
a
|
b
|
static int mov_create_timecode_track(AVFormatContext *s, int index, int src_inde
|
| 3673 | 3673 | /* |
| 3674 | 3674 | * st->disposition controls the "enabled" flag in the tkhd tag. |
| 3675 | 3675 | * QuickTime will not play a track if it is not enabled. So make sure |
| 3676 | | * that one track of each type (audio, video, subtitle) is enabled. |
| | 3676 | * that at most one track of each type (audio, video, subtitle) is enabled. |
| 3677 | 3677 | * |
| 3678 | 3678 | * Subtitles are special. For audio and video, setting "enabled" also |
| 3679 | 3679 | * makes the track "default" (i.e. it is rendered when played). For |
| … |
… |
static void enable_tracks(AVFormatContext *s)
|
| 3700 | 3700 | st->codec->codec_type >= AVMEDIA_TYPE_NB) |
| 3701 | 3701 | continue; |
| 3702 | 3702 | |
| | 3703 | // note the first stream number for each type |
| 3703 | 3704 | if (first[st->codec->codec_type] < 0) |
| 3704 | 3705 | first[st->codec->codec_type] = i; |
| 3705 | | if (st->disposition & AV_DISPOSITION_DEFAULT) { |
| 3706 | | mov->tracks[i].flags |= MOV_TRACK_ENABLED; |
| | 3706 | |
| | 3707 | // note whether each media type has any enabled streams |
| | 3708 | if (st->disposition & AV_DISPOSITION_DEFAULT) |
| 3707 | 3709 | enabled[st->codec->codec_type] = 1; |
| 3708 | | } |
| | 3710 | |
| | 3711 | // clear the enables for each stream and track |
| | 3712 | st->disposition &= ~AV_DISPOSITION_DEFAULT; |
| | 3713 | mov->tracks[i].flags &= ~MOV_TRACK_ENABLED; |
| 3709 | 3714 | } |
| 3710 | 3715 | |
| | 3716 | // for each media type, if no stream was explicitly enabled |
| | 3717 | // then enable the first one found for that type |
| 3711 | 3718 | for (i = 0; i < AVMEDIA_TYPE_NB; i++) { |
| 3712 | 3719 | switch (i) { |
| 3713 | 3720 | case AVMEDIA_TYPE_VIDEO: |
| 3714 | 3721 | case AVMEDIA_TYPE_AUDIO: |
| 3715 | 3722 | case AVMEDIA_TYPE_SUBTITLE: |
| 3716 | 3723 | if (!enabled[i] && first[i] >= 0) |
| | 3724 | enabled[i] = 1; |
| | 3725 | break; |
| | 3726 | } |
| | 3727 | } |
| | 3728 | |
| | 3729 | // translate the first enabled stream of each media type |
| | 3730 | // into its stream being default and its output track being enabled |
| | 3731 | for (i = 0; i < AVMEDIA_TYPE_NB; i++) { |
| | 3732 | switch (i) { |
| | 3733 | case AVMEDIA_TYPE_VIDEO: |
| | 3734 | case AVMEDIA_TYPE_AUDIO: |
| | 3735 | case AVMEDIA_TYPE_SUBTITLE: |
| | 3736 | if (enabled[i]) { |
| | 3737 | s->streams[first[i]]->disposition |= AV_DISPOSITION_DEFAULT; |
| 3717 | 3738 | mov->tracks[first[i]].flags |= MOV_TRACK_ENABLED; |
| | 3739 | } |
| 3718 | 3740 | break; |
| 3719 | 3741 | } |
| 3720 | 3742 | } |