diff --git a/avplay.c b/avplay.c
index b1ce057d463087a521ba1d57b5098dad462eb35a..e98e3ade23a8aeb5f1f8c735bae8c61552f04ff1 100644
--- a/avplay.c
+++ b/avplay.c
@@ -1580,6 +1580,8 @@ static int video_thread(void *arg)
     AVFilterContext *filt_out = NULL, *filt_in = NULL;
     int last_w = is->video_st->codec->width;
     int last_h = is->video_st->codec->height;
+    if (!graph)
+        return AVERROR(ENOMEM);
 
     if ((ret = configure_video_filters(graph, is, vfilters)) < 0)
         goto the_end;