]> git.sesse.net Git - ffmpeg/commitdiff
lavf/segment: do not copy codec_tag when not available
authorChanMin Kim <kcm1700@gmail.com>
Sat, 17 Nov 2012 16:39:51 +0000 (17:39 +0100)
committerMichael Niedermayer <michaelni@gmx.at>
Tue, 20 Nov 2012 18:19:31 +0000 (19:19 +0100)
Some muxers do not allow stream if codec_tag is incompatible.

Sometimes the passed input codec's codec_tag is not compatible with the
output muxer.

Because the codec_tag field of the segment muxer cannot be set, ffmpeg.c
doesn't know how to handle these cases.

Signed-off-by: ChanMin Kim <kcm1700@gmail.com>
Signed-off-by: Stefano Sabatini <stefasab@gmail.com>
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
libavformat/segment.c

index f31b25fb3611fd50607c7ef633dad23df2a5b91c..339f9683e10c64b3638b54a4449ddccf3392749a 100644 (file)
@@ -108,9 +108,20 @@ static int segment_mux_init(AVFormatContext *s)
 
     for (i = 0; i < s->nb_streams; i++) {
         AVStream *st;
+        AVCodecContext *icodec, *ocodec;
+
         if (!(st = avformat_new_stream(oc, NULL)))
             return AVERROR(ENOMEM);
-        avcodec_copy_context(st->codec, s->streams[i]->codec);
+        icodec = s->streams[i]->codec;
+        ocodec = st->codec;
+        avcodec_copy_context(ocodec, icodec);
+        if (!oc->oformat->codec_tag ||
+            av_codec_get_id (oc->oformat->codec_tag, icodec->codec_tag) == ocodec->codec_id ||
+            av_codec_get_tag(oc->oformat->codec_tag, icodec->codec_id) <= 0) {
+            ocodec->codec_tag = icodec->codec_tag;
+        } else {
+            ocodec->codec_tag = 0;
+        }
         st->sample_aspect_ratio = s->streams[i]->sample_aspect_ratio;
     }