Skip to main content
Version: v5.9.0

IDR Frame Forcing

The QUADRA encoder supports forcing IDR frames at any point. Forcing an IDR is useful for several reasons:

  • When doing commercial substitution, an I-frame is required in the bitstream upon returning from the commercial. This frame will likely not coincide with the intra period and so a forced IDR frame can be used.
  • Another application is to force IDRs in the transcoded bitstream at the same period as in the input bitstream.

FFmpeg supports the forcing of IDRs using the -force_key_frames parameter. This parameter can accept a list of frame numbers or times for forcing. It also supports regular expressions in the form of -force_key_frames ‘expr:gte(t,n_forced*REFRESH_PERIOD)’ where REFRESH_PERIOD is the refresh period in seconds (ex. 1,2,etc). The period can also be specified in frames using -force_key_frames ‘expr:gte(n,n_forced*REFRESH_FRAMES)’ where REFRESH_FRAMES is the refresh period in frames.

note

These forced IDR frames are generated in addition to any generated by a non-zero intraPeriod parameter.

An example FFmpeg command line to encode a 1920x1080 YUV420 video to H.265 and force IDR pictures every 2 seconds (-force_key_frames). The intraPeriod parameter is set to zero so that the only I frames are the forced ones:

ffmpeg -f rawvideo -pix_fmt yuv420p -s:v 1920x1080 -r 30 -i input.yuv -force_key_frames ‘expr:gte(t,n_forced*2)’ -c:v h265_ni_quadra_enc -xcoder-params “intraPeriod=0:RcEnable=1:bitrate=7500000” output.265

The force_key_frames parameter can also be used while transcoding to force IDR I-frames at the same positions as in the source file as shown in the following example:

ffmpeg -c:v h264_ni_quadra_dec -i input.264 -force_key_frames source -c:v h265_ni_quadra_enc -xcoder-params “intraPeriod=0:RcEnable=1:bitrate=7500000” output.265

To force the insertion of IDR I-frames at the locations of both IDR and non-IDR I-frames, use the enableFollowIFrame decoder parameter, as described in Section 9.1.

See the FFmpeg documentation for more information on the –force_key_frames parameter.