Externalised the CLI parsing.

This commit is contained in:
Delalande Ivan 2012-07-12 11:36:34 +02:00
parent cbc9a7a686
commit 4cfab2eaa0
5 changed files with 62 additions and 14 deletions

View File

@ -23,7 +23,7 @@ prpa_LDADD = \
lib/libfilterSample.a \ lib/libfilterSample.a \
lib/libencoder.a lib/libencoder.a
prpa_SOURCES = src/main.cc prpa_SOURCES = src/main.cc src/configuration.cc
prpa_LDFLAGS = \ prpa_LDFLAGS = \
$(BOOST_LDFLAGS) \ $(BOOST_LDFLAGS) \

View File

@ -14,7 +14,7 @@ AC_CONFIG_MACRO_DIR([m4])
# Look for a C++ compiler.CXXFLAGS_save="$CXXFLAGS" # Look for a C++ compiler.CXXFLAGS_save="$CXXFLAGS"
AC_PROG_CXX AC_PROG_CXX
AC_PROG_RANLIB AC_PROG_RANLIB
CXXFLAGS="$CXXFLAGS_save" CXXFLAGS="$CXXFLAGS_save -std=c++11 -g"
AC_ARG_ENABLE(debug, AC_ARG_ENABLE(debug,
[ --enable-debug compile with debugging support], [ --enable-debug compile with debugging support],

1
src/configuration.cc Normal file
View File

@ -0,0 +1 @@
#include "configuration.hh"

17
src/configuration.hh Normal file
View 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_ */

View File

@ -1,12 +1,15 @@
#include <iostream> #include <iostream>
#include <boost/program_options.hpp> #include <boost/program_options.hpp>
#include <string>
#include <vector>
#include "configuration.hh"
#include "encoder/video.hh" #include "encoder/video.hh"
#include "encoder/video_reader.hh" #include "encoder/video_reader.hh"
#include "encoder/video_writer.hh" #include "encoder/video_writer.hh"
int bool parse_cli(Configuration& conf, int argc, char** argv)
main (int argc, char** argv)
{ {
namespace po = boost::program_options; namespace po = boost::program_options;
@ -16,8 +19,8 @@ main (int argc, char** argv)
("help,h", "produce help message") ("help,h", "produce help message")
("filter,f", po::value<std::vector<std::string>>(), "apply a filter") ("filter,f", po::value<std::vector<std::string>>(), "apply a filter")
("input-file,i", po::value<std::vector<std::string>>(), "file to treat") ("input-file,i", po::value<std::vector<std::string>>(), "file to treat")
("output,o", po::value<std::vector<std::string> > (), "output file") ("output,o", po::value<std::string>(), "output file")
("codec,c", po::value<std::vector<std::string> > (), "output codec") ("codec,c", po::value<std::string>(), "output codec")
; ;
// Handle ./prpa file.avi instead of ./prpa --input-file=file.avi // 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) catch (po::invalid_command_line_syntax e)
{ {
std::cerr << argv[0] << ": " << e.what() << std::endl; std::cerr << argv[0] << ": " << e.what() << std::endl;
return 1; return false;
} }
po::notify(vm); po::notify(vm);
@ -42,7 +45,7 @@ main (int argc, char** argv)
if (argc <= 1 || vm.count("help")) if (argc <= 1 || vm.count("help"))
{ {
std::cout << desc << "\n"; std::cout << desc << "\n";
return 1; return false;
} }
// GO! // GO!
@ -60,11 +63,38 @@ main (int argc, char** argv)
else else
std::cout << 0 << std::endl; 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(); VideoWriter vw = VideoWriter();
vw.open(vm["output"].as<std::vector<std::string> >()[0], vw.open(conf.output, conf.codec, vr.fps_get(), vr.width_get(), vr.height_get());
vm["codec"].as<std::vector<std::string> >()[0],
vr.fps_get(), vr.width_get(), vr.height_get());
vw.copy(vr); vw.copy(vr);
vw.write(); vw.write();