diff --git a/libavformat/nuv.c b/libavformat/nuv.c
index 74393afaa7059965c48186c81b222bf28603a776..995775dc393ec71491c36fc32176046817fc8da7 100644
--- a/libavformat/nuv.c
+++ b/libavformat/nuv.c
@@ -179,7 +179,7 @@ static int nuv_header(AVFormatContext *s, AVFormatParameters *ap) {
         ctx->a_id = -1;
 
     get_codec_data(pb, vst, ast, is_mythtv);
-    ctx->rtjpg_video = vst->codec->codec_id == CODEC_ID_NUV;
+    ctx->rtjpg_video = vst && vst->codec->codec_id == CODEC_ID_NUV;
     return 0;
 }