@@ -10,15 +10,16 @@ extern "C" {
10
10
#include < string>
11
11
#include < map>
12
12
#include < utility> // pair
13
- #include < exception >
13
+ #include < iostream >
14
14
15
15
namespace avtranscoder
16
16
{
17
17
18
18
OptionLoader::OptionLoader ()
19
- : m_options()
20
- , m_avFormatContext( NULL )
19
+ : m_avFormatContext( NULL )
21
20
, m_avCodecContext( NULL )
21
+ , m_outputFormat( NULL )
22
+ , m_codec( NULL )
22
23
{
23
24
m_avFormatContext = avformat_alloc_context ();
24
25
@@ -38,31 +39,63 @@ OptionLoader::~OptionLoader()
38
39
av_free ( m_avCodecContext );
39
40
}
40
41
41
- void OptionLoader::loadOptions ( int req_flags )
42
+ OptionLoader::OptionArray OptionLoader::loadFormatContextOptions ( int req_flags )
42
43
{
43
- std::map<std::string, int > optionUnitToIndex;
44
- std::vector<Option> childOptions;
44
+ return loadOptions ( (void *)m_avFormatContext, req_flags );
45
+ }
46
+
47
+ OptionLoader::OptionArray OptionLoader::loadCodecContextOptions ( int req_flags )
48
+ {
49
+ return loadOptions ( (void *)m_avCodecContext, req_flags );
50
+ }
51
+
52
+ OptionLoader::OptionMap OptionLoader::loadOutputFormatOptions ()
53
+ {
54
+ OptionMap outputFormatOptions;
45
55
46
- const AVOption* avOption = NULL ;
56
+ m_outputFormat = av_oformat_next ( NULL ) ;
47
57
48
- // get ffmpeg / libav object on which we'll scan AVOption
49
- void * av_class = NULL ;
50
- if ( ( req_flags & AV_OPT_FLAG_VIDEO_PARAM ) == AV_OPT_FLAG_VIDEO_PARAM ||
51
- ( req_flags & AV_OPT_FLAG_AUDIO_PARAM ) == AV_OPT_FLAG_AUDIO_PARAM ||
52
- ( req_flags & AV_OPT_FLAG_METADATA ) == AV_OPT_FLAG_METADATA ||
53
- ( req_flags & AV_OPT_FLAG_FILTERING_PARAM ) == AV_OPT_FLAG_FILTERING_PARAM ||
54
- ( req_flags & AV_OPT_FLAG_SUBTITLE_PARAM ) == AV_OPT_FLAG_SUBTITLE_PARAM )
55
- {
56
- av_class = (void *)m_avCodecContext;
57
- }
58
- else
58
+ // iterate on formats
59
+ while ( m_outputFormat )
59
60
{
60
- av_class = (void *)m_avFormatContext;
61
+ // add only format with video track
62
+ // m_outputFormat->audio_codec ?
63
+ if ( m_outputFormat->video_codec != AV_CODEC_ID_NONE )
64
+ {
65
+ if ( m_outputFormat->priv_class )
66
+ {
67
+ std::string outputFormatName ( m_outputFormat->name );
68
+ OptionArray optionsArray = loadOptions ( (void *)&m_outputFormat->priv_class );
69
+
70
+ outputFormatOptions.insert (
71
+ std::pair< std::string, OptionArray >(
72
+ outputFormatName,
73
+ optionsArray )
74
+ );
75
+ }
76
+ }
77
+ m_outputFormat = av_oformat_next ( m_outputFormat );
61
78
}
79
+ return outputFormatOptions;
80
+ }
81
+
82
+
83
+ OptionLoader::OptionArray OptionLoader::loadOptions ( void * av_class, int req_flags )
84
+ {
85
+ OptionArray options;
86
+
87
+ std::map<std::string, int > optionUnitToIndex;
88
+ std::vector<Option> childOptions;
89
+
90
+ const AVOption* avOption = NULL ;
62
91
63
92
// iterate on options
64
- while ( ( avOption = av_opt_next ( av_class, avOption ) ) != NULL )
65
- {
93
+ #if LIBAVCODEC_VERSION_INT < AV_VERSION_INT( 51, 12, 0 )
94
+ while ( ( avOption = av_next_option ( av_class, avOption ) ) )
95
+ #else
96
+ while ( ( avOption = av_opt_next ( av_class, avOption ) ) )
97
+ #endif
98
+ {
66
99
if ( !avOption ||
67
100
! avOption->name ||
68
101
( avOption->flags & req_flags ) != req_flags )
@@ -80,29 +113,31 @@ void OptionLoader::loadOptions( int req_flags )
80
113
}
81
114
else
82
115
{
83
- m_options .push_back ( Option ( *avOption, optionType ) );
116
+ options .push_back ( Option ( *avOption, optionType ) );
84
117
optionUnitToIndex.insert (
85
118
std::pair<std::string, int >(
86
119
std::string ( avOption->unit ? avOption->unit : " " ),
87
- m_options .size () - 1 )
120
+ options .size () - 1 )
88
121
);
89
122
}
90
123
}
91
124
92
- // iterate on childs option
125
+ // iterate on child options
93
126
for ( std::vector<Option>::iterator it = childOptions.begin (); it != childOptions.end (); ++it )
94
127
{
95
128
int indexParentOption = optionUnitToIndex.at ( it->getUnit () );
129
+ Option& parentOption = options.at ( indexParentOption );
96
130
97
- m_options. at ( indexParentOption ) .appendChild ( *it );
131
+ parentOption .appendChild ( *it );
98
132
99
133
// child of a Choice
100
- if ( m_options. at ( indexParentOption ) .getType () == TypeChoice )
134
+ if ( parentOption .getType () == TypeChoice )
101
135
{
102
- if ( it->getDefaultValueInt () == m_options. at ( indexParentOption ) .getDefaultValueInt () )
103
- m_options. at ( indexParentOption ). setDefaultChildIndex ( m_options. at ( indexParentOption ) .getNbChilds () - 1 );
136
+ if ( it->getDefaultValueInt () == parentOption .getDefaultValueInt () )
137
+ parentOption. setDefaultChildIndex ( parentOption .getNbChilds () - 1 );
104
138
}
105
139
}
140
+ return options;
106
141
}
107
142
108
143
}
0 commit comments