Opencv gstreamer

My input is
My Input is
grayframe = Mat(H,W, CV_8UC1,p_buff);
I want to create cv:writer to encode it with h265
It didn’t work for me

sprintf(buff,"appsrc ! video/x-raw, format=(string)GRAY8,width=(int)704, height=(int)540 "
"! nvvidconv ! video/x-raw(memory:NVMM), width=(int)704, height=(int)540,format=(string)I420 "
“! nvvidconv ! video/x-raw(memory:NVMM) ! omxh265enc control-rate=2 bitrate=2000000 ! h265parse”
“! mpegtsmux ! udpsink host=%s port=%d”
,sdest_ip.c_str(),pmux->port);

    writer.open(buff
                , 0, (double)18, cv::Size(704, 540), true);
    if (!writer.isOpened()) {
        printf("=ERR= can't create video writer\n");
        return 0;
    }

hi,
We are deprecating omx plugins. Suggest you try nvv4l2h265enc. I can get a valid file in running the command:

$ gst-launch-1.0 videotestsrc num-buffers=300 ! video/x-raw,format=GRAY8 ! nvvidconv ! nvv4l2h265enc ! h265parse ! qtmux ! filesink location=a.mp4

FYR. You may check if your pipeline can be run in gst-launch-1.0 command.