diff --git a/libavcodec/loco.c b/libavcodec/loco.c
index cc8ce21c1250faa21cf0f09536eb94b99f8bc92b..b4f8ad4424db803aebb87e7ed1fc837c4b7c560d 100644
--- a/libavcodec/loco.c
+++ b/libavcodec/loco.c
@@ -233,7 +233,7 @@ stop:
     *data_size = sizeof(AVFrame);
     *(AVFrame*)data = l->pic;
 
-    return buf_size < 0 ? -1 : buf_size;
+    return buf_size < 0 ? -1 : avpkt->size - buf_size;
 }
 
 static av_cold int decode_init(AVCodecContext *avctx){