Unable to open gstreamer pipeline using opencv VideoCapture on Jetson Xavier

I am trying to send the video through opencv.
But, I cannot open gstreamer pipleline.

The opencv version is 3.3.1

This is my code.

cv::VideoCapture cap("/home/nvidia/Desktop/Video16.mp4");

cv::VideoWriter out;
out.open(“appsrc ! queue ! videoconvert ! autovideosink ! video/x-raw,format=I420,width=640,height=480,framerate=30/1 ! jpegenc ! rtpjpegpay ! udpsink host=127.0.0.1 port=5000”,cv::CAP_GSTREAMER,0,30,cv::Size(640,480),true);

if(!cap.isOpened()){
std::cout<<“can not capture video”<<std::endl;
exit(-1);
}

if(!out.isOpened()){
std::cout<<“sender is not opened”<<std::endl;
std::cout<<out.isOpened()<<std::endl;
exit(-1);
}

why do you send it through opencv?
I would send it through the test-launch and receive it in opencv[cpp/python], as in the referenced thread.
Regards,
Andrei
Reference:https://devtalk.nvidia.com/default/topic/1042892/jetson-agx-xavier/nvarguscamerasrc-opencv-solved-/

you may try:

#include <stdio.h>
#include <opencv2/opencv.hpp>

using namespace cv;
using namespace std;

int main(int argc, char** argv)
{
VideoCapture cap("rtspsrc location=rtsp://184.72.239.149/vod/mp4:BigBuckBunny_115k.mov  latency=30 ! decodebin ! nvvidconv ! appsink");

 if (!cap.isOpened())
    {
      cout << "Failed to open camera." << endl;
      return -1;
    }

  for(;;)
    {
      Mat frame;
      cap >> frame;
      Mat bgr;
      cvtColor(frame, bgr, COLOR_YUV2BGR_NV12);
      imshow("original", bgr);
      waitKey(1);
    }

  cap.release();
g++ -o simple_opencv -Wall -std=c++11 simple_opencv.cpp $(pkg-config --libs opencv)

The problem may be that you are using autovideosink in your pipeline, but it has no SRC (output) capabilities. You may remove it from your pipeline, or use tee if you need to keep this display.