1
1
#include " util.hpp"
2
2
3
3
extern " C" {
4
- #include < libavcodec/avcodec.h>
5
- #include < libavformat/avformat.h>
6
4
#include < libavutil/pixdesc.h>
7
5
}
8
6
@@ -111,16 +109,28 @@ std::string getSampleFormatName(const AVSampleFormat sampleFormat)
111
109
return formatName ? std::string (formatName) : " " ;
112
110
}
113
111
114
- NamesMap getAvailableFormatsNames ()
112
+ std::vector<AVOutputFormat*> getAvailableFormats ()
115
113
{
116
- NamesMap formatsNames ;
114
+ std::vector<AVOutputFormat*> formats ;
117
115
118
116
AVOutputFormat* fmt = NULL ;
119
117
while ((fmt = av_oformat_next (fmt)))
120
118
{
121
119
if (!fmt->name )
122
120
continue ;
123
121
122
+ formats.push_back (fmt);
123
+ }
124
+ return formats;
125
+ }
126
+
127
+ NamesMap getAvailableFormatsNames ()
128
+ {
129
+ NamesMap formatsNames;
130
+ std::vector<AVOutputFormat*> formats = getAvailableFormats ();
131
+ for (size_t i = 0 ; i < formats.size (); ++i)
132
+ {
133
+ AVOutputFormat* fmt = formats.at (i);
124
134
formatsNames.insert (std::make_pair (std::string (fmt->name ), std::string (fmt->long_name ? fmt->long_name : " " )));
125
135
}
126
136
return formatsNames;
@@ -129,16 +139,13 @@ NamesMap getAvailableFormatsNames()
129
139
NamesMap getAvailableVideoFormatsNames ()
130
140
{
131
141
NamesMap formatsNames;
132
-
133
- AVOutputFormat* fmt = NULL ;
134
- while ((fmt = av_oformat_next (fmt)))
142
+ std::vector<AVOutputFormat*> formats = getAvailableFormats ();
143
+ for (size_t i = 0 ; i < formats.size (); ++i)
135
144
{
136
- if (!fmt->name )
137
- continue ;
138
-
145
+ AVOutputFormat* fmt = formats.at (i);
146
+ // skip format which cannot handle video
139
147
if (fmt->video_codec == AV_CODEC_ID_NONE)
140
148
continue ;
141
-
142
149
formatsNames.insert (std::make_pair (std::string (fmt->name ), std::string (fmt->long_name ? fmt->long_name : " " )));
143
150
}
144
151
return formatsNames;
@@ -147,33 +154,42 @@ NamesMap getAvailableVideoFormatsNames()
147
154
NamesMap getAvailableAudioFormatsNames ()
148
155
{
149
156
NamesMap formatsNames;
150
-
151
- AVOutputFormat* fmt = NULL ;
152
- while ((fmt = av_oformat_next (fmt)))
157
+ std::vector<AVOutputFormat*> formats = getAvailableFormats ();
158
+ for (size_t i = 0 ; i < formats.size (); ++i)
153
159
{
154
- if (!fmt->name )
155
- continue ;
156
-
160
+ AVOutputFormat* fmt = formats.at (i);
161
+ // skip format which cannot handle audio
157
162
if (fmt->audio_codec == AV_CODEC_ID_NONE)
158
163
continue ;
159
-
160
164
formatsNames.insert (std::make_pair (std::string (fmt->name ), std::string (fmt->long_name ? fmt->long_name : " " )));
161
165
}
162
166
return formatsNames;
163
167
}
164
168
165
- NamesMap getAvailableVideoCodecsNames ()
169
+ std::vector<AVCodec*> getAvailableCodecs ()
166
170
{
167
- NamesMap videoCodecsNames ;
171
+ std::vector<AVCodec*> codecs ;
168
172
169
173
AVCodec* c = NULL ;
170
- while ((c = av_codec_next (c)) != NULL )
174
+ while ((c = av_codec_next (c)))
175
+ {
176
+ if (!c->name )
177
+ continue ;
178
+
179
+ codecs.push_back (c);
180
+ }
181
+ return codecs;
182
+ }
183
+
184
+ NamesMap getAvailableVideoCodecsNames ()
185
+ {
186
+ NamesMap videoCodecsNames;
187
+ std::vector<AVCodec*> codecs = getAvailableCodecs ();
188
+ for (size_t i = 0 ; i < codecs.size (); ++i)
171
189
{
190
+ AVCodec* c = codecs.at (i);
172
191
if (c->type == AVMEDIA_TYPE_VIDEO)
173
192
{
174
- if (!c->name )
175
- continue ;
176
-
177
193
videoCodecsNames.insert (std::make_pair (std::string (c->name ), std::string (c->long_name ? c->long_name : " " )));
178
194
}
179
195
}
@@ -183,15 +199,12 @@ NamesMap getAvailableVideoCodecsNames()
183
199
NamesMap getAvailableAudioCodecsNames ()
184
200
{
185
201
NamesMap audioCodecsNames;
186
-
187
- AVCodec* c = NULL ;
188
- while ((c = av_codec_next (c)) != NULL )
202
+ std::vector<AVCodec*> codecs = getAvailableCodecs ();
203
+ for (size_t i = 0 ; i < codecs.size (); ++i)
189
204
{
205
+ AVCodec* c = codecs.at (i);
190
206
if (c->type == AVMEDIA_TYPE_AUDIO)
191
207
{
192
- if (!c->name )
193
- continue ;
194
-
195
208
audioCodecsNames.insert (std::make_pair (std::string (c->name ), std::string (c->long_name ? c->long_name : " " )));
196
209
}
197
210
}
0 commit comments