This repository has been archived on 2021-03-01. You can view files and clone it, but cannot push or open issues or pull requests.
prpa/src/main.cc
Delalande Ivan cbc9a7a686 Implemented a video reader and writer with OpenCV.
The program now works as a video cat or converter :
./prpa -c MP42 -o /tmp/bar.avi /tmp/foo.flv
-c specify a 4-letter codec to be used for the output file and follow a strict
code defined on this page : http://www.fourcc.org/codecs.php
The file output extension *does* matter and must match the selected output
codec.
2012-07-12 10:42:38 +02:00

73 lines
1.9 KiB
C++

#include <iostream>
#include <boost/program_options.hpp>
#include "encoder/video.hh"
#include "encoder/video_reader.hh"
#include "encoder/video_writer.hh"
int
main (int argc, char** argv)
{
namespace po = boost::program_options;
// Register all possible options
po::options_description desc("Allowed options");
desc.add_options()
("help,h", "produce help message")
("filter,f", po::value<std::vector<std::string> > (), "apply a filter")
("input-file,i", po::value<std::vector<std::string> > (), "file to treat")
("output,o", po::value<std::vector<std::string> > (), "output file")
("codec,c", po::value<std::vector<std::string> > (), "output codec")
;
// Handle ./prpa file.avi instead of ./prpa --input-file=file.avi
po::positional_options_description p;
p.add("input-file", -1);
// Read command line
po::variables_map vm;
try
{
po::store(po::command_line_parser(argc, argv).
options(desc).positional(p).run(), vm);
}
catch (po::invalid_command_line_syntax e)
{
std::cerr << argv[0] << ": " << e.what() << std::endl;
return 1;
}
po::notify(vm);
// Handle -h and --help
if (argc <= 1 || vm.count("help"))
{
std::cout << desc << "\n";
return 1;
}
// GO!
std::cout << "Given filters: ";
if (vm.count("filter"))
std::cout << vm["filter"].as<std::vector<std::string> > ().size()
<< std::endl;
else
std::cout << 0 << std::endl;
std::cout << "Given files: ";
if (vm.count("input-file"))
std::cout << vm["input-file"].as<std::vector<std::string> > ().size()
<< std::endl;
else
std::cout << 0 << std::endl;
VideoReader vr(vm["input-file"].as<std::vector<std::string> >()[0]);
VideoWriter vw = VideoWriter();
vw.open(vm["output"].as<std::vector<std::string> >()[0],
vm["codec"].as<std::vector<std::string> >()[0],
vr.fps_get(), vr.width_get(), vr.height_get());
vw.copy(vr);
vw.write();
return 0;
}