GOP, B Frames and Codec Threads - What Do They Mean?


#21

Below are my current settings for Shotcut for editing video games.
I upload game videos to YouTube.
1920x1080 resolution (source and output)
16:9 aspect ratio (source and output)
Source files: VBR 3kbps or 12kbps bitrates, 2 B-frames
Encoder I use with OBS: NVENC H.264
Color Format NV12, YUV Color Space 709, YUV Color Range: Full.
File format. MP4 (source & output)
codec setting

Nobody told me how to get the 3k, 12k bitrates, as I had to experiment to find the best setting for what game I’m playing, and what I’m willing to be happy with. The free advice I got online told me record everything at 35k to 50k bitrates, but I get the same end result from 3k result on one game. Not sure if anyone else could benefit from my settings, nor could I recommend anyone use them.

I don’t fully understand the GOP, but enough to where I’m not going to mess with the settings. I’m taking @kenj69 advice to not mess with them and only use the presets.

There are inherent reasons why there are presets in Shotcut, specifically to this issue. Like you, myself, and probably many others don’t understand the settings, yet we want this to work. The export presets are extremely useful and I have never had a bad export, ever. But understand that I have only save to MP4. I can’t speak to the other containers (extensions like .mov .mkv .m4a).


#22

Try mediainfo software https://downloads.tomsguide.com/MediaInfo,0301-3290.html


#23

Fixed GOP means that frames in one GOP will not depend on frames from another GOP

So the “Fixed” checkbox controls what is called “Closed GOP” in YouTube’s recommended upload encoding settings. Is there a reason why it is not checked in Shotcut’s YouTube preset? And also, when I perform H.264 exports the log files show that libx264 is used with option “open_gop=0” regardless of this checkbox, but when it is checked the option “scenecut=0” is set instead of “scenecut=40”…


#24

No, sorry. I misinformed you. There is no setting in Shotcut for open/closed GOP (although you may be able to set it in the “Other” tab).

“Fixed” relates to the GOP size parameter. If “fixed” is enabled, then every GOP will be exactly the size specified. If “fixed” is disabled, then the encoder is allowed to start a new GOP at its discretion - the most common reason being scene changes. In that case, the GOP size is the “maximum GOP size”.


#25

Thank you for clearing that up!

I’m still a bit curious about the GOP length setting… When I start Shotcut it shows the value 125. When I click the YouTube preset it changes to 15, and I see this is specified in the preset file. When I click any of the H.264 presets it changes to 13, but I cannot find that specified in any of the default preset files so where does that value come from?

YouTube’s recommended upload encoding settings specifies GOP of half the frame rate, but does not indicate what this means for PAL - half the frame rate is 12.5, so either 12 or 13. My impression is that 12 is most used. My PAL AVCHD camera records with GOP length 12 (according to MediaInfo). From guides on internet it seems to me that 12 for PAL and 15 for NTSC are kind of a (de facto) standard. Is the intention behind the GOP length 15 in the YouTube preset to be half the frame rate - but assuming NTSC? I guess it is not possible to create a preset with a GOP length depending on the current frame rate setting? Why is the other H.264 presets using GOP length 13 - why different from the YouTube preset, and if assuming PAL then would 12 more in line with others than 13?

(Sorry if I’m asking too much about unnecessary details here, I’m just curious).


Video degrading when export
#26

13 is the default value if a preset does not specify it:

Probably. It stands to reason.

Correct - Shotcut does not support that.

I think you are reading into this too much. 12 or 13 are both close enough to “half the framerate” to achieve the goal.


#27

Probably true. Thank you for your answer.


Audio and video slowly get out of sync over time
#28

Actually, that is a remnant I missed during the change to make the defaults deviate some from the YouTube preset. I am changing this to be (5 * FPS) per the new defaults. YouTube does just fine when you deviate from their recommendation. They simply needed to give people some target to prevent getting crap (e.g. MPEG-4 part 2 simple profile), and Shotcut needs a preset to match what they published. However, that recommendation gives quite large file size that people complain about.


#29

A GOP (Group Of Pictuires) always starts with an I-frame (Intra frame).
An I-frame contains all the information needed to produce the picture for that frame, it does not depend on the contents of any other frame. If the GOP consists of only I-frames it would emulate an old cinematographic spool of tape, where e.g. damage to one frame would not affect any other frame.

The GOP can also contain zero or more B-frames (Bi-directional frame).
B-frames consist of information that describes the changes in the picture between this frame and the previous one. So damage or corruption of an I-frame or B-frame would affect the validity of subsequent consecutive B-frames.

The GOP can also contain zero or more P-frames (Predictive frames).
P-frames consists of information that describes the changes in the picture beween this frame and the previous I-frame and also the following I-frame. In this way any discrepancies or corruption within previous B-frames are eliminated from this P-frame onwards.

e.g. IBBBPBBBPBBBIBBBPBBBPBBBI (GOP = 12)

If you have a GOP of 1 (only consists of I-frames), you can easily jump (move the playhead) to any frame. The higher the GOP number the more difficult it is to move to playhead to a particular frame, since that frame may be a B- or P-frame and you have to seek to the corresponding I-frame (and intervening B-frames) to get the whole picture.
This becomes even harder if you have multiple tracks that may not have the same GOP number so that their I-frames to not coincide, or even if the GOP numbers are the same but the I-frames are aligned differently. Also playing in reverse is considerably harder for the hardware to do.

Obviously the main advantage of high GOP numbers is that the filesize is less than with large GOP numbers (usually considerably less unless there is a huge amount of motion between consecutive frames). The main disadvantage of large GOP numbers is the amount of processing power needed to create/handle the B- and P-frames.

@moonthink I hope this clarifies the situation for you.


#30

GOP size is very important to a frame-precision seeking tool such as Shotcut and nearly all other video editors. Some media players only seek to keyframes (I-frame). A long GOP is much less important to any tool or service that merely needs to convert (e.g. YouTube), processing sequentially, or stream over a reliable transport (i.e. HTTP).


#31

That is the best explanation I have seen anywhere!


#32

Thank you - I tried to summarise the information contained in these two useful articles:

https://larryjordan.com/articles/a-primer-i-frame-vs-gop-compression/
http://www.tiliam.com/Blog/2015/07/06/effective-use-long-gop-video-codecs


#33

I got this book (and a few others) before we started making our first video attempts:

Ascher, Steven. The Filmmaker’s Handbook: A Comprehensive Guide for the Digital Age: 2013 Edition (p. 247). Penguin Publishing Group. Kindle Edition.

I love it, I can really recommend it. Got it as an e-book (some of those are badly layouted, not adapted to the e-format, but this one is nice and well structured and well indexed etc.). I can only quote a few lines, but you will find entire chapters on “Digital Compression” and “Compression Methods” and “A Few Common Codecs” under the Area “The Video Image”.

Here a mini-sample:

Different interframe formats use a different-length GOP. The length of the GOP affects how the compressor handles motion and complexity: the longer the GOP, the more you can compress the data, but that means more processing power is needed to keep up with the calculations. The 720p version of HDV, for instance, uses a 6-frame GOP; the 1080i version uses a longer, 15-frame GOP. …

Then he goes on in full detail and with graphs, showing how the GOP work together with the interframes etc.


#34

Mr Eko has 20 odd Shortcut tutorial on his Youtube channel @ https://www.youtube.com/channel/UCuQN51H4IrDGOm5CXKIsipg/videos Tutorial part 6 give a simple explanation of GOP B frames and threads.


#35

I have a better understanding of GOP/B frames now, thanks to this thread (and I didn’t need to buy a book). Hopefully it helps someone else too.

I have one more related question (so not worth new thread)…

Is there any easy way to read the GOP/B frames of source material? It doesn’t show up in properties, and I can’t find any info on it in my camera’s documentation. Would be great if there is a free app, or function in some app that can tell me what the GOP/B frames info is of any file.

Any help along those lines would be greatly appreciated.


#36

Mediainfo (https://mediaarea.net/en/MediaInfo) gives the GOP information as e.g. M=3, N=12.

See Wikipedia (https://en.wikipedia.org/wiki/Group_of_pictures) for the explanation:

GOP Structure
The GOP structure is often referred by two numbers, for example, M=3, N=12. The first number tells the distance between two anchor frames (I or P). The second one tells the distance between two full images (I-frames): it is the GOP size.[2] For the example M=3, N=12, the GOP structure is IBBPBBPBBPBBI. Instead of the M parameter the maximal count of B-frames between two consecutive anchor frames can be used.

For example, in a sequence with pattern IBBBBPBBBBPBBBBI, the GOP size is equal to 15 (length between two I frames) and distance between two anchor frames (M value) is 5 (length between I and P frames or length between two consecutive P Frames).


#38

Hmmm, I’m running mediainfo, but I don’t see any GOP structure/info.


#39

Not sure about MediaInfo not showing the information, but one thing to keep in mind is that the GOP structure only applies if the video was actually encoded that way. While it’s very common for DVDs and Blu-Rays, as well as some streaming solutions, most modern encoders don’t use a strict structure by default.

You would need to extract the frame type on a per-frame basis. AviSynth with ffmpeg and a little scripting can do this; https://forum.doom9.org/showthread.php?p=1834810#post1834810

Though I could’ve sworn VLC was able to show the info as well.


#40

that’s a good point, so I checked a file that I had already exported using shotcut (that I know used gop/b-frame settings) and still there was no GOP info listed in mediainfo.

I also tried looking at codec etc. view info in VLC, but no luck there either.


#41

Yeah, I know it was years ago that I saw it last. Unless you’re a researcher, or have a very specific need, there’s little reason to care about the frame types as either the person doing the encoding (other than knowing the intended delivery platform - seeking VP9 files is a nightmare if you don’t litter them with the equivalent key frames), and even less so the consumer.

The AviSynth script works, though I’m fairly sure the frame where the following video goes back to Morena Baccarin is not suposed to be a P frame - but for all I know that’s exactly what the encoder ended up using there.
https://streamable.com/ufhtk

Is this just a curiosity itch you’re hoping to scratch?