Skip to content

Fix util functions #162

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Apr 16, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
107 changes: 39 additions & 68 deletions src/AvTranscoder/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ extern "C" {
}

#include <utility>
#include <algorithm>

namespace avtranscoder
{
Expand Down Expand Up @@ -144,25 +145,18 @@ NamesArray getVideoCodecsNames()
AVCodec* c = NULL;
while( ( c = av_codec_next( c ) ) != NULL )
{
#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT( 53, 34, 0 )
if( ! c->encode )
continue;
#else
if( ! c->encode2 )
continue;
#endif
switch( c->type )
if( c->type == AVMEDIA_TYPE_VIDEO)
{
case AVMEDIA_TYPE_VIDEO:
{
if( ! c->name && ! c->long_name )
continue;
if( ! c->name && ! c->long_name )
continue;

videoCodecsNames.push_back( std::make_pair( std::string( c->name ? c->name : "" ), std::string( c->long_name ? c->long_name : "" ) ) );
break;
}
default:
break;
std::pair< std::string, std::string > codecNames( std::string( c->name ? c->name : "" ), std::string( c->long_name ? c->long_name : "" ) );

// skip duplicates
if( std::find( videoCodecsNames.begin(), videoCodecsNames.end(), codecNames ) != videoCodecsNames.end() )
continue;

videoCodecsNames.push_back( codecNames );
}
}
return videoCodecsNames;
Expand All @@ -175,35 +169,26 @@ NamesArray getAudioCodecsNames()
AVCodec* c = NULL;
while( ( c = av_codec_next( c ) ) != NULL )
{
#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT( 53, 34, 0 )
if( ! c->encode )
continue;
#else
if( ! c->encode2 )
continue;
#endif
switch( c->type )
if( c->type == AVMEDIA_TYPE_AUDIO )
{
case AVMEDIA_TYPE_AUDIO:
{
if( ! c->name && ! c->long_name )
continue;
if( ! c->name && ! c->long_name )
continue;

audioCodecsNames.push_back( std::make_pair( std::string( c->name ? c->name : "" ), std::string( c->long_name ? c->long_name : "" ) ) );
break;
}
default:
break;
std::pair< std::string, std::string > codecNames( std::string( c->name ? c->name : "" ), std::string( c->long_name ? c->long_name : "" ) );

// skip duplicates
if( std::find( audioCodecsNames.begin(), audioCodecsNames.end(), codecNames ) != audioCodecsNames.end() )
continue;

audioCodecsNames.push_back( codecNames );
}
}
return audioCodecsNames;
}

OptionArrayMap getOutputFormatOptions()
{
av_register_all();

std::map< std::string, std::vector<Option> > optionsPerFormat;
OptionArrayMap optionsPerFormat;

AVOutputFormat* outputFormat = av_oformat_next( NULL );

Expand All @@ -216,7 +201,7 @@ OptionArrayMap getOutputFormatOptions()
{
if( outputFormat->priv_class )
{
std::string outputFormatName( outputFormat->name );
const std::string outputFormatName( outputFormat->name );
OptionArray options;
loadOptions( options, (void*)&outputFormat->priv_class, 0 );
optionsPerFormat.insert( std::make_pair( outputFormatName, options ) );
Expand All @@ -229,29 +214,22 @@ OptionArrayMap getOutputFormatOptions()

OptionArrayMap getVideoCodecOptions()
{
std::map< std::string, std::vector<Option> > videoCodecOptions;
OptionArrayMap videoCodecOptions;

AVCodec* codec = av_codec_next( NULL );

// iterate on codecs
while( codec )
{
#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT( 53, 34, 0 )
if( codec->encode )
#else
if( codec->encode2 )
#endif
// add only video codec
if( codec->type == AVMEDIA_TYPE_VIDEO )
{
// add only video codec
if( codec->type == AVMEDIA_TYPE_VIDEO )
if( codec->priv_class )
{
if( codec->priv_class )
{
std::string videoCodecName( codec->name );
OptionArray options;
loadOptions( options, (void*)&codec->priv_class, 0 );
videoCodecOptions.insert( std::make_pair( videoCodecName, options ) );
}
std::string videoCodecName( codec->name );
OptionArray options;
loadOptions( options, (void*)&codec->priv_class, 0 );
videoCodecOptions.insert( std::make_pair( videoCodecName, options ) );
}
}
codec = av_codec_next( codec );
Expand All @@ -261,29 +239,22 @@ OptionArrayMap getVideoCodecOptions()

OptionArrayMap getAudioCodecOptions()
{
std::map< std::string, std::vector<Option> > audioCodecOptions;
OptionArrayMap audioCodecOptions;

AVCodec* codec = av_codec_next( NULL );

// iterate on codecs
while( codec )
{
#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT( 53, 34, 0 )
if( codec->encode )
#else
if( codec->encode2 )
#endif
// add only audio codec
if( codec->type == AVMEDIA_TYPE_AUDIO )
{
// add only audio codec
if( codec->type == AVMEDIA_TYPE_AUDIO )
if( codec->priv_class )
{
if( codec->priv_class )
{
std::string audioCodecName( codec->name );
OptionArray options;
loadOptions( options, (void*)&codec->priv_class, 0 );
audioCodecOptions.insert( std::make_pair( audioCodecName, options ) );
}
std::string audioCodecName( codec->name );
OptionArray options;
loadOptions( options, (void*)&codec->priv_class, 0 );
audioCodecOptions.insert( std::make_pair( audioCodecName, options ) );
}
}
codec = av_codec_next( codec );
Expand Down