Gstreamer nvh264enc ref frames tweaking, issue with decoding video after input selector switch

Hello,

I’ve got an issue with nvh264enc setup - basically it encodes videotestsrc with pattern black, which is connected to input-selector, at the beginning it works fine, but after first switch to another source - decoder fails or outputs corrupted frames, never recovering.

decoder outputs errors like this

0:00:35.708987797     8 0x7f3b00002120 WARN       codecparsers_h264 gsth264parser.c:727:gst_h264_slice_parse_dec_ref_pic_marking: value for 'mem_mgmt_ctrl_op' greater than max. value: 573, max 6
0:00:35.709002179     8 0x7f3b00002120 WARN       codecparsers_h264 gsth264parser.c:763:gst_h264_slice_parse_dec_ref_pic_marking: error parsing "Decoded reference picture marking"
0:00:35.709007053     8 0x7f3b00002120 WARN       codecparsers_h264 gsth264parser.c:2399:gst_h264_parser_parse_slice_hdr: error parsing "Slice header"
0:00:35.743621442     8      0x3430c00 WARN       codecparsers_h264 gsth264parser.c:662:slice_parse_ref_pic_list_modification_1: value for 'entries[i].value.abs_diff_pic_num_minus1' greater than max. value: 25, max 15
0:00:35.743655712     8      0x3430c00 WARN       codecparsers_h264 gsth264parser.c:681:slice_parse_ref_pic_list_modification_1: error parsing "Reference picture list 0 modification"
0:00:35.743665840     8      0x3430c00 WARN       codecparsers_h264 gsth264parser.c:2399:gst_h264_parser_parse_slice_hdr: error parsing "Slice header"
0:00:35.743700898     8 0x7f3b00002120 WARN       codecparsers_h264 gsth264parser.c:2366:gst_h264_parser_parse_slice_hdr: value for 'slice->slice_qp_delta' not in allowed range. value: -143, range -87-77
0:00:35.743723181     8 0x7f3b00002120 WARN       codecparsers_h264 gsth264parser.c:2399:gst_h264_parser_parse_slice_hdr: error parsing "Slice header"

Here’s basic setup I’ve got (bitrate and vbv depends on picked resolution)
nvh264enc bitrate={bitrate} rc-mode=cbr gop-size=60 vbv-buffer-size={vbv}
I’ve tried using presets like high quality, lossless etc. but it doesn’t change much, I mentioned that with HQ preset it’s more likely to output corrupted frames, rather than totally discard them…
Switching to cpu x264enc solves issue tweaking to superfast and 4 ref frames.
I didn’t find the way to set amount of ref frames for nvh264enc.
Thanks for Your help in advance!