diff --git a/libavdevice/v4l2.c b/libavdevice/v4l2.c
index ae51d837af3570d1f9c1640a0aafcced5f30a970..b57909bda6d3b596269a1c011a4202814fb245f0 100644
--- a/libavdevice/v4l2.c
+++ b/libavdevice/v4l2.c
@@ -936,6 +936,7 @@ static int v4l2_read_header(AVFormatContext *ctx)
         goto fail;
 
     st->codecpar->format = ff_fmt_v4l2ff(desired_format, codec_id);
+    if (st->codecpar->format != AV_PIX_FMT_NONE)
     s->frame_size = av_image_get_buffer_size(st->codecpar->format,
                                              s->width, s->height, 1);