Ticket #3622: ffmpeg-2.2.2-defaultstreams.patch

File ffmpeg-2.2.2-defaultstreams.patch, 2.6 KB (added by Michael Cashwell, 12 years ago)

Proposed patch

  • libavformat/movenc.c

    # 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  
    36733673/*
    36743674 * st->disposition controls the "enabled" flag in the tkhd tag.
    36753675 * 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.
    36773677 *
    36783678 * Subtitles are special.  For audio and video, setting "enabled" also
    36793679 * makes the track "default" (i.e. it is rendered when played). For
    static void enable_tracks(AVFormatContext *s)  
    37003700            st->codec->codec_type >= AVMEDIA_TYPE_NB)
    37013701            continue;
    37023702
     3703        // note the first stream number for each type
    37033704        if (first[st->codec->codec_type] < 0)
    37043705            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)
    37073709            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;
    37093714    }
    37103715
     3716    // for each media type, if no stream was explicitly enabled
     3717    // then enable the first one found for that type
    37113718    for (i = 0; i < AVMEDIA_TYPE_NB; i++) {
    37123719        switch (i) {
    37133720        case AVMEDIA_TYPE_VIDEO:
    37143721        case AVMEDIA_TYPE_AUDIO:
    37153722        case AVMEDIA_TYPE_SUBTITLE:
    37163723            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;
    37173738                mov->tracks[first[i]].flags |= MOV_TRACK_ENABLED;
     3739            }
    37183740            break;
    37193741        }
    37203742    }