MEASURED KEYFRAME TEST

Keyframe Interval (GOP) Tested: File Size, Seek Time and Where Stream-Copy Cuts Start

One synthetic 720p clip encoded with x264 at six keyframe intervals, from every frame to every 20 seconds. Measured file size, FFmpeg seek-decode time at 24 points, and what a -ss stream-copy cut really contains.

Laptop running DaVinci Resolve with the File menu open, a clip in the viewer and an orange playhead on the timeline, with a blurred hand in the foreground
Illustrative stock photo: Houssam benamara / Pexels. The photo is not a screenshot demonstrating the steps in this guide.
AT A GLANCE

On this source, going from a keyframe every 12 frames to every 600 frames saved 38% of the file but raised the worst measured seek from 0.090 s to 0.477 s, and stream-copy cuts carried hidden frames back to the previous keyframe.

What the keyframe interval decides

An H.264 file is mostly made of frames that only describe changes from other frames. A keyframe (an IDR frame in x264 output) is the exception: it can be decoded on its own. The keyframe interval, also called the GOP length, is the maximum distance between those frames. In FFmpeg it is set with -g.

That one number touches three practical things. Long intervals save bits, because keyframes are expensive. Short intervals make random access cheaper, because a decoder that jumps to frame 500 has to start at the keyframe before it and decode forward. And when you cut with -c copy, nothing is re-encoded, so a cut that starts between keyframes has to deal with frames it cannot decode on their own. The diagram at the top of this guide is conceptual. The tables below are measured.

This guide does not repeat the general theory of exact trimming. For that, read trimming at an exact frame with stream copy. For how FFmpeg seek placement changes frame-extraction speed on a different source, see extracting a frame from a video.

Test setup and exact commands

The source is FFmpeg's own testsrc2 pattern with temporal noise added, so that every frame is different and inter-frame prediction has real work to do. It is 1280x720, 30 fps, 60 seconds, 1,800 frames, generated on the fly so anyone can rebuild it byte for byte. I checked that the generator is deterministic by hashing the first 90 decoded frames on two separate runs; the hashes matched.

Each file used the same x264 settings, changing only -g. Scene-cut detection was disabled with -sc_threshold 0 so x264 would not add keyframes of its own, and B-frames were left at the preset default.

ffmpeg -hide_banner -y -f lavfi -i "testsrc2=s=1280x720:r=30:d=60,noise=alls=6:allf=t,format=yuv420p" -c:v libx264 -preset medium -crf 23 -g 120 -sc_threshold 0 -threads 4 -an -movflags +faststart gop-g120.mp4

Seek cost was measured as the wall-clock time for FFmpeg to seek and decode one frame, with input seeking (the -ss placed before -i):

ffmpeg -hide_banner -loglevel error -threads 4 -ss 41.4667 -i gop-g120.mp4 -map 0:v:0 -frames:v 1 -f null -

I drew 24 seek points with a fixed random seed (20261113), between 0.5 s and 59.5 s. Each point was timed three times per file, in shuffled order, and the median of the three was kept. All runs used FFmpeg 8.1.1 (gyan.dev full build) on one Windows 11 laptop, capped at four threads. The timings include starting the FFmpeg process, which is the same fixed cost for every file.

To make sure fast seeks were not wrong seeks, I compared the MD5 of every input-seeked frame with the same frame decoded by slow output seeking. All 24 points matched in all six files.

Conceptual diagram for Keyframe interval test
Original ToolWillow diagram. Illustrated concept, not measured product results.

File size and keyframe count

Same CRF, same preset, same source. Only the interval changed. Keyframe counts come from ffprobe -show_entries packet=flags.

-gKeyframesBytesAverage kbpsSize vs -g 600PSNR vs source (dB)
11,80078,127,07710,4172.94x37.65
1215043,028,6085,7371.62x37.13
483832,043,7574,2731.21x37.18
1201528,914,7613,8551.09x37.22
250827,496,9613,6661.04x37.24
600326,565,1553,5421.00x37.26

The size curve flattens quickly. Most of the saving happens between 12 and 120 frames; going from 120 to 600 saved only another 8%. CRF kept measured quality nearly flat: every inter-coded file landed within 0.13 dB of the others. The all-keyframe file scored about 0.4 dB higher at almost three times the size. The absolute PSNR is low because the added noise is random and hard to code. Treat the column as a consistency check, not a quality grade.

Seek time at 24 random points

Each figure is a median of three runs at one point. The table gives the mean and median of those 24 medians, the slowest one, and how far the slowest point was from the keyframe it had to start at.

-gMean (s)Median (s)Worst (s)Most frames decoded before the target
10.0710.0700.0880
120.0690.0690.09011
480.0870.0860.11447
1200.1090.0970.192119
2500.1500.1260.306244
6000.2090.1730.477546

Two things stand out. First, below about 48 frames the interval barely mattered here, because the cost of launching FFmpeg (roughly 0.05 to 0.07 s on this machine) was larger than the decoding. Second, the worst case grows much faster than the average. A 600-frame interval was only about 2.5 times slower on the median point, but more than five times slower at the unlucky point that sat 523 frames past its keyframe.

Across all 144 point medians, seek time tracked the number of frames between the keyframe and the target closely (correlation r = 0.97). A straight-line fit gave 0.067 s of fixed cost plus about 0.71 ms per extra 720p frame decoded. That slope is specific to this CPU, this resolution and this noisy source. An editor that keeps its decoder running avoids the start-up cost, so it would feel the per-frame part more, not less.

Where a stream-copy cut actually starts

I cut 4 seconds from each file at 7.3 s, 21.1 s and 44.4 s without re-encoding:

ffmpeg -hide_banner -y -ss 7.3 -i gop-g120.mp4 -t 4 -map 0:v:0 -c copy cut-g120-7.3.mp4

Decoded normally by FFmpeg, every cut began on the requested frame. That looks like a frame-exact cut, but it is not what is in the file. The MP4 muxer kept the packets back to the previous keyframe and wrote an edit list telling players to hide them. Decoding the same files with -ignore_editlist 1 and matching every frame against the source by MD5 shows what is really stored:

-gCut at 7.3 s: first stored framePackets in a 4 s cutBytes
1frame 219 (7.3 s)120about 5.1 MB
12frame 216 (7.2 s)1253,036,460
120frame 120 (4.0 s)2213,581,817
250frame 0 (0.0 s)3415,138,214

With a 250-frame interval, a 4-second cut at 7.3 s carried all 7.3 seconds before it as hidden pre-roll, with timestamps going down to -7.3 s. At 44.4 s the same file stored 204 packets; the 600-frame file stored 254. The amount of hidden material depends on where the cut falls, not just on the interval. Only the all-keyframe file produced cuts with exactly 120 packets and a 4.000 s duration.

FFmpeg honours edit lists, so in FFmpeg the hidden frames stay hidden. I did not test any other player, editor or upload service. Software that ignores edit lists would show the pre-roll, starting at the keyframe instead of your in-point. You can check this yourself with the small published samples: 640x360 10 s sample, keyframe every 120 frames (keyframes at 0, 4 and 8 s), the same clip with a keyframe every 12 frames, and a 3 s stream-copy cut requested at 5 s. The cut holds 122 packets. FFmpeg normally shows 92 frames starting at 5.0 s. With -ignore_editlist 1 it shows 122 frames starting at 4.0 s.

Choosing an interval: a decision table

The rows below apply these measurements to common jobs. They are judgement calls built from one test source. They are not measured results for your footage or software.

JobSuggested intervalWhy, from this test
Editing proxies, heavy scrubbing1 (all-intra) or very short, such as 12 at 30 fpsWorst seek stayed under 0.09 s, but all-intra cost 2.9x the size of the longest GOP. Proxies are small anyway, so the size cost usually matters less.
Delivery files watched start to finishAbout 2 to 4 s (60 to 120 at 30 fps)-g 120 was within 9% of the smallest file, and its worst seek was 0.19 s. Longer intervals saved little more.
Archives you will seek into or cut losslesslyAbout 1 to 2 s (30 to 48 at 30 fps)Bounds the hidden pre-roll in stream-copy cuts to under 2 s and the worst seek to about 0.11 s, for about 21% more size than -g 600.
Smallest file, seeking rareLong (250+)Saved only 3 to 8% over -g 120 here, but worst-case seeks were 0.31 to 0.48 s and cuts carried up to 7 s of hidden pre-roll.

Streaming platforms often publish their own keyframe requirements for live ingest. If one applies to you, follow it over this table. If you need cuts that are exact in any software, re-encode at the cut point or cut only on keyframes.

What this test does not show

  • One synthetic source. Noise makes every frame expensive, so real footage with still shots will show different sizes and gaps between intervals.
  • One machine, one decoder (FFmpeg's software H.264 decoder), 720p. Hardware decoders, 4K footage and NLE caches behave differently.
  • Wall-clock times include process start-up. They describe a command-line seek, not timeline scrubbing in an editor.
  • No editor, browser or player was tested for edit-list handling. Only FFmpeg was.
  • The large 720p test files are not published; they can be rebuilt from the commands. Every command, timing, byte count and SHA-256 hash for the published samples is in the results JSON.

To read a file's real keyframe spacing before cutting, list keyframe timestamps:

ffprobe -v error -select_streams v:0 -skip_frame nokey -show_entries frame=pts_time -of csv=p=0 input.mp4

Common questions

Does a shorter keyframe interval lower quality?

Not in this test. At CRF 23, all intervals from 12 to 600 frames scored within 0.13 dB PSNR of each other. CRF spent more bits on shorter intervals instead, so the files grew.

Why did my stream-copy cut start earlier than I asked?

Without re-encoding, a cut can only begin decoding at a keyframe. FFmpeg keeps the frames back to the previous keyframe and writes an edit list to hide them. Software that ignores the edit list shows those extra frames.

Is -g 1 needed for smooth scrubbing?

Here, -g 12 seeked as fast as -g 1 because process start-up dominated. Its files were 45% smaller. Very short intervals gave most of the scrubbing benefit at this resolution.

How much does each extra decoded frame cost?

About 0.71 ms per 720p frame on the test laptop, from a straight-line fit over 144 measurements. Other machines, resolutions and sources will differ.

Does scene-cut detection change these results?

The test disabled it with -sc_threshold 0 so each file had exactly the intended interval. With it enabled, x264 adds keyframes at cuts, which shortens some gaps on real footage.

Sources & further reading

Written for ToolWillow with original explanations and examples. Consult current product documentation for controls that vary by version.

Try the free browser tools →