From 56f322ec1a496cb2a6fe6b7c5ffb2987e2ad0876 Mon Sep 17 00:00:00 2001 From: Clement Champetier Date: Wed, 25 Mar 2015 10:55:33 +0100 Subject: [PATCH 1/4] util: get format/videoCodec/audioCodec names with a map Instead of two functions for each case: short and long names. --- src/AvTranscoder/util.cpp | 110 ++++++-------------------------------- src/AvTranscoder/util.hpp | 19 +++---- 2 files changed, 24 insertions(+), 105 deletions(-) diff --git a/src/AvTranscoder/util.cpp b/src/AvTranscoder/util.cpp index 1d567077..d85bf193 100644 --- a/src/AvTranscoder/util.cpp +++ b/src/AvTranscoder/util.cpp @@ -6,6 +6,8 @@ extern "C" { #include } +#include + namespace avtranscoder { @@ -116,27 +118,9 @@ AVSampleFormat getAVSampleFormat( const std::string& sampleFormat ) return av_get_sample_fmt( sampleFormat.c_str() ); } -std::vector getFormatsLongNames() -{ - std::vector formatsLongNames; - - AVOutputFormat* fmt = NULL; - while( ( fmt = av_oformat_next( fmt ) ) ) - { - // skip undefined codec - if( fmt->video_codec == AV_CODEC_ID_NONE ) - continue; - - if( ! fmt->long_name ) - continue; - - formatsLongNames.push_back( std::string( fmt->long_name ) ); - } - return formatsLongNames; -} -std::vector getFormatsShortNames() +NamesArray getFormatsNames() { - std::vector formatsShortNames; + NamesArray formatsNames; AVOutputFormat* fmt = NULL; while( ( fmt = av_oformat_next( fmt ) ) ) @@ -145,47 +129,17 @@ std::vector getFormatsShortNames() if( fmt->video_codec == AV_CODEC_ID_NONE ) continue; - if( ! fmt->name ) + if( ! fmt->name && ! fmt->long_name ) continue; - formatsShortNames.push_back( std::string( fmt->name ) ); + formatsNames.push_back( std::make_pair( std::string( fmt->name ? fmt->name : "" ), std::string( fmt->long_name ? fmt->long_name : "" ) ) ); } - return formatsShortNames; + return formatsNames; } -std::vector getVideoCodecsLongNames() -{ - std::vector videoCodecsLongNames; - - 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 ) - { - case AVMEDIA_TYPE_VIDEO: - { - if( ! c->long_name ) - continue; - - videoCodecsLongNames.push_back( std::string( c->long_name ) ); - break; - } - default: - break; - } - } - return videoCodecsLongNames; -} -std::vector getVideoCodecsShortNames() +NamesArray getVideoCodecsNames() { - std::vector videoCodecsShortNames; + NamesArray videoCodecsNames; AVCodec* c = NULL; while( ( c = av_codec_next( c ) ) != NULL ) @@ -201,52 +155,22 @@ std::vector getVideoCodecsShortNames() { case AVMEDIA_TYPE_VIDEO: { - if( ! c->name ) + if( ! c->name && ! c->long_name ) continue; - videoCodecsShortNames.push_back( std::string( c->name ) ); + videoCodecsNames.push_back( std::make_pair( std::string( c->name ? c->name : "" ), std::string( c->long_name ? c->long_name : "" ) ) ); break; } default: break; } } - return videoCodecsShortNames; + return videoCodecsNames; } -std::vector getAudioCodecsLongNames() -{ - std::vector audioCodecsLongNames; - - 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 ) - { - case AVMEDIA_TYPE_AUDIO: - { - if( ! c->long_name ) - continue; - - audioCodecsLongNames.push_back( std::string( c->long_name ) ); - break; - } - default: - break; - } - } - return audioCodecsLongNames; -} -std::vector getAudioCodecsShortNames() +NamesArray getAudioCodecsNames() { - std::vector audioCodecsShortNames; + NamesArray audioCodecsNames; AVCodec* c = NULL; while( ( c = av_codec_next( c ) ) != NULL ) @@ -262,17 +186,17 @@ std::vector getAudioCodecsShortNames() { case AVMEDIA_TYPE_AUDIO: { - if( ! c->name ) + if( ! c->name && ! c->long_name ) continue; - audioCodecsShortNames.push_back( std::string( c->name ) ); + audioCodecsNames.push_back( std::make_pair( std::string( c->name ? c->name : "" ), std::string( c->long_name ? c->long_name : "" ) ) ); break; } default: break; } } - return audioCodecsShortNames; + return audioCodecsNames; } OptionArrayMap getOutputFormatOptions() diff --git a/src/AvTranscoder/util.hpp b/src/AvTranscoder/util.hpp index 5c39302e..bde5a27f 100644 --- a/src/AvTranscoder/util.hpp +++ b/src/AvTranscoder/util.hpp @@ -17,6 +17,7 @@ namespace avtranscoder { typedef std::map OptionArrayMap; +typedef std::vector< std::pair > NamesArray; //< short/long names of format/video codec/audio codec /** * @brief Get format name from a given filename @@ -53,25 +54,19 @@ AVPixelFormat getAVPixelFormat( const std::string& pixelFormat ); AVSampleFormat getAVSampleFormat( const std::string& sampleFormat ); /** - * @brief Get long name of all format supported by FFmpeg / libav. - * @see getFormatsShortNames: to get short names + * @brief Get array of short/long names of all format supported by FFmpeg / libav. */ -std::vector getFormatsLongNames(); -std::vector getFormatsShortNames(); +NamesArray getFormatsNames(); /** - * @brief Get long name of all video codec supported by FFmpeg / libav. - * @see getVideoCodecsShortNames: to get short names + * @brief Get array of short/long names of all video codec supported by FFmpeg / libav. */ -std::vector getVideoCodecsLongNames(); -std::vector getVideoCodecsShortNames(); +NamesArray getVideoCodecsNames(); /** - * @brief Get long name of all audio codec supported by FFmpeg / libav. - * @see getAudioCodecsShortNames: to get short names + * @brief Get array of short/long names of all audio codec supported by FFmpeg / libav. */ -std::vector getAudioCodecsLongNames(); -std::vector getAudioCodecsShortNames(); +NamesArray getAudioCodecsNames(); /** * @brief Get the list of options for each output format From c47b8ed6f676d1a42cdcf7885f5bdd9d7ae043a9 Mon Sep 17 00:00:00 2001 From: Clement Champetier Date: Wed, 25 Mar 2015 10:56:24 +0100 Subject: [PATCH 2/4] util: AvExport all functions --- src/AvTranscoder/util.hpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/AvTranscoder/util.hpp b/src/AvTranscoder/util.hpp index bde5a27f..66e4b711 100644 --- a/src/AvTranscoder/util.hpp +++ b/src/AvTranscoder/util.hpp @@ -33,55 +33,55 @@ bool AvExport matchFormat( const std::string& format, const std::string& filenam * @brief Get pixel format supported by a video codec. * @param videoCodecName: the video codec name (empty if not indicated, and so get all pixel formats supported by all video codecs). */ -std::vector getPixelFormats( const std::string& videoCodecName = "" ); +std::vector AvExport getPixelFormats( const std::string& videoCodecName = "" ); /** * @brief Get sample format supported by an audio codec. * @param audioCodecName: the audio codec name (empty if not indicated, and so get all sample formats supported by all audio codecs). */ -std::vector getSampleFormats( const std::string& audioCodecName = "" ); +std::vector AvExport getSampleFormats( const std::string& audioCodecName = "" ); /** * @brief Get the corresponding AVPixelFormat from the pixel format name * @param pixelFormat: the name of the pixel format */ -AVPixelFormat getAVPixelFormat( const std::string& pixelFormat ); +AVPixelFormat AvExport getAVPixelFormat( const std::string& pixelFormat ); /** * @brief Get the corresponding AVSampleFormat from the sample format name * @param sampleFormat: the name of the sample format */ -AVSampleFormat getAVSampleFormat( const std::string& sampleFormat ); +AVSampleFormat AvExport getAVSampleFormat( const std::string& sampleFormat ); /** * @brief Get array of short/long names of all format supported by FFmpeg / libav. */ -NamesArray getFormatsNames(); +NamesArray AvExport getFormatsNames(); /** * @brief Get array of short/long names of all video codec supported by FFmpeg / libav. */ -NamesArray getVideoCodecsNames(); +NamesArray AvExport getVideoCodecsNames(); /** * @brief Get array of short/long names of all audio codec supported by FFmpeg / libav. */ -NamesArray getAudioCodecsNames(); +NamesArray AvExport getAudioCodecsNames(); /** * @brief Get the list of options for each output format */ -OptionArrayMap getOutputFormatOptions(); +OptionArrayMap AvExport getOutputFormatOptions(); /** * @brief Get the list of options for each video codec */ -OptionArrayMap getVideoCodecOptions(); +OptionArrayMap AvExport getVideoCodecOptions(); /** * @brief Get the list of options for each audio codec */ -OptionArrayMap getAudioCodecOptions(); +OptionArrayMap AvExport getAudioCodecOptions(); } From 6cc5adda61356f0223d9e9381a6a5e272131cb97 Mon Sep 17 00:00:00 2001 From: Clement Champetier Date: Wed, 25 Mar 2015 11:13:45 +0100 Subject: [PATCH 3/4] Option: add SWIG interface --- src/AvTranscoder/avTranscoder.i | 3 +-- src/AvTranscoder/option.i | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 src/AvTranscoder/option.i diff --git a/src/AvTranscoder/avTranscoder.i b/src/AvTranscoder/avTranscoder.i index 6ea1ddd8..e3ebaa7a 100644 --- a/src/AvTranscoder/avTranscoder.i +++ b/src/AvTranscoder/avTranscoder.i @@ -16,7 +16,6 @@ %{ #include -#include #include %} @@ -30,9 +29,9 @@ namespace std { %include "AvTranscoder/profile/profile.i" %include -%include %include +%include "AvTranscoder/option.i" %include "AvTranscoder/codec/codec.i" %include "AvTranscoder/stream/stream.i" %include "AvTranscoder/decoder/decoder.i" diff --git a/src/AvTranscoder/option.i b/src/AvTranscoder/option.i new file mode 100644 index 00000000..ff550d2e --- /dev/null +++ b/src/AvTranscoder/option.i @@ -0,0 +1,15 @@ +%{ +#include +%} + +namespace std { +// Allow vector of object with no default constructor +%ignore vector< avtranscoder::Option >::vector(size_type); +%ignore vector< avtranscoder::Option >::resize; + +// Create instantiations of a template classes +%template(OptionArray) vector< avtranscoder::Option >; +%template(IntPair) pair< size_t, size_t >; +} + +%include From 5cf90ee5956626971f0ffa1dbcd9993e70f3a262 Mon Sep 17 00:00:00 2001 From: Clement Champetier Date: Wed, 25 Mar 2015 11:21:34 +0100 Subject: [PATCH 4/4] util: add SWIG interface --- src/AvTranscoder/avTranscoder.i | 5 +---- src/AvTranscoder/util.i | 9 +++++++++ 2 files changed, 10 insertions(+), 4 deletions(-) create mode 100644 src/AvTranscoder/util.i diff --git a/src/AvTranscoder/avTranscoder.i b/src/AvTranscoder/avTranscoder.i index e3ebaa7a..8d463428 100644 --- a/src/AvTranscoder/avTranscoder.i +++ b/src/AvTranscoder/avTranscoder.i @@ -19,10 +19,6 @@ #include %} -namespace std { -%template(IntPair) pair< size_t, size_t >; -} - %include "AvTranscoder/progress/progress.i" %include "AvTranscoder/mediaProperty/mediaProperty.i" %include "AvTranscoder/frame/frame.i" @@ -32,6 +28,7 @@ namespace std { %include %include "AvTranscoder/option.i" +%include "AvTranscoder/util.i" %include "AvTranscoder/codec/codec.i" %include "AvTranscoder/stream/stream.i" %include "AvTranscoder/decoder/decoder.i" diff --git a/src/AvTranscoder/util.i b/src/AvTranscoder/util.i new file mode 100644 index 00000000..f670928f --- /dev/null +++ b/src/AvTranscoder/util.i @@ -0,0 +1,9 @@ +%{ +#include +%} + +namespace std { +%template(StrVector) vector< string >; +} + +%include