--- a/libavcodec/v4l2_context.c +++ b/libavcodec/v4l2_context.c @@ -416,6 +416,29 @@ memcpy(avbuf->planes, planes, sizeof(planes)); avbuf->buf.m.planes = avbuf->planes; } + + /* + * A capture queue can return empty buffers while a decoder establishes + * its output format. They are not decoded frames. Requeue them so that + * the driver retains its capture pool, but do not alter drain or LAST + * handling above. + */ + if (!V4L2_TYPE_IS_OUTPUT(ctx->type) && + !ctx_to_m2mctx(ctx)->draining && + (V4L2_TYPE_IS_MULTIPLANAR(buf.type) ? + buf.m.planes[0].bytesused == 0 : buf.bytesused == 0) +#ifdef V4L2_BUF_FLAG_LAST + && !(buf.flags & V4L2_BUF_FLAG_LAST) +#endif + ) { + ret = ff_v4l2_buffer_enqueue(avbuf); + if (ret < 0) { + ctx->done = 1; + av_log(logger(ctx), AV_LOG_ERROR, + "%s failed to requeue empty capture buffer\n", ctx->name); + } + return NULL; + } return avbuf; }