Skip to content

Commit 8a98e1a

Browse files
author
Clement Champetier
committed
OptionLoader: get all pixel formats supported by all video codecs
* To do this, call getPixelFormats function with no videoCodec informed (empty string by default).
1 parent ad206cf commit 8a98e1a

File tree

2 files changed

+22
-14
lines changed

2 files changed

+22
-14
lines changed

src/AvTranscoder/OptionLoader.cpp

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -276,28 +276,35 @@ std::vector<std::string> OptionLoader::getPixelFormats ( const std::string& vide
276276
{
277277
std::vector<std::string> pixelFormats;
278278

279-
AVCodec* videoCodec = avcodec_find_encoder_by_name( videoCodecName.c_str() );
280-
281-
if( videoCodec->pix_fmts == 0 )
279+
// all video codec concerned
280+
if( videoCodecName == "" )
282281
{
283-
for( int pix_fmt = 0; pix_fmt < PIX_FMT_NB; pix_fmt++ )
282+
for( int pix_fmt = 0; pix_fmt < PIX_FMT_NB; ++pix_fmt )
284283
{
285-
const AVPixFmtDescriptor* pix_desc = &av_pix_fmt_descriptors[pix_fmt];
284+
const AVPixFmtDescriptor *pix_desc = &av_pix_fmt_descriptors[pix_fmt];
286285
if( ! pix_desc->name )
287286
continue;
288287
pixelFormats.push_back( std::string( pix_desc->name ) );
289288
}
290-
return pixelFormats;
291289
}
292-
293-
int i = 0;
294-
while( videoCodec->pix_fmts[i] != -1 )
290+
// specific video codec
291+
else
295292
{
296-
const AVPixFmtDescriptor* pix_desc = &av_pix_fmt_descriptors[ videoCodec->pix_fmts[i] ];
297-
pixelFormats.push_back( std::string( pix_desc->name ) );
298-
i++;
293+
AVCodec* videoCodec = avcodec_find_encoder_by_name( videoCodecName.c_str() );
294+
295+
if( videoCodec->pix_fmts != NULL )
296+
{
297+
size_t pix_fmt = 0;
298+
while( videoCodec->pix_fmts[pix_fmt] != -1 )
299+
{
300+
const AVPixFmtDescriptor* pix_desc = &av_pix_fmt_descriptors[ videoCodec->pix_fmts[pix_fmt] ];
301+
if( ! pix_desc->name )
302+
continue;
303+
pixelFormats.push_back( std::string( pix_desc->name ) );
304+
++pix_fmt;
305+
}
306+
}
299307
}
300-
301308
return pixelFormats;
302309
}
303310

src/AvTranscoder/OptionLoader.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,9 @@ class OptionLoader
6363

6464
/**
6565
* Get array of pixel format supported by video codec.
66+
* @param videoCodecName: the video codec name (empty if not indicated, and so get all pixel formats supported by all video codecs).
6667
*/
67-
std::vector<std::string> getPixelFormats( const std::string& videoCodecName ) const;
68+
std::vector<std::string> getPixelFormats( const std::string& videoCodecName = "" ) const;
6869

6970
private:
7071
/**

0 commit comments

Comments
 (0)