OpenCV获取MJGP-Streamer视频流处理方法并保存至本地

//#include "opencv\stdafx.h"
#include "opencv\cv.h"
#include "opencv\highgui.h"




int main(int argc, char** argv)
{
CvCapture* capture = cvCaptureFromFile("http://172.20.10.8:8080/?action=stream?dummy=param.mjpg");
IplImage* frame = cvQueryFrame(capture);
cvNamedWindow("Monitor");
//while (frame = cvQueryFrame(capture))
//{
// cvShowImage("Monitor", frame);
//cvWaitKey(33);
//}
//选择视频流格式
cvSetCaptureProperty(capture, CV_CAP_PROP_FOURCC, CV_FOURCC('M', 'J', 'P', 'G'));
//设置视频帧宽高;
//cvSetCaptureProperty(capture, CV_CAP_PROP_FRAME_WIDTH, 1280);
//cvSetCaptureProperty(capture, CV_CAP_PROP_FRAME_HEIGHT, 720);
//保存
char* writePath = "F:\\新建文件夹 (2)\\OPENCV\\录像视频\\000.avi";
CvVideoWriter* writer = cvCreateVideoWriter(
writePath,
CV_FOURCC('D', 'I', 'V', 'X'),
24,
//cvSize(1280, 720)
cvGetSize(frame)
);
while (1) {
frame = cvQueryFrame(capture);
cvShowImage("Monitor", frame);
if (!frame) break;


cvWriteFrame(writer, frame);


char c = cvWaitKey(1000 / 24);
if (c == 27) break;
}
//释放
cvReleaseVideoWriter(&writer);
cvReleaseCapture(&capture);
cvDestroyAllWindows();
return 0;
}

你可能感兴趣的:(OpenCV获取MJGP-Streamer视频流处理方法并保存至本地)