The encoder can adapt the number of B-frames used in the GOP pattern based on heuristics on the video content. To enable this, specify the maximum number of B-frames that can be used in a GOP and set the GOP mode to adaptive. The encoder does not go higher than the maximum number of B frames that is set.
Using ctrlsw-encoder set GopCtrlMode=ADAPTIVE_GOP in the encoder configuration file.
[GOP]
GopCtrlMode = ADAPTIVE_GOP
When using GStreamer, set property gop-mode=adaptive.
gst-launch-1.0 filesrc location=in.yuv ! rawvideoparse format=nv12 width=1280 height=720 framerate=30/1 ! omxh265enc b-frames=4 gop-mode=adaptive ! filesink location=out.hevc