@@ -7,6 +7,7 @@ extern "C" {
7
7
}
8
8
9
9
#include < utility>
10
+ #include < algorithm>
10
11
11
12
namespace avtranscoder
12
13
{
@@ -144,25 +145,18 @@ NamesArray getVideoCodecsNames()
144
145
AVCodec* c = NULL ;
145
146
while ( ( c = av_codec_next ( c ) ) != NULL )
146
147
{
147
- #if LIBAVCODEC_VERSION_INT < AV_VERSION_INT( 53, 34, 0 )
148
- if ( ! c->encode )
149
- continue ;
150
- #else
151
- if ( ! c->encode2 )
152
- continue ;
153
- #endif
154
- switch ( c->type )
148
+ if ( c->type == AVMEDIA_TYPE_VIDEO)
155
149
{
156
- case AVMEDIA_TYPE_VIDEO:
157
- {
158
- if ( ! c->name && ! c->long_name )
159
- continue ;
150
+ if ( ! c->name && ! c->long_name )
151
+ continue ;
160
152
161
- videoCodecsNames.push_back ( std::make_pair ( std::string ( c->name ? c->name : " " ), std::string ( c->long_name ? c->long_name : " " ) ) );
162
- break ;
163
- }
164
- default :
165
- break ;
153
+ std::pair< std::string, std::string > codecNames ( std::string ( c->name ? c->name : " " ), std::string ( c->long_name ? c->long_name : " " ) );
154
+
155
+ // skip duplicates
156
+ if ( std::find ( videoCodecsNames.begin (), videoCodecsNames.end (), codecNames ) != videoCodecsNames.end () )
157
+ continue ;
158
+
159
+ videoCodecsNames.push_back ( codecNames );
166
160
}
167
161
}
168
162
return videoCodecsNames;
@@ -175,35 +169,26 @@ NamesArray getAudioCodecsNames()
175
169
AVCodec* c = NULL ;
176
170
while ( ( c = av_codec_next ( c ) ) != NULL )
177
171
{
178
- #if LIBAVCODEC_VERSION_INT < AV_VERSION_INT( 53, 34, 0 )
179
- if ( ! c->encode )
180
- continue ;
181
- #else
182
- if ( ! c->encode2 )
183
- continue ;
184
- #endif
185
- switch ( c->type )
172
+ if ( c->type == AVMEDIA_TYPE_AUDIO )
186
173
{
187
- case AVMEDIA_TYPE_AUDIO:
188
- {
189
- if ( ! c->name && ! c->long_name )
190
- continue ;
174
+ if ( ! c->name && ! c->long_name )
175
+ continue ;
191
176
192
- audioCodecsNames.push_back ( std::make_pair ( std::string ( c->name ? c->name : " " ), std::string ( c->long_name ? c->long_name : " " ) ) );
193
- break ;
194
- }
195
- default :
196
- break ;
177
+ std::pair< std::string, std::string > codecNames ( std::string ( c->name ? c->name : " " ), std::string ( c->long_name ? c->long_name : " " ) );
178
+
179
+ // skip duplicates
180
+ if ( std::find ( audioCodecsNames.begin (), audioCodecsNames.end (), codecNames ) != audioCodecsNames.end () )
181
+ continue ;
182
+
183
+ audioCodecsNames.push_back ( codecNames );
197
184
}
198
185
}
199
186
return audioCodecsNames;
200
187
}
201
188
202
189
OptionArrayMap getOutputFormatOptions ()
203
190
{
204
- av_register_all ();
205
-
206
- std::map< std::string, std::vector<Option> > optionsPerFormat;
191
+ OptionArrayMap optionsPerFormat;
207
192
208
193
AVOutputFormat* outputFormat = av_oformat_next ( NULL );
209
194
@@ -216,7 +201,7 @@ OptionArrayMap getOutputFormatOptions()
216
201
{
217
202
if ( outputFormat->priv_class )
218
203
{
219
- std::string outputFormatName ( outputFormat->name );
204
+ const std::string outputFormatName ( outputFormat->name );
220
205
OptionArray options;
221
206
loadOptions ( options, (void *)&outputFormat->priv_class , 0 );
222
207
optionsPerFormat.insert ( std::make_pair ( outputFormatName, options ) );
@@ -229,29 +214,22 @@ OptionArrayMap getOutputFormatOptions()
229
214
230
215
OptionArrayMap getVideoCodecOptions ()
231
216
{
232
- std::map< std::string, std::vector<Option> > videoCodecOptions;
217
+ OptionArrayMap videoCodecOptions;
233
218
234
219
AVCodec* codec = av_codec_next ( NULL );
235
220
236
221
// iterate on codecs
237
222
while ( codec )
238
223
{
239
- #if LIBAVCODEC_VERSION_INT < AV_VERSION_INT( 53, 34, 0 )
240
- if ( codec->encode )
241
- #else
242
- if ( codec->encode2 )
243
- #endif
224
+ // add only video codec
225
+ if ( codec->type == AVMEDIA_TYPE_VIDEO )
244
226
{
245
- // add only video codec
246
- if ( codec->type == AVMEDIA_TYPE_VIDEO )
227
+ if ( codec->priv_class )
247
228
{
248
- if ( codec->priv_class )
249
- {
250
- std::string videoCodecName ( codec->name );
251
- OptionArray options;
252
- loadOptions ( options, (void *)&codec->priv_class , 0 );
253
- videoCodecOptions.insert ( std::make_pair ( videoCodecName, options ) );
254
- }
229
+ std::string videoCodecName ( codec->name );
230
+ OptionArray options;
231
+ loadOptions ( options, (void *)&codec->priv_class , 0 );
232
+ videoCodecOptions.insert ( std::make_pair ( videoCodecName, options ) );
255
233
}
256
234
}
257
235
codec = av_codec_next ( codec );
@@ -261,29 +239,22 @@ OptionArrayMap getVideoCodecOptions()
261
239
262
240
OptionArrayMap getAudioCodecOptions ()
263
241
{
264
- std::map< std::string, std::vector<Option> > audioCodecOptions;
242
+ OptionArrayMap audioCodecOptions;
265
243
266
244
AVCodec* codec = av_codec_next ( NULL );
267
245
268
246
// iterate on codecs
269
247
while ( codec )
270
248
{
271
- #if LIBAVCODEC_VERSION_INT < AV_VERSION_INT( 53, 34, 0 )
272
- if ( codec->encode )
273
- #else
274
- if ( codec->encode2 )
275
- #endif
249
+ // add only audio codec
250
+ if ( codec->type == AVMEDIA_TYPE_AUDIO )
276
251
{
277
- // add only audio codec
278
- if ( codec->type == AVMEDIA_TYPE_AUDIO )
252
+ if ( codec->priv_class )
279
253
{
280
- if ( codec->priv_class )
281
- {
282
- std::string audioCodecName ( codec->name );
283
- OptionArray options;
284
- loadOptions ( options, (void *)&codec->priv_class , 0 );
285
- audioCodecOptions.insert ( std::make_pair ( audioCodecName, options ) );
286
- }
254
+ std::string audioCodecName ( codec->name );
255
+ OptionArray options;
256
+ loadOptions ( options, (void *)&codec->priv_class , 0 );
257
+ audioCodecOptions.insert ( std::make_pair ( audioCodecName, options ) );
287
258
}
288
259
}
289
260
codec = av_codec_next ( codec );
0 commit comments