Skip to content
streamneo.
Streaming Settings10 min read

How to Set the Correct GOP and Keyframe Interval for FFmpeg YouTube Live

Set FFmpeg GOP and keyframe intervals for YouTube Live by converting its two-second target into frames, then test the emitted stream.

sn.
StreamNeoPublished 4 October 2026
Worth sharing?

For YouTube Live, aim for one keyframe every two seconds and do not let the interval exceed four seconds. With a constant frame rate, that means setting the GOP length to twice the number of frames produced each second: 60 frames at 30 fps or 120 frames at 60 fps.

For FFmpeg’s libx264, -g sets the maximum GOP size, -keyint_min sets minimum keyframe spacing, and -flags +cgop requests a closed GOP. These are encoder options, not a complete streaming command; retain and test the input, output, rate-control, audio and RTMP or RTMPS settings your stream needs.

YouTube’s keyframe interval target

YouTube’s live encoder guidance recommends a keyframe frequency of two seconds and says not to exceed four seconds. That is a time-based target, not one fixed frame count: the number of frames in two seconds depends on the output frame rate. See YouTube’s live encoder settings for the current platform guidance, and check it again when setting up a stream rather than relying on a saved command from an older project.

A keyframe, also called an intra-coded frame, can be decoded without first reconstructing the frames immediately before it. Other frames in a GOP commonly refer to information in neighbouring frames. The GOP, or group of pictures, is the sequence between keyframes. Its length therefore affects how often the stream offers a fresh decoding point, but it is not a general-purpose quality control: changing it does not fix an unsuitable bitrate, wrong output frame rate, missing audio or an unreliable connection.

A two-second interval is the practical target because it follows YouTube’s recommendation. Four seconds is the stated upper limit, not a second equally preferred preset. Choosing the longer interval simply because it is permitted can increase the wait for a fresh keyframe when a viewer joins or playback recovers. For a continuous bhajan or ambience loop, that distinction still matters even if most viewers keep the stream open for a long time.

YouTube’s troubleshooting guidance for live-stream errors makes the frame-rate relationship explicit: at 30 fps, a two-second interval is every 60 frames. If the frame rate changes, the keyframe frequency must change too. Treat the output frame rate actually sent to YouTube as the basis for calculation, not necessarily the frame rate of the source file.

Convert seconds into frames

For a constant-frame-rate output, multiply frames per second by the target interval in seconds:

GOP frames = output frames per second × interval in seconds

At 30 fps, 30 × 2 = 60 frames. At 60 fps, 60 × 2 = 120 frames. If the output is 25 fps, two seconds corresponds to 50 frames; if it is 24 fps, it corresponds to 48. Those examples illustrate the arithmetic, not a recommendation to change a source’s frame rate. Keep the intended output rate consistent with the rest of the stream.

The frame count is a means of expressing elapsed time to the encoder. Setting 60 frames does not mean “two seconds” for every stream: at 60 fps it is one second, and at 25 fps it is longer than two seconds. This is why copying an option block between projects without checking the output rate can produce a keyframe interval YouTube flags as too long or simply different from the one you intended.

Constant output frame rate Frames in two seconds Example -g value Practical note
24 fps 48 -g 48 Calculate from the actual output rate.
25 fps 50 -g 50 Avoid reusing a 30 fps value without recalculating.
30 fps 60 -g 60 YouTube gives this frame count in its troubleshooting guidance.
60 fps 120 -g 120 Double the 30 fps frame count for the same duration.

The table assumes constant frame rate and a two-second interval. Variable-frame-rate input complicates the relationship between frames and elapsed time. If your workflow accepts variable-rate material, establish and verify the output behaviour rather than assuming the input’s nominal rate makes the GOP duration exact. For guidance on preparing source media before it reaches the encoder, see what video formats work best for a YouTube 24/7 stream.

Set GOP size with -g

In FFmpeg’s libx264 encoder options, -g sets the maximum GOP size in frames. To target two seconds at a constant 30 fps, use -g 60; at 60 fps, use -g 120. These numbers correspond to the output rate only if that is the rate the encoder produces. Confirm where your command sets frame rate and which encoder is active before choosing the value.

For example, the following is an encoder-option fragment for a 30 fps libx264 output:

-g 60 -keyint_min 60 -flags +cgop

At 60 fps, the corresponding fragment is:

-g 120 -keyint_min 120 -flags +cgop

Neither fragment is a complete streaming command. They do not specify an input file, output frame rate, video bitrate, rate-control behaviour, audio encoding, output format, destination URL or stream key. Those choices depend on your source and delivery setup. In particular, do not paste these fragments into a command and infer that the resulting stream must have the intended GOP. Confirm that FFmpeg accepted the options and inspect or test what it emitted.

FFmpeg documents codec-specific options in its codec documentation. The examples here are scoped to libx264; a flag or option supported by that encoder should not be presumed to have identical meaning or availability with another codec. FFmpeg builds can differ in which encoders they include, too. Check the encoder shown by your actual build and its help or documentation if you use a hardware encoder or a different codec.

Set minimum spacing with -keyint_min

For libx264, -keyint_min sets the minimum distance between keyframes, expressed in frames. Pairing it with -g at the same two-second frame count asks for a regular interval: for 30 fps, -g 60 -keyint_min 60; for 60 fps, -g 120 -keyint_min 120. In this use, -g limits the maximum GOP size, while the minimum value discourages the encoder from inserting keyframes closer together than the target spacing.

Why set both? Using only a maximum GOP size establishes a ceiling, but it does not express the same minimum-spacing preference. A shorter-than-expected GOP may be produced for reasons related to encoder behaviour or scene changes. If your aim is a steady two-second cadence, setting both values to the calculated frame count states that intent more clearly. It still does not replace verification: the encoded result and YouTube’s observations are what matter.

Do not confuse the minimum spacing with a universal command-line setting. The option belongs to the encoder context, and command-line placement can affect which output or encoder receives it when a command handles several streams. If FFmpeg reports an unrecognised option, or if you are not using libx264, consult the selected encoder’s options rather than assuming the libx264 fragment transfers directly. The FFmpeg guide to VAAPI encoding for YouTube streaming is relevant if you are considering a hardware-encoding path, but verify the controls supported in your own build.

Request a closed GOP

YouTube says its pipeline requires a closed GOP for optimal transcoding. In the libx264 examples, -flags +cgop requests closed-GOP behaviour. A closed GOP does not rely on frames from the preceding GOP for decoding, which gives a decoder a more self-contained group to work with at a keyframe boundary.

The word “requests” matters. The option is not a promise that every encoder accepts it, applies it as expected, or produces the same bitstream structure. YouTube supports more than one codec, and the controls for GOP structure vary by encoder. If you use anything other than libx264, look up that encoder’s own documentation and determine how it expresses closed-GOP behaviour. Do not assume that copying +cgop is meaningful for every encoder.

Closed-GOP structure and interval are related but separate checks. A 60-frame GOP at 30 fps can still be open, and a closed GOP can still be too long for the intended interval. Set the duration from the frame rate, request the required structure using the correct encoder option, then test the emitted stream. For more context on a continuous FFmpeg workflow, see how to loop pre-recorded Hindi meditation videos on YouTube Live using FFmpeg.

Adjust for 30 fps and 60 fps

At 30 fps, two seconds contain 60 frames, so the libx264 option values are -g 60 -keyint_min 60 -flags +cgop. At 60 fps, two seconds contain 120 frames, so use -g 120 -keyint_min 120 -flags +cgop. The duration stays the same; the frame count doubles because the output contains twice as many frames each second.

Keep the entire output configuration coherent. If the input is 60 fps but your command outputs 30 fps, calculate for 30 fps. Conversely, if a filter or encoder setting changes output to 60 fps, the 30 fps GOP count no longer represents two seconds. Re-check the final output rate after edits, including changes made when adapting a command for another source file or channel.

A stream with lower motion does not justify changing the YouTube interval target by itself. A static artwork loop, a slowly moving temple scene and a music visualiser may look very different, but the keyframe calculation still follows the encoded frame rate. Content affects other encoding decisions; it does not alter the multiplication used to express a two-second interval in frames.

Verify settings in a test stream

Before an important broadcast, run a test stream with audio and movement representative of the real programme. YouTube recommends testing and monitoring stream health; a still image with silence may not expose issues that appear when music, transitions or motion are present. Check the live control room’s status and messages, and make any corrections before relying on the setup overnight.

If YouTube reports that keyframes are too far apart, start by confirming the actual output frame rate. Recalculate fps × 2 from that value, then check that the intended encoder received the options. YouTube’s error guidance notes that ingestion errors can lead to an incorrectly observed GOP size, so do not treat the reported duration as proof that one particular FFmpeg option alone is at fault. Review the full path from the encoder output to YouTube’s ingest and test again after changes.

Keep a record of the known-good output rate, encoder and option fragment alongside the rest of the stream configuration. This is useful when you change an input file or move a channel to a different machine, because the nominal source frame rate may no longer match the encoded output. If a keyframe error appears after a change, compare the current settings with the tested record instead of adjusting several unrelated values at once.

For a long-running channel, also decide who or what will notice a failed broadcast and how it will be restarted. Correct GOP settings address a video-encoding requirement, not the operational problem of a computer sleeping or a process stopping while nobody is watching. StreamNeo removes that particular need to leave your own computer running: you upload a video, provide your YouTube stream key, and the broadcast continues from the cloud with monitoring and automatic restart if it drops. It is YouTube-only, so it does not solve a need to deliver the same stream to other platforms.

Once a test confirms the intended frame rate, interval and GOP structure, preserve those settings as part of the channel’s runbook. Change them deliberately when the output frame rate or encoder changes, rather than tweaking them in response to unrelated playback symptoms. A controlled test with the real audio and motion gives you better evidence than assuming the command is correct because it ran without an error.

Before committing, compare the operating options on the pricing page. When the file and channel are ready, start free — 24-hour trial, no card.

FAQ

What GOP size should I use for YouTube Live at 30 fps?

For a constant 30 fps output, a two-second interval is 60 frames. With libx264, the example settings are -g 60 -keyint_min 60 -flags +cgop; confirm the emitted stream and YouTube’s health messages in a test.

What GOP size should I use at 60 fps?

For a constant 60 fps output, use 120 frames to represent two seconds. The corresponding libx264 example is -g 120 -keyint_min 120 -flags +cgop, not a complete streaming command.

Does -g 60 always mean two seconds?

No. It means a maximum GOP size of 60 frames for libx264; its duration depends on the output frame rate. At 30 fps that is two seconds, while at 60 fps it is one second.

Do these options guarantee a stable stream or optimal transcoding?

No. They express encoder settings for GOP size, minimum keyframe spacing and a closed-GOP request; they do not guarantee a particular transcode or overall stream stability. Test with representative content, check YouTube’s current guidance and monitor stream health.

YOU’VE REACHED THE END

Keep the ideas coming.

More guides, useful tools and a little help for your next broadcast.

Back to the journal ↗
YOUR NEXT READ

A little more to explore.

More Streaming Settings guides ↗ · All topics ↗