Skip to content

Commit e07fb93

Browse files
author
Clement Champetier
committed
OptionLoader: getPixelFormats and getSampleFormats are static
You can get the list of pixel formats and sample formats without an instance of OptionLoader. Conflicts: src/AvTranscoder/OptionLoader.cpp src/AvTranscoder/OptionLoader.hpp
1 parent 24da5e0 commit e07fb93

File tree

2 files changed

+40
-3
lines changed

2 files changed

+40
-3
lines changed

src/AvTranscoder/OptionLoader.cpp

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ OptionLoader::OptionArray OptionLoader::loadOptions( void* av_class, int req_fla
276276
return options;
277277
}
278278

279-
std::vector<std::string> OptionLoader::getPixelFormats( const std::string& videoCodecName ) const
279+
std::vector<std::string> OptionLoader::getPixelFormats( const std::string& videoCodecName )
280280
{
281281
std::vector<std::string> pixelFormats;
282282

@@ -322,4 +322,34 @@ std::vector<std::string> OptionLoader::getPixelFormats( const std::string& video
322322
return pixelFormats;
323323
}
324324

325+
std::vector<std::string> OptionLoader::getSampleFormats( const std::string& audioCodecName )
326+
{
327+
std::vector<std::string> sampleFormats;
328+
329+
if( audioCodecName.empty() )
330+
{
331+
for( size_t sampleFormat = 0; sampleFormat < AV_SAMPLE_FMT_NB; ++sampleFormat)
332+
{
333+
sampleFormats.push_back( av_get_sample_fmt_name( static_cast<AVSampleFormat>( sampleFormat ) ) );
334+
}
335+
}
336+
else
337+
{
338+
const AVCodec* audioCodec = avcodec_find_encoder_by_name( audioCodecName.c_str() );
339+
if( audioCodec && audioCodec->sample_fmts != NULL )
340+
{
341+
size_t sample_fmt = 0;
342+
while( audioCodec->sample_fmts[sample_fmt] != -1 )
343+
{
344+
const char* sampleFormatName = av_get_sample_fmt_name( audioCodec->sample_fmts[sample_fmt] );
345+
if( sampleFormatName )
346+
sampleFormats.push_back( std::string( sampleFormatName ) );
347+
sample_fmt++;
348+
}
349+
}
350+
}
351+
352+
return sampleFormats;
353+
}
354+
325355
}

src/AvTranscoder/OptionLoader.hpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,19 @@ class OptionLoader
6060

6161
std::vector<std::string>& getAudioCodecsLongNames() { return _audioCodecsLongNames; }
6262
std::vector<std::string>& getAudioCodecsShortNames() { return _audioCodecsShortNames; }
63-
63+
64+
public:
6465
/**
6566
* Get array of pixel format supported by video codec.
6667
* @param videoCodecName: the video codec name (empty if not indicated, and so get all pixel formats supported by all video codecs).
6768
*/
68-
std::vector<std::string> getPixelFormats( const std::string& videoCodecName = "" ) const;
69+
static std::vector<std::string> getPixelFormats( const std::string& videoCodecName = "" );
70+
71+
/**
72+
* Get array of sample format supported by an audio codec.
73+
* @param audioCodecName: the audio codec name (empty if not indicated, and so get all sample formats supported by all audio codecs).
74+
*/
75+
static std::vector<std::string> getSampleFormats( const std::string& audioCodecName = "" );
6976

7077
private:
7178
/**

0 commit comments

Comments
 (0)