[FFmpeg-devel] [PATCH] segment: don't copy codec_tag when not available

ChanMin Kim kcm1700 at gmail.com
Thu Nov 15 18:30:16 CET 2012


- Some muxers do not allow stream if codec_tag is incompatible
- Sometimes passed input codec's codec_tag isn't compatible to output muxer
- Because codec_tag field of segment muxer cannot be set, ffmpeg.c doesn't
know how to handle these cases.

Signed-off-by: ChanMin Kim <kcm1700 at gmail.com>
---
 libavformat/segment.c |   13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/libavformat/segment.c b/libavformat/segment.c
index f31b25f..cbe46e1 100644
--- a/libavformat/segment.c
+++ b/libavformat/segment.c
@@ -108,9 +108,20 @@ static int segment_mux_init(AVFormatContext *s)

     for (i = 0; i < s->nb_streams; i++) {
         AVStream *st;
+        AVCodecContext *icodec, *codec;
         if (!(st = avformat_new_stream(oc, NULL)))
             return AVERROR(ENOMEM);
-        avcodec_copy_context(st->codec, s->streams[i]->codec);
+
+        icodec = s->streams[i]->codec;
+        codec = st->codec;
+        avcodec_copy_context(codec, icodec);
+        if (!oc->oformat->codec_tag ||
+             av_codec_get_id (oc->oformat->codec_tag,
icodec->codec_tag) == codec->codec_id ||
+             av_codec_get_tag(oc->oformat->codec_tag, icodec->codec_id) <= 0) {
+            codec->codec_tag = icodec->codec_tag;
+        } else {
+            codec->codec_tag = 0;
+        }
         st->sample_aspect_ratio = s->streams[i]->sample_aspect_ratio;
     }

-- 
1.7.10.4


More information about the ffmpeg-devel mailing list