<p>The first frame of a video from any codec will always be an <code>I</code> frame.  There is no previous picture for other frame types to use as a reference.</p>

<p><code>B</code> frames might still work.  The video will start to distort ahead of the cut point, too, if any <code>B</code> frames are trying to reference a future frame that's not there anymore.  Actually, with <code>B</code> frames present, display order differs from decode order, and the h.264 stream is always stored in decode order.</p>

<p>Anyway <code>-x264opts bframes=0:keyint_min=250</code> would force the minimum GOP size to 250 frames, and disallow use of <code>B</code> frames.  <code>keyint</code> sets the max GOP size.  (By default, x264 does scenecut detection for placing <code>I</code> frames, so if you want <code>I</code> frames at scenecuts, you might do well to leave it as-is.)</p>

<p>Err, is that tutorial using ffmpeg's MPEG4-part2 encoder?  (the same format as divx/xvid).  In that case, nvm.  My instructions were for <code>-c:v libx264</code>.</p>

<p>Look at the output of <code>ffmpeg -h encoder=mpeg4 | less</code>, and search for stuff you want to set.  There will be command line options for most everything.  e.g. <code>-bf 0</code> to set no <code>B</code> frames.  <code>ffmpeg -codecs</code> for a list of codecs, or even <code>ffmpeg -h full</code>.  Also google / check the <a href="https://ffmpeg.org/ffmpeg.html" rel="nofollow">manual</a></p>

CC BY-SA 3.0
2015-06-26T05:50:40.757Z
2015-06-26T06:12:01.870Z
2015-06-26T06:12:01.870Z
Peter Cordes
<p>What you want is a very long GOP or I-frame interval. I believe the ffmpeg option <code>-g nnnn</code> will do that, where <code>nnnn</code> is the length of your video in frames. I don't know how to specify "no B-frames", and this will certainly all be codec-dependent. Give it a try.</p>

CC BY-SA 3.0
2015-06-18T22:12:33.763Z
2015-06-18T22:12:33.763Z
Jim Mack
<p>I'd like to try to do some datamoshing like <a href="http://www.reddit.com/r/brokenanimegifs/wiki/tutorial" rel="nofollow">this tutorial</a>.  But I'd like to be able to do it programatically, so instead of vdub and avidemux, I'd like to figure out how to do as many parts of this process as I can with ffmpeg and/or other command-line tools.</p>

<p>The first problem I am having is that when I use the <a href="http://www.videohelp.com/software/ffdshow/old-versions" rel="nofollow">ffdshow codec rev 3556</a> with VDub it just outputs a broken video.  I feel like I got close to getting <strong>what I want, which is frame 0 as an I-frame and all the rest as P-frames with the following command</strong></p>

<pre><code>ffmpeg -i input.mp4 -force_key_frames 00:00:00.000 output.avi
</code></pre>

<p>There are a couple of problems with this:</p>

<ol>
<li><p>I get B-frames too, which don't work with that type of data-moshing</p></li>
<li><p>There's still I-frames every 10 or so frames</p></li>
</ol>

<p>I feel like the problem is that I need to use a certain codec to encode the video in and also that <code>-force_key_frames</code> probably just enforces the addition of extra keyframe(I-frames) but doesn't prevent other I-frames from being created.</p>

<ffmpeg><codec><keyframes>
How can I set the first frame of a video to an I-frame and the rest to P-frames (preferably with ffmpeg)?
Jason
# How can I set the first frame of a video to an I-frame and the rest to P-frames (preferably with ffmpeg)?

(Asked by: username_0 on 2015-06-18)

I'd like to try to do some datamoshing like this tutorial.  But I'd like to be able to do it programatically, so instead of vdub and avidemux, I'd like to figure out how to do as many parts of this process as I can with ffmpeg and/or other command-line tools.
The first problem I am having is that when I use the ffdshow codec rev 3556 with VDub it just outputs a broken video.  I feel like I got close to getting what I want, which is frame 0 as an I-frame and all the rest as P-frames with the following command
ffmpeg -i input.mp4 -force_key_frames 00:00:00.000 output.avi

There are a couple of problems with this:

I get B-frames too, which don't work with that type of data-moshing
There's still I-frames every 10 or so frames

I feel like the problem is that I need to use a certain codec to encode the video in and also that -force_key_frames probably just enforces the addition of extra keyframe(I-frames) but doesn't prevent other I-frames from being created.

**Tags:** ffmpeg, codec, keyframes


---

## 2 answers

### Answer by username_1 on 2015-06-26. Score: 2

The first frame of a video from any codec will always be an `I` frame. There is no previous picture for other frame types to use as a reference.

`B` frames might still work. The video will start to distort ahead of the cut point, too, if any `B` frames are trying to reference a future frame that's not there anymore. Actually, with `B` frames present, display order differs from decode order, and the h.264 stream is always stored in decode order.

Anyway `-x264opts bframes=0:keyint_min=250` would force the minimum GOP size to 250 frames, and disallow use of `B` frames. `keyint` sets the max GOP size. (By default, x264 does scenecut detection for placing `I` frames, so if you want `I` frames at scenecuts, you might do well to leave it as-is.)

Err, is that tutorial using ffmpeg's MPEG4-part2 encoder? (the same format as divx/xvid). In that case, nvm. My instructions were for `-c:v libx264`.

Look at the output of `ffmpeg -h encoder=mpeg4 | less`, and search for stuff you want to set. There will be command line options for most everything. e.g. `-bf 0` to set no `B` frames. `ffmpeg -codecs` for a list of codecs, or even `ffmpeg -h full`. Also google / check the [manual](https://ffmpeg.org/ffmpeg.html)


---

### Answer by username_2 on 2015-06-18. Score: 2

What you want is a very long GOP or I-frame interval. I believe the ffmpeg option `-g nnnn` will do that, where `nnnn` is the length of your video in frames. I don't know how to specify "no B-frames", and this will certainly all be codec-dependent. Give it a try.


---

