<p><em>Is there a simpler option using -force_key_frames? Unfortunately, this option only seems to allow inserting key_frames using an interval</em></p>

<p>Not so. To force keyframes for frames 45, 99 and 154 where first frame has index 0, use</p>

<pre><code>-force_key_frames expr:eq(n,45)+eq(n,99)+eq(n,154)
</code></pre>

<p>You may need to escape the commas, depending on your shell.</p>

CC BY-SA 4.0
2019-04-27T18:21:30.647Z
That makes things so much easier and it works very nicely. Thanks a ton Gyan!
David
CC BY-SA 4.0
2019-04-27T16:28:37.777Z
2019-04-27T16:28:37.777Z
Gyan
<p>I am trying to improve the perceived quality of certain predefined frames (like the frames 45, 99, 154, ...). Reason is, that the video is interactive and pauses at these keyframes until the user clicks next. So the quality should be higher just for these frames.</p>

<p>Using ffmpeg, I am currently splitting the video in segments so that each segment starts with one of those important frames as a key frame and then merge it again as a single video. This is suboptimal as lookahead and various other encoder/decoder tweaks can not benefit from this segmented video encoding</p>

<p>Is there a simpler option using -force_key_frames? Unfortunately, this option only seems to allow inserting key_frames using an interval, but the keyframes i require do not follow a rhythm.</p>

<p>P.S. the video is running at a constant 30fps and is merely 32 seconds long. Encoded as x264, vp9 and vp8 for web, so it won't feature a high bitrate.</p>

<ffmpeg><x264><vp9>
Encoding: Insert keyframes at certain positions
David
# Encoding: Insert keyframes at certain positions

(Asked by: username_0 on 2019-04-27)

I am trying to improve the perceived quality of certain predefined frames (like the frames 45, 99, 154, ...). Reason is, that the video is interactive and pauses at these keyframes until the user clicks next. So the quality should be higher just for these frames.

Using ffmpeg, I am currently splitting the video in segments so that each segment starts with one of those important frames as a key frame and then merge it again as a single video. This is suboptimal as lookahead and various other encoder/decoder tweaks can not benefit from this segmented video encoding

Is there a simpler option using -force\_key\_frames? Unfortunately, this option only seems to allow inserting key\_frames using an interval, but the keyframes i require do not follow a rhythm.

P.S. the video is running at a constant 30fps and is merely 32 seconds long. Encoded as x264, vp9 and vp8 for web, so it won't feature a high bitrate.

**Tags:** ffmpeg, x264, vp9


---

## 1 answers

### Answer by username_1 on 2019-04-27. Score: 0 | Accepted answer

Is there a simpler option using -force_key_frames? Unfortunately, this option only seems to allow inserting key_frames using an interval
Not so. To force keyframes for frames 45, 99 and 154 where first frame has index 0, use
-force_key_frames expr:eq(n,45)+eq(n,99)+eq(n,154)

You may need to escape the commas, depending on your shell.

> **Comments:**
> **username_0**: That makes things so much easier and it works very nicely. Thanks a ton username_1!  

---

