-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathoptions.cpp
More file actions
179 lines (148 loc) · 5.07 KB
/
Copy pathoptions.cpp
File metadata and controls
179 lines (148 loc) · 5.07 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
/*
* 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 "util.h"
#include "program_options.h"
using namespace std;
using namespace primo::avblocks;
using namespace primo::codecs;
using namespace primo::program_options;
ColorDescriptor color_formats[] = {
{ ColorFormat::YV12, L"yv12", L"Planar Y, V, U (4:2:0) (note V,U order!)" },
{ ColorFormat::NV12, L"nv12", L"Planar Y, merged U->V (4:2:0)" },
{ ColorFormat::YUY2, L"yuy2", L"Composite Y->U->Y->V (4:2:2)" },
{ ColorFormat::UYVY, L"uyvy", L"Composite U->Y->V->Y (4:2:2)" },
{ ColorFormat::YUV411, L"yuv411", L"Planar Y, U, V (4:1:1)" },
{ ColorFormat::YUV420, L"yuv420", L"Planar Y, U, V (4:2:0)" },
{ ColorFormat::YUV422, L"yuv422", L"Planar Y, U, V (4:2:2)" },
{ ColorFormat::YUV444, L"yuv444", L"Planar Y, U, V (4:4:4)" },
{ ColorFormat::Y411, L"y411", L"Composite Y, U, V (4:1:1)" },
{ ColorFormat::Y41P, L"y41p", L"Composite Y, U, V (4:1:1)" },
{ ColorFormat::BGRA32, L"bgra32", L"Composite B->G->R" },
{ ColorFormat::BGR32, L"bgr32", L"Composite B->G->R->A" },
{ ColorFormat::BGR24, L"bgr24", L"Composite B->G->R" },
{ ColorFormat::BGR565, L"bgr565", L"Composite B->G->R, 5 bit per B & R, 6 bit per G" },
{ ColorFormat::BGR555, L"bgr555", L"Composite B->G->R->A, 5 bit per component, 1 bit per A" },
{ ColorFormat::BGR444, L"bgr444", L"Composite B->G->R->A, 4 bit per component" },
{ ColorFormat::GRAY, L"gray", L"Luminance component only" },
{ ColorFormat::YUV420A, L"yuv420a", L"Planar Y, U, V, Alpha (4:2:0)" },
{ ColorFormat::YUV422A, L"yuv422a", L"Planar Y, U, V, Alpha (4:2:2)" },
{ ColorFormat::YUV444A, L"yuv444a", L"Planar Y, U, V, Alpha (4:4:4)" },
{ ColorFormat::YVU9, L"yvu9", L"Planar Y, V, U, 9 bits per sample" },
};
const int color_formats_len = sizeof(color_formats) / sizeof(ColorDescriptor);
ColorDescriptor* getColorByName(const wchar_t* colorName)
{
for (int i=0; i < color_formats_len; ++i)
{
ColorDescriptor& color = color_formats[i];
if (compareNoCase(color.name, colorName))
return &color;
}
return NULL;
}
ColorDescriptor* getColorById(primo::codecs::ColorFormat::Enum Id)
{
for (int i=0; i < color_formats_len; ++i)
{
ColorDescriptor& color = color_formats[i];
if (color.Id == Id)
return &color;
}
return NULL;
}
void listColors()
{
wcout << L"\nCOLORS:" << endl;
wcout << L"-------" << endl;
for (int i=0; i < color_formats_len; ++i)
{
const ColorDescriptor& color = color_formats[i];
wcout << left << setw(20) << color.name << color.description << endl;
}
}
void help(OptionsConfig<wchar_t>& optionsConfig)
{
wcout << L"\nUsage: dec_avc_au --input <directory> [--output <file>] [--frame <width>x<height>] [--rate <fps>] [--color <COLOR>]";
wcout << L" [--colors]" << endl;
doHelp(wcout, optionsConfig);
}
void setDefaultOptions(Options& opt)
{
opt.input_dir = L"..\\..\\assets\\vid\\foreman_qcif.h264.au\\";
opt.output_color = *getColorById(primo::codecs::ColorFormat::YUV420);
}
std::wistringstream &operator>>(std::wistringstream &in, FrameSize &frameSize)
{
in >> frameSize.width;
wchar_t ch;
in >> ch;
in >> frameSize.height;
return in;
}
std::wistringstream &operator>>(std::wistringstream &in, ColorDescriptor &color)
{
std::wstring strColorName;
in >> strColorName;
ColorDescriptor* colorDesc = getColorByName(strColorName.c_str());
if(!colorDesc)
throw primo::program_options::ParseFailure<wchar_t>(L"", strColorName, L"Parse error");
color = *colorDesc;
return in;
}
bool validateOptions(Options& opt)
{
return opt.input_dir.empty() ? false : true;
}
ErrorCodes prepareOptions(Options& opt, int argc, wchar_t* argv[])
{
if (argc < 2)
{
setDefaultOptions(opt);
wcout << L"Using defaults:\n";
wcout << L" --input " << opt.input_dir;
wcout << endl;
return Parsed;
}
OptionsConfig<wchar_t> optionsConfig;
optionsConfig.addOptions()
(L"help,?", opt.help, L"")
(L"input,i", opt.input_dir, wstring(), L"input directory (contains sequence of compressed file)")
(L"output,o", opt.output_file, wstring(), L"output YUV file")
(L"frame,f", opt.frame_size, FrameSize(), L"frame size, <width>x<height>")
(L"rate,r", opt.fps, 0.0, L"frame rate")
(L"color,c", opt.output_color, ColorDescriptor(), L"output color format. Use --colors to list all supported color formats")
(L"colors", opt.list_colors, L"list COLOR constants");
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 (opt.list_colors)
{
listColors();
return Command;
}
if (!validateOptions(opt))
{
help(optionsConfig);
return Error;
}
return Parsed;
}