Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit afe3e4e

Browse files
author
Clement Champetier
committedOct 31, 2014
util: clean getPixel/Sample functions
* Test NULL pointer to avoid possible crash. * Do not skip format name with no video track possible.
1 parent 2e6fd67 commit afe3e4e

File tree

1 file changed

+3
-10
lines changed

1 file changed

+3
-10
lines changed
 

‎src/AvTranscoder/util.cpp‎

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ std::vector<std::string> getPixelFormats( const std::string& videoCodecName )
4141
else
4242
{
4343
const AVCodec* videoCodec = avcodec_find_encoder_by_name( videoCodecName.c_str() );
44-
4544
if( videoCodec && videoCodec->pix_fmts != NULL )
4645
{
4746
size_t pix_fmt = 0;
@@ -52,7 +51,7 @@ std::vector<std::string> getPixelFormats( const std::string& videoCodecName )
5251
#else
5352
const AVPixFmtDescriptor* pix_desc = av_pix_fmt_desc_get( videoCodec->pix_fmts[pix_fmt] );
5453
#endif
55-
if( ! pix_desc->name )
54+
if( ! pix_desc || ! pix_desc->name )
5655
continue;
5756
pixelFormats.push_back( std::string( pix_desc->name ) );
5857
++pix_fmt;
@@ -66,13 +65,15 @@ std::vector<std::string> getSampleFormats( const std::string& audioCodecName )
6665
{
6766
std::vector<std::string> sampleFormats;
6867

68+
// all audio codec concerned
6969
if( audioCodecName.empty() )
7070
{
7171
for( size_t sampleFormat = 0; sampleFormat < AV_SAMPLE_FMT_NB; ++sampleFormat)
7272
{
7373
sampleFormats.push_back( av_get_sample_fmt_name( static_cast<AVSampleFormat>( sampleFormat ) ) );
7474
}
7575
}
76+
// specific audio codec
7677
else
7778
{
7879
const AVCodec* audioCodec = avcodec_find_encoder_by_name( audioCodecName.c_str() );
@@ -109,10 +110,6 @@ std::vector<std::string> getFormatsLongNames()
109110
AVOutputFormat* fmt = NULL;
110111
while( ( fmt = av_oformat_next( fmt ) ) )
111112
{
112-
// add only format with video track
113-
if( fmt->video_codec == AV_CODEC_ID_NONE )
114-
continue;
115-
116113
if( ! fmt->long_name )
117114
continue;
118115

@@ -127,10 +124,6 @@ std::vector<std::string> getFormatsShortNames()
127124
AVOutputFormat* fmt = NULL;
128125
while( ( fmt = av_oformat_next( fmt ) ) )
129126
{
130-
// add only format with video track
131-
if( fmt->video_codec == AV_CODEC_ID_NONE )
132-
continue;
133-
134127
if( ! fmt->name )
135128
continue;
136129

0 commit comments

Comments
 (0)
Failed to load comments.