Skip to content

Commit 44f1f41

Browse files
author
Clement Champetier
committed
OptionLoader: add functions to load video / audio codec options
* 2 functions: * loadVideoCodecOptions. * loadVideoCodecOptions. * These functions return an OptionMap: * first: codec name (string). * second: vector of related Options.
1 parent 7504d2d commit 44f1f41

File tree

2 files changed

+75
-0
lines changed

2 files changed

+75
-0
lines changed

src/AvTranscoder/OptionLoader.cpp

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@ OptionLoader::OptionLoader()
2121
, m_outputFormat( NULL )
2222
, m_codec( NULL )
2323
{
24+
// Alloc format context
2425
m_avFormatContext = avformat_alloc_context();
2526

27+
// Alloc codec context
2628
#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT( 53, 8, 0 )
2729
m_avCodecContext = avcodec_alloc_context();
2830
// deprecated in the same version
@@ -79,6 +81,77 @@ OptionLoader::OptionMap OptionLoader::loadOutputFormatOptions()
7981
return outputFormatOptions;
8082
}
8183

84+
OptionLoader::OptionMap OptionLoader::loadVideoCodecOptions()
85+
{
86+
OptionMap videoCodecOptions;
87+
88+
m_codec = av_codec_next( NULL );
89+
90+
// iterate on codecs
91+
while( m_codec )
92+
{
93+
#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT( 53, 34, 0 )
94+
if( m_codec->encode2 )
95+
#else
96+
if( m_codec->encode )
97+
#endif
98+
{
99+
// add only video codec
100+
if( m_codec->type == AVMEDIA_TYPE_VIDEO )
101+
{
102+
if( m_codec->priv_class )
103+
{
104+
std::string videoCodecName( m_codec->name );
105+
OptionArray optionsArray = loadOptions( (void*)&m_codec->priv_class );
106+
107+
videoCodecOptions.insert(
108+
std::pair< std::string, OptionArray >(
109+
videoCodecName,
110+
optionsArray )
111+
);
112+
}
113+
}
114+
}
115+
m_codec = av_codec_next( m_codec );
116+
}
117+
return videoCodecOptions;
118+
}
119+
120+
OptionLoader::OptionMap OptionLoader::loadAudioCodecOptions()
121+
{
122+
OptionMap audioCodecOptions;
123+
124+
m_codec = av_codec_next( NULL );
125+
126+
// iterate on codecs
127+
while( m_codec )
128+
{
129+
#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT( 53, 34, 0 )
130+
if( m_codec->encode2 )
131+
#else
132+
if( m_codec->encode )
133+
#endif
134+
{
135+
// add only audio codec
136+
if( m_codec->type == AVMEDIA_TYPE_AUDIO )
137+
{
138+
if( m_codec->priv_class )
139+
{
140+
std::string audioCodecName( m_codec->name );
141+
OptionArray optionsArray = loadOptions( (void*)&m_codec->priv_class );
142+
143+
audioCodecOptions.insert(
144+
std::pair< std::string, OptionArray >(
145+
audioCodecName,
146+
optionsArray )
147+
);
148+
}
149+
}
150+
}
151+
m_codec = av_codec_next( m_codec );
152+
}
153+
return audioCodecOptions;
154+
}
82155

83156
OptionLoader::OptionArray OptionLoader::loadOptions( void* av_class, int req_flags )
84157
{

src/AvTranscoder/OptionLoader.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ class OptionLoader
4949
OptionArray loadCodecContextOptions( int req_flags = 0 );
5050

5151
OptionMap loadOutputFormatOptions();
52+
OptionMap loadVideoCodecOptions();
53+
OptionMap loadAudioCodecOptions();
5254
private:
5355
/**
5456
* @brief: load array of Option depending on the flags.

0 commit comments

Comments
 (0)