diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c
index 85b5146..0bebb13 100644
--- a/libavformat/mpegts.c
+++ b/libavformat/mpegts.c
@@ -692,7 +692,8 @@ static int mpegts_set_stream_info(AVStream *st, PESContext *pes,
         mpegts_find_stream_type(st, pes->stream_type, MISC_types);
     if (st->codec->codec_id == AV_CODEC_ID_NONE){
         st->codec->codec_id  = old_codec_id;
-        st->codec->codec_type= old_codec_type;
+        if (old_codec_type != AVMEDIA_TYPE_UNKNOWN)
+            st->codec->codec_type= old_codec_type;
     }
 
     return 0;
