Skip to content

Commit 39314e1

Browse files
author
Clement Champetier
committed
OptionLoader: add getSampleFormats
1 parent 24da5e0 commit 39314e1

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

src/AvTranscoder/OptionLoader.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ extern "C" {
77
#include <libavutil/opt.h>
88
#include <libavutil/pixfmt.h>
99
#include <libavutil/pixdesc.h>
10+
#include <libavutil/samplefmt.h>
1011
}
1112

1213
#ifndef AV_OPT_FLAG_FILTERING_PARAM
@@ -322,4 +323,34 @@ std::vector<std::string> OptionLoader::getPixelFormats( const std::string& video
322323
return pixelFormats;
323324
}
324325

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

src/AvTranscoder/OptionLoader.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,12 @@ class OptionLoader
6767
*/
6868
std::vector<std::string> getPixelFormats( const std::string& videoCodecName = "" ) const;
6969

70+
/**
71+
* Get array of sample format supported by an audio codec.
72+
* @param audioCodecName: the audio codec name (empty if not indicated, and so get all sample formats supported by all audio codecs).
73+
*/
74+
std::vector<std::string> getSampleFormats( const std::string& audioCodecName = "" ) const;
75+
7076
private:
7177
/**
7278
* @brief: load array of Option depending on the flags.

0 commit comments

Comments
 (0)