2012-07-09 05:29:17 +00:00
|
|
|
#include <iostream>
|
|
|
|
#include <boost/program_options.hpp>
|
2012-07-12 09:36:34 +00:00
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
2012-07-12 17:50:16 +00:00
|
|
|
#include "tbb/task_scheduler_init.h"
|
2012-07-12 09:36:34 +00:00
|
|
|
|
|
|
|
#include "configuration.hh"
|
2012-07-12 17:50:16 +00:00
|
|
|
#include "pipeline.hh"
|
2012-07-09 05:29:17 +00:00
|
|
|
|
2012-07-12 08:42:38 +00:00
|
|
|
#include "encoder/video_reader.hh"
|
|
|
|
#include "encoder/video_writer.hh"
|
|
|
|
|
2012-07-12 09:36:34 +00:00
|
|
|
bool parse_cli(Configuration& conf, int argc, char** argv)
|
2012-07-09 05:29:17 +00:00
|
|
|
{
|
|
|
|
namespace po = boost::program_options;
|
|
|
|
|
|
|
|
// Register all possible options
|
|
|
|
po::options_description desc("Allowed options");
|
|
|
|
desc.add_options()
|
|
|
|
("help,h", "produce help message")
|
2012-07-12 09:36:34 +00:00
|
|
|
("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::string>(), "output file")
|
|
|
|
("codec,c", po::value<std::string>(), "output codec")
|
2012-07-09 05:29:17 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
// 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;
|
2012-07-12 09:36:34 +00:00
|
|
|
return false;
|
2012-07-09 05:29:17 +00:00
|
|
|
}
|
|
|
|
po::notify(vm);
|
|
|
|
|
|
|
|
// Handle -h and --help
|
|
|
|
if (argc <= 1 || vm.count("help"))
|
|
|
|
{
|
|
|
|
std::cout << desc << "\n";
|
2012-07-12 09:36:34 +00:00
|
|
|
return false;
|
2012-07-09 05:29:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
|
2012-07-12 09:36:34 +00:00
|
|
|
/* Store configuration */
|
|
|
|
conf.output = std::string(vm["output"].as<std::string>());
|
|
|
|
conf.codec = std::string(vm["codec"].as<std::string>());
|
|
|
|
|
|
|
|
std::vector<std::string> vs;
|
|
|
|
if (vm.count("input-file"))
|
|
|
|
{
|
|
|
|
vs = vm["input-file"].as<std::vector<std::string>>();
|
|
|
|
for (auto it = vs.begin(); it != vs.end(); ++it)
|
|
|
|
conf.input.push_back(std::string(*it));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (vm.count("filter"))
|
|
|
|
{
|
|
|
|
vs = vm["filter"].as<std::vector<std::string>> ();
|
|
|
|
for (auto it = vs.begin(); it != vs.end(); ++it)
|
|
|
|
conf.filters.push_back(std::string(*it));
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
int main (int argc, char** argv)
|
|
|
|
{
|
2012-07-12 17:50:16 +00:00
|
|
|
tbb::task_scheduler_init init;
|
2012-07-12 09:36:34 +00:00
|
|
|
Configuration conf = Configuration();
|
|
|
|
|
|
|
|
if (!parse_cli(conf, argc, argv))
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
VideoReader vr(conf.input.front());
|
2012-07-12 08:42:38 +00:00
|
|
|
VideoWriter vw = VideoWriter();
|
2012-07-12 09:36:34 +00:00
|
|
|
vw.open(conf.output, conf.codec, vr.fps_get(), vr.width_get(), vr.height_get());
|
2012-07-12 17:50:16 +00:00
|
|
|
|
|
|
|
Pipeline pipe(std::list<VideoReader> { vr }, vw);
|
2012-07-12 22:03:02 +00:00
|
|
|
// add filters here
|
|
|
|
pipe.add_filter("grey");
|
2012-07-12 17:50:16 +00:00
|
|
|
pipe.run();
|
2012-07-12 08:42:38 +00:00
|
|
|
|
2012-07-09 05:29:17 +00:00
|
|
|
return 0;
|
|
|
|
}
|