Keyframe interval for streaming: the 2-second setting and how to prove it held

For streaming to HLS players, the keyframe interval belongs at a fixed 2 seconds in your encoder: Apple's HLS authoring rules ask for an IDR keyframe every two seconds, and every HLS video segment has to open on one. A steady interval gives the packager clean places to cut, lets a viewer's player begin quickly, and keeps the delay predictable. This run sheet covers what the setting means, where each common encoder hides it, and a one-line check that shows the real spacing.

Steps
7
Reviewed
Runs on
Live video
Written by
Get Stream Hosting

By the Get Stream Hosting team

Every step was checked against the software's official documentation by independent reviewers before publishing. Last reviewed .

Pre-flight check

What the setting actually controls

The keyframe interval is the distance between two complete pictures in your video. Most frames an H.264 encoder sends are only changes from the frames around them. A keyframe, or I-frame, is different: RFC 8216, the HLS specification, describes I-frames as frames whose encoding does not depend on any other frame. An IDR frame is the strict kind of keyframe that also tells the decoder to forget everything before it, so decoding can start cleanly from that point.

The run of frames from one keyframe to the next is the group of pictures, or GOP. That is why FFmpeg calls its setting -g, the GOP size, and why some encoders ask for a number of frames while others ask for seconds. Both describe the same gap.

Why HLS playback depends on a steady gap

Your channel takes RTMP from your encoder and plays as HLS in the browser, so the HLS rules decide what a good interval is. Three of them matter here.

  • Segments open on an IDR frame. Apple's authoring specification says video segments must start with one. The packager can only cut where your encoder put an IDR, so every segment's length is a whole number of keyframe gaps.
  • Segments have a ceiling. RFC 8216 makes EXT-X-TARGETDURATION the maximum segment length. Apple's specification suggests 6-second target durations and segments of nominally 6 seconds. A 2-second gap divides into that evenly; a wandering gap does not.
  • Players start a few segments back. For a live playlist, RFC 8216 says a client should not pick a segment that starts less than three target durations from the end. Longer segments push every viewer further behind the live moment.

Put simply: if keyframes arrive every 2 seconds, segments come out even and short, and the player can join from any of them. If the encoder is left on auto, the gap is whatever that encoder picks, and segment lengths follow it.

Shorter is not better without limit. A keyframe holds a full picture, so packing them much closer than 2 seconds spends more of your bitrate on them and leaves less for the moving parts of the image.

Settings to copy, by frame rate

When an encoder asks for frames rather than seconds, multiply your frame rate by 2. Keep the frame rate fixed too: a frame-count interval only means 2 seconds while the frame rate stays where you set it.

Frame rateKeyframe interval in secondsSame interval in frames
25 fps250
30 fps260
50 fps2100
60 fps2120

On your live video channel, a paid plan takes 1080p, and each channel's ingest is capped at 5 Mbps. The free plan is for wiring up your encoder and player, which makes it a sensible place to get this setting right before an audience arrives. On paid plans you also get a branded TV app for Samsung and LG sets; the app publishing runbooks cover putting it in the stores.

Where each encoder keeps it

EncoderWhere to find itUnitEnter
OBS StudioSettings, Output, Output Mode set to Advanced, Streaming tab: Keyframe Interval (0=auto)Seconds2
vMixStreaming Quality window: Keyframe FrequencySeconds2 (the vMix default)
WirecastWindow menu, Encoder Presets, your H.264 or x264 profile: the key frame valueFramesTwice the frame rate
FFmpegThe -g option, with -keyint_min set to the same numberFramesTwice the frame rate

In OBS, do not leave the field on 0. Zero means auto, which hands the decision to the encoder; the Advanced Recording Settings Guide on the OBS knowledge base also uses 2 for every encoder it covers: x264, NVENC, AMD and QuickSync. Once the interval is set, the rest of the encoder setup is the RTMP address and stream key your control panel shows for the channel.

In Wirecast, remember the value counts frames. If you change a preset from 30 fps to 25 fps and leave the key frame value at 60, the gap grows to 2.4 seconds.

Pinning the gap in FFmpeg

FFmpeg needs four output options to hold a fixed gap. For 30 fps output they read:

-r 30 -g 60 -keyint_min 60 -sc_threshold 0
  • -r 30 fixes the output frame rate, so 60 frames always means 2 seconds.
  • -g 60 sets the GOP size, the longest gap allowed. Leave it out and the encoder's own default decides, so always set it.
  • -keyint_min 60 sets the minimum GOP size (libx264 caps it at about half of -g). Combined with -g 60 and -sc_threshold 0, the encoder places a keyframe every 60 frames and adds none in between.
  • -sc_threshold 0 sets the scene-change detection threshold, so a hard cut in your picture does not add a keyframe off the beat.

If your source's frame rate drifts, FFmpeg also accepts a time-based rule. Its documentation gives expr:gte(t,n_forced*5) as the way to force a keyframe every 5 seconds. For the HLS advice, use 2 and quote it on a shell command line: -force_key_frames "expr:gte(t,n_forced*2)"

Checks before you go live

Do not trust the settings screen alone. Measure what actually leaves the encoder or arrives at the player. ffprobe, which ships with FFmpeg, lists every video packet and flags the keyframes with a K. Point it at a test recording made with the same settings, or at your channel's HLS link while you are live:

ffprobe -v error -select_streams v:0 -show_entries packet=pts_time,flags -of csv -read_intervals "%+20" INPUT
  1. Replace INPUT with the file path or the HLS link, in quotes if it holds spaces or symbols. The %+20 interval reads only the first 20 seconds, so it stops on its own even on a live link.
  2. Look at the lines whose flags column starts with K. Those are keyframes; the number before the flags is the time in seconds.
  3. Subtract each keyframe time from the next. At a 2-second interval every difference is 2.0, give or take a frame. Longer or uneven gaps mean the encoder is still on auto or adding scene-change keyframes.
  4. Fetch the HLS playlist as text, for example with curl. The #EXTINF values are segment lengths in seconds; with a steady 2-second gap each one comes out as a multiple of 2. If the link lists other playlists instead of segments, open the one it names.

When it goes wrong

  • The player takes a long time to show a picture. Check the interval first. A long or automatic gap means long segments, and the player starts several segments back from the live end.
  • The delay behind real time grew after a settings change. A frame-count interval that no longer matches the frame rate is one likely cause. Recalculate it from the table above.
  • ffprobe shows keyframes at irregular times. Scene-change detection is the likely source of the extras. Turn it off in the encoder, or in FFmpeg set -keyint_min equal to -g with -sc_threshold 0.
  • Everything checks out and playback still stutters. Look at bitrate and upload next: a PRO or Platinum channel ingests at most 5 Mbps, and your connection has to carry whatever the encoder sends. If you are stuck, open a ticket or start a chat: live chat answers day and night; its AI assistant reads your account details, and a person steps in whenever you ask for one.

Questions people ask

Is 2 seconds right for every live stream?

For a stream that viewers watch as HLS, 2 seconds is the value Apple's authoring specification gives for IDR keyframes, and it divides evenly into the 6-second segments the same document suggests. It is also the value OBS's own Advanced Recording Settings Guide uses for every encoder. For your channel here, use 2.

Does a 1-second interval make the stream faster to start?

It can let the packager cut shorter segments, but it also spends more bitrate on full pictures, which costs detail at the same bitrate. How short the segments are depends on the packager's settings, not on your encoder alone. Unless you have a measured reason, stay on 2 seconds.

Why do OBS and Wirecast show different numbers for the same setting?

OBS counts the keyframe interval in seconds, and Wirecast counts it in frames. At 30 fps, 2 in OBS and 60 in Wirecast describe the same gap. Multiply your frame rate by 2 whenever an encoder asks for frames.

What happens if I leave the keyframe interval on auto?

The encoder chooses the gap itself, and you no longer know what it is. HLS segments can only begin on an IDR frame, so a long or uneven gap gives long or uneven segments, a slower start and a bigger delay. Set a fixed value and confirm it with ffprobe.

Is the keyframe interval the same as the HLS segment length?

No. The segment length is chosen when the stream is packaged, and RFC 8216 caps it at the playlist's target duration. Because each segment has to open on an IDR frame, its length is always a whole number of keyframe gaps: with a 2-second interval, a 6-second segment holds three. The interval is the building block; the segment is what the player downloads.

Live video

Put your channel on air

Start on the free plan, set the 2-second interval in the encoder you already use, and check it with ffprobe before you announce the stream.