Skip to content

Commit 05389cd

Browse files
committed
Merge pull request #142 from cchampet/hotfix_getFormatsAndCodecsName
Hotfix: get formats and codecs name
2 parents b06a78f + 5cf90ee commit 05389cd

File tree

5 files changed

+57
-118
lines changed

5 files changed

+57
-118
lines changed

src/AvTranscoder/avTranscoder.i

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,19 @@
1616

1717
%{
1818
#include <AvTranscoder/Library.hpp>
19-
#include <AvTranscoder/Option.hpp>
2019
#include <AvTranscoder/log.hpp>
2120
%}
2221

23-
namespace std {
24-
%template(IntPair) pair< size_t, size_t >;
25-
}
26-
2722
%include "AvTranscoder/progress/progress.i"
2823
%include "AvTranscoder/mediaProperty/mediaProperty.i"
2924
%include "AvTranscoder/frame/frame.i"
3025
%include "AvTranscoder/profile/profile.i"
3126

3227
%include <AvTranscoder/Library.hpp>
33-
%include <AvTranscoder/Option.hpp>
3428
%include <AvTranscoder/log.hpp>
3529

30+
%include "AvTranscoder/option.i"
31+
%include "AvTranscoder/util.i"
3632
%include "AvTranscoder/codec/codec.i"
3733
%include "AvTranscoder/stream/stream.i"
3834
%include "AvTranscoder/decoder/decoder.i"

src/AvTranscoder/option.i

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
%{
2+
#include <AvTranscoder/Option.hpp>
3+
%}
4+
5+
namespace std {
6+
// Allow vector of object with no default constructor
7+
%ignore vector< avtranscoder::Option >::vector(size_type);
8+
%ignore vector< avtranscoder::Option >::resize;
9+
10+
// Create instantiations of a template classes
11+
%template(OptionArray) vector< avtranscoder::Option >;
12+
%template(IntPair) pair< size_t, size_t >;
13+
}
14+
15+
%include <AvTranscoder/Option.hpp>

src/AvTranscoder/util.cpp

Lines changed: 17 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ extern "C" {
66
#include <libavutil/pixdesc.h>
77
}
88

9+
#include <utility>
10+
911
namespace avtranscoder
1012
{
1113

@@ -116,27 +118,9 @@ AVSampleFormat getAVSampleFormat( const std::string& sampleFormat )
116118
return av_get_sample_fmt( sampleFormat.c_str() );
117119
}
118120

119-
std::vector<std::string> getFormatsLongNames()
120-
{
121-
std::vector<std::string> formatsLongNames;
122-
123-
AVOutputFormat* fmt = NULL;
124-
while( ( fmt = av_oformat_next( fmt ) ) )
125-
{
126-
// skip undefined codec
127-
if( fmt->video_codec == AV_CODEC_ID_NONE )
128-
continue;
129-
130-
if( ! fmt->long_name )
131-
continue;
132-
133-
formatsLongNames.push_back( std::string( fmt->long_name ) );
134-
}
135-
return formatsLongNames;
136-
}
137-
std::vector<std::string> getFormatsShortNames()
121+
NamesArray getFormatsNames()
138122
{
139-
std::vector<std::string> formatsShortNames;
123+
NamesArray formatsNames;
140124

141125
AVOutputFormat* fmt = NULL;
142126
while( ( fmt = av_oformat_next( fmt ) ) )
@@ -145,47 +129,17 @@ std::vector<std::string> getFormatsShortNames()
145129
if( fmt->video_codec == AV_CODEC_ID_NONE )
146130
continue;
147131

148-
if( ! fmt->name )
132+
if( ! fmt->name && ! fmt->long_name )
149133
continue;
150134

151-
formatsShortNames.push_back( std::string( fmt->name ) );
135+
formatsNames.push_back( std::make_pair( std::string( fmt->name ? fmt->name : "" ), std::string( fmt->long_name ? fmt->long_name : "" ) ) );
152136
}
153-
return formatsShortNames;
137+
return formatsNames;
154138
}
155139

156-
std::vector<std::string> getVideoCodecsLongNames()
157-
{
158-
std::vector<std::string> videoCodecsLongNames;
159-
160-
AVCodec* c = NULL;
161-
while( ( c = av_codec_next( c ) ) != NULL )
162-
{
163-
#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT( 53, 34, 0 )
164-
if( ! c->encode )
165-
continue;
166-
#else
167-
if( ! c->encode2 )
168-
continue;
169-
#endif
170-
switch( c->type )
171-
{
172-
case AVMEDIA_TYPE_VIDEO:
173-
{
174-
if( ! c->long_name )
175-
continue;
176-
177-
videoCodecsLongNames.push_back( std::string( c->long_name ) );
178-
break;
179-
}
180-
default:
181-
break;
182-
}
183-
}
184-
return videoCodecsLongNames;
185-
}
186-
std::vector<std::string> getVideoCodecsShortNames()
140+
NamesArray getVideoCodecsNames()
187141
{
188-
std::vector<std::string> videoCodecsShortNames;
142+
NamesArray videoCodecsNames;
189143

190144
AVCodec* c = NULL;
191145
while( ( c = av_codec_next( c ) ) != NULL )
@@ -201,52 +155,22 @@ std::vector<std::string> getVideoCodecsShortNames()
201155
{
202156
case AVMEDIA_TYPE_VIDEO:
203157
{
204-
if( ! c->name )
158+
if( ! c->name && ! c->long_name )
205159
continue;
206160

207-
videoCodecsShortNames.push_back( std::string( c->name ) );
161+
videoCodecsNames.push_back( std::make_pair( std::string( c->name ? c->name : "" ), std::string( c->long_name ? c->long_name : "" ) ) );
208162
break;
209163
}
210164
default:
211165
break;
212166
}
213167
}
214-
return videoCodecsShortNames;
168+
return videoCodecsNames;
215169
}
216170

217-
std::vector<std::string> getAudioCodecsLongNames()
218-
{
219-
std::vector<std::string> audioCodecsLongNames;
220-
221-
AVCodec* c = NULL;
222-
while( ( c = av_codec_next( c ) ) != NULL )
223-
{
224-
#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT( 53, 34, 0 )
225-
if( ! c->encode )
226-
continue;
227-
#else
228-
if( ! c->encode2 )
229-
continue;
230-
#endif
231-
switch( c->type )
232-
{
233-
case AVMEDIA_TYPE_AUDIO:
234-
{
235-
if( ! c->long_name )
236-
continue;
237-
238-
audioCodecsLongNames.push_back( std::string( c->long_name ) );
239-
break;
240-
}
241-
default:
242-
break;
243-
}
244-
}
245-
return audioCodecsLongNames;
246-
}
247-
std::vector<std::string> getAudioCodecsShortNames()
171+
NamesArray getAudioCodecsNames()
248172
{
249-
std::vector<std::string> audioCodecsShortNames;
173+
NamesArray audioCodecsNames;
250174

251175
AVCodec* c = NULL;
252176
while( ( c = av_codec_next( c ) ) != NULL )
@@ -262,17 +186,17 @@ std::vector<std::string> getAudioCodecsShortNames()
262186
{
263187
case AVMEDIA_TYPE_AUDIO:
264188
{
265-
if( ! c->name )
189+
if( ! c->name && ! c->long_name )
266190
continue;
267191

268-
audioCodecsShortNames.push_back( std::string( c->name ) );
192+
audioCodecsNames.push_back( std::make_pair( std::string( c->name ? c->name : "" ), std::string( c->long_name ? c->long_name : "" ) ) );
269193
break;
270194
}
271195
default:
272196
break;
273197
}
274198
}
275-
return audioCodecsShortNames;
199+
return audioCodecsNames;
276200
}
277201

278202
OptionArrayMap getOutputFormatOptions()

src/AvTranscoder/util.hpp

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ namespace avtranscoder
1717
{
1818

1919
typedef std::map<std::string, OptionArray> OptionArrayMap;
20+
typedef std::vector< std::pair<std::string, std::string> > NamesArray; //< short/long names of format/video codec/audio codec
2021

2122
/**
2223
* @brief Get format name from a given filename
@@ -32,61 +33,55 @@ bool AvExport matchFormat( const std::string& format, const std::string& filenam
3233
* @brief Get pixel format supported by a video codec.
3334
* @param videoCodecName: the video codec name (empty if not indicated, and so get all pixel formats supported by all video codecs).
3435
*/
35-
std::vector<std::string> getPixelFormats( const std::string& videoCodecName = "" );
36+
std::vector<std::string> AvExport getPixelFormats( const std::string& videoCodecName = "" );
3637

3738
/**
3839
* @brief Get sample format supported by an audio codec.
3940
* @param audioCodecName: the audio codec name (empty if not indicated, and so get all sample formats supported by all audio codecs).
4041
*/
41-
std::vector<std::string> getSampleFormats( const std::string& audioCodecName = "" );
42+
std::vector<std::string> AvExport getSampleFormats( const std::string& audioCodecName = "" );
4243

4344
/**
4445
* @brief Get the corresponding AVPixelFormat from the pixel format name
4546
* @param pixelFormat: the name of the pixel format
4647
*/
47-
AVPixelFormat getAVPixelFormat( const std::string& pixelFormat );
48+
AVPixelFormat AvExport getAVPixelFormat( const std::string& pixelFormat );
4849

4950
/**
5051
* @brief Get the corresponding AVSampleFormat from the sample format name
5152
* @param sampleFormat: the name of the sample format
5253
*/
53-
AVSampleFormat getAVSampleFormat( const std::string& sampleFormat );
54+
AVSampleFormat AvExport getAVSampleFormat( const std::string& sampleFormat );
5455

5556
/**
56-
* @brief Get long name of all format supported by FFmpeg / libav.
57-
* @see getFormatsShortNames: to get short names
57+
* @brief Get array of short/long names of all format supported by FFmpeg / libav.
5858
*/
59-
std::vector<std::string> getFormatsLongNames();
60-
std::vector<std::string> getFormatsShortNames();
59+
NamesArray AvExport getFormatsNames();
6160

6261
/**
63-
* @brief Get long name of all video codec supported by FFmpeg / libav.
64-
* @see getVideoCodecsShortNames: to get short names
62+
* @brief Get array of short/long names of all video codec supported by FFmpeg / libav.
6563
*/
66-
std::vector<std::string> getVideoCodecsLongNames();
67-
std::vector<std::string> getVideoCodecsShortNames();
64+
NamesArray AvExport getVideoCodecsNames();
6865

6966
/**
70-
* @brief Get long name of all audio codec supported by FFmpeg / libav.
71-
* @see getAudioCodecsShortNames: to get short names
67+
* @brief Get array of short/long names of all audio codec supported by FFmpeg / libav.
7268
*/
73-
std::vector<std::string> getAudioCodecsLongNames();
74-
std::vector<std::string> getAudioCodecsShortNames();
69+
NamesArray AvExport getAudioCodecsNames();
7570

7671
/**
7772
* @brief Get the list of options for each output format
7873
*/
79-
OptionArrayMap getOutputFormatOptions();
74+
OptionArrayMap AvExport getOutputFormatOptions();
8075

8176
/**
8277
* @brief Get the list of options for each video codec
8378
*/
84-
OptionArrayMap getVideoCodecOptions();
79+
OptionArrayMap AvExport getVideoCodecOptions();
8580

8681
/**
8782
* @brief Get the list of options for each audio codec
8883
*/
89-
OptionArrayMap getAudioCodecOptions();
84+
OptionArrayMap AvExport getAudioCodecOptions();
9085

9186
}
9287

src/AvTranscoder/util.i

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
%{
2+
#include <AvTranscoder/util.hpp>
3+
%}
4+
5+
namespace std {
6+
%template(StrVector) vector< string >;
7+
}
8+
9+
%include <AvTranscoder/util.hpp>

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy