Skip to content

Commit a269316

Browse files
author
Clement Champetier
committed
OptionLoader: add getPixelFormats
* Returns the list of supported pixel formats depending on the video codec.
1 parent 4690467 commit a269316

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

src/AvTranscoder/OptionLoader.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ extern "C" {
55
#define __STDC_CONSTANT_MACROS
66
#endif
77
#include <libavutil/opt.h>
8+
#include <libavutil/pixfmt.h>
9+
#include <libavutil/pixdesc.h>
810
}
911

1012
#include <string>
@@ -270,4 +272,33 @@ OptionLoader::OptionArray OptionLoader::loadOptions( void* av_class, int req_fla
270272
return options;
271273
}
272274

275+
std::vector<std::string> OptionLoader::getPixelFormats ( const std::string& videoCodecName ) const
276+
{
277+
std::vector<std::string> pixelFormats;
278+
279+
AVCodec* videoCodec = avcodec_find_encoder_by_name( videoCodecName.c_str() );
280+
281+
if( videoCodec->pix_fmts == 0 )
282+
{
283+
for( int pix_fmt = 0; pix_fmt < PIX_FMT_NB; pix_fmt++ )
284+
{
285+
const AVPixFmtDescriptor* pix_desc = &av_pix_fmt_descriptors[pix_fmt];
286+
if( ! pix_desc->name )
287+
continue;
288+
pixelFormats.push_back( std::string( pix_desc->name ) );
289+
}
290+
return pixelFormats;
291+
}
292+
293+
int i = 0;
294+
while( videoCodec->pix_fmts[i] != -1 )
295+
{
296+
const AVPixFmtDescriptor* pix_desc = &av_pix_fmt_descriptors[ videoCodec->pix_fmts[i] ];
297+
pixelFormats.push_back( std::string( pix_desc->name ) );
298+
i++;
299+
}
300+
301+
return pixelFormats;
302+
}
303+
273304
}

src/AvTranscoder/OptionLoader.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ class OptionLoader
6161
std::vector<std::string>& getAudioCodecsLongNames() { return m_audioCodecsLongNames; }
6262
std::vector<std::string>& getAudioCodecsShortNames() { return m_audioCodecsShortNames; }
6363

64+
/**
65+
* Get array of pixel format supported by video codec.
66+
*/
67+
std::vector<std::string> getPixelFormats( const std::string& videoCodecName ) const;
68+
6469
private:
6570
/**
6671
* @brief: load array of Option depending on the flags.

0 commit comments

Comments
 (0)