AvTranscoder  0.9.4
C++APIforLibav/FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Library.cpp
Go to the documentation of this file.
1 #include "Library.hpp"
2 
3 extern "C" {
4 #include <libavutil/version.h>
5 #include <libavcodec/version.h>
6 #include <libswscale/version.h>
7 #include <libswscale/swscale.h>
8 #include <libavfilter/version.h>
9 #ifdef AVTRANSCODER_LIBAV_DEPENDENCY
10 #include <libavresample/version.h>
11 #else
12 #include <libswresample/version.h>
13 #endif
14 #include <libavformat/avformat.h>
15 #include <libavfilter/avfilter.h>
16 }
17 
18 #include <cstring>
19 #include <sstream>
20 #include <algorithm>
21 
22 namespace avtranscoder
23 {
24 
25 Library::Library(const std::string& name, const std::string& license, const size_t major, const size_t minor,
26  const size_t release)
27  : _name(name)
28  , _licence(license)
29  , _major(major)
30  , _minor(minor)
31  , _release(release)
32 {
33 }
34 
35 std::string Library::getName()
36 {
37  return _name;
38 }
39 
40 std::vector<size_t> Library::getVersion()
41 {
42  std::vector<size_t> version;
43  version.push_back(_major);
44  version.push_back(_minor);
45  version.push_back(_release);
46  return version;
47 }
48 
50 {
51  std::stringstream version;
52  version << _major << ".";
53  version << _minor << ".";
54  version << _release;
55  return version.str();
56 }
57 
59 {
60  return _major;
61 }
62 
64 {
65  return _minor;
66 }
67 
69 {
70  return _release;
71 }
72 
73 std::string Library::getLicense()
74 {
75  return _licence;
76 }
77 
79 {
80  Libraries libs;
81 
82  libs.push_back(Library("avtranscoder", "GPL v2 or LGPL v2.1", AVTRANSCODER_VERSION_MAJOR, AVTRANSCODER_VERSION_MINOR,
84  libs.push_back(
85  Library("avutil", avutil_license(), LIBAVUTIL_VERSION_MAJOR, LIBAVUTIL_VERSION_MINOR, LIBAVUTIL_VERSION_MICRO));
86  libs.push_back(Library("avformat", avformat_license(), LIBAVFORMAT_VERSION_MAJOR, LIBAVFORMAT_VERSION_MINOR,
87  LIBAVFORMAT_VERSION_MICRO));
88  libs.push_back(
89  Library("avcodec", avcodec_license(), LIBAVCODEC_VERSION_MAJOR, LIBAVCODEC_VERSION_MINOR, LIBAVCODEC_VERSION_MICRO));
90 #ifdef AVTRANSCODER_LIBAV_DEPENDENCY
91  libs.push_back(Library("avresample", avutil_license(), LIBAVRESAMPLE_VERSION_MAJOR, LIBAVRESAMPLE_VERSION_MINOR,
92  LIBAVRESAMPLE_VERSION_MICRO));
93 #else
94  libs.push_back(Library("swresample", avutil_license(), LIBSWRESAMPLE_VERSION_MAJOR, LIBSWRESAMPLE_VERSION_MINOR,
95  LIBSWRESAMPLE_VERSION_MICRO));
96 #endif
97  libs.push_back(
98  Library("swscale", swscale_license(), LIBSWSCALE_VERSION_MAJOR, LIBSWSCALE_VERSION_MINOR, LIBSWSCALE_VERSION_MICRO));
99  libs.push_back(Library("avfilter", avfilter_license(), LIBAVFILTER_VERSION_MAJOR, LIBAVFILTER_VERSION_MINOR,
100  LIBAVFILTER_VERSION_MICRO));
101 
102  return libs;
103 }
104 
105 std::vector<std::string> getInputExtensions()
106 {
107  std::vector<std::string> extensions;
108  AVInputFormat* iFormat = NULL;
109 
110  while((iFormat = av_iformat_next(iFormat)))
111  {
112  if(iFormat->extensions != NULL)
113  {
114  // parse extensions
115  std::string exts = std::string(iFormat->extensions);
116  char* ext = strtok(const_cast<char*>(exts.c_str()), ",");
117  while(ext != NULL)
118  {
119  extensions.push_back(std::string(ext));
120  ext = strtok(NULL, ",");
121  }
122 
123  // parse name (name's format defines (in general) extensions )
124  // don't need to do it in recent LibAV/FFMpeg versions
125  exts = std::string(iFormat->name);
126  ext = strtok(const_cast<char*>(exts.c_str()), ",");
127  while(ext != NULL)
128  {
129  extensions.push_back(std::string(ext));
130  ext = strtok(NULL, ",");
131  }
132  }
133  }
134  // sort
135  std::sort(extensions.begin(), extensions.end());
136  // suppress duplicates
137  std::vector<std::string>::iterator last = std::unique(extensions.begin(), extensions.end());
138  extensions.erase(last, extensions.end());
139 
140  return extensions;
141 }
142 
143 std::vector<std::string> getOutputExtensions()
144 {
145  std::vector<std::string> extensions;
146  AVOutputFormat* oFormat = NULL;
147 
148  while((oFormat = av_oformat_next(oFormat)))
149  {
150  if(oFormat->extensions != NULL)
151  {
152  // parse extensions
153  std::string exts = std::string(oFormat->extensions);
154  char* ext = strtok(const_cast<char*>(exts.c_str()), ",");
155  while(ext != NULL)
156  {
157  extensions.push_back(std::string(ext));
158  ext = strtok(NULL, ",");
159  }
160 
161  // parse name (name's format defines (in general) extensions )
162  // don't need to do it in recent LibAV/FFMpeg versions
163  exts = std::string(oFormat->name);
164  ext = strtok(const_cast<char*>(exts.c_str()), ",");
165  while(ext != NULL)
166  {
167  extensions.push_back(std::string(ext));
168  ext = strtok(NULL, ",");
169  }
170  }
171  }
172  // sort
173  std::sort(extensions.begin(), extensions.end());
174  // suppress duplicates
175  std::vector<std::string>::iterator last = std::unique(extensions.begin(), extensions.end());
176  extensions.erase(last, extensions.end());
177 
178  return extensions;
179 }
180 }
std::vector< size_t > getVersion()
Definition: Library.cpp:40
#define AVTRANSCODER_VERSION_MICRO
Definition: common.hpp:6
size_t getMinorVersion()
Definition: Library.cpp:63
#define AVTRANSCODER_VERSION_MINOR
Definition: common.hpp:5
std::string getLicense()
Definition: Library.cpp:73
size_t getReleaseVersion()
Definition: Library.cpp:68
std::string _licence
Definition: Library.hpp:30
std::vector< std::string > getOutputExtensions()
Definition: Library.cpp:143
std::vector< Library > Libraries
Definition: Library.hpp:36
std::string getName()
Definition: Library.cpp:35
#define AVTRANSCODER_VERSION_MAJOR
Definition: common.hpp:4
std::string _name
Definition: Library.hpp:29
std::string getStringVersion()
Definition: Library.cpp:49
size_t getMajorVersion()
Definition: Library.cpp:58
Libraries getLibraries()
Definition: Library.cpp:78
Library(const std::string &name, const std::string &license, const size_t major, const size_t minor, const size_t release)
Definition: Library.cpp:25
std::vector< std::string > getInputExtensions()
Definition: Library.cpp:105