Log in

View Full Version : H.264 GOP Format settings, M,N frames


john_z
16th February 2013, 09:07
I learnt the GOP well by Wikipedia (http://en.wikipedia.org/wiki/Group_of_pictures) http://en.wikipedia.org/wiki/Group_of_pictures.

When I encoded a movie , I always check the encoding parameter by reviewing in Mediainfo.( thanks to this great software).

So I found a strange thing, in some movie there is a line when you checking in the Text view in mediainfo. It is “Format settings, GOP : M=1, N=49”, sometimes there is none.


Video #2
ID :2
Format/ Info: Advanced Video Codec
Format profile : High@L4.1
Format settings, CaBAC : Yes
Format settings, ReFrames : 16 frames
Format settings, GOP : M=1, N=49
Muxing mode : Header stripping
Codec ID : V_MPEG4/ISO/AVC
Duration : 2h 7mn
Bit rate : 3 305 Kbps
Nominal bit rate : 3 500 Kbps
Width : 1 024 pixels
Height : 432 pixels
Display aspect ratio : 2.35:1
Frame rate : 24.000 fps
Color space : YUV
Chroma subsampling : 4:2:0
Bit depth : 8 bits
Scan type : Progressive
Bits/(Pixel*Frame) : 0.311
Stream size : 2.93 GiB (67%)
Writing library : x264 core 115 r1995 c1e60b9
Encoding settings : cabac=1 / ref=16 / deblock=1:-3:-3 / analyse=0x3:0x133 / me=umh / subme=7 / psy=1 / psy_rd=1.05:0.10 / mixed_ref=1 / me_range=24 / chroma_me=1 / trellis=2 / 8x8dct=1 / cqm=0 / deadzone=21,11 / fast_pskip=0 / chroma_qp_offset=-3 / threads=6 / sliced_threads=0 / nr=0 / decimate=1 / interlaced=0 / bluray_compat=0 / constrained_intra=0 / bframes=3 / b_pyramid=2 / b_adapt=2 / b_bias=0 / direct=3 / weightb=1 / open_gop=0 / weightp=2 / keyint=250 / keyint_min=24 / scenecut=40 / intra_refresh=0 / rc_lookahead=250 / rc=2pass / mbtree=1 / bitrate=3500 / ratetol=1.0/ qcomp=0.50 / qpmin=0 / qpmax=61 / qpstep=5 / cplxblur=20.0 / qblur=0.5 / ip_ratio=1.40 / aq=1:0.70




Also in some h.264 movie not encoded by X264 there exist too.


Format : MPEG-4
Format profile : Base Media
Codec ID : isom
File size : 1.10 GiB
Duration : 1h 0mn
Overall bit rate mode : Constant
Overall bit rate : 1 330 Kbps
Encoded date : UTC 2013-02-01 15:04:21
Tagged date : UTC 2013-02-01 15:04:21

Video
ID : 1
Format : AVC
Format/Info : Advanced Video Codec
Format profile : High@L3.0
Format settings, CABAC : No
Format settings, ReFrames : 1 frame
Format settings, GOP : M=1, N=33
Codec ID : avc1
Codec ID/Info : Advanced Video Coding
Duration : 1h 58mn
Source duration : 1h 58mn
Bit rate mode : Constant
Bit rate : 1 141 Kbps
Nominal bit rate : 1 200 Kbps
Width : 720 pixels
Height : 404 pixels
Display aspect ratio : 16:9
Frame rate mode : Constant
Frame rate : 29.970 fps
Standard : NTSC
Color space : YUV
Chroma subsampling : 4:2:0
Bit depth : 8 bits
Scan type : Progressive
Bits/(Pixel*Frame) : 0.131
Stream size : 967 MiB (86%)
Source stream size : 1 016 MiB (90%)
Language : English
Encoded date : UTC 2013-02-01 15:04:21
Tagged date : UTC 2013-02-01 15:04:21
mdhd_Duration : 7097572
Color primaries : BT.601 NTSC
Transfer characteristics : BT.601
Matrix coefficients : BT.601





I googled a lot and found many threads discussing “M=/N= values” in mpeg2, not in AVC/H.264. I made a lot of testing encoding in MeGUI, no matter how big the value set for --Keyint/--min-keyint, or calculation based on --FPS or fixed. It seems there still NO such M=?, N=?.

When I checked the “enable Blu-Ray compatibility”, the Open GOP is enabled and my final video will show “blocks & colorful mosaic”. Even I tweak the win7 default AVC decoder to Microsoft/LAV/ffdshow/Dxva, the result is the same. Only a close GOP makes the final watchable. ( avs script is generated by MeGUI using DirectShowSource, because FFMSindex stopped by errors when indexing.)

the question is:

1. GOP size(M=) and GOP length(N=) still implement in X264, if so why sometimes it shows and sometime not?

2. When Open GOP enabled and there is a broken frame, will it cause consecutive errors and displays color blocks/ mosaic ? If shorter -keyint & close GOP solves this question, is -keyint=frame(24/30) rate and –min-keyint <=3 legal in X264?

john_z
16th February 2013, 09:31
I tried other encoders too, like Handbrake, Avidemux , StaxRip, RipBot264, there is no such parameter in tweak. Only found a plug-in in Adobe Creative Suite CS6, but I don't have that software.

Enclosed is the introduction.

13274

Blue_MiSfit
16th February 2013, 20:06
I think M vs N GOP length description in MediaInfo is unnecessary.

x264 has several adjustments related to GOP structure. Most important is probably --keyint, which defaults to 250. In other words, a 250 frame GOP is the max allowed. By default x264 is adaptive, and inserts keyframes based on scene cut detection. This can be disabled by using --no-scenecut. These all influence the "N" number above.

Then there's B-frames. --bframes defaults to 3, and controls the maximum number of B-frames between I and P frames. I think this directly maps to "M" above, but I'm not sure.

john_z
18th February 2013, 01:58
Thanks for your kindly response.

Yes, you are right, I know the Key frame placement of x264 is adaptive. and fixed GOP size is not recommended by the developers.
But sometimes there are peculiar situations need smaller GOP. like the official user guide :


The default setting is fine for most videos. When encoding for Blu-ray, broadcast, live streaming or certain other specialist scenarios you may require a significantly smaller GOP length (often ~1x fps).


I tried encoded different length of videos in close fixed GOP structure. using the method of this http://forum.doom9.org/showthread.php?p=1173827#post1173827

I used crf20, bframes 3, -keyint /-minkeyint set 25/25, or 25/3(as the source fps is 25), the final filesize is little difference. I believe the final file is fixed GOP(But pity I don't know to verify). But still the mediainfo show no M=/ N=.

Maybe the pursuing of M/N is nonsense, but I would like to know indeed the difference of these videos with and without this.
Also why sometime the encoded file by x264 shows while sometimes not?

Blue_MiSfit
18th February 2013, 07:34
why sometime the encoded file by x264 shows while sometimes not?
No idea. I haven't paid attention to this :)

Encoding for special cases like you mention - BluRay, broadcast, live streaming etc - the goal is usually to keep the keyframe interval short to make seeking / channel changes very fast. In these cases, it's not usually necessary to have a FIXED GOP, you just want to have a shorter maximum GOP size. In other words, x264 will respect your chosen maximum (of 25 frames in your case), but will still use less, if a scene change dictates it. This is important, since scene changes should always accompany an I-Frame whenever possible.

In these cases, you should just set --keyint to whatever the max GOP size is. Don't mess with --min-keyint unless you really know what you're doing - this is an adaptive setting.

If you actually want a fixed GOP, then set --keyint, and use --no-scenecut. This will turn off scene cut detection, and simply use a 25 frame GOP in your example. x264 will still adaptively choose between P and B frames in this case. You shouldn't ever need to restrict things into obeying a fixed pattern.

Again, don't mess with --min-keyint

roa
23rd August 2013, 12:14
Hi,

I tested H.264 using a HD input video and GOP of various sizes (from 4 to 16) with a target bitrate enabled. I noticed that the final bitrate is very different of the target bitrate I specified, and it is decreasing as Gop size increases. So, finally I have binary files of different sizes for the same target bitrate specified, when changing only the Gop size; Is the bitrate considered per GOP ? I don't know how to explain this. If someone could help me, it would be great.
Thank you

Selur
23rd August 2013, 14:56
assuming you used x264: use 2pass encoding if you aim for an average bitrate,..

sneaker_ger
23rd August 2013, 15:17
I tested H.264 using a HD input video and GOP of various sizes (from 4 to 16) with a target bitrate enabled. I noticed that the final bitrate is very different of the target bitrate I specified, and it is decreasing as Gop size increases. So, finally I have binary files of different sizes for the same target bitrate specified, when changing only the Gop size; Is the bitrate considered per GOP ?

x264 knows two ways to control the bitrate (putting things like vbv aside...):
--bitrate
--crf

--bitrate controls the average bitrate of the encode, i.e. the number of bits per second. The filesize/bitrate should not depend on the GOP size. If it does for you, there is something wrong.
--crf tries to keep the quality constant. If you limit x264's I frame decisions to small GOP sizes by choosing a low value for --keyint the compression will become worse, i.e. you will need more bitrate(->bigger filesize) to achieve the same quality.

As others have mentioned: don't use --no-scenecut or --min-keyint unless you really really know what you are doing.

Only touch --keyint if either:
- it is dictated by your target format specification (e.g. Blu-Ray) or
- you want to reduce seeking time. It would also be legal to do so for the purpose you asked in question #2 of your start post, i.e. allow faster recovery after a transmission error.
As said above, lower --keyint means worse compression, so handle it with care.

About legal values for min-keyint: It cannot exceed --keyint/2+1 ever, so --keyint/--min-keyint 25/25 is not really possible. x264 will silently reduce --min-keyint if you try something like that.

shagun
17th March 2015, 11:33
Hello OP, Can you please tell me step to configure Megui. I want the same setting for my video files. I try to encode but my mediainfo is completely different than your.

benwaggoner
17th March 2015, 19:19
If you actually want a fixed GOP, then set --keyint, and use --no-scenecut. This will turn off scene cut detection, and simply use a 25 frame GOP in your example. x264 will still adaptively choose between P and B frames in this case.
It'll also insert non-IDR I-frames mid GOP when appropriate as well.