How to Set rav1e Keyframe Interval in FFmpeg
This article provides a straightforward guide on how to configure the
master keyframe interval (GOP size) when encoding AV1 video using the
librav1e encoder in FFmpeg. You will learn the specific
command-line arguments required to control both the maximum and minimum
distance between keyframes to optimize your video compression,
seekability, and playback compatibility.
To configure the keyframe interval (also known as the Group of
Pictures or GOP size) in FFmpeg using the rav1e encoder,
you must use standard FFmpeg video options. FFmpeg maps these global
flags directly to rav1e’s internal keyframe interval
parameters.
Setting the Maximum Keyframe Interval
The maximum keyframe interval defines the maximum number of frames that can pass before the encoder is forced to write a keyframe.
To set this, use the -g option:
ffmpeg -i input.mp4 -c:v librav1e -g 240 output.mp4In this example, -g 240 sets the maximum keyframe
interval to 240 frames. For a 24 fps video, this translates to a
keyframe at least every 10 seconds.
Setting the Minimum Keyframe Interval
To prevent rav1e from placing keyframes too close
together—which can waste bitrate during high-motion scenes—you should
set a minimum keyframe interval.
To set this, use the -keyint_min option:
ffmpeg -i input.mp4 -c:v librav1e -keyint_min 24 output.mp4In this example, -keyint_min 24 ensures that keyframes
are spaced at least 24 frames apart, even if the encoder detects a scene
change.
Complete Command Example
To set both the minimum and maximum keyframe intervals together, combine the flags in your FFmpeg command:
ffmpeg -i input.mp4 -c:v librav1e -g 240 -keyint_min 24 -crf 30 output.mp4Key Considerations
- Scene Cut Detection: By default,
rav1eutilizes scene change detection to automatically insert keyframes at scene transitions. The-gparameter acts as a hard limit; if no scene change is detected before the limit is reached, a keyframe is forced. - Streaming Compatibility: For adaptive bitrate
streaming (like DASH or HLS), it is recommended to use a fixed keyframe
interval (e.g.,
-g 48 -keyint_min 48for 24 fps content) to ensure segments align perfectly across different quality levels.