diff --git a/ffmpeg.c b/ffmpeg.c
index e3ed179b802f840360066d0e63daf5e1ec54a56a..dea93e528e9b7c19cd7354d0f1fea59cd22e50aa 100644
--- a/ffmpeg.c
+++ b/ffmpeg.c
@@ -2792,10 +2792,13 @@ static void parse_forced_key_frames(char *kf, OutputStream *ost,
         av_log(NULL, AV_LOG_FATAL, "Could not allocate forced key frames array.\n");
         exit_program(1);
     }
+    p = kf;
     for (i = 0; i < n; i++) {
-        p = i ? strchr(p, ',') + 1 : kf;
+        char *next = strchr(p, ',');
+        if (next) *next++ = 0;
         t = parse_time_or_die("force_key_frames", p, 1);
         ost->forced_kf_pts[i] = av_rescale_q(t, AV_TIME_BASE_Q, avctx->time_base);
+        p = next;
     }
 }