ffmpeg - 得到各种音频格式支持的参数

来源:互联网 发布:手机淘宝刷到单流程图 编辑:程序博客网 时间:2024/06/06 17:46

这个小程序可以得到ffmpeg音频编码器所支持的参数,AAC,MP2,MP3,AC3等等。

直接上代码:


#ifndef _UTIL_H_ #define _UTIL_H_#include <stdint.h>extern "C" {#include <libavutil/opt.h>#include <libavcodec/avcodec.h>#include <libavutil/channel_layout.h>#include <libavutil/common.h>#include <libavutil/imgutils.h>#include <libavutil/mathematics.h>#include <libavutil/samplefmt.h>#include <libavformat/avformat.h>#include <libavfilter/buffersink.h>#include <libavfilter/buffersrc.h>#include <libavfilter/avfiltergraph.h>#include <libavutil/pixdesc.h>};namespace unil{enum AVSampleFormat_t{AV_SAMPLE_FMT_NONE_t = -1,AV_SAMPLE_FMT_U8_t,          ///< unsigned 8 bits  AV_SAMPLE_FMT_S16_t,         ///< signed 16 bits  AV_SAMPLE_FMT_S32_t,         ///< signed 32 bits  AV_SAMPLE_FMT_FLT_t,         ///< float  AV_SAMPLE_FMT_DBL_t,         ///< double  AV_SAMPLE_FMT_U8P_t,         ///< unsigned 8 bits, planar  AV_SAMPLE_FMT_S16P_t,        ///< signed 16 bits, planar  AV_SAMPLE_FMT_S32P_t,        ///< signed 32 bits, planar  AV_SAMPLE_FMT_FLTP_t,        ///< float, planar  AV_SAMPLE_FMT_DBLP_t,        ///< double, planar  AV_SAMPLE_FMT_NB_t           ///< Number of sample formats. DO NOT USE if linking dynamically  };typedef signed char        int8_t;typedef short              int16_t;typedef int                int32_t;typedef long long          int64_t;typedef unsigned char      uint8_t;typedef unsigned short     uint16_t;typedef unsigned int       uint32_t;typedef unsigned long long uint64_t;const int AV_IO_BUFF_SIZE = 1024;/* just pick the highest supported samplerate */static int select_sample_rate(AVCodec *codec){const int *p;int best_samplerate = 0;if (!codec->supported_samplerates)return 44100;p = codec->supported_samplerates;while (*p) {best_samplerate = FFMAX(*p, best_samplerate);p++;}return best_samplerate;}/* select layout with the highest channel count */static uint64_t select_channel_layout(AVCodec *codec){const uint64_t *p;uint64_t best_ch_layout = 0;int best_nb_channels = 0;if (!codec->channel_layouts)return AV_CH_LAYOUT_STEREO;p = codec->channel_layouts;while (*p) {int nb_channels = av_get_channel_layout_nb_channels(*p);if (nb_channels > best_nb_channels) {best_ch_layout = *p;best_nb_channels = nb_channels;}p++;}return best_ch_layout;}};#endif



#include "unil.h"#include <iostream>using namespace std;void print_sample_rate(AVCodec *codec){if (!codec->supported_samplerates){cout << "!supported samplerates";return;}const int *p = codec->supported_samplerates;while (*p) {cout << *p << endl;p++;}cout << endl;}void print_channel_layout(AVCodec *codec){uint64_t best_ch_layout = 0;int best_nb_channels = 0;if (!codec->channel_layouts) {cout << "AV_CH_LAYOUT_STEREO" << endl;return;}const uint64_t *p = codec->channel_layouts;while (*p) {int nb_channels = av_get_channel_layout_nb_channels(*p);cout <<"channel_layouts: " <<*p <<" nb_channels: "<<nb_channels << endl;p++;}}void print_sample_fmt(AVCodec *codec){const enum AVSampleFormat *p = codec->sample_fmts;while (*p != AV_SAMPLE_FMT_NONE) {cout << *p << endl;p++;}}void printFormatMsg(AVCodecID id) {AVCodec* codec = avcodec_find_encoder(id);if (codec){const AVCodecDescriptor* descriptor = avcodec_descriptor_get(id);cout << "id: " << id << " name: " << descriptor->long_name << endl;cout << "print_sample_rate: " <<  endl;print_sample_rate(codec);cout << "print_channel_layout: " << endl;print_channel_layout(codec);cout << "print_sample_fmt: " << endl;print_sample_fmt(codec);}elsecout << "no codec" << endl;cout << endl;}void printformat() {av_register_all();cout << "print AV_CODEC_ID_AAC : ";printFormatMsg(AVCodecID::AV_CODEC_ID_AAC);cout << "print AV_CODEC_ID_MP2 : ";printFormatMsg(AVCodecID::AV_CODEC_ID_MP2);cout << "print AV_CODEC_ID_MP3 : ";printFormatMsg(AVCodecID::AV_CODEC_ID_MP3);cout << "print AV_CODEC_ID_MP1 : ";printFormatMsg(AVCodecID::AV_CODEC_ID_MP1);cout << "print AV_CODEC_ID_PCM_S16LE : ";printFormatMsg(AVCodecID::AV_CODEC_ID_PCM_S16LE);}void main(int argc, char *argv[]){av_register_all();for (int i = 1; i < argc;++i){AVCodecID id = (AVCodecID)atoi(argv[i]);printFormatMsg(id);cout << endl;}}



使用方法:

编译后,在BAT中写

Codec.exe 86019 86018 86017 86016 86020  
pause

运行BAT文件


0 0