I have a mpeg4 video at 25fps. This video contains just one static frame. I'm trying to downsample the frame rate to 1fps and convert the video to x246 (mp4).

I ran the following ffmpeg command:

ffmpeg -i vid.avi -acodec aac -ar 32000 -ab 64k -ac 2 \
-vcodec libx264 -strict -2 -y -r 1 -force_key_frames 0 vid.mp4

FFmpeg then drops a lot of frames until it inserts the first keyframe. Sometimes image appears only after 16 or 20 seconds.

I gather ffmpeg doesn't insert a keyframe at very beginning.

Does anyone know how could I take the first frame of vid.avi and use it as the key frame for vid.mp4?

  • have you tried it without -force_key_frames 0? Also might want to try changing the 0 to a 1 to have it start on the first frame instead -force_key_frames 1 Oct 3 '12 at 14:36
  • yes, i tried without -force_key_frames 0 and with -force_key_frames 1, but that didn't help. I'm pretty stuck.
    – bodacydo
    Oct 3 '12 at 18:19
  • is doing it exactly this way required? I'm going to take a wild guess and assume the following: the audio is the focus of the video. The image isn't a huge concern. Sooo couldn't you extract an mp3 from the video (lossless quality of course) and then, acquire the image, maybe even a screenshot if you're that desperate, then create a new video in ffmpeg using the extracted mp3 and image with the fps set to 1? Oct 3 '12 at 20:06
  • 1
    The force_key_frames syntax for using the frame number is -force_key_frames "expr:eq(n,0)"
    – robd
    Jul 28 '13 at 21:08
  • I'm fairly sure the root issue here was something else. Encoders always start with a keyframe.
    – Gyan
    Mar 24 '19 at 17:03

To force a keyframe at the 00:00:00.000 time code, you should try using the following flag:

-force_key_frames 00:00:00.000
  • What does this do exactly? Nov 14 '12 at 22:32
  • it will force position the keyframe at 00:00:00.000 time code, which was asked with the original request.
    – Maxim
    Nov 14 '12 at 23:58
  • Could you please elaborate: Is this applicable to x264 only, or any codec? What does the time refer to - the output file time? I.e. for overlays, how could I put a keyframe to beginning of any overlayed video? Thanks Mar 23 '19 at 23:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.