For a YouTube Live broadcast sent over RTMP or RTMPS, aim for one keyframe every two seconds and keep the interval at or below four seconds. In FFmpeg, that means setting the GOP size from the output frame rate; at 30 fps, -g 60 is the two-second example.
A “looping playlist” may mean files played one after another into a continuous stream, or it may mean an HLS output playlist sent to YouTube. Those are different workflows. The settings below explain both without treating one command as a universal solution for every input, encoder or protocol.
YouTube’s keyframe target and maximum interval
YouTube’s live encoder guidance recommends a keyframe interval of two seconds and says not to exceed four seconds for RTMP/RTMPS. A keyframe, also called an intra frame or I-frame, gives a decoder a point from which it can begin reconstructing the picture without depending on earlier frames. Regular keyframes help YouTube ingest and process the feed predictably.
The interval is a duration, not a fixed number of frames for every stream. YouTube Help’s live-streaming error guidance explains the relationship and gives the 30 fps example: every 60 frames. That is why copying -g 60 into an output running at a different frame rate changes the time between keyframes. See YouTube’s live encoder settings and its live-streaming error guidance for the current requirements and troubleshooting context.
The four-second ceiling is not a reason to choose the longest interval by default. Two seconds is the target to configure around; longer gaps can make ingest less suitable for the expected live pipeline. If YouTube reports irregular keyframes, do not assume the -g value alone proves the output is correct. Frame-rate conversion, dropped frames, timestamps and encoder behaviour can affect the spacing that is actually delivered.
These values apply to the outgoing encoded video, not simply to the files in your local playlist. A source file may have one frame rate while your output is encoded at another. Base the calculation on the frame rate you are sending to YouTube, then verify the resulting stream if you are diagnosing an ingest warning.
Calculate GOP length from the output frame rate
FFmpeg’s -g option sets the maximum GOP size in frames. For a fixed output frame rate, a useful calculation is:
GOP frames = output frames per second × target interval in seconds
For the two-second target, multiply the output frame rate by two. At 30 fps, that gives 60 frames. At another frame rate, use the same calculation rather than reusing that number. This is configuration arithmetic, not a guarantee that every encoder will produce the requested cadence exactly.
Check what “30 fps” means in your setup. The relevant rate is the rate of the encoded output sent to YouTube, not necessarily the source file’s advertised rate or the monitor’s refresh rate. If your input files have mixed frame rates, FFmpeg may need to convert them to a consistent output rate. The GOP calculation should match that chosen output rate.
A variable-frame-rate or timestamp-altered workflow deserves extra care: a frame-count setting does not by itself express a fixed wall-clock interval under every circumstance. Encoder behaviour, time base, dropped frames and timestamp handling can affect observed spacing. If you need to force keyframes by time, FFmpeg also documents -force_key_frames, but its timestamp expression needs to match the output timing and encoder behaviour. Avoid adding it as a second setting without understanding how it interacts with the encoder’s normal GOP controls.
If you are turning a set of clips into a continuous feed, decide how each clip is decoded and re-encoded before choosing the final GOP settings. The playlist mechanism controls what content comes next; the encoder controls the outgoing keyframes. For practical context on the “what plays after the last file?” problem, see how to keep a podcast stream running when its playlist ends. That is a continuity question, separate from the output GOP interval.
Example: -g 60 at 30 fps
For a 30 fps output, -g 60 corresponds to 60 frames, or two seconds at that rate. An illustrative set of video encoder options is:
-g 60 -flags +cgop
Treat this as a fragment of encoder configuration, not a complete streaming command. It does not specify how a playlist is read, how the audio is mapped, what codec or bitrate you use, how output frame rate is set, or how the RTMP/RTMPS destination is addressed. Those details depend on your media, encoder and ingest workflow.
In particular, do not assume a playlist of arbitrary files can be made continuous just by attaching this fragment to FFmpeg. Input options, stream mapping, format compatibility and looping behaviour need to match the files and the way they are being combined. A workflow that ends when its last clip finishes needs a separate continuity fix; it is not solved by changing the GOP size. The guide to fixing OBS when playback stops after the last study video addresses that distinct failure mode.
For a 30 fps RTMP/RTMPS output, the sensible starting point is to configure the encoder for a two-second GOP, request closed-GOP operation where supported, and then check the actual outgoing stream if YouTube flags the keyframe cadence. Do not infer success solely from a command line: an encoder may interpret options differently, or the output may not be running at the rate you expected.
Other encoder settings matter to the quality and ingest of the same output. YouTube’s encoder table lists codec, frame-rate and bitrate guidance; follow the row that matches your resolution and frame rate rather than treating a bitrate figure as universal. The platform also recommends CBR in its settings. If your concern is the overall picture and sound rather than keyframe timing, this guide to improving video and audio quality in Streamlabs Desktop covers adjacent quality decisions.
Request a closed GOP where applicable
YouTube’s troubleshooting guidance says its pipeline requires a closed GOP for optimal transcoding. In FFmpeg, -flags +cgop requests closed-GOP operation. The word “requests” matters: flags describe encoder configuration, and the outcome can depend on codec implementation, encoder options and the media being encoded.
A closed GOP does not rely on frames from a preceding GOP for decoding. That property is useful when a pipeline needs to process groups independently. It is not a replacement for the two-second interval, and adding the flag does not establish that the delivered stream has the expected keyframe spacing. Keep the GOP-size and closed-GOP concerns distinct when troubleshooting.
The FFmpeg documentation defines the cgop flag as “Use closed gop.” Its HLS muxer guidance also advises requiring a closed GOP and choosing a GOP size that fits the segment-time constraint. Consult the FFmpeg documentation for the options relevant to your selected encoder and muxer. These are configuration references, not a claim that one pair of flags has been independently tested for every codec, source or playlist arrangement.
If the stream is being re-encoded, confirm which encoder receives the options. FFmpeg can pass settings to different video encoders, and an option placed in the wrong context may not affect the intended output. Likewise, if the stream is copied rather than re-encoded, GOP settings cannot reshape frames that are not being encoded anew. Inspect the actual workflow before changing flags.
Distinguish a playlist input from HLS output
A local playlist feeding an RTMP or RTMPS broadcast is an input arrangement. It may be a list of files played in sequence while FFmpeg encodes a continuous video and sends it to YouTube. In that case, apply the two-second target to the encoded output stream. The source playlist itself is not YouTube’s HLS playlist, and its file order does not determine the outgoing segment requirements.
HLS output is different: it packages the live video into segments and maintains a playlist that describes those segments. YouTube’s HLS ingest guidance specifies MPEG-TS segments between one and four seconds, a rolling playlist with no more than five outstanding segments, no byte-range mode, and HTTPS POST/PUT. YouTube also says HLS has higher latency than a continuous RTMP stream because media is sent in segments. Review YouTube’s HLS setup requirements before choosing that route.
| Workflow | What “playlist” means | Keyframe and delivery considerations |
|---|---|---|
| RTMP/RTMPS | Files or another source feed a continuous encoded stream | Target a two-second keyframe interval, do not exceed four seconds, and configure the output GOP from its frame rate. |
| HLS to YouTube | The encoder produces segments and an output playlist | Use YouTube’s HLS segment and transport requirements, and coordinate keyframes with segment timing. |
The HLS muxer’s -hls_time is a target, not a promise of an exact cut at that duration. FFmpeg cuts a segment at the next keyframe after the target duration has passed, so the GOP and segment target interact. If keyframes do not land near the target, segments may run longer than the nominal target. This is why the encoder’s GOP size should be selected with the HLS segment constraint in mind.
Do not confuse -hls_list_size with YouTube’s outstanding-segment limit. FFmpeg’s option controls the number of entries in its output playlist; YouTube’s requirement concerns the segments outstanding at its ingest. Setting one option does not by itself establish compliance with the other requirements. If your intended workflow is a local looping input sent over RTMP, HLS playlist controls are not relevant to that input playlist.
Check the ingest workflow and encoder settings
Before editing a command, identify the protocol selected in YouTube Live and the actual output you are sending. Is it one continuous RTMP/RTMPS connection, or are you generating HLS segments? Then check the encoded frame rate, codec, audio and whether the video is re-encoded. This prevents changing an HLS muxer option when the real issue is the outgoing GOP, or applying RTMP guidance to a segmented HLS output.
For the common continuous RTMP/RTMPS case, set the output rate first, calculate the two-second GOP length, and request a closed GOP if supported. Keep the rest of the encoder settings aligned with YouTube’s current guidance for your selected resolution, frame rate and codec. YouTube’s live encoder page lists H.264, HEVC and AV1 for RTMP/RTMPS and recommends CBR; consult it rather than copying an unrelated bitrate or codec setting from another stream.
When the stream is assembled from clips, test the transitions as well as steady playback. A clip boundary can involve a decoder reset, a frame-rate change or a timestamp discontinuity. Those transitions may reveal problems that a short test of one file does not. If playback stops after the final item, diagnose looping and process continuity separately; a useful comparison is the guide to keeping a pre-recorded YouTube stream running in India.
For a stream that needs to continue through the night without keeping your computer running, StreamNeo removes the recurring task of leaving a local machine on to keep an uploaded video broadcasting, while the keyframe and ingest choices still need to suit the YouTube workflow you select.
If YouTube reports a GOP or keyframe error, check the output rather than merely increasing the -g value. Confirm the output frame rate, the encoder that is actually active, and whether timing changes or dropped frames are present. YouTube notes that ingestion errors can lead to incorrect GOP-size readings, so a warning can point to the delivered stream or the ingest path, not just the nominal command-line setting.
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 keyframe interval should I use for YouTube Live?
For RTMP or RTMPS, target one keyframe every two seconds and do not exceed four seconds. YouTube publishes this guidance for live encoder settings; verify the current official recommendation if your ingest workflow changes.
What does -g 60 mean at 30 fps?
It sets a maximum GOP size of 60 frames, which corresponds to two seconds at a fixed output rate of 30 fps. At another output rate, calculate the frame count again instead of copying 60.
Does -flags +cgop guarantee a closed GOP?
It requests closed-GOP operation in FFmpeg, but it should not be treated as a universally verified result for every codec, encoder and source. Check the selected encoder’s behaviour and inspect the actual output when the distinction matters.
Is my looping file list the same as an HLS playlist?
No. A local list of media files can feed a continuous RTMP/RTMPS output; an HLS playlist describes segmented output and has separate YouTube ingest requirements. Identify which one you are using before applying segment or playlist settings.