AvTranscoder  0.9.4
C++APIforLibav/FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
main.cpp
Go to the documentation of this file.
3 
4 #include "Window.hpp"
5 
6 #include <cstdlib>
7 
8 int main(int argc, char** argv)
9 {
10  std::string filename;
11  size_t streamIndex = 0;
12  size_t width = 0;
13  size_t height = 0;
14 
15  std::string help;
16  help += "Usage\n";
17  help += "\tavplayer filename [streamIndex] [--width width] [--height height] [--help]\n";
18  help += "Command line options\n";
19  help += "\tstreamIndex: specify the index of the stream to read (by default 0)\n";
20  help += "\t--width: specify the output width (by default the same as input)\n";
21  help += "\t--height: specify the output height (by default the same as input)\n";
22  help += "\t--help: display this help\n";
23 
24  // List command line arguments
25  std::vector<std::string> arguments;
26  for(int argument = 1; argument < argc; ++argument)
27  {
28  arguments.push_back(argv[argument]);
29  }
30  for(size_t argument = 0; argument < arguments.size(); ++argument)
31  {
32  if(arguments.at(argument) == "--help")
33  {
34  std::cout << help << std::endl;
35  return 0;
36  }
37  else if(arguments.at(argument) == "--width")
38  {
39  try
40  {
41  width = atoi(arguments.at(++argument).c_str());
42  }
43  catch(...)
44  {
45  std::cout << help << std::endl;
46  return 0;
47  }
48  }
49  else if(arguments.at(argument) == "--height")
50  {
51  try
52  {
53  height = atoi(arguments.at(++argument).c_str());
54  }
55  catch(...)
56  {
57  std::cout << help << std::endl;
58  return 0;
59  }
60  }
61  // positional arguments
62  if(argument == 0)
63  {
64  filename = arguments.at(argument);
65  }
66  else if(argument == 1)
67  {
68  streamIndex = atoi(arguments.at(argument).c_str());
69  }
70  }
71 
72  // Check required arguments
73  if(argc < 2)
74  {
75  std::cout << "avplay can play the given video media file." << std::endl;
76  std::cout << "Use option --help to display help" << std::endl;
77  return (-1);
78  }
79 
80  // Setup avtranscoder
83 
84  avtranscoder::VideoReader reader(filename, streamIndex);
85  if(width == 0)
86  width = reader.getOutputWidth();
87  if(height == 0)
88  height = reader.getOutputHeight();
89  reader.updateOutput(width, height, "rgb24");
90  Window window(reader);
91  window.launch();
92 }
void launch()
Definition: Window.cpp:130
int main(int argc, char **argv)
Definition: main.cpp:8
Definition: Window.hpp:8
void preloadCodecsAndFormats()
Register all the codecs and formats which are enabled at configuration time.
Definition: common.cpp:16
size_t getOutputHeight() const
Definition: VideoReader.hpp:34
void updateOutput(const size_t width, const size_t height, const std::string &pixelFormat)
Update width, height and pixelFormat of the output.
Definition: VideoReader.cpp:70
static void setLogLevel(const int level)
Set the log level of ffmpeg/libav.
Definition: log.cpp:26
size_t getOutputWidth() const
Definition: VideoReader.hpp:33