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

My main goal is to be able to export files with the same GOP/b frame settings as the source file(s). In that way, shotcut can be of more use to me as part of the workflow, not necessarily the final editor – sometimes I prefer certain options in other editors. Also, that way I can use shotcut to “pre-edit” some files before sending to collaborators.

I just ran my “Hunt for Red October” credits video that was exported by Shotcut through Mediainfo (latest Windows 10 version) and it definitely shows the GOP info, but you have to set the VIEW->TREE option. It shows:

1 Like

Yes, I was using tree as well. What version is that? Could it be a recent change?
I tried several different files, including source files, shotcut exported finished files, and although I don’t have hunt for red october, I also tried some mp4 movies that were downloaded.

Source file:

Shotcut exported file:

Movie from internet:

My version is 18.05, I even tried the online version, but no GOP info in any of those format settings there either. Bizarre…

How weird. My version is also 18.05, downloaded today from their website. I just ran my video through their online version and it too shows the GOP info (see the last line below):

General
Complete name                            : Hunt_for_Red_October.mp4
Format                                   : MPEG-4
Format profile                           : Base Media
Codec ID                                 : isom (isom/iso2/avc1/mp41)
File size                                : 2.72 MiB
Duration                                 : 30 s 486 ms
Overall bit rate mode                    : Variable
Overall bit rate                         : 748 kb/s
Writing application                      : Lavf57.83.100

Video
ID                                       : 1
Format                                   : AVC
Format/Info                              : Advanced Video Codec
Format profile                           : High@L4
Format settings                          : CABAC / 4 Ref Frames
Format settings, CABAC                   : Yes
Format settings, ReFrames                : 4 frames
Format settings, GOP                     : M=3, N=15

Weird. I know for sure that the file that shotcut exported used GOP: 15 and B frames: 2, but it doesn’t show in mediainfo.

Oh well, this is above my pay grade. Thanks anyway! This app will still be useful in other ways.

Shotcut version 18.06.02, using the YouTube preset, no adjustments.

Hmmm. I started with the youtube preset (just to have a frame of reference), but I did change one thing: quality from 60% to 100%. Could that somehow disable (or render useless) the GOP/B frame settings?

I’ve seen several queries on the web which indicate that the GOP is only output if it is fixed for the whole video. If it is variable, it obviously cannot produce a (constant) value for M and N. e.g.

Any thought about why the encoding of the original might be lacking the GOP data?

Your file has variable GOP size. Classic with non real time encoding (quality optimization for the same final file size)

and:

MediaInfo is open source project so you can always look in to source code (that is what I did to answer your question) if not sure what some value mean. In the case of AVC you need to read File_Avc::GOP_Detect (http://sourceforge.net/p/mediainfo/code/HEAD/tree/MediaInfoLib/trunk/Source/MediaInfo/Video/File_Avc.cpp#l3631) method.

  1. “M=” is constant delta between non-B-frames i.e. B-frames continues sequence length + 1. “N=” is constant delta between I-frames (btw, MediaInfo don’t make difference between IDR-frames and I-frames). It doesn’t report it on the most x264 encoded files because it usually use adaptive (not constant) number of B-frames and adaptive GOP length (scenecut detection) but MediaInfo report this only when M and N is same for all file GOPs.
  2. Mostly if you will ignore the fact about ignoring IDR- vs I-frame difference.
  3. GOPs length in x264 is defined by --keyint and scenecut detection algorithm which can make GOP shorter than --keyint. Only IDR-frames (and recovery points) close the GOPs. Simple I-frames don’t close the GOP.
2 Likes

Interesting, but also confusing. What determines if GOP is fixed or variable?

Basically, whether scene change detection for the encoder is enabled. This is the “sc_threshold” option in FFmpeg, MLT, and Shotcut Other tab. Generally, it is not desired to disable this unless you are doing something special such as adaptive bitrate streaming and unable to maintain a strict period of I frames otherwise.
Here is my bash script that uses ffprobe to report GOP information including both fixed and variable GOP:

1 Like

I was looking for an explanation on GOP and found this PDF article (with diagrams) very helpful https://www2.acti.com/support_old/Package/{6060C79F-2A5D-40A4-8837-16B835E3364.PDF

I exported a video using Default settings and the file byte size was about 58MB. Later I exported using the ‘YouTube’ preset and was surprised the file byte size increased to 167MB. Both files are mp4 but I noticed the Codec GOP setting for YouTube is 15 compared to 150 for Default; so the higher GOP setting produces a smaller video file.

I noticed the same thing.

I never use the YouTube preset now.

Last week I uploaded 22 videos to my primary YouTube channel; 21 used H.264 Main, one used “YouTube”.

All of them uploaded to YouTube without incident.

A lot of things work with YouTube, but the YouTube preset follows their guidance as much as possible since many people want exactly that.

1 Like

…as it should.

You don’t ever want someone complaining on this forum:
“I used your YouTube preset, and YouTube rejected my video.”
…without being able to say
“That preset exactly follows what YouTube published.”

I would NEVER recommend changing that preset.

But those of us with limited disk space and limited upload bandwidth will share ways to optimize both.

…and we will take our own chances with YouTube.

A few weeks ago I ran some tests; I found three things that could decrease the file size dramatically:

  • Decreasing the Frame Rate
  • Decreasing the Quality
  • Increasing the GOP size

Of the three, increasing the GOP size had the least impact on the quality of the output video.

Link to tests:

When you set quality to 100% you’re encoding all intraframes and there will be no GOP. If mediaInfo does not display GOP info, you can attempt to manually count frames between i frames on desired sections using avidemux. Avidemux displays frame type and allows frame accurate seeking and key frame skipping.

Not necessarily. 100% quality simply means lossless mode. It is possible to have IPB (GOP > 1) in lossless mode. The Shotcut lossless H.264 preset uses GOP 25, and the file size reduction is usually dramatic compared to All-Intra.

GOP can be difficult to detect due to its variable nature, unless Fixed GOP was specifically chosen at encode time. This could be why some tools don’t report it… it’s always changing from scene to scene.

Apologies, I missed the fact that this setting was changed.

Though it does show the ssim on the chroma evaluation is not 1.0, does that imply there is some loss when using a gop to compress temporally? Perhaps I am misunderstanding the metrics. Thanks for the fact checking!

No worries! Shotcut does image processing with 4:2:2 chroma. If there is any conversion between 4:2:0 and 4:2:2 during processing using any scaling method other than Nearest Neighbor, then that probably explains the chroma deviation in SSIM. (The default is bicubic, which will “create data” while scaling the chroma plane up to 4:2:2.) GOP > 1 shouldn’t be a reason for chroma deviation. In the screenshots you saw, H.264 was likely encoded in 4:2:0 whereas Ut Video was encoded as 4:2:2 and wouldn’t have had any conversion to introduce errors.

1 Like

I too, think people’s attitude of “google it” is absolutely terrible. If nothing else it’s deliberately an insult. Is it easier for me to google it, or to write a post about it, after logging in to my account here?

Finding someone’s full on description of what the different frames types are is fine, it doesn’t really make it any clearer what changing the number does though; does it?

I actually want an answer to this too, so I’m gonna try something different: -

i-frame - a full complete picture for a single frame. Only the bitrate will determine how good the quality is of this single picture (dismissing obviously codec, therefore compression type [think jpg vs bmp]; and resolution). Set your video to only have i-frames (GOP of 1) and it’s theoretically the best possible quality, but also the biggest file size. The only real number here you can set is the actual video frame-rate. This is how often a frame will be saved.

p-frame. These frames only save what has changed since the last i-frame. the decoder reads the i-frame, then makes the changes saved in the p-frame, and displays the result. Leaving scene changes to auto is a good idea to improve quality. When there’s a lot of stuff change on the screen, the encoder decides its a good idea to save an i-frame. A new scene that is a p-frame might produce a frame that’s larger (filesize) than just saving the fresh new i-frame, since its saving changes from last frame, not just the new frame. A high number means the encoder can save more p-frames between a complete picture (i-frame) being saved.

A perfect demonstration is a PowerPoint slideshow. The encoder detects the slide changes and saves the new slide as a complete picture (i-frame). for the next minute the picture doesn’t change at all, so there’s no need to save any data for these frames. You’ve just saved yourself a minutes worth of frames in file size. The number forces the encoder to save a complete picture if no slide changes are detected after that many frames.

There’s a couple caveats here, mostly: bitrate. The bitrate is how many bits (e.g. 500kbps) can be used for the frames in that second. Saving 24 individual frames will mean each frame gets only 20kbits. If it’s the slideshow example above, you can save the first frame at 500kbits (much better quality) and the remainder of the frames for that second don’t need any storage space. Roughly speaking. This results in the video appearing much higher quality for the same bitrate.

b-frames, the explanations I’ve found say it uses data from forward and backward. Thanks for letting me know, what happens when I change it from 3 to 50? What happens if I change it to be 3 times as big as my GOP? Can I even do that?

Is there an example that will demonstrate when b-frame should be set to a high number? set to a low number? etc.