Skip to content

Commit

Permalink
Merge pull request #142 from cchampet/hotfix_getFormatsAndCodecsName
Browse files Browse the repository at this point in the history
Hotfix: get formats and codecs name
  • Loading branch information
valnoel committed Mar 25, 2015
2 parents b06a78f + 5cf90ee commit 05389cd
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 118 deletions.
8 changes: 2 additions & 6 deletions src/AvTranscoder/avTranscoder.i
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,19 @@

%{
#include <AvTranscoder/Library.hpp>
#include <AvTranscoder/Option.hpp>
#include <AvTranscoder/log.hpp>
%}

namespace std {
%template(IntPair) pair< size_t, size_t >;
}

%include "AvTranscoder/progress/progress.i"
%include "AvTranscoder/mediaProperty/mediaProperty.i"
%include "AvTranscoder/frame/frame.i"
%include "AvTranscoder/profile/profile.i"

%include <AvTranscoder/Library.hpp>
%include <AvTranscoder/Option.hpp>
%include <AvTranscoder/log.hpp>

%include "AvTranscoder/option.i"
%include "AvTranscoder/util.i"
%include "AvTranscoder/codec/codec.i"
%include "AvTranscoder/stream/stream.i"
%include "AvTranscoder/decoder/decoder.i"
Expand Down
15 changes: 15 additions & 0 deletions src/AvTranscoder/option.i
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
%{
#include <AvTranscoder/Option.hpp>
%}

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 <AvTranscoder/Option.hpp>
110 changes: 17 additions & 93 deletions src/AvTranscoder/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ extern "C" {
#include <libavutil/pixdesc.h>
}

#include <utility>

namespace avtranscoder
{

Expand Down Expand Up @@ -116,27 +118,9 @@ AVSampleFormat getAVSampleFormat( const std::string& sampleFormat )
return av_get_sample_fmt( sampleFormat.c_str() );
}

std::vector<std::string> getFormatsLongNames()
{
std::vector<std::string> 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<std::string> getFormatsShortNames()
NamesArray getFormatsNames()
{
std::vector<std::string> formatsShortNames;
NamesArray formatsNames;

AVOutputFormat* fmt = NULL;
while( ( fmt = av_oformat_next( fmt ) ) )
Expand All @@ -145,47 +129,17 @@ std::vector<std::string> 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<std::string> getVideoCodecsLongNames()
{
std::vector<std::string> 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<std::string> getVideoCodecsShortNames()
NamesArray getVideoCodecsNames()
{
std::vector<std::string> videoCodecsShortNames;
NamesArray videoCodecsNames;

AVCodec* c = NULL;
while( ( c = av_codec_next( c ) ) != NULL )
Expand All @@ -201,52 +155,22 @@ std::vector<std::string> 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<std::string> getAudioCodecsLongNames()
{
std::vector<std::string> 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<std::string> getAudioCodecsShortNames()
NamesArray getAudioCodecsNames()
{
std::vector<std::string> audioCodecsShortNames;
NamesArray audioCodecsNames;

AVCodec* c = NULL;
while( ( c = av_codec_next( c ) ) != NULL )
Expand All @@ -262,17 +186,17 @@ std::vector<std::string> 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()
Expand Down
33 changes: 14 additions & 19 deletions src/AvTranscoder/util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ namespace avtranscoder
{

typedef std::map<std::string, OptionArray> OptionArrayMap;
typedef std::vector< std::pair<std::string, std::string> > NamesArray; //< short/long names of format/video codec/audio codec

/**
* @brief Get format name from a given filename
Expand All @@ -32,61 +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<std::string> getPixelFormats( const std::string& videoCodecName = "" );
std::vector<std::string> 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<std::string> getSampleFormats( const std::string& audioCodecName = "" );
std::vector<std::string> 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 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<std::string> getFormatsLongNames();
std::vector<std::string> getFormatsShortNames();
NamesArray AvExport 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<std::string> getVideoCodecsLongNames();
std::vector<std::string> getVideoCodecsShortNames();
NamesArray AvExport 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<std::string> getAudioCodecsLongNames();
std::vector<std::string> getAudioCodecsShortNames();
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();

}

Expand Down
9 changes: 9 additions & 0 deletions src/AvTranscoder/util.i
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
%{
#include <AvTranscoder/util.hpp>
%}

namespace std {
%template(StrVector) vector< string >;
}

%include <AvTranscoder/util.hpp>

0 comments on commit 05389cd

Please sign in to comment.