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

Carl Eugen Hoyos cehoyos at ag.or.at
Sun Jun 1 14:58:41 CEST 2014


Hi!

On Sunday 19 May 2013 10:21:59 pm Carl Eugen Hoyos wrote:
> FFmpeg currently allows to mux transport streams that cannot be 
> decoded, attached patch allows to report an error in such a case.

I still believe this is an important issue (that hits 
users regularly). I also think it is important to distinguish 
between codecs not supported in transport streams and codecs 
that are supported but support is not implemented in FFmpeg.

Please comment, Carl Eugen
-------------- next part --------------
diff --git a/libavformat/mpegtsenc.c b/libavformat/mpegtsenc.c
index f773019..9571789 100644
--- a/libavformat/mpegtsenc.c
+++ b/libavformat/mpegtsenc.c
@@ -608,6 +608,44 @@ 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 ||
+            st->codec->strict_std_compliance <= FF_COMPLIANCE_EXPERIMENTAL)
+            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:
+        case AV_CODEC_ID_DVB_TELETEXT:
+            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:
+            av_log(s, AV_LOG_ERROR, "Muxing %s in transport streams is not yet implemented, use -strict experimental to write invalid files\n",
+                   avcodec_get_name(st->codec->codec_id));
+            return AVERROR_PATCHWELCOME;
+        }
+        av_log(s, AV_LOG_ERROR, "Codec %s not supported in transport streams, use -strict experimental to write invalid files\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