diff --git a/libavformat/rtpdec_vp8.c b/libavformat/rtpdec_vp8.c
index 6dbf402df6d8c6a4ff837ee0e14a56c0425bfea2..966f7b87342393c27056486f06bf444f05d11ac0 100644
--- a/libavformat/rtpdec_vp8.c
+++ b/libavformat/rtpdec_vp8.c
@@ -233,12 +233,13 @@ static int vp8_handle_packet(AVFormatContext *ctx, PayloadContext *vp8,
     vp8->prev_seq = seq;
     avio_write(vp8->data, buf, len);
 
+    if (returned_old_frame) {
+        *timestamp = old_timestamp;
+        return end_packet ? 1 : 0;
+    }
+
     if (end_packet) {
         int ret;
-        if (returned_old_frame) {
-            *timestamp = old_timestamp;
-            return 1;
-        }
         ret = ff_rtp_finalize_packet(pkt, &vp8->data, st->index);
         if (ret < 0)
             return ret;