Externalised the CLI parsing.
This commit is contained in:
parent
cbc9a7a686
commit
4cfab2eaa0
@ -23,7 +23,7 @@ prpa_LDADD = \
|
||||
lib/libfilterSample.a \
|
||||
lib/libencoder.a
|
||||
|
||||
prpa_SOURCES = src/main.cc
|
||||
prpa_SOURCES = src/main.cc src/configuration.cc
|
||||
|
||||
prpa_LDFLAGS = \
|
||||
$(BOOST_LDFLAGS) \
|
||||
|
@ -14,7 +14,7 @@ AC_CONFIG_MACRO_DIR([m4])
|
||||
# Look for a C++ compiler.CXXFLAGS_save="$CXXFLAGS"
|
||||
AC_PROG_CXX
|
||||
AC_PROG_RANLIB
|
||||
CXXFLAGS="$CXXFLAGS_save"
|
||||
CXXFLAGS="$CXXFLAGS_save -std=c++11 -g"
|
||||
|
||||
AC_ARG_ENABLE(debug,
|
||||
[ --enable-debug compile with debugging support],
|
||||
|
1
src/configuration.cc
Normal file
1
src/configuration.cc
Normal file
@ -0,0 +1 @@
|
||||
#include "configuration.hh"
|
17
src/configuration.hh
Normal file
17
src/configuration.hh
Normal file
@ -0,0 +1,17 @@
|
||||
#ifndef CONFIGURATION_HH_
|
||||
# define CONFIGURATION_HH_
|
||||
|
||||
# include <string>
|
||||
# include <list>
|
||||
|
||||
class Configuration
|
||||
{
|
||||
public:
|
||||
std::list<std::string> input;
|
||||
std::string output;
|
||||
std::string codec;
|
||||
std::list<std::string> filters;
|
||||
private:
|
||||
};
|
||||
|
||||
#endif /* !CONFIGURATION_HH_ */
|
50
src/main.cc
50
src/main.cc
@ -1,12 +1,15 @@
|
||||
#include <iostream>
|
||||
#include <boost/program_options.hpp>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "configuration.hh"
|
||||
|
||||
#include "encoder/video.hh"
|
||||
#include "encoder/video_reader.hh"
|
||||
#include "encoder/video_writer.hh"
|
||||
|
||||
int
|
||||
main (int argc, char** argv)
|
||||
bool parse_cli(Configuration& conf, int argc, char** argv)
|
||||
{
|
||||
namespace po = boost::program_options;
|
||||
|
||||
@ -16,8 +19,8 @@ main (int argc, char** argv)
|
||||
("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")
|
||||
("output,o", po::value<std::string>(), "output file")
|
||||
("codec,c", po::value<std::string>(), "output codec")
|
||||
;
|
||||
|
||||
// Handle ./prpa file.avi instead of ./prpa --input-file=file.avi
|
||||
@ -34,7 +37,7 @@ main (int argc, char** argv)
|
||||
catch (po::invalid_command_line_syntax e)
|
||||
{
|
||||
std::cerr << argv[0] << ": " << e.what() << std::endl;
|
||||
return 1;
|
||||
return false;
|
||||
}
|
||||
po::notify(vm);
|
||||
|
||||
@ -42,7 +45,7 @@ main (int argc, char** argv)
|
||||
if (argc <= 1 || vm.count("help"))
|
||||
{
|
||||
std::cout << desc << "\n";
|
||||
return 1;
|
||||
return false;
|
||||
}
|
||||
|
||||
// GO!
|
||||
@ -60,11 +63,38 @@ main (int argc, char** argv)
|
||||
else
|
||||
std::cout << 0 << std::endl;
|
||||
|
||||
VideoReader vr(vm["input-file"].as<std::vector<std::string> >()[0]);
|
||||
/* 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)
|
||||
{
|
||||
Configuration conf = Configuration();
|
||||
|
||||
if (!parse_cli(conf, argc, argv))
|
||||
return 1;
|
||||
|
||||
VideoReader vr(conf.input.front());
|
||||
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.open(conf.output, conf.codec, vr.fps_get(), vr.width_get(), vr.height_get());
|
||||
vw.copy(vr);
|
||||
vw.write();
|
||||
|
||||
|
Reference in New Issue
Block a user