我尝试使用OpenCV 2.4.8
从IP-camera读取RTSP h.264流:
#include <opencv2/opencv.hpp>
int main()
{
cv::VideoCapture capture("rtsp://admin:@192.168.1.168:80/ch0_0.264");
if(!capture.isOpened())
{
std::cout << "Error opening video stream" << std::endl;
return -1;
}
cv::Mat frame;
cv::namedWindow("Frame");
int i = 0;
while (true)
{
if(capture.read(frame))
{
std::cout << ++i << std::endl;
cv::imshow("Frame", frame);
if (cv::waitKey(1) >= 0)
break;
}
else
{
std::cout << "No frame" << std::endl;
}
}
}
首先捕获了670-700帧(流的25-30秒),但是进一步capture.read(frame)
总是返回false
(未抓取的帧)。如何解决这个问题?