diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index b0b32a69f2ea2d1b77e188ceb8c1982c6ab53409..855db934bfbadf525a35e3d0bf42491789007c54 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -1138,6 +1138,7 @@ static void do_subtitle_out(OutputFile *of,
     }
 }
 
+/* May modify/reset next_picture */
 static void do_video_out(OutputFile *of,
                          OutputStream *ost,
                          AVFrame *next_picture)
@@ -1421,8 +1422,7 @@ static void do_video_out(OutputFile *of,
 
     av_frame_unref(ost->last_frame);
     if (next_picture)
-        if (av_frame_ref(ost->last_frame, next_picture) < 0)
-            goto error;
+        av_frame_move_ref(ost->last_frame, next_picture);
 
     return;
 error: