As shown in the following code, when I use the following code to access the video (whether it is rtsp or mp4), the imshow display is always a black screen, and I try to output the frame, but I can only get a bunch of 0. But I can use the following pipeline normally inside the command line. In addition, opencv’s support for gstreamer is also yes。
int main(int argc, char *argv[]) {
using namespace cv;
using namespace std;
gst_init(&argc, &argv);
// const string gst_in = "rtspsrc location=rtsp://admin:fgfg5678@192.168.10.66:554/h264/ch1/main/av_stream latency=0 ! decodebin ! videoconvert ! appsink";
const string gst_in="filesrc location=test.mp4 ! decodebin ! videoconvert ! appsink sync=false";
VideoCapture cap(gst_in, cv::CAP_GSTREAMER);
if(!cap.isOpened())
{
cout << "error to open camera." << endl;
return -1;
}
namedWindow("Received Frame",WINDOW_NORMAL);
Mat frame ;
// 逐帧显示
while(cap.read(frame))
{
imshow("Received Frame", frame);
if (waitKey(10) == 27) // Esc key to exit
break;
}
cap.release();
return 0;
}
filesrc location=test.mp4 ! decodebin ! videoconvert ! autovideosink
I don’t know where the problem is, the version I use is as follows:
opencv:4.8.0
gstreamer:1.16.2