4 #include <libavutil/pixdesc.h>
15 std::vector<std::string> pixelFormats;
18 if(videoCodecName ==
"")
20 const AVPixFmtDescriptor* pixFmtDesc = NULL;
22 #if LIBAVUTIL_VERSION_INT < AV_VERSION_INT(51, 44, 0)
23 for(
int pix_fmt = 0; pix_fmt < PIX_FMT_NB; ++pix_fmt)
24 pixFmtDesc = &av_pix_fmt_descriptors[pix_fmt];
26 while((pixFmtDesc = av_pix_fmt_desc_next(pixFmtDesc)) != NULL)
31 pixelFormats.push_back(std::string(pixFmtDesc->name));
37 const AVCodec* videoCodec = avcodec_find_encoder_by_name(videoCodecName.c_str());
38 if(videoCodec && videoCodec->pix_fmts != NULL)
41 while(videoCodec->pix_fmts[pix_fmt] != -1)
43 #if LIBAVUTIL_VERSION_INT < AV_VERSION_INT(51, 44, 0)
44 const AVPixFmtDescriptor* pix_desc = &av_pix_fmt_descriptors[videoCodec->pix_fmts[pix_fmt]];
46 const AVPixFmtDescriptor* pix_desc = av_pix_fmt_desc_get(videoCodec->pix_fmts[pix_fmt]);
48 if(!pix_desc || !pix_desc->name)
50 pixelFormats.push_back(std::string(pix_desc->name));
60 std::vector<std::string> sampleFormats;
63 if(audioCodecName.empty())
65 for(
size_t sampleFormat = 0; sampleFormat < AV_SAMPLE_FMT_NB; ++sampleFormat)
67 sampleFormats.push_back(av_get_sample_fmt_name(static_cast<AVSampleFormat>(sampleFormat)));
73 const AVCodec* audioCodec = avcodec_find_encoder_by_name(audioCodecName.c_str());
74 if(audioCodec && audioCodec->sample_fmts != NULL)
76 size_t sample_fmt = 0;
77 while(audioCodec->sample_fmts[sample_fmt] != -1)
79 const char* sampleFormatName = av_get_sample_fmt_name(audioCodec->sample_fmts[sample_fmt]);
81 sampleFormats.push_back(std::string(sampleFormatName));
92 return av_get_pix_fmt(pixelFormat.c_str());
97 return av_get_sample_fmt(sampleFormat.c_str());
102 const char* formatName = av_get_pix_fmt_name(pixelFormat);
103 return formatName ? std::string(formatName) :
"";
108 const char* formatName = av_get_sample_fmt_name(sampleFormat);
109 return formatName ? std::string(formatName) :
"";
114 std::vector<AVOutputFormat*> formats;
116 AVOutputFormat* fmt = NULL;
117 while((fmt = av_oformat_next(fmt)))
122 formats.push_back(fmt);
131 for(
size_t i = 0; i < formats.size(); ++i)
133 AVOutputFormat* fmt = formats.at(i);
134 formatsNames.insert(std::make_pair(std::string(fmt->name), std::string(fmt->long_name ? fmt->long_name :
"")));
143 for(
size_t i = 0; i < formats.size(); ++i)
145 AVOutputFormat* fmt = formats.at(i);
149 formatsNames.insert(std::make_pair(std::string(fmt->name), std::string(fmt->long_name ? fmt->long_name :
"")));
158 for(
size_t i = 0; i < formats.size(); ++i)
160 AVOutputFormat* fmt = formats.at(i);
164 formatsNames.insert(std::make_pair(std::string(fmt->name), std::string(fmt->long_name ? fmt->long_name :
"")));
171 std::vector<AVCodec*> codecs;
174 while((c = av_codec_next(c)))
188 for(
size_t i = 0; i < codecs.size(); ++i)
190 AVCodec* c = codecs.at(i);
191 if(c->type == AVMEDIA_TYPE_VIDEO)
193 videoCodecsNames.insert(std::make_pair(std::string(c->name), std::string(c->long_name ? c->long_name :
"")));
196 return videoCodecsNames;
203 for(
size_t i = 0; i < codecs.size(); ++i)
205 AVCodec* c = codecs.at(i);
206 if(c->type == AVMEDIA_TYPE_AUDIO)
208 audioCodecsNames.insert(std::make_pair(std::string(c->name), std::string(c->long_name ? c->long_name :
"")));
211 return audioCodecsNames;
218 AVOutputFormat* outputFormat = av_oformat_next(NULL);
223 if(!outputFormat->name)
226 const std::string outputFormatName(outputFormat->name);
228 if(outputFormat->priv_class)
230 loadOptions(options, (
void*)&outputFormat->priv_class, 0);
232 optionsPerFormat.insert(std::make_pair(outputFormatName, options));
233 outputFormat = av_oformat_next(outputFormat);
235 return optionsPerFormat;
242 AVCodec* codec = av_codec_next(NULL);
251 if(codec->type == AVMEDIA_TYPE_VIDEO)
253 const std::string videoCodecName(codec->name);
255 if(codec->priv_class)
257 loadOptions(options, (
void*)&codec->priv_class, 0);
259 videoCodecOptions.insert(std::make_pair(videoCodecName, options));
261 codec = av_codec_next(codec);
263 return videoCodecOptions;
270 AVCodec* codec = av_codec_next(NULL);
279 if(codec->type == AVMEDIA_TYPE_AUDIO)
281 const std::string audioCodecName(codec->name);
283 if(codec->priv_class)
285 loadOptions(options, (
void*)&codec->priv_class, 0);
287 audioCodecOptions.insert(std::make_pair(audioCodecName, options));
289 codec = av_codec_next(codec);
291 return audioCodecOptions;
std::map< std::string, OptionArray > OptionArrayMap
void loadOptions(OptionMap &outOptions, void *av_class, int req_flags)
NamesMap getAvailableAudioCodecsNames()
Get a map of short/long names of all audio codecs available in FFmpeg / libav.
std::vector< Option > OptionArray
std::vector< std::string > getSupportedPixelFormats(const std::string &videoCodecName)
Get pixel format supported by a video codec.
AVPixelFormat getAVPixelFormat(const std::string &pixelFormat)
Get the corresponding AVPixelFormat from the pixel format name.
std::vector< std::string > getSupportedSampleFormats(const std::string &audioCodecName)
Get sample format supported by an audio codec.
std::vector< AVOutputFormat * > getAvailableFormats()
std::string getPixelFormatName(const AVPixelFormat pixelFormat)
OptionArrayMap getAvailableOptionsPerOutputFormat()
Get the list of options for each output format.
std::map< std::string, std::string > NamesMap
NamesMap getAvailableAudioFormatsNames()
Get a map of short/long names of all formats dedicate for video available in FFmpeg / libav...
std::vector< AVCodec * > getAvailableCodecs()
NamesMap getAvailableVideoCodecsNames()
Get a map of short/long names of all video codecs available in FFmpeg / libav.
NamesMap getAvailableFormatsNames()
Get a map of short/long names of all formats available in FFmpeg / libav.
OptionArrayMap getAvailableOptionsPerVideoCodec()
Get the list of options for each video codec.
NamesMap getAvailableVideoFormatsNames()
Get a map of short/long names of all formats dedicate for video available in FFmpeg / libav...
OptionArrayMap getAvailableOptionsPerAudioCodec()
Get the list of options for each audio codec.
std::string getSampleFormatName(const AVSampleFormat sampleFormat)
AVSampleFormat getAVSampleFormat(const std::string &sampleFormat)
Get the corresponding AVSampleFormat from the sample format name.