diff --git a/libavformat/demux.c b/libavformat/demux.c
index cba1f2e4df..17a29146af 100644
--- a/libavformat/demux.c
+++ b/libavformat/demux.c
@@ -3046,7 +3046,7 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options)
         AVStream *const st  = ic->streams[i];
         FFStream *const sti = ffstream(st);
 
-        if (sti->avctx_inited) {
+        if (sti->avctx_inited && has_codec_parameters(sti, NULL)) {
             ret = avcodec_parameters_from_context(st->codecpar, sti->avctx);
             if (ret < 0)
                 goto find_stream_info_err;
