For a standard YouTube Live stream sent over RTMP or RTMPS, aim for a keyframe every two seconds and do not exceed four seconds. In FFmpeg, that usually means setting a GOP length in frames: at 30 fps, use 60 frames; at 60 fps, use 120.
Also request closed GOP behaviour where your selected encoder supports it. YouTube identifies open GOP as unsupported, but FFmpeg options differ by encoder and build, so check the encoder’s own help and test the result rather than assuming one command works everywhere.
What GOP size controls
A group of pictures (GOP) is a sequence of encoded video frames organised around keyframes. A keyframe can be decoded without relying on earlier frames; other frames may describe changes relative to a previous or future reference frame. GOP size controls how many frames the encoder places between those keyframes in configurations where the option is frame-count based.
For a live stream, the interval matters because the receiving service needs regular points at which it can begin decoding a picture cleanly. A long interval may mean a viewer or downstream process waits longer for a usable keyframe. It can also conflict with the receiving platform’s expectations. A shorter interval creates more frequent keyframes, but keyframes generally take more data than predicted frames. Depending on bitrate and image complexity, making them too frequent can leave less data for detail in the other frames.
That is why the practical setting is not “as low as possible”. Use the platform’s interval guidance, account for the actual encoded frame rate, and avoid changing multiple encoding variables at once when diagnosing a problem. GOP size is separate from resolution, bitrate, frame rate and audio configuration, even though those choices interact in the overall stream.
The wording can be confusing: YouTube Help calls the setting “Keyframe frequency”, while FFmpeg documentation and encoder options often call it GOP size. In this context, both descriptions concern the spacing of keyframes, but the FFmpeg option’s precise semantics can depend on the codec and encoder. The FFmpeg codec documentation describes GOP-size options for relevant encoders; it is not a promise that all encoders expose identical controls.
YouTube’s keyframe interval guidance
For the usual RTMP or RTMPS workflow, YouTube Help recommends a two-second keyframe frequency and says not to exceed four seconds. The direct source is YouTube’s live encoder settings guidance. For a typical FFmpeg setup, use two seconds as the target rather than treating the four-second ceiling as the ideal.
There is a protocol-specific distinction worth keeping in view. YouTube’s DASH ingestion guide says GOP size should be about two seconds and less than eight seconds. That statement belongs to its DASH workflow; it does not replace the four-second ceiling in the general encoder settings for a standard RTMP/RTMPS stream. If you are configuring DASH, follow the DASH guide’s own instructions and check that your encoder and delivery method match that workflow.
The Live API health documentation may report problems when the frequency is long or very short, and it also identifies mismatched keyframe frequency between primary and backup feeds. Its diagnostic wording can be useful when troubleshooting, but a health message is not a substitute for choosing the right protocol-specific guidance. For most readers asking about an FFmpeg YouTube Live stream, the sensible starting point remains two seconds, with four seconds as the maximum under the general encoder recommendation.
A frequent practical mistake is to set a number without knowing what it represents. “60” can mean two seconds at 30 frames per second, but it is only one second at 60 fps. Establish the encoded output rate first, then calculate the GOP value. If your input is variable-frame-rate or the output rate changes, do not rely on a frame count derived from an assumed rate.
Convert seconds to FFmpeg frames
For an encoder whose GOP option counts frames, multiply the chosen interval in seconds by the encoded frame rate:
GOP frame count = interval in seconds × encoded frames per second
For the two-second target, the common calculations are:
| Encoded frame rate | Two-second GOP value | Four-second ceiling value |
|---|---|---|
| 24 fps | 48 frames | 96 frames |
| 25 fps | 50 frames | 100 frames |
| 30 fps | 60 frames | 120 frames |
| 50 fps | 100 frames | 200 frames |
| 60 fps | 120 frames | 240 frames |
These are arithmetic conversions, not separate YouTube presets. The right-hand column shows the frame count corresponding to four seconds; it should not be read as a recommendation to target that longer interval. YouTube’s general guidance says not to exceed four seconds, while recommending two.
For a fixed 30 fps H.264 encode using libx264, a GOP-related command fragment could look like this:
ffmpeg -i INPUT -c:v libx264 -r 30 -g 60 -flags +cgop -c:a aac OUTPUT
This fragment illustrates the frame-rate, GOP and closed-GOP controls only. It is not a complete publishing command: it does not specify a YouTube ingest destination, rate control, bitrate, audio details or the other settings needed for a real stream. It has not been tested here. Adapt it to your input, output and FFmpeg build, and confirm the options supported by the chosen encoder before using it on a live channel.
If you are setting up a loop from a recorded file, check that the output frame rate is what you intend rather than assuming the source file’s rate will carry through unchanged. The video-file readiness checklist for a 24/7 YouTube stream is useful for checking the source before you combine it with live encoding settings.
Set closed GOP behaviour
A closed GOP keeps the group’s frame dependencies within that group rather than requiring references into an adjacent GOP. This makes each group more self-contained. YouTube’s Live API configuration-issues documentation explicitly reports open GOP as unsupported and asks the operator to change the encoder to closed GOP. See the official health-status messages.
FFmpeg documents a cgop flag for closed GOP behaviour in relevant contexts, and describes disabling it as a way to enable open GOP. The illustrative -flags +cgop above is therefore a useful example, but do not assume it applies identically to every codec wrapper. Some encoder options are private to a particular implementation; an option accepted by one FFmpeg build may be unavailable or behave differently in another.
Check the help output for the encoder you are actually using, not merely the top-level FFmpeg options. A command can run while an option is ignored, overridden, or interpreted differently than expected. Confirm the selected encoder and its documented private options, then run a test stream and inspect YouTube’s health messages. Do not try to solve an open-GOP warning by increasing or decreasing the frame count alone: GOP length and GOP closure are related but distinct settings.
If you send a primary and backup feed, check that they use compatible keyframe intervals. A mismatch can be reported as a health issue even when one feed on its own appears to have the desired interval. Keep the settings aligned where practical and verify each feed rather than assuming the backup inherits the primary’s configuration.
Check encoder-specific options
FFmpeg is a framework that can use different codecs and encoder implementations. The -g option is commonly used to set GOP size, but the available controls and their exact effects depend on the selected encoder. The same command line should not be treated as portable across libx264, hardware encoders and other codec implementations without checking their documentation.
First identify the encoder in the command you will run. Then inspect FFmpeg’s encoder-specific help and the relevant FFmpeg codec documentation. Look for GOP size, keyframe interval, closed-GOP or equivalent controls, and confirm whether the option counts frames. If you use a hardware encoder, also check its own FFmpeg wrapper options; do not copy a private option name from a different encoder and expect it to work.
A useful test is to encode a short sample using the exact command and build intended for the stream. Inspect the output or send a private test stream, then review YouTube’s health status. If the keyframe frequency is reported unexpectedly, verify the actual output frame rate and encoder settings before changing the GOP count. Ingestion errors can also make reported GOP sizes inaccurate, so treat one diagnosis as a clue to investigate rather than definitive proof of a particular command-line mistake.
Keep your first test narrow. Set the intended output rate, calculate the two-second count, request closed GOP if supported, and leave unrelated settings alone. If the stream has an issue, change one relevant variable at a time and test again. This gives you a clearer link between the setting changed and the result observed.
For an always-on loop, there is another distinction: encoder settings do not by themselves keep a channel running after a computer or process stops. A local FFmpeg setup needs a reliable host and a way to supervise and restart the process. If the recurring problem is keeping a computer switched on and recovering a dropped process, StreamNeo removes that particular burden by letting you upload a video and run it as a YouTube live stream without leaving your own computer on; it does not change the need to prepare the video and channel settings carefully.
Verify stream health in YouTube Live
Before making the configuration part of a regular broadcast, run a test stream and open YouTube Live’s stream health view. YouTube recommends testing and monitoring during a live event. Look for messages about keyframe frequency, open GOP behaviour or primary and backup feed mismatch, and make sure the stream is being sent over the protocol for which you chose the settings.
If YouTube reports a long interval, revisit the multiplication: the GOP count should correspond to the encoded output rate, not simply the input file’s nominal rate. For instance, a value of 60 at a 60 fps output rate means one second between keyframes, not two. If the diagnostic indicates open GOP, investigate whether the chosen encoder supports a closed-GOP option and whether it was actually applied.
A very short GOP can also be worth reviewing. More frequent keyframes can consume more of a constrained bitrate, and YouTube’s health diagnostics may flag very short GOPs. Do not force a smaller and smaller value in pursuit of a better stream. Return to the two-second target unless a documented workflow or a specific test gives you a reason to choose otherwise.
Health status is useful but not infallible. The API documentation notes that ingestion errors can lead to inaccurate reported GOP sizes. If the diagnosis conflicts with your command and the encoded output, verify that the encoder is applying the intended settings and that the ingest path is stable. Keep a copy of the working command and record the tested FFmpeg version and encoder so you can reproduce the result after an update.
For a local continuous setup, also distinguish stream health from process health. YouTube can report what it receives, but it cannot ensure the FFmpeg process stays alive on your machine. The guide to diagnosing an OBS encoder-overloaded message covers a different encoder, yet the general discipline is relevant: separate the symptom at the receiving end from the cause on the sending system. If you are deciding whether a local machine is suitable for overnight operation, see how to keep a YouTube product-demo loop running overnight with OBS.
Once a test looks right, avoid changing the frame rate or encoder without recalculating the GOP count and rechecking closed-GOP behaviour. A change from 30 to 60 fps doubles the frame count needed for the same two-second interval. Save the tested settings alongside the stream notes, especially if someone else may need to restart the channel.
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?
For the usual RTMP or RTMPS workflow, target a keyframe interval of two seconds and do not exceed four seconds, following YouTube’s live encoder settings guidance. Convert the target interval to frames using the actual encoded frame rate and the semantics of your chosen encoder.
What should -g be at 30 fps or 60 fps?
For a two-second interval, a frame-count-based GOP setting is 60 at 30 fps and 120 at 60 fps. Check that the output really uses the frame rate you calculated from, and confirm your selected encoder accepts -g as expected.
Does YouTube support open GOP?
YouTube’s Live API health-status documentation says open GOP is unsupported and directs the encoder to use closed GOP. Request closed GOP where your encoder exposes a supported control, then verify it with a test stream; options are not identical across FFmpeg encoders and builds.
Is the same interval guidance used for DASH?
The general YouTube live encoder guidance for the usual RTMP/RTMPS workflow recommends two seconds and sets a four-second maximum. The DASH-specific guide gives its own GOP statement, about two seconds and less than eight seconds, so follow the official instructions for the protocol you are actually using.