Skip to content
streamneo.
Troubleshooting11 min read

How to Verify YouTube Live Keyframe Intervals in an FFmpeg Command

Calculate GOP frames from the output frame rate, then use ffprobe to verify YouTube Live keyframe spacing.

sn.
StreamNeoPublished 5 October 2026
Worth sharing?

YouTube recommends a keyframe every two seconds for live streams and says not to exceed four seconds. In FFmpeg, calculate the GOP size from the video’s actual output frame rate, then inspect the encoded frames with ffprobe; an encoder option alone does not prove the emitted keyframe timing.

For example, a two-second GOP is 60 frames at 30 fps and 120 frames at 60 fps. Those are frame counts, not universal settings: if your output rate differs, the count changes. The check is the elapsed time between observed keyframes, not merely whether your command contains -g.

Know YouTube’s keyframe guidance

YouTube Help’s encoder settings guidance recommends a two-second keyframe interval and says not to exceed four seconds. Treat two seconds as the target and four seconds as the upper limit. A stream that meets the upper limit is not necessarily meeting the recommended target.

A keyframe, often called an I-frame in video terminology, provides a point from which a decoder can reconstruct a picture without relying on earlier pictures in the same sequence. GOP means group of pictures: the sequence between keyframes, including the keyframe itself according to the encoder’s conventions. GOP length is commonly configured as a number of frames, while YouTube’s guidance is expressed in seconds. That difference is why the frame rate matters.

The platform’s live encoder troubleshooting page gives the example that at 30 fps, keyframes every two seconds means 60 frames. It also notes that ingestion errors can cause incorrect GOP sizes and says a closed GOP is required for optimal transcoding in YouTube’s pipeline. These are separate checks: ask what your encoder was configured to do, what the output actually contains, and whether YouTube reports an ingestion problem.

This article focuses on the keyframe interval, not every live-stream setting. Codec, bitrate, frame rate, transport and audio settings still matter, and a correct GOP does not establish that the rest of the stream is suitable. If you are already investigating a wider YouTube stream-health warning, compare the symptoms with the practical checks in this guide to stream health after a broadband change.

Determine the actual output frame rate

Use the rate of the video that FFmpeg is producing, not an assumed rate copied from the source file, a camera specification or an earlier command. Filters, frame-rate conversion, timestamp handling and input characteristics can mean that the output differs from what you expected. A variable-frame-rate source makes a simple frames-per-second assumption particularly risky: equal frame counts do not always represent equal elapsed time.

Inspect the output stream’s reported rate with ffprobe. For a file, a compact stream query is:

ffprobe -v error -select_streams v:0 \
  -show_entries stream=avg_frame_rate,r_frame_rate \
  -of default=noprint_wrappers=1 OUTPUT

The output can include both avg_frame_rate and r_frame_rate. These values describe aspects of the stream’s rate; they are not a reason to ignore timestamps when the material is variable frame rate or has unusual timing. For a straightforward constant-frame-rate output, identify the intended and observed rate, and use that rate for the GOP calculation. If the figures do not match the format you intended, resolve that first rather than selecting a GOP count based on a guess.

If your command contains an output -r or a frame-rate filter, record it as part of the expected output configuration, but still check the resulting file or capture. The input may report a different rate, and the value you meant to request is not itself evidence of what was emitted. This is the same distinction that matters when you troubleshoot a looping file: inspect the actual result, rather than assuming the command behaved as intended. For a separate looping failure mode, see the FFmpeg black-screen troubleshooting guide.

For a live broadcast that is not saved as a conventional file, use an appropriate capture of the encoded output or another inspectable output produced by your workflow. Do not base the conclusion only on the input media. Your verification needs the timestamps and keyframe flags of the video that was encoded for transmission.

Calculate GOP frames for a two-second target

The basic calculation is:

GOP frames = output frame rate × target interval in seconds

For YouTube’s two-second target, multiply the actual output frame rate by two. At 24 fps, that is 48 frames; at 30 fps, it is 60; at 60 fps, it is 120. The 30 fps conversion is also given in YouTube’s troubleshooting guidance. The other values are arithmetic conversions, not separate YouTube-published limits.

Actual output rate GOP frames for a 2-second target Frames spanning 4 seconds
24 fps 48 96
30 fps 60 120
60 fps 120 240

The right-hand column is useful as a frame-count cross-check only when the output is constant frame rate. YouTube’s limit is a time interval, so for variable-frame-rate material you should compare keyframe timestamps directly. A count that appears acceptable under an assumed rate can conceal a longer gap in elapsed time.

Check that the arithmetic produces a sensible whole-frame setting for your output. If your frame rate is expressed as a fraction, calculate using that value rather than rounding it casually. The two-second interval may not correspond to an integer frame count at every possible rate; in that case, use the closest appropriate encoder setting and verify the resulting timestamps against YouTube’s time-based target and maximum.

Keep the target and maximum distinct in your notes. The command’s configured GOP expresses an encoder constraint or request; the observed interval is what determines whether the output stays within YouTube’s guidance. A 60-frame configuration is not a universal answer for every channel, even if 30 fps is common in your workflow.

Configure the encoder

For a 30 fps H.264 example, an FFmpeg command fragment is:

ffmpeg -i INPUT -c:v libx264 -g 60 -flags +cgop OUTPUT

This illustrates configuration only. It is not a command reported as run or a claim that every emitted gap will be exactly two seconds. FFmpeg documents -g as the maximum GOP size: an encoder may insert keyframes sooner. The FFmpeg codec documentation describes the encoder options; consult the documentation for your selected encoder and version when adapting the command.

Replace 60 with the count calculated from your actual output frame rate and target. For 60 fps, for instance, 120 frames corresponds to two seconds. The example uses libx264; do not assume that the same encoder-specific options apply unchanged to another codec or encoder. YouTube’s guidance lists supported stream settings separately, and the selected codec and setup must be compatible with your use case.

The +cgop flag requests closed-GOP behaviour in this example. YouTube’s troubleshooting guidance states that its pipeline requires a closed GOP for optimal transcoding. This remains a configuration request to check in context, not a substitute for output inspection. When you change codec, encoder, presets, frame rate or other options, review the resulting output again rather than carrying forward an old verification.

Keep the command readable and record the effective video settings alongside the output you inspect: encoder, codec, output frame rate, GOP option and closed-GOP setting. That small record helps when the live control room reports a warning later, because you can distinguish a wrong calculation from a setting that was not applied or an emitted result that differs from the request. If you manage a continuous playlist, interval correctness is one part of the chain; the workflow for switching FFmpeg videos without disconnecting addresses a different operational risk.

Inspect encoded output intervals

Use ffprobe’s frame-level output to find keyframe flags and their timestamps. The ffprobe documentation describes -show_frames, which reports information for each frame. A useful starting command is:

ffprobe -v error -select_streams v:0 -show_frames \
  -show_entries frame=key_frame,best_effort_timestamp_time,pict_type \
  -of csv=p=0 OUTPUT

The result lists frames from the selected video stream. Look for frames where key_frame is set, note their best_effort_timestamp_time values, and calculate the difference in seconds between each successive keyframe. The pict_type field can help you read the frame output, but use the keyframe flag and timestamps for this check. The first keyframe’s position and stream-start behaviour can affect how the first interval appears, so examine successive keyframe pairs rather than judging from a single opening timestamp.

A simple manual workflow is often enough for a short sample: collect the keyframe timestamps, subtract each timestamp from the next, and write down the largest gap as well as the typical gap. Check a representative span rather than only the first few frames. If output is long, automate the extraction and subtraction, but retain the same evidence: timestamps of frames marked as keyframes. Do not infer the interval from file duration divided by a frame count, or from the configured GOP alone.

Interpret timestamps carefully. A constant-frame-rate file will usually make frame counts and elapsed time align predictably. With variable frame rate, timestamp differences are the more direct measure of the interval. If timestamps are missing, discontinuous or surprising, investigate the output and capture method before deciding that the GOP passes. The purpose is to verify the encoded material that YouTube receives, not to produce a tidy-looking command line.

For a live stream, a capture can reveal what was emitted during the sampled period, but it cannot prove behaviour outside that sample. If YouTube Live Control Room flags an incorrect keyframe frequency, compare the report with your captured output and investigate ingestion errors as well as encoder settings. A clean file inspection and a platform warning can point to different stages in the path; avoid changing several unrelated settings at once, or you will lose track of which change addressed the interval.

Compare the configured and observed results

Keep two columns in your check: configured and observed. The configured value is your intended maximum GOP size in frames, derived from the output rate. The observed value comes from the time differences between successive encoded keyframes. The first helps you review the command; the second answers whether the output actually met the timing target.

Check What it tells you What it does not tell you
-g value and output frame rate The requested maximum GOP size in frames The exact timestamps the encoder emitted
-flags +cgop in the command Closed-GOP behaviour was requested in the example That every other stream setting is correct
ffprobe keyframe flags and timestamps The keyframes and elapsed intervals in the inspected output That an uninspected part of a live broadcast behaves identically
YouTube Live Control Room warning YouTube has identified a stream issue to investigate By itself, which setting or stage caused it

The distinction prevents a common troubleshooting dead end: treating a command that looks right as proof that the broadcast is right. If the requested GOP count is wrong for the output rate, fix the arithmetic and re-encode or restart as appropriate. If the count is plausible but observed timestamps show a larger gap, examine whether the setting was applied, whether the encoder inserted keyframes as expected, and whether the output you inspected is the same output being sent.

For always-on channels, this is worth checking before leaving a change unattended. A devotional playlist, a study room or a local news loop may run through overnight hours, when a warning is less likely to be noticed immediately. If your operating model depends on a long-running stream while your own computer is off, StreamNeo removes the need to keep that machine running; you should still validate the video file and YouTube stream settings before relying on a broadcast. Interval verification remains a separate task from keeping a stream running.

Compare results with the four-second maximum

For each pair of successive keyframes, subtract the earlier timestamp from the later one. Aim for approximately two seconds and check that no observed interval exceeds four seconds. Use actual timestamp differences, particularly if frame timing is variable; the frame-count table is a convenient conversion for constant-rate output, not a replacement for time-based inspection.

If intervals are around two seconds, the output is consistent with YouTube’s recommendation for the sample you inspected. If a gap is over two seconds but at or below four, it is within the stated maximum but misses the recommended target. If an interval exceeds four seconds, it is beyond the guidance and calls for investigation. These comparisons describe the observed sample, not a guarantee about every future moment of a live stream.

When the observed timing is wrong, work through the chain in order. Confirm the actual output rate; recalculate frames from that rate; check the encoder and its effective options; inspect the emitted output again. If the settings and output appear correct but YouTube reports a GOP problem, consider ingestion errors as YouTube’s troubleshooting page advises. Make one relevant adjustment at a time and repeat the inspection so you know whether the change affected the result.

Save the command, the ffprobe excerpt around the largest observed interval, and the arithmetic used for the GOP setting. This creates a useful before-and-after record if you need to troubleshoot a later stream-health alert or reproduce the encoding setup. It is more useful than a note that says only “GOP set to 60”, because that note omits the frame rate and provides no evidence of emitted timing.

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 should -g be for YouTube Live?

Set it from the actual output frame rate multiplied by the two-second target interval. That gives 60 frames at 30 fps and 120 at 60 fps; then inspect timestamps because the option alone does not verify emitted spacing.

Does -g 60 guarantee a keyframe every two seconds?

No. FFmpeg documents -g as a maximum GOP size, and the encoder may insert keyframes sooner; the option does not prove the timestamps in the output. Use ffprobe to check successive keyframe flags and their elapsed times.

How do I check a variable-frame-rate output?

Inspect keyframe timestamps and measure the time between them rather than relying on a frame count. A given number of frames can span different durations when frame timing varies.

What should I do if YouTube reports an incorrect keyframe frequency?

Check the output frame rate, recalculate the GOP size, review the encoder configuration and inspect the emitted output again. YouTube’s troubleshooting guidance also notes that ingestion errors can cause incorrect GOP sizes, so investigate the ingest path if the output and platform report do not agree.

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 Troubleshooting guides ↗ · All topics ↗