Answers.Body: <p>To force a keyframe at the 00:00:00.000 time code, you should try using the following flag:</p>
  
  <pre><code>-force_key_frames 00:00:00.000
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2012-11-14T22:32:34.020Z
Answers.Text: What does this do exactly?
Answers.UserDisplayName: Warrior Bob
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2012-11-14T23:58:32.143Z
Answers.Text: it will force position the keyframe at 00:00:00.000 time code, which was asked with the original request.
Answers.UserDisplayName: Maxim
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-03-23T23:13:11.160Z
Answers.Text: 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
Answers.UserDisplayName: Ondra Žižka
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2012-11-14T22:23:58.970Z
Answers.LastActivityDate: 2019-03-24T14:14:14.507Z
Answers.LastEditDate: 2019-03-24T14:14:14.507Z
Answers.UserDisplayName: Maxim
Body: <p>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).</p>
  
  <p>I ran the following ffmpeg command:</p>
  
  <pre><code>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
  </code></pre>
  
  <p>FFmpeg then drops a lot of frames until it inserts the first keyframe. Sometimes image appears only after 16 or 20 seconds.</p>
  
  <p>I gather ffmpeg doesn't insert a keyframe at very beginning.</p>
  
  <p>Does anyone know how could I take the first frame of vid.avi and use it as the key frame for vid.mp4?</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2012-10-03T14:36:57.663Z
Comments.Text: 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`
Comments.UserDisplayName: Travis Crum
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2012-10-03T18:19:13.727Z
Comments.Text: yes, i tried without -force_key_frames 0 and with -force_key_frames 1, but that didn't help. I'm pretty stuck.
Comments.UserDisplayName: bodacydo
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2012-10-03T20:06:49.970Z
Comments.Text: 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?
Comments.UserDisplayName: Travis Crum
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2013-07-28T21:08:08.410Z
Comments.Text: The [force_key_frames syntax for using the frame number](https://www.ffmpeg.org/ffmpeg.html#Advanced-Video-Options) is `-force_key_frames "expr:eq(n,0)"`
Comments.UserDisplayName: robd
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-03-24T17:03:29.953Z
Comments.Text: I'm fairly sure the root issue here was something else. Encoders always start with a keyframe.
Comments.UserDisplayName: Gyan
Tags: <ffmpeg><mp4><transcoding>
Title: How to force ffmpeg to insert keyframe at first frame when downsampling a framerate of a video with x264 vcodec
UserDisplayName: bodacydo
ThreadText: # How to force ffmpeg to insert keyframe at first frame when downsampling a framerate of a video with x264 vcodec
  
  (Asked by: username_0 on 2012-10-03)
  
  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?
  
  **Tags:** ffmpeg, mp4, transcoding
  
  > **Comments:**
  > **username_1**: 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`  
  > **username_0**: yes, i tried without -force_key_frames 0 and with -force_key_frames 1, but that didn't help. I'm pretty stuck.  
  > **username_1**: 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?  
  > **username_2**: The [force_key_frames syntax for using the frame number](https://www.ffmpeg.org/ffmpeg.html#Advanced-Video-Options) is `-force_key_frames "expr:eq(n,0)"`  
  > **username_3**: I'm fairly sure the root issue here was something else. Encoders always start with a keyframe.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_4 on 2012-11-14. Score: 6
  
  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
  
  ```
  
  > **Comments:**
  > **username_5**: What does this do exactly?  
  > **username_4**: it will force position the keyframe at 00:00:00.000 time code, which was asked with the original request.  
  > **username_6**: 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  
  
  ---
  
  