最近使用网络摄像机做人脸检测、识别;在Ubuntu14.04下用opencv播放1029*1080P的rtsp视频流会出现画面卡顿、花屏;为确定时接收时问题还是sdl显示问题,将接收的视频码流直接保存到视频文件里,再播放查看。
OpenCV3中保存视频文件用的是VideoWriter,一下代码保存10分钟视频;
#include <opencv2/opencv.hpp>
#include <iostream>
#include <stdio.h>
#include <sys/time.h>
using namespace cv;
using namespace std;
int main(int, char**)
{
Mat src;
// use default camera as video source
VideoCapture cap("rtsp://admin:ijx967111@192.168.5.11/h264/ch1/main/av_stream");
// check if we succeeded
if (!cap.isOpened()) {
cerr << "ERROR! Unable to open camera\n";
return -1;
}
// get one frame from camera to know frame size and type
cap >> src;
// check if we succeeded
if (src.empty()) {