This is the official description of parameter:

‘-g[:stream_specifier] integer (output,video)’
set the group of picture (GOP) size

Not very informative I'd say.

Can anyone explain what does it actually do and what is the optimal value?

And on what depends moov atom size?



The video quality and compression ratio depends on Group of Pictures (GOP) structure. GOP structure also affects the distortion sensitivity of the video stream due to packet losses.

Increasing the GOP length, also increases the video quality. But after reaching the highest PSNR (Peak Signal to Noise Ratio), it starts to decrease. In the first increasing period, the efficient coding plays major role, so higher of GOP lengths lead to a better quality. After the optimal of GOP settings, when the video quality is the highest, the error propagation effect becomes more significant. Hence, using higher Intra frame (I-frame or Key frame) intervals, the error will be spreading because of significant distortion.Source

Each type of video has different optimal GOP, depend on its characteristic.

Key Frame and Animation:

Videos or moving images - we're just tricking our minds; they're just still images displayed at a rapid succession! And the illusion gets better and smoother if the next frame appears at/before 1/25th of a second which is the Human eye afterimage persistance time interval and the reason for motion perception.

Illustration 1: (source: Wikipedia)


Fig: A sequence of video frames, consisting of two keyframes (I), one forward-predicted frame (P) and one bi-directionally predicted frame (B).

(You may note that, in the above image the value of GOP, -g is 3, one key-frame with two supplimentary frames.)

Illustration 2: (source: Wikipedia)


Fig: A very simple animation created by key-framing. The animation lacks smoothness because each frame is completely independent of any other frame.

A possible Q&A:

Q. Aren't key frames enough? Why would we need to have the supplimentary/intermediate P-frames, B-frames?

A. Yes... but the use of such intermediate frames allow to reduce the overall size of the file (video).

For better quality video/streaming, you'd look to use low compression ratio but high frame rate which means high -g value with avconv (optimum GOP value is nearly half the value of frames/sec). As evident, the value for -g will have to be specified based on the coders, compression ratio, frame rates that you're using for the transcoding/streaming purpose; it's a relative quantity so there's no general value you can use with all inputs.

According to this link the value of GOP for most media would be about half the value of frame rate so that the key frame would be about 0.5 seconds apart and would produce a good quality video. We may also note that other link shows the PSNR attains a constant value at around half the test frame rate as indicated in the graph plot.


But the optimal value seems to lie around 1/6th to 1/4th the test frame rate.

And yeah, so you should be looking to use -g value around or in the range 1/6th to 1/4th so that the key frames appear every 0.17 to 0.25 seconds; and probably comment to improve the answer :)


| improve this answer | |
  • So... the -g is the controller for the GOP value? – Braiam Mar 1 '14 at 20:51
  • @Braiam, I've update the answer to include some more on the GOP value selection.. – precise Mar 2 '14 at 7:12

You have several examples of usage on the official avconv documentation.

From Section Tips:

avconv -g 3 -r 3 -t 10 -b 50k -s qcif -f rv10 /tmp/b.rm

If your computer is not fast enough, you can speed up the compression at the expense of the compression ratio. You can use ’-me zero’ to speed up motion estimation, and ’-g 0’ to disable motion estimation completely (you have only I-frames, which means it is about as good as JPEG compression).

| improve this answer | |
  • So, what the -g means? – Braiam Mar 1 '14 at 17:50
  • After some internet queries, I don't know. I guess the best place to ask this question (and expect a useful answer) is the Libav mailing lists. They also have an [IRC channel](irc://irc.freenode.net/libav). – landroni Mar 1 '14 at 19:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.