-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathoptions.cpp
More file actions
85 lines (70 loc) · 2.22 KB
/
Copy pathoptions.cpp
File metadata and controls
85 lines (70 loc) · 2.22 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
84
85
#include "stdafx.h"
#include "options.h"
#include "program_options.h"
#include "util.h"
namespace fs = std::filesystem;
using namespace std;
using namespace primo::program_options;
using namespace primo::codecs;
void setDefaultOptions(Options& opt)
{
//audio and video flags are enabled by default
opt.inputFile = getExeDir() + L"/../../assets/mov/big_buck_bunny_trailer.mp4";
fs::path output(getExeDir() + L"/../../output/re-encode");
fs::create_directories(output);
wostringstream s;
s << output.c_str() << L"/big_buck_bunny_trailer.mp4";
opt.outputFile = s.str();
}
void help(OptionsConfig<wchar_t>& optionsConfig)
{
wcout << L"Usage: re-encode [--input inputFile.mp4] [--output outputFile.mp4] [--audio yes|no] [--video yes|no]\n" << endl;
doHelp(wcout, optionsConfig);
}
bool validateOptions(Options& opt)
{
return (!opt.inputFile.empty() &&
!opt.outputFile.empty());
}
ErrorCodes prepareOptions(Options& opt, int argc, wchar_t* argv[])
{
if (argc < 2)
{
setDefaultOptions(opt);
wcout << L"Using defaults:\n";
wcout << L"--input " << opt.inputFile;
wcout << L" --output " << opt.outputFile;
wcout << L" --video " << opt.reEncodeVideo;
wcout << L" --audio " << opt.reEncodeAudio;
wcout << endl;
return Parsed;
}
OptionsConfig<wchar_t> optionsConfig;
optionsConfig.addOptions()
(L"help,?", opt.help, L"")
(L"input,i", opt.inputFile, wstring(), L"input file")
(L"output,o", opt.outputFile, wstring(), L"output file")
(L"audio,a", opt.reEncodeAudio, YesNo(true), L"re-encode audio with yes|no")
(L"video,v", opt.reEncodeVideo, YesNo(true), L"re-encode video with yes|no");
try
{
scanArgv(optionsConfig, argc, argv);
}
catch (ParseFailure<wchar_t> &ex)
{
wcout << ex.message() << endl;
help(optionsConfig);
return Error;
}
if(opt.help)
{
help(optionsConfig);
return Command;
}
if (!validateOptions(opt))
{
help(optionsConfig);
return Error;
}
return Parsed;
}