Setting the Group of Pictures (GOP) Structure
When defining encoding parameters for long GOP codecs that use i
, b
, and p
frames you may wish to specify what your GOP looks like. There are a few parameters in Hybrik’s video
object that may be used to achieve a specific GOP structure.
Common Controls
Setting a Regular GOP
More details can be found for each of these settings on our Video API page:
idr_interval
- This is the easiest way to control your GOP interval. By specifying one or more of the following you can tell the encoder at what frequency you want to insert an IDR frame:
frames
- Set an IDR frame exactly every N frames
seconds
- Set an IDR frame exactly every N seconds
min_sec
- Set an IDR frame at least every N seconds, defining the minimum number of seconds per GOP (can be combined with
max_sec
)
- Set an IDR frame at least every N seconds, defining the minimum number of seconds per GOP (can be combined with
max_sec
- Set an IDR frame at most every N seconds, defining the maximum number of seconds per GOP (can be combined with
min_sec
)
- Set an IDR frame at most every N seconds, defining the maximum number of seconds per GOP (can be combined with
min_frames
- Set an IDR frame at least every N frames, defining the minimum number of frames per GOP (can be combined with
max_frames
)
- Set an IDR frame at least every N frames, defining the minimum number of frames per GOP (can be combined with
max_frames
- Set an IDR frame at most every N frames, defining the maximum number of frames per GOP (can be combined with
min_frames
)
- Set an IDR frame at most every N frames, defining the maximum number of frames per GOP (can be combined with
- This is the easiest way to control your GOP interval. By specifying one or more of the following you can tell the encoder at what frequency you want to insert an IDR frame:
Forcing Specific Keyframes
forced_keyframes
- Forced keyframes provides a way to insert i/idr frames in specific places. This can be useful for Digital Ad Insertion (DAI). You can insert frames in specific locations using the following options:
- Note: Forced Keyframes requires a minimum
encoder_version
ofhybrik_3.4_8bit
frames
- Specify an array of frame numbers for key frame insertion
times_sec
- Specify an array of times in seconds for key frame insertions
timecodes
- Specify an array of timecodes for key frame insertions
Other GOP Controls
use_scene_detection
- Scene detection gives the codec some agency to insert IDR frames when it detects significant differences. This can be used in combination with
forced_keyframes
andidr_interval
.
- Scene detection gives the codec some agency to insert IDR frames when it detects significant differences. This can be used in combination with
max_bframes
- This controls the maximum number of B frames that occur between I and P frames
refs
- This controls how many decoded frames a single frame may refer to for each macroblock
use_closed_gop
- This tells the encoder not to go beyond the bounds of the current GOP for any reference frames
Example Usage
Inside of a video
element of our transcode
task, we can specify the above paramters. Here are a few simple examples, all contained within the sample job a the bottom of this page.
Every 2 Seconds
"video": {
"codec": "h264",
"width": 1280,
"height": 720,
"bitrate_kb": 1000,
"use_scene_detection": false,
"idr_interval": {
"seconds": 2
}
},
With a 24fps source, the resulting GOP will have a regular interval every 48 frames as seen here (visuals courtesy of Switch player):
Every 12 Frames
"video": {
"codec": "h264",
"width": 1280,
"height": 720,
"bitrate_kb": 1000,
"use_scene_detection": false,
"idr_interval": {
"frames": 12
}
},
With a 24fps source, the resulting GOP will have a regular interval every 12 frames as seen here (visuals courtesy of Switch player):
Every 4 Seconds with Scene Detection
"video": {
"codec": "h264",
"width": 1280,
"height": 720,
"bitrate_kb": 1000,
"use_scene_detection": true,
"idr_interval": {
"seconds": 4
}
},
With a 24fps source, the resulting GOP will have a regular interval every 96 frames and additional frames inserted by scene change detection as seen here (visuals courtesy of Switch player):
Forced Keyframes
This job inserts keyframes at frames 8, 12, 16, and 24. This is not a practical example but demonstrates the usefulness when you need to insert keyframes at exact points.
"video": {
"codec": "h264",
"width": 1280,
"height": 720,
"bitrate_kb": 1000,
"use_scene_detection": true,
"forced_keyframes": {
"frames": [
8,
12,
16,
24
]
}
},
The resulting GOP will have keyframes at frames 8, 12, 16, and 24 as seen here (visuals courtesy of Switch player):
Example
- This is an example job with several GOP manipulations