-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathoptions.cpp
More file actions
83 lines (70 loc) · 1.96 KB
/
Copy pathoptions.cpp
File metadata and controls
83 lines (70 loc) · 1.96 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
/*
* Copyright (c) Primo Software. All Rights Reserved.
*
* Use of this source code is governed by a MIT License
* that can be found in the LICENSE file in the root of the source
* tree.
*/
#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/foreman_qcif.h265";
fs::path output(getExeDir() + L"/../../output/dec_hevc_file");
fs::create_directories(output);
wostringstream s;
s << output.c_str() << L"/foreman_qcif.yuv";
opt.outputFile = s.str();
}
void help(primo::program_options::OptionsConfig<wchar_t>& optcfg)
{
wcout << L"Usage: dec_hevc_file -i <h265 file> -o <yuv file>\n";
primo::program_options::doHelp(wcout, optcfg);
}
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 << 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"H265 input file.")
(L"output,o", opt.outputFile, wstring(), L"YUV output file.");
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;
}
if (!validateOptions(opt))
{
help(optcfg);
return Error;
}
return Parsed;
}