运行下面这段代码
#include <gst/gst.h>
#include <opencv2/opencv.hpp>
#include <iostream>
#include <chrono>
using namespace std;
int main(int argc, char *argv[]) {
std::stringstream ss;
std::string rtsp_url = "rtsp://admin:fgfg5678@192.168.10.66:554/h264/ch1/main/av_stream";
size_t latency = 200;
size_t frame_width = 1920;
size_t frame_height = 1080;
size_t framerate = 15;
typedef std::chrono::milliseconds milliseconds_type;
// rtsp视频流
ss << "rtspsrc location=" << rtsp_url << " latency ! rtph264depay ! decodebin ! videoconvert ! video/x-raw,format=(string)BGR ! appsink drop=true";
// mp4视频流
// ss << "filesrc location=" << rtsp_url << " ! decodebin ! videoconvert ! video/x-raw,format=(string)BGR ! appsink drop=true caps=video/x-raw,format=BGR";
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 ;
chrono::steady_clock::time_point start = chrono::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 % framerate == 0)
{
chrono::steady_clock::time_point end = chrono::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;
}
出现问题
rtspsrc location=rtsp://admin:fgfg5678@192.168.10.66:554/h264/ch1/main/av_stream latency ! rtph264depay ! decodebin ! videoconvert ! video/x-raw,format=(string)BGR ! appsink drop=true
[ WARN:0@2.293] global cap_gstreamer.cpp:2784 handleMessage OpenCV | GStreamer warning: Embedded video playback halted; module udpsrc4 reported: Internal data stream error.
[ WARN:0@2.316] global cap_gstreamer.cpp:1679 open OpenCV | GStreamer warning: unable to start pipeline
[ WARN:0@2.316] global cap_gstreamer.cpp:1164 isPipelinePlaying OpenCV | GStreamer warning: GStreamer: pipeline have not been created
[ WARN:0@2.316] global cap.cpp:204 open VIDEOIO(GSTREAMER): backend is generally available but can't be used to capture by name
error to open camera.
各位知道是什么原因吗?
从报错信息看 问题可能出在GStreamer的rtspsrc和udpsrc4模块
由于缺乏具体的代码和上下文环境,无法确定使用的操作系统和编译器。同时也无法确定是否尝试过其他网络摄像头或本地摄像头,以及具体的代码和调用摄像头的方式。需要更多的信息才能给出具体的解决方案。