#include <iostream>
#include <string>
static void help()
{
cout
<< "------------------------------------------------------------------------------" << endl
<< "This program shows how to write video files." << endl
<< "You can extract the R or G or B color channel of the input video." << endl
<< "Usage:" << endl
<< "./video-write <input_video_name> [ R | G | B] [Y | N]" << endl
<< "------------------------------------------------------------------------------" << endl
<< endl;
}
int main(
int argc,
char *argv[])
{
help();
if (argc != 4)
{
cout << "Not enough parameters" << endl;
return -1;
}
const string source = argv[1];
const bool askOutputType = argv[3][0] =='Y';
if (!inputVideo.isOpened())
{
cout << "Could not open the input video: " << source << endl;
return -1;
}
string::size_type pAt = source.find_last_of('.');
const string NAME = source.substr(0, pAt) + argv[2][0] + ".avi";
int ex = static_cast<int>(inputVideo.get(CAP_PROP_FOURCC));
char EXT[] = {(char)(ex & 0XFF) , (char)((ex & 0XFF00) >> 8),(char)((ex & 0XFF0000) >> 16),(char)((ex & 0XFF000000) >> 24), 0};
Size S =
Size((
int) inputVideo.get(CAP_PROP_FRAME_WIDTH),
(int) inputVideo.get(CAP_PROP_FRAME_HEIGHT));
if (askOutputType)
outputVideo.
open(NAME, ex=-1, inputVideo.get(CAP_PROP_FPS), S,
true);
else
outputVideo.
open(NAME, ex, inputVideo.get(CAP_PROP_FPS), S,
true);
{
cout << "Could not open the output video for write: " << source << endl;
return -1;
}
cout <<
"Input frame resolution: Width=" << S.
width <<
" Height=" << S.
height
<< " of nr#: " << inputVideo.get(CAP_PROP_FRAME_COUNT) << endl;
cout << "Input codec type: " << EXT << endl;
int channel = 2;
switch(argv[2][0])
{
case 'R' : channel = 2; break;
case 'G' : channel = 1; break;
case 'B' : channel = 0; break;
}
vector<Mat> spl;
for(;;)
{
inputVideo >> src;
if (src.empty()) break;
for (int i =0; i < 3; ++i)
if (i != channel)
spl[i] = Mat::zeros(S, spl[0].type());
outputVideo << res;
}
cout << "Finished writing" << endl;
return 0;
}
n-dimensional dense array class
Definition mat.hpp:951
Template class for specifying the size of an image or rectangle.
Definition types.hpp:338
_Tp height
the height
Definition types.hpp:366
_Tp width
the width
Definition types.hpp:365
Class for video capturing from video files, image sequences or cameras.
Definition videoio.hpp:727
Video writer class.
Definition videoio.hpp:994
virtual bool open(const String &filename, int fourcc, double fps, Size frameSize, bool isColor=true)
Initializes or reinitializes video writer.
virtual bool isOpened() const
Returns true if video writer has been successfully initialized.
void split(const Mat &src, Mat *mvbegin)
Divides a multi-channel array into several single-channel arrays.
void merge(const Mat *mv, size_t count, OutputArray dst)
Creates one multi-channel array out of several single-channel ones.
int main(int argc, char *argv[])
Definition highgui_qt.cpp:3