-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathoptions.cpp
More file actions
77 lines (66 loc) · 2.29 KB
/
Copy pathoptions.cpp
File metadata and controls
77 lines (66 loc) · 2.29 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
#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;
void setDefaultOptions(Options& opt)
{
opt.inputFile = getExeDir() + L"/../../assets/vid/big_buck_bunny_trailer.vid.mp4";
opt.cropLeft = 60;
opt.cropRight = 60;
opt.cropTop = 0;
opt.cropBottom = 0;
fs::path output(getExeDir() + L"/../../output/video_crop");
fs::create_directories(output);
wostringstream s;
s << output.c_str() << L"/cropped.mp4";
opt.outputFile = s.str();
}
void help(OptionsConfig<wchar_t>& optcfg)
{
wcout << L"Usage: video_crop -i <input.mp4> -o <output.mp4> [--crop-left <left>] [--crop-right <right>] [--crop-top <top>] [--crop-bottom <bottom>]" << endl;
doHelp(wcout, optcfg);
}
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" --crop-left " << opt.cropLeft;
wcout << L" --crop-right " << opt.cropRight;
wcout << L" --crop-top " << opt.cropTop;
wcout << L" --crop-bottom " << opt.cropBottom;
wcout << endl;
return Parsed;
}
primo::program_options::OptionsConfig<wchar_t> optcfg;
optcfg.addOptions()
(L"help,h", opt.help, L"")
(L"input, i", opt.inputFile, wstring(), L"MP4 input file.")
(L"output, o", opt.outputFile, wstring(), L"MP4 output file.")
(L"crop-left", opt.cropLeft, 60, L"Pixels to crop from left.")
(L"crop-right", opt.cropRight, 60, L"Pixels to crop from right.")
(L"crop-top", opt.cropTop, 0, L"Pixels to crop from top.")
(L"crop-bottom", opt.cropBottom, 0, L"Pixels to crop from bottom.");
try
{
primo::program_options::scanArgv(optcfg, argc, argv);
}
catch (primo::program_options::ParseFailure<wchar_t> &ex)
{
wcout << ex.message() << endl;
help(optcfg);
return Error;
}
if (opt.help)
{
help(optcfg);
return Command;
}
return Parsed;
}