[FFmpeg-devel] [PATCH]Refuse to mux invalid transport streams

Carl Eugen Hoyos cehoyos at ag.or.at
Sun May 19 22:21:59 CEST 2013


Hi!

FFmpeg currently allows to mux transport streams that cannot be decoded, 
attached patch allows to report an error in such a case.

Please comment, Carl Eugen
-------------- next part --------------
diff --git a/libavformat/mpegtsenc.c b/libavformat/mpegtsenc.c
index 0ddae65..ec40390 100644
--- a/libavformat/mpegtsenc.c
+++ b/libavformat/mpegtsenc.c
@@ -519,6 +519,43 @@ static int mpegts_write_header(AVFormatContext *s)
     int *pids;
     int ret;
 
+    for (i = 0; i < s->nb_streams; i++) {
+        st = s->streams[i];
+        if (st->codec->codec_type == AVMEDIA_TYPE_DATA)
+            continue;
+        switch (st->codec->codec_id) {
+        case AV_CODEC_ID_CAVS:
+        case AV_CODEC_ID_DIRAC:
+        case AV_CODEC_ID_H264:
+        case AV_CODEC_ID_MPEG1VIDEO:
+        case AV_CODEC_ID_MPEG2VIDEO:
+        case AV_CODEC_ID_MPEG4:
+        case AV_CODEC_ID_AAC:
+        case AV_CODEC_ID_AAC_LATM:
+        case AV_CODEC_ID_AC3:
+        case AV_CODEC_ID_DTS:
+        case AV_CODEC_ID_EAC3:
+        case AV_CODEC_ID_MP2:
+        case AV_CODEC_ID_MP3:
+        case AV_CODEC_ID_S302M:
+        case AV_CODEC_ID_DVB_SUBTITLE:
+            continue;
+        }
+        switch (st->codec->codec_id) {
+        case AV_CODEC_ID_VC1:
+        case AV_CODEC_ID_TRUEHD:
+        case AV_CODEC_ID_PCM_BLURAY:
+        case AV_CODEC_ID_HDMV_PGS_SUBTITLE:
+        case AV_CODEC_ID_DVB_TELETEXT:
+            av_log(s, AV_LOG_ERROR, "Muxing %s in transport streams is not yet supported\n",
+                   avcodec_get_name(st->codec->codec_id));
+            return AVERROR_PATCHWELCOME;
+        }
+        av_log(s, AV_LOG_ERROR, "Codec %s not supported in transport streams\n",
+               avcodec_get_name(st->codec->codec_id));
+        return AVERROR(EINVAL);
+    }
+
     if (s->max_delay < 0) /* Not set by the caller */
         s->max_delay = 0;
 


More information about the ffmpeg-devel mailing list