forked from google/spatial-media
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathparser.cpp
190 lines (167 loc) · 6.06 KB
/
parser.cpp
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
180
181
182
183
184
185
186
187
188
189
/* *******************************************************************************
** usage: spatialmedia [options] [files...]
**
** By default prints out spatial media metadata from specified files.
**
** positional arguments:
** file input/output files
**
** optional arguments:
** -h, --help show this help message and exit
** -i, --inject injects spatial media metadata into the first file
** specified (.mp4 or .mov) and saves the result to the
** second file specified
**
** Spherical Video:
** -s STEREO-MODE, --stereo STEREO-MODE
** stereo mode (none | top-bottom | left-right)
** -c CROP, --crop CROP crop region. Must specify 6 integers in the form of
** "w:h:f_w:f_h:x:y" where w=CroppedAreaImageWidthPixels
** h=CroppedAreaImageHeightPixels f_w=FullPanoWidthPixels
** f_h=FullPanoHeightPixels x=CroppedAreaLeftPixels
** y=CroppedAreaTopPixels
**
** Spatial Audio:
** -a, --spatial-audio spatial audio. First-order periphonic ambisonics with
** ACN channel ordering and SN3D normalization
**
*********************************************************************************/
#include <algorithm>
#include <iostream>
#include <getopt.h>
#include "parser.h"
using namespace std;
namespace SpatialMedia
{
Parser::Parser ( )
{
m_bInject = true;
m_StereoMode = SM_NONE;
for ( int t=0; t<6; t++ )
m_crop[t] = 0;
m_bSpatialAudio = false;
}
Parser::~Parser ( )
{
}
void Parser::parseCommandLine ( int argc, char *argv[] )
{
(void)argc;
(void)argv;
int iChar = 0;
static struct option longOpts[] = {
{ "help", no_argument, 0, 'h' },
{ "inject", no_argument, 0, 'i' },
{ "stereo", required_argument, 0, 's' },
{ "crop", required_argument, 0, 'c' },
{ "spatial-audio", no_argument, 0, 'a' },
{ 0, 0, 0, 0 } };
while ( true ) {
iChar = getopt_long_only ( argc, argv, "?hias:c:", longOpts, NULL );
if ( iChar == -1 )
break;
switch ( iChar ) {
case 'i':
m_bInject = true;
break;
case 'a':
m_bSpatialAudio = true;
break;
case 's': {
std::string str ( optarg );
std::transform ( str.begin ( ), str.end ( ), str.begin ( ), ::tolower );
if ( str == "top-bottom" )
m_StereoMode = SM_TOP_BOTTOM;
else if ( str == "left-right" )
m_StereoMode = SM_LEFT_RIGHT;
else
m_StereoMode = SM_NONE;
}
break;
case 'c': {
std::string str ( optarg ); // w:h:f_w:f_h:x:y => E.g. 2048:1024:3186:1482:100:100
// crop_match = re.match(crop_regex, crop)
// if not crop_match:
// print "Error: Invalid crop params: {crop}".format(crop=crop)
// return False
}
break;
case 'h':
case '?':
default:
printHelp ( );
exit ( 0 );
}
}
if ( argc > 2 )
m_strInFile = argv[argc-2];
if ( argc > 3 )
m_strOutFile = argv[argc-1];
}
void Parser::printHelp ( )
{
cout << "usage: spatialmedia [options] [files...]" << endl;
cout << endl;
cout << "By default prints out spatial media metadata from specified files." << endl;
cout << endl;
cout << "positional arguments:" << endl;
cout << " file input/output files" << endl;
cout << endl;
cout << "optional arguments:" << endl;
cout << " -h, --help show this help message and exit" << endl;
cout << " -i, --inject injects spatial media metadata into the first file" << endl;
cout << " specified (.mp4 or .mov) and saves the result to the" << endl;
cout << " second file specified" << endl;
cout << endl;
cout << "Spherical Video:" << endl;
cout << " -s STEREO-MODE, --stereo STEREO-MODE" << endl;
cout << " stereo mode (none | top-bottom | left-right)" << endl;
cout << " \"none\": Mono frame layout." << endl;
cout << " \"top-bottom\": Top half contains the left eye and bottom half contains the right eye." << endl;
cout << " \"left-right\": Left half contains the left eye and right half contains the right eye." << endl;
cout << " ( RFC: https://github.com/google/spatial-media/tree/master/docs/spherical-video-rfc.md )" << endl;
cout << endl;
cout << " -c CROP, --crop CROP crop region. Must specify 6 integers in the form of" << endl;
cout << " \"w:h:f_w:f_h:x:y\" where w=CroppedAreaImageWidthPixels" << endl;
cout << " h=CroppedAreaImageHeightPixels f_w=FullPanoWidthPixels" << endl;
cout << " f_h=FullPanoHeightPixels x=CroppedAreaLeftPixels" << endl;
cout << " y=CroppedAreaTopPixels" << endl;
cout << endl;
cout << "Spatial Audio:" << endl;
cout << " -a, --spatial-audio spatial audio. First-order periphonic ambisonics with" << endl;
cout << " ACN channel ordering and SN3D normalization" << endl;
cout << " Enables injection of spatial audio metadata. If enabled, the file must contain a" << endl;
cout << " 4-channel first-order ambisonics audio track with ACN channel ordering and SN3D" << endl;
cout << " normalization; see the [Spatial Audio RFC](../docs/spatial-audio-rfc.md) for" << endl;
cout << " more information." << endl;
}
std::string &Parser::getInFile ( )
{
return m_strInFile;
}
std::string &Parser::getOutFile ( )
{
return m_strOutFile;
}
bool Parser::getInject ( )
{
return m_bInject;
}
Parser::enMode Parser::getStereoMode ( )
{
return m_StereoMode;
}
int *Parser::getCrop ( )
{
// return NULL if no croping was specified.
for ( int t=0; t<6; t++ ) {
if ( m_crop[t] != 0 )
return m_crop;
}
return NULL;
}
bool Parser::getSpatialAudio ( )
{
return m_bSpatialAudio;
}
}; // nd of namespace SpatialMedia