An example using VideoCapture and VideoWriter class
#include <iostream>
#include <stdio.h>
{
Mat src;
VideoCapture cap(0);
if (!cap.isOpened()) {
cerr << "ERROR! Unable to open camera\n";
return -1;
}
cap >> src;
if (src.empty()) {
cerr << "ERROR! blank frame grabbed\n";
return -1;
}
bool isColor = (src.type() ==
CV_8UC3);
VideoWriter writer;
int codec = VideoWriter::fourcc('M', 'J', 'P', 'G');
double fps = 25.0;
string filename = "./live.avi";
writer.open(filename, codec, fps, src.size(), isColor);
if (!writer.isOpened()) {
cerr << "Could not open the output video file for write\n";
return -1;
}
cout << "Writing videofile: " << filename << endl
<< "Press any key to terminate" << endl;
for (;;)
{
if (!cap.read(src)) {
cerr << "ERROR! blank frame grabbed\n";
break;
}
writer.write(src);
break;
}
return 0;
}
#define CV_8UC3
Definition: core/include/opencv2/core/hal/interface.h:90
void imshow(const String &winname, InputArray mat)
Displays an image in the specified window.
int waitKey(int delay=0)
Waits for a pressed key.
int main(int argc, char *argv[])
Definition: highgui_qt.cpp:3
Definition: core/include/opencv2/core.hpp:107