An example using VideoCapture and VideoWriter class
#include <iostream>
#include <stdio.h>
using namespace std;
{
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;
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;
}
static int fourcc(char c1, char c2, char c3, char c4)
Concatenates 4 chars to a fourcc code.
#define CV_8UC3
Definition: 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: affine.hpp:52