Skip to main content
Version: v5.9.0

GOP Structure and Customization

Quadra supports three ways to set the gop patterns. The first method is the default method, where gopPresetIdx = -1 or is not set. By default, encoder uses Adaptive Gop, for which the encoder dynamically adjusts gop pattern while encoding. The second method is setting custom gop structures via xcoder-gop parameters, where gopPresetIdx must be set to 0. The third method is the preset gop structure, where gopPresetIdx can be set from 1 to 10.

Now we introduce the custom gop structure and the predefined gop structures in detail. Some commonly used gop patterns are shown below as examples.

note

Quadra generates all I‑frames as IDR frames that include the relevant headers/parameter sets where defined (H.264: SPS/PPS; H.265: VPS/SPS/PPS, AV1: key frames with sequence header OBU).

Custom Gop Structure​

The following table lists the custom gop parameters, xcoder-gop.

note

The order of the custom GOP parameters does not matter. E.g. g2numRefPics can be placed before g0numRefPics

Quadra Custom Gop Parameters (xcoder-gop)

ParameterValuesDescription
customGopSize1 to 8Specifies size of custom GOP pattern.
note

in following frame parameters, prefix g0 means this setting corresponds to the 1st frame in the gop structure, g1 corresponds to the 2nd frame in gop structure, and so on

note

Number of frames in gop structure (e.g. g0, g1, …) must match customGopSize

Frame Parameters​

ParameterValuesDescription
g0pocOffset1 to gop sizePOC (display order) of the frame within a GOP, ranging from 1 to gop size
g0QpOffset-51 to 51Delta QP, will be added to the frame QP to set the final QP
g0temporalId0 to highest temporal layer in the goptemporal layer ID
g0picType1: P frame

2: B frame
Frame type, can be either P or B frame
g0numRefPics1 to gop sizeNumber of reference pictures kept for this frame, including references for current and future pictures.

NOTE - in the following Reference List parameters, prefix g0refPic0 means the setting corresponds to 1st reference frame, g0refPic1 corresponds to 2nd reference frame, and so on

NOTE – if a reference frame will be referenced by future frame(s) but is not referenced by the current frame, it would need to be included in current frame reference list as well.

For example, in hierarchical-P GOP pattern (see Custom GOP Example 3), Frame 3 only references Frame 2, but its reference list must also include Frame 0 for Frame 4 to reference; therefore g2numRefPics=2

NOTE - Number of Reference List parameters must match g0numRefPics

NOTE - The maximum number of reference frames referenced by the current picture is 2

Reference List parameters​

ParameterValuesDescription
g0refPic0- (gop size) to gop size


0 is not allowed
Delta POC of the reference picture, relative to the POC of the current frame
NOTE - g0refPic0 cannot be 0, since a picture cannot refer to itself

NOTE – the index of reference frames (E.g. g0refPic0, g0refPic1, etc.) in the reference list must follow order described below

1. Forward references (past) must precede Backward references (future)
2. Forward references (past) must be in poc order High to Low
3. Backward references (future) must be in poc order Low to High

The purpose is to assign lower indices to reference frames closet to the current frame in display order, because these are the reference frames which are most often used for reference, and lower reference index helps to reduce bit count

For example, in hierarchical-P GOP pattern (see Custom GOP Example 3), Frame 3 reference list must assign index 0 (g2refPic0) to Frame 2 (g2refPic0=-1), and assign index 1 (g2refPic1) to Frame 0 (g2refPic1=-3)
g0refPic0Used0: Not referenced by current frame

1: Referenced by current frame
Specifies whether each reference frame in reference list is used in current (1) or future (0)

Custom GOP Example 1 (GOP size 2, low delay):​

A black background with white rectangles Description automatically generated

ffmpeg -y -f rawvideo -pix_fmt yuv420p -s:v 1440x1080 -r 24 -i input1440x1080.yuv -c:v h264_ni_quadra_enc -vframes 50 -xcoder-params 'profile=2:level=6:RcEnable=1:bitrate=10000000:intraPeriod=0:gopPresetIdx=0' -xcoder-gop "customGopSize=2:g0pocOffset=1:g0QpOffset=0:g0temporalId=0:g0picType=2:g0numRefPics=2:g0refPic0=-1:g0refPic0Used=1:g0refPic1=-3:g0refPic1Used=1:g1pocOffset=2:g1QpOffset=0:g1temporalId=0:g1picType=2:g1numRefPics=2:g1refPic0=-1:g1refPic0Used=1:g1refPic1=-2:g1refPic1Used=1" -enc 0 output1440x1080.h264

Custom GOP Example 2 (Hierarchical-B with GOP size 4):​

A diagram of a structure Description automatically generated

ffmpeg -y -f rawvideo -pix_fmt yuv420p -s:v 1440x1080 -r 24 -i input1440x1080.yuv -c:v h264_ni_quadra_enc -vframes 50 -xcoder-params 'profile=2:level=6:RcEnable=1:bitrate=10000000:intraPeriod=0:gopPresetIdx=0' -xcoder-gop "customGopSize=4:g0pocOffset=4:g0QpOffset=0:g0temporalId=0:g0picType=1:g0numRefPics=1:g0refPic0=-4:g0refPic0Used=1:g1pocOffset=2:g1QpOffset=0:g1temporalId=0:g1picType=2:g1numRefPics=2:g1refPic0=-2:g1refPic0Used=1:g1refPic1=2:g1refPic1Used=1:g2pocOffset=1:g2QpOffset=0:g2temporalId=0:g2picType=2:g2numRefPics=3:g2refPic0=-1:g2refPic0Used=1:g2refPic1=1:g2refPic1Used=1:g2refPic2=3:g2refPic2Used=0:g3pocOffset=3:g3QpOffset=0:g3temporalId=0:g3picType=2:g3numRefPics=2:g3refPic0=-1:g3refPic0Used=1:g3refPic1=1:g3refPic1Used=1" -enc 0 output1440x1080.h264

Custom GOP Example 3 (Hierarchical-P with GOP size 4):​

A diagram of a diagram of a structure Description automatically generated

ffmpeg -y -f rawvideo -pix_fmt yuv420p -s:v 1440x1080 -r 24 -i input1440x1080.yuv -c:v h264_ni_quadra_enc -vframes 50 -xcoder-params 'profile=2:level=6:RcEnable=1:bitrate=10000000:intraPeriod=0:gopPresetIdx=0' -xcoder-gop " customGopSize=4:g0pocOffset=1:g0QpOffset=0:g0temporalId=0:g0picType=1:g0numRefPics=1:g0refPic0=-1:g0refPic0Used=1:g1pocOffset=2:g1QpOffset=0:g1temporalId=0:g1picType=1:g1numRefPics=1:g1refPic0=-2:g1refPic0Used=1:g2pocOffset=3:g2QpOffset=0:g2temporalId=0:g2picType=1:g2numRefPics=2:g2refPic0=-1:g2refPic0Used=1:g2refPic1=-3:g2refPic1Used=0:g3pocOffset=4:g3QpOffset=0:g3temporalId=0:g3picType=1:g3numRefPics=1:g3refPic0=-4:g3refPic0Used=1" -enc 0 output1440x1080.h264

Pre-defined GOP Structure​

The gopPresetIdx are pre-configured gop patterns that fit most applications without the complexity of configuring a custom gop.

According to the different values set for the gopPresetIdx, lookAheadDepth, and enable2PassGop parameters, the gop structure can be divided into two types:

  1. 1-pass, lookaheadDepth = 0, enable2PassGop takes no effects, the gop structure is determined by gopPresetIdx.
  2. 2-pass, lookaheadDepth > 0, the gop structure is determined by gopPresetIdx and enable2PassGop.

Here are the predefined GOP structures for H.264 / H.265 / AV1.

Preset GOP Patterns for AVC / HEVC / AV1​

1-pass encode (lookaheadDepth = 0)​

note

temporal ID field only takes effects when parameter temporalLayersEnable is set to 1. When temporalLayersEnable is not specified (default 0), all frames are assigned temporal ID 0

gopPresetIdxframeTypePOCQP offsetnum of

ref
Reference Listused_by

cur
temporal ID *
-1Adaptive Gop(default)
0Custom Gop
11I110XX0
2obsolete
31B112-1 -210
41P211-210
2B132-1 11 11
51P411-410
2B232-2 21 11
3B153-1 1 31 1 02
4B352-1 11 12
6obsolete
71B152-1 -51 10
2B232-1 -21 10
3B352-1 -31 10
4B412-1 -41 10
81B812-8 -161 10
2B432-4 41 11
3B253-2 2 61 1 02
4B174-1 1 3 71 1 0 03
5B374-1 -3 1 51 0 1 03
6B653-2 -6 21 0 12
7B574-1 -5 1 31 0 1 03
8B773-1 -7 11 0 13
91P111-110
101P151-112
2P231-211
3P352-1 -31 02
4P411-410

2-pass encode (lookaheadDepth > 0 and enable2PassGop = 0)​

note

temporal ID field only takes effects when parameter temporalLayersEnable is set to 1. When temporalLayersEnable is not specified (default 0), all frames are assigned temporal ID 0

note

2-pass encode algorithm adjusts QP. Therefore, picQp may not be reflected in coded frame

gopPresetIdxframeTypePOCQP offsetnum of

ref
Reference Listused_by

cur
temporal ID *
-1Adaptive Gop(default)
0Custom Gop
1Not supported for 2-pass
2obsolete
3Not supported for 2-pass
41B212-2 -41 10
2B132-1 11 11
51B412-4 -81 10
2B232-2 21 11
3B153-1 1 31 1 02
4B353-1 -3 11 0 12
6obsolete
7Not supported for 2-pass
81B812-8 -161 10
2B432-4 41 11
3B253-2 2 61 1 02
4B174-1 1 3 71 1 0 03
5B374-1 -3 1 51 0 1 03
6B653-2 -6 21 0 12
7B574-1 -5 1 31 0 1 03
8B773-1 -7 11 0 13
91P111-110
10Not supported for 2-pass

2-pass encode (lookaheadDepth > 0 and enable2PassGop=1)​

gopPresetIdxframeTypePOCQP offsetnum of

ref
Reference Listused_by

cur
temporal ID *
-1Adaptive Gop(default)
0Custom Gop
1Not supported for 2-pass
2obsolete
3Not supported for 2-pass
41P211-210
2B132-1 11 11
51P411-410
2B232-2 21 11
3B153-1 1 31 1 02
4B352-1 11 12
6obsolete
7Not supported for 2-pass
81P811-810
2B432-4 41 11
3B253-2 2 61 1 02
4B174-1 1 3 71 1 0 03
5B373-1 1 51 1 03
6B652-2 21 12
7B573-1 1 31 1 03
8B772-1 11 13
91P111-110
10Not supported for 2-pass

Description of GOP Patterns​

The following is the gop structure for when gopPresetIdx=5, lookaheadDepth = 0 or for when gopPresetIdx = 5, lookahead > 0, enable2Pass=1.

A diagram of a diagram Description automatically generated

The four frames in this gop are described below in decoding order.

  • Frame 1 is a P frame with POC 4, referencing one frame with POC 0. The reference frame is defined by delta POC value relative to current frame. In this case it is -4.
  • Frame 2 is a B frame with POC 2, referencing two frames with POC 0 and 4 respectively. So its reference frames are listed as -2 and 2.
  • Frame 3 is a B frame with POC 1, referencing two frames with POC 0 and 2 respectively. It also needs to keep the frame with POC 4 as a reference frame to be used in future. So its reference frame list is -1, 1 and 3.
  • Frame 4 is a B frame with POC 3, referencing two frames with POC 2 and 4 respectively. Its reference list is -1 and 1.

The corresponding GOP structure table is show below, where:

  • QP Offset will be added to the QP parameter to set the final QP;
  • Used by Current Frame specifies whether each reference frame in Reference List is used in current(1) or future(0).
FrameTypePOCQP OffsetNumber of ReferencesReference Listused_by_cur
1P411-41
2B232-2 21 1
3B153-1 1 31 1 0
4B352-1 11 1

The diagrams of all gop patterns for 1 pass (lookAheadDepth=0) are shown below. P and B pictures can have one to multiple reference frames as illustrated by the arrows. The inter frame immediately after I-frame is encoded as P-frame, although it appears in the table as B-frame because only one reference frame is available:

Diagram of gopPresetIdx=1

A picture containing font, text, diagram, white Description automatically generated

Diagram of gopPresetIdx=3

A diagram of a block diagram Description automatically generated

Diagram of gopPresetIdx=4

A diagram of a diagram Description automatically generated

Diagram of gopPresetIdx=5

A diagram of a network Description automatically generated

Diagram of gopPresetIdx=7

A diagram of a flowchart Description automatically generated

Diagram of gopPresetIdx=8

A diagram of a diagram Description automatically generated

Diagram of gopPresetIdx=9

A diagram of a flowchart Description automatically generated

Note that frame number count is relative to adjacent frames. For example, in the gopPresetIdx=9 diagram above, if the user sees encoding order frame number 2 as frame 0, the adjacent frame numbers should change accordingly. The following diagram shows the case when the user sees encoding order frame number 2 as 0 in the diagram above. This helps to better interpret the indexes on the table.

A diagram of a block diagram Description automatically generated

Diagram of gopPresetIdx=10

A diagram of a diagram Description automatically generated

The diagrams of gop patterns for 2 pass (2-pass & enable2PassGop=0) are shown below:

Diagram of gopPresetIdx=4 for 2 pass

A diagram of a diagram Description automatically generated

Diagram of gopPresetIdx=5 for 2 pass

A diagram of a diagram Description automatically generated

Diagram of gopPresetIdx=8 for 2 pass

A diagram of a network Description automatically generated