1
1
#include " util.hpp"
2
2
3
3
extern " C" {
4
- #include < libavcodec/avcodec.h>
5
- #include < libavformat/avformat.h>
6
4
#include < libavutil/pixdesc.h>
7
5
}
8
6
@@ -12,13 +10,7 @@ extern "C" {
12
10
namespace avtranscoder
13
11
{
14
12
15
- bool matchFormat (const std::string& format, const std::string& filename)
16
- {
17
- AVOutputFormat* avOutputFormat = av_guess_format (format.c_str (), filename.c_str (), NULL );
18
- return avOutputFormat != NULL ;
19
- }
20
-
21
- std::vector<std::string> getPixelFormats (const std::string& videoCodecName)
13
+ std::vector<std::string> getSupportedPixelFormats (const std::string& videoCodecName)
22
14
{
23
15
std::vector<std::string> pixelFormats;
24
16
@@ -63,7 +55,7 @@ std::vector<std::string> getPixelFormats(const std::string& videoCodecName)
63
55
return pixelFormats;
64
56
}
65
57
66
- std::vector<std::string> getSampleFormats (const std::string& audioCodecName)
58
+ std::vector<std::string> getSupportedSampleFormats (const std::string& audioCodecName)
67
59
{
68
60
std::vector<std::string> sampleFormats;
69
61
@@ -117,77 +109,109 @@ std::string getSampleFormatName(const AVSampleFormat sampleFormat)
117
109
return formatName ? std::string (formatName) : " " ;
118
110
}
119
111
120
- NamesArray getFormatsNames ()
112
+ std::vector<AVOutputFormat*> getAvailableFormats ()
121
113
{
122
- NamesArray formatsNames ;
114
+ std::vector<AVOutputFormat*> formats ;
123
115
124
116
AVOutputFormat* fmt = NULL ;
125
117
while ((fmt = av_oformat_next (fmt)))
126
118
{
127
- // skip undefined codec
128
- if (fmt->video_codec == AV_CODEC_ID_NONE)
119
+ if (!fmt->name )
129
120
continue ;
130
121
131
- if (!fmt->name && !fmt->long_name )
122
+ formats.push_back (fmt);
123
+ }
124
+ return formats;
125
+ }
126
+
127
+ NamesMap getAvailableFormatsNames ()
128
+ {
129
+ NamesMap formatsNames;
130
+ std::vector<AVOutputFormat*> formats = getAvailableFormats ();
131
+ for (size_t i = 0 ; i < formats.size (); ++i)
132
+ {
133
+ AVOutputFormat* fmt = formats.at (i);
134
+ formatsNames.insert (std::make_pair (std::string (fmt->name ), std::string (fmt->long_name ? fmt->long_name : " " )));
135
+ }
136
+ return formatsNames;
137
+ }
138
+
139
+ NamesMap getAvailableVideoFormatsNames ()
140
+ {
141
+ NamesMap formatsNames;
142
+ std::vector<AVOutputFormat*> formats = getAvailableFormats ();
143
+ for (size_t i = 0 ; i < formats.size (); ++i)
144
+ {
145
+ AVOutputFormat* fmt = formats.at (i);
146
+ // skip format which cannot handle video
147
+ if (fmt->video_codec == AV_CODEC_ID_NONE)
132
148
continue ;
149
+ formatsNames.insert (std::make_pair (std::string (fmt->name ), std::string (fmt->long_name ? fmt->long_name : " " )));
150
+ }
151
+ return formatsNames;
152
+ }
133
153
134
- formatsNames.push_back (
135
- std::make_pair (std::string (fmt->name ? fmt->name : " " ), std::string (fmt->long_name ? fmt->long_name : " " )));
154
+ NamesMap getAvailableAudioFormatsNames ()
155
+ {
156
+ NamesMap formatsNames;
157
+ std::vector<AVOutputFormat*> formats = getAvailableFormats ();
158
+ for (size_t i = 0 ; i < formats.size (); ++i)
159
+ {
160
+ AVOutputFormat* fmt = formats.at (i);
161
+ // skip format which cannot handle audio
162
+ if (fmt->audio_codec == AV_CODEC_ID_NONE)
163
+ continue ;
164
+ formatsNames.insert (std::make_pair (std::string (fmt->name ), std::string (fmt->long_name ? fmt->long_name : " " )));
136
165
}
137
166
return formatsNames;
138
167
}
139
168
140
- NamesArray getVideoCodecsNames ()
169
+ std::vector<AVCodec*> getAvailableCodecs ()
141
170
{
142
- NamesArray videoCodecsNames ;
171
+ std::vector<AVCodec*> codecs ;
143
172
144
173
AVCodec* c = NULL ;
145
- while ((c = av_codec_next (c)) != NULL )
174
+ while ((c = av_codec_next (c)))
146
175
{
147
- if (c->type == AVMEDIA_TYPE_VIDEO)
148
- {
149
- if (!c->name && !c->long_name )
150
- continue ;
151
-
152
- std::pair<std::string, std::string> codecNames (std::string (c->name ? c->name : " " ),
153
- std::string (c->long_name ? c->long_name : " " ));
176
+ if (!c->name )
177
+ continue ;
154
178
155
- // skip duplicates
156
- if (std::find (videoCodecsNames.begin (), videoCodecsNames.end (), codecNames) != videoCodecsNames.end ())
157
- continue ;
179
+ codecs.push_back (c);
180
+ }
181
+ return codecs;
182
+ }
158
183
159
- videoCodecsNames.push_back (codecNames);
184
+ NamesMap getAvailableVideoCodecsNames ()
185
+ {
186
+ NamesMap videoCodecsNames;
187
+ std::vector<AVCodec*> codecs = getAvailableCodecs ();
188
+ for (size_t i = 0 ; i < codecs.size (); ++i)
189
+ {
190
+ AVCodec* c = codecs.at (i);
191
+ if (c->type == AVMEDIA_TYPE_VIDEO)
192
+ {
193
+ videoCodecsNames.insert (std::make_pair (std::string (c->name ), std::string (c->long_name ? c->long_name : " " )));
160
194
}
161
195
}
162
196
return videoCodecsNames;
163
197
}
164
198
165
- NamesArray getAudioCodecsNames ()
199
+ NamesMap getAvailableAudioCodecsNames ()
166
200
{
167
- NamesArray audioCodecsNames;
168
-
169
- AVCodec* c = NULL ;
170
- while ((c = av_codec_next (c)) != NULL )
201
+ NamesMap audioCodecsNames;
202
+ std::vector<AVCodec*> codecs = getAvailableCodecs ();
203
+ for (size_t i = 0 ; i < codecs.size (); ++i)
171
204
{
205
+ AVCodec* c = codecs.at (i);
172
206
if (c->type == AVMEDIA_TYPE_AUDIO)
173
207
{
174
- if (!c->name && !c->long_name )
175
- continue ;
176
-
177
- std::pair<std::string, std::string> codecNames (std::string (c->name ? c->name : " " ),
178
- std::string (c->long_name ? c->long_name : " " ));
179
-
180
- // skip duplicates
181
- if (std::find (audioCodecsNames.begin (), audioCodecsNames.end (), codecNames) != audioCodecsNames.end ())
182
- continue ;
183
-
184
- audioCodecsNames.push_back (codecNames);
208
+ audioCodecsNames.insert (std::make_pair (std::string (c->name ), std::string (c->long_name ? c->long_name : " " )));
185
209
}
186
210
}
187
211
return audioCodecsNames;
188
212
}
189
213
190
- OptionArrayMap getOutputFormatOptions ()
214
+ OptionArrayMap getAvailableOptionsPerOutputFormat ()
191
215
{
192
216
OptionArrayMap optionsPerFormat;
193
217
@@ -196,24 +220,22 @@ OptionArrayMap getOutputFormatOptions()
196
220
// iterate on formats
197
221
while (outputFormat)
198
222
{
199
- // add only format with video track
200
- // outputFormat->audio_codec ?
201
- if (outputFormat->video_codec != AV_CODEC_ID_NONE)
223
+ if (!outputFormat->name )
224
+ continue ;
225
+
226
+ const std::string outputFormatName (outputFormat->name );
227
+ OptionArray options;
228
+ if (outputFormat->priv_class )
202
229
{
203
- if (outputFormat->priv_class )
204
- {
205
- const std::string outputFormatName (outputFormat->name );
206
- OptionArray options;
207
- loadOptions (options, (void *)&outputFormat->priv_class , 0 );
208
- optionsPerFormat.insert (std::make_pair (outputFormatName, options));
209
- }
230
+ loadOptions (options, (void *)&outputFormat->priv_class , 0 );
210
231
}
232
+ optionsPerFormat.insert (std::make_pair (outputFormatName, options));
211
233
outputFormat = av_oformat_next (outputFormat);
212
234
}
213
235
return optionsPerFormat;
214
236
}
215
237
216
- OptionArrayMap getVideoCodecOptions ()
238
+ OptionArrayMap getAvailableOptionsPerVideoCodec ()
217
239
{
218
240
OptionArrayMap videoCodecOptions;
219
241
@@ -222,23 +244,26 @@ OptionArrayMap getVideoCodecOptions()
222
244
// iterate on codecs
223
245
while (codec)
224
246
{
247
+ if (!codec->name )
248
+ continue ;
249
+
225
250
// add only video codec
226
251
if (codec->type == AVMEDIA_TYPE_VIDEO)
227
252
{
253
+ const std::string videoCodecName (codec->name );
254
+ OptionArray options;
228
255
if (codec->priv_class )
229
256
{
230
- std::string videoCodecName (codec->name );
231
- OptionArray options;
232
257
loadOptions (options, (void *)&codec->priv_class , 0 );
233
- videoCodecOptions.insert (std::make_pair (videoCodecName, options));
234
258
}
259
+ videoCodecOptions.insert (std::make_pair (videoCodecName, options));
235
260
}
236
261
codec = av_codec_next (codec);
237
262
}
238
263
return videoCodecOptions;
239
264
}
240
265
241
- OptionArrayMap getAudioCodecOptions ()
266
+ OptionArrayMap getAvailableOptionsPerAudioCodec ()
242
267
{
243
268
OptionArrayMap audioCodecOptions;
244
269
@@ -247,16 +272,19 @@ OptionArrayMap getAudioCodecOptions()
247
272
// iterate on codecs
248
273
while (codec)
249
274
{
275
+ if (!codec->name )
276
+ continue ;
277
+
250
278
// add only audio codec
251
279
if (codec->type == AVMEDIA_TYPE_AUDIO)
252
280
{
281
+ const std::string audioCodecName (codec->name );
282
+ OptionArray options;
253
283
if (codec->priv_class )
254
284
{
255
- std::string audioCodecName (codec->name );
256
- OptionArray options;
257
285
loadOptions (options, (void *)&codec->priv_class , 0 );
258
- audioCodecOptions.insert (std::make_pair (audioCodecName, options));
259
286
}
287
+ audioCodecOptions.insert (std::make_pair (audioCodecName, options));
260
288
}
261
289
codec = av_codec_next (codec);
262
290
}
0 commit comments