diff --git a/libavcodec/subviewerdec.c b/libavcodec/subviewerdec.c
index 7580cbe67964d137db21787b3dbd79900d8deca2..63be4188b92f4fa8e3c5efd11389f0d1e48bb65b 100644
--- a/libavcodec/subviewerdec.c
+++ b/libavcodec/subviewerdec.c
@@ -56,7 +56,7 @@ static int subviewer_decode_frame(AVCodecContext *avctx,
     AVBPrint buf;
 
     /* To be removed later */
-    if (sscanf(ptr, "%*u:%*u:%*u.%*u,%*u:%*u:%*u.%*u%c", &c) == 1) {
+    if (ptr && sscanf(ptr, "%*u:%*u:%*u.%*u,%*u:%*u:%*u.%*u%c", &c) == 1) {
         av_log(avctx, AV_LOG_ERROR, "AVPacket is not clean (contains timing "
                "information). You need to upgrade your libavformat or "
                "sanitize your packet.\n");