Can't construct proper pipeline for gstreamer backend and videowriter with x265enc encoder

Hi guys,

So I have a working example how to encode my frames into h264:

std::string gst_out = "appsrc ! videoconvert ! x264enc ! filesink location=videotestsrc.mp4 ";
cv::VideoWriter video_writer(gst_out, cv::CAP_GSTREAMER, 0, video_capture.get(cv::VideoCaptureProperties::CAP_PROP_FPS), S, true);

I would like to switch to x265enc and I’ve tried multiple different pipelines but most of the time I am getting this error:

[ WARN:0@1.762] global /home/opencv/modules/videoio/src/cap_gstreamer.cpp (2401) handleMessage OpenCV | GStreamer warning: Embedded video playback halted; module x265enc0 reported: Encode x265 failed.
[DEBUG:0@1.762] global /home/opencv/modules/videoio/src/cap_gstreamer.cpp (2403) handleMessage GStreamer debug: gstx265enc.c(800): gst_x265_enc_set_level_tier_and_profile (): /GstPipeline:pipeline0/GstX265Enc:x265enc0:
Failed to find correct level, tier or profile in VPS

Here I’ve found such information:

“May abort the encode if the specified profile is impossible to be supported by the compile options chosen for the encoder (a high bit depth encoder will be unable to output bitstreams compliant with Main or MainStillPicture).”

Maybe this is my case, but how to deal with it?