-
Notifications
You must be signed in to change notification settings - Fork 50
Expand file tree
/
Copy pathmain.cpp
More file actions
92 lines (84 loc) · 2.61 KB
/
Copy pathmain.cpp
File metadata and controls
92 lines (84 loc) · 2.61 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
#include <AvTranscoder/common.hpp>
#include <AvTranscoder/reader/VideoReader.hpp>
#include "Window.hpp"
#include <cstdlib>
int main(int argc, char** argv)
{
std::string filename;
size_t streamIndex = 0;
size_t width = 0;
size_t height = 0;
std::string help;
help += "Usage\n";
help += "\tavplayer filename [streamIndex] [--width width] [--height height] [--help]\n";
help += "Command line options\n";
help += "\tstreamIndex: specify the index of the stream to read (by default 0)\n";
help += "\t--width: specify the output width (by default the same as input)\n";
help += "\t--height: specify the output height (by default the same as input)\n";
help += "\t--help: display this help\n";
// List command line arguments
std::vector<std::string> arguments;
for(int argument = 1; argument < argc; ++argument)
{
arguments.push_back(argv[argument]);
}
for(size_t argument = 0; argument < arguments.size(); ++argument)
{
if(arguments.at(argument) == "--help")
{
std::cout << help << std::endl;
return 0;
}
else if(arguments.at(argument) == "--width")
{
try
{
width = atoi(arguments.at(++argument).c_str());
}
catch(...)
{
std::cout << help << std::endl;
return 0;
}
}
else if(arguments.at(argument) == "--height")
{
try
{
height = atoi(arguments.at(++argument).c_str());
}
catch(...)
{
std::cout << help << std::endl;
return 0;
}
}
// positional arguments
if(argument == 0)
{
filename = arguments.at(argument);
}
else if(argument == 1)
{
streamIndex = atoi(arguments.at(argument).c_str());
}
}
// Check required arguments
if(argc < 2)
{
std::cout << "avplay can play the given video media file." << std::endl;
std::cout << "Use option --help to display help" << std::endl;
return (-1);
}
// Setup avtranscoder
avtranscoder::preloadCodecsAndFormats();
avtranscoder::Logger::setLogLevel(AV_LOG_QUIET);
avtranscoder::VideoReader reader(avtranscoder::InputStreamDesc(filename, streamIndex));
if(width == 0)
width = reader.getOutputWidth();
if(height == 0)
height = reader.getOutputHeight();
reader.updateOutput(width, height, "rgb24");
Window window(reader);
window.launch();
}