-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathoptions.cpp
More file actions
83 lines (68 loc) · 2.12 KB
/
options.cpp
File metadata and controls
83 lines (68 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include <iostream>
#include <filesystem>
#include "options.h"
#include "program_options.h"
#include "util.h"
using namespace std;
namespace fs = std::filesystem;
void help(primo::program_options::OptionsConfig<char>& optcfg)
{
cout << "Usage: re-encode --input inputFile.mp4 --output outputFile.mp4 [--audio yes|no] [--video yes|no]\n" << endl;
primo::program_options::doHelp(cout, optcfg);
}
void setDefaultOptions(Options& opt)
{
opt.inputFile = getExeDir() + "/../../assets/mov/big_buck_bunny_trailer.mp4";
fs::path output(getExeDir() + "/../../output/re-encode");
fs::create_directories(output);
ostringstream s;
s << output.c_str() << "/big_buck_bunny_trailer.mp4";
opt.outputFile = s.str();
}
bool validateOptions(Options& opt)
{
return (!opt.inputFile.empty() &&
!opt.outputFile.empty());
}
ErrorCodes prepareOptions(Options &opt, int argc, char* argv[])
{
if (argc < 2)
{
setDefaultOptions(opt);
cout << "Using defaults:\n";
cout << " --input " << opt.inputFile << endl;
cout << " --output " << opt.outputFile << endl;
cout << " --audio " << opt.reEncodeAudio << endl;
cout << " --video " << opt.reEncodeVideo << endl;
cout << endl;
return Parsed;
}
primo::program_options::OptionsConfig<char> optcfg;
optcfg.addOptions()
("help,h", opt.help, "")
("input,i", opt.inputFile, string(), "input mp4 file")
("output,o", opt.outputFile, string(), "output mp4 file")
("audio,a", opt.reEncodeAudio, YesNo(true), "re-encode audio, yes|no")
("video,v", opt.reEncodeVideo, YesNo(true), "re-encode video, yes|no");
try
{
primo::program_options::scanArgv(optcfg, argc, argv);
}
catch (primo::program_options::ParseFailure<char> &ex)
{
cout << ex.message() << endl;
help(optcfg);
return Error;
}
if (opt.help)
{
help(optcfg);
return Command;
}
if (!validateOptions(opt))
{
help(optcfg);
return Error;
}
return Parsed;
}