diff --git a/doc/examples/decode_video.c b/doc/examples/decode_video.c
index dd1177b8b0..3413ad9312 100644
--- a/doc/examples/decode_video.c
+++ b/doc/examples/decode_video.c
@@ -64,7 +64,7 @@ static int decode_write_frame(const char *outfilename, AVCodecContext *avctx,
         fflush(stdout);
 
         /* the picture is allocated by the decoder, no need to free it */
-        snprintf(buf, sizeof(buf), outfilename, *frame_count);
+        snprintf(buf, sizeof(buf), "%s-%d", outfilename, *frame_count);
         pgm_save(frame->data[0], frame->linesize[0],
                  frame->width, frame->height, buf);
         (*frame_count)++;