I am using opencv with gstreamer,to get a rtsp input.
error:
while trying to get the rtsp it occurs that:
(test:107702): GStreamer-CRITICAL **: 18:15:47.076: gst_caps_get_structure: assertion ‘GST_IS_CAPS (caps)’ failed
(test:107702): GStreamer-CRITICAL **: 18:15:47.076: gst_structure_get_int: assertion ‘structure != NULL’ failed
[ WARN:0@30.178] global cap_gstreamer.cpp:1714 open OpenCV | GStreamer warning: cannot query video width/height
(test:107702): GStreamer-CRITICAL **: 18:15:47.076: gst_structure_get_fraction: assertion ‘structure != NULL’ failed
while trying to get frame,it occurs that:
(test:107702): GStreamer-CRITICAL **: 18:19:02.078: gst_sample_get_caps: assertion ‘GST_IS_SAMPLE (sample)’ failed
[ERROR:0@225.181] global cap_gstreamer.cpp:934 retrieveVideoFrame GStreamer: gst_sample_get_caps() returns NULL
my code:
#include <opencv2/opencv.hpp>
#include <iostream>
#include <chrono>
int main()
{
using std::chrono::steady_clock;
typedef std::chrono::milliseconds milliseconds_type;
const int interval = 15;
std::stringstream ss;
std::string rtsp_url = "rtsp://admin:qk123456@192.168.1.100";
size_t latency = 200;
size_t frame_width = 1920;
size_t frame_height = 1080;
size_t framerate = 20;
ss << "rtspsrc location=" << rtsp_url << " latency=" << latency << " ! application/x-rtp, media=video, encoding-name=H264 "
<< "! rtph264depay ! video/x-h264, clock-rate=90000, width=" << frame_width << ", height=" << frame_height << ", framerate="
<< framerate << "/1 ! nvv4l2decoder ! video/x-raw(memory:NVMM), width=" << frame_width << ", height=" << frame_height
<< ", framerate=" << framerate << "/1 ! nvvideoconvert ! video/x-raw, format=BGRx ! videoconvert ! video/x-raw, format=BGR ! appsink";
std::cout << ss.str() << std::endl;
cv::VideoCapture cap = cv::VideoCapture(ss.str(), cv::CAP_GSTREAMER);
if(!cap.isOpened())
{
std::cerr << "error to open camera." << std::endl;
return -1;
}
std::cout << cv::getBuildInformation() << std::endl;
cv::Mat frame ;
steady_clock::time_point start = steady_clock::now();
size_t frame_idx = 0;
while(1)
{
bool ret = cap.read(frame);
if(ret)
{
// cv::imwrite("tmp.jpg", frame);
++frame_idx;
}
if(frame_idx % interval == 0)
{
steady_clock::time_point end = steady_clock::now();
milliseconds_type span = std::chrono::duration_cast<milliseconds_type>(end - start) ;
std::cout << "it took " << span.count() / frame_idx << " millisencods." << std::endl;
start = end;
}
}
return 0;
}
all the index are correct, I can normally use it in another device(jetson nano)
this to device have same environments:
opencv4.8.0
gstreamer2.16.3
jetpack5.1.1
waiting for you reply!