libfaac个个参数说明
https://blog.csdn.net/qinglongzhan/article/details/81315532?utm_source=blogxgwz0
1. 打开faac编码器引擎。
faacEncHandle FAACAPI faacEncOpen(
unsigned long sampleRate, // pcm音频采样率,8k,16k,44100等
unsigned int numChannels, // pcm音频通道,mono = 1 / stereo = 2
unsigned long *inputSamples, // 一次输入的样本数
unsigned long *maxOutputBytes);// 输出aac buffer的最大size
函数调用成功会return一个编码器faacEncHandle,同时确定输入样本数和输出aac buffer最大size;
申请输入buffer及输出buffer
int nPCMBufferSize = inputSamples * nPCMBitSize / 8; //nPCMBitSize 单次样本位数
unsinged char* pbPCMBuffer = new BYTE[nPCMBufferSize];
unsigned char* pbAACBuffer = new BYTE[maxOutputBytes];
2. 获取当前编码器配置。
faacEncConfigurationPtr FAACAPI faacEncGetCurrentConfiguration(
faacEncHandle hEncoder); //编码器handle
函数调用成功会返回一个faacEncConfigurationPtr用来查看及设置编码器配置。
3. 修改当前编码器的配置并设置。
//copy this struct from headfile
typedef struct faacEncConfiguration{
/* config version - 配置版本,可以默认不设置*/
int version;
/* library version - 库版本,可以默认不设置*/
char *name;
/* copyright string - 版权,可以默认不设置*/
char *copyright;
/* MPEG version, 2 or 4 - MPEG版本,MPEG2 or MPEG4*/
unsigned int mpegVersion;
/* AAC object type - AAC对象类型,详细见补充说明1,取值:1-MAIN 2-LOW 3-SSR 4-LTP*/
unsigned int aacObjectType;
/* Allow mid/side coding - 是否允许mid/side coding, 详细见补充说明2,取值:0-NO 1-YES*/
unsigned int allowMidside;
/* Use one of the channels as LFE channel - 是否允许一个通道为低频通道,取值:0-NO 1-YES*/
/* LFE(low-frequencyeffects) */
unsigned int useLfe;
/* Use Temporal Noise Shaping - 瞬时噪声定形(temporal noise shaping,TNS)滤波器,取值:0-NO 1-YES*/
unsigned int useTns;
/* bitrate / channel of AAC file - AAC文件的bitrate / channel 取值:0和48000都可以,暂时不清楚这个参数作用*/
unsigned long bitRate;
/* AAC file frequency bandwidth - 频宽 取值:0, 32000,64000都可以,暂时不清楚参数作用*/
unsigned int bandWidth;
/* Quantizer quality - 编码质量,取值:efault=100 LOWER<100 HIGHER>100*/
/* 默认100,值越大音质越高 */
unsigned long quantqual;
/* Bitstream output format (取值:0 = Raw; 1 = ADTS) - 输出数据类型(是否包包含adts头),录制MP4文件时,要用raw流,ADTS详细见补充说明3*/
unsigned int outputFormat;
/* psychoacoustic model list*/
psymodellist_t *psymodellist;
/* selected index in psymodellist*/
unsigned int psymodelidx;
/*
PCM Sample Input Format - 输入pcm数据类型
0 FAAC_INPUT_NULL invalid, signifies a misconfigured config
1 FAAC_INPUT_16BIT native endian 16bit
2 FAAC_INPUT_24BIT native endian 24bit in 24 bits(not implemented)
3 FAAC_INPUT_32BIT native endian 24bit in 32 bits (DEFAULT)
4 FAAC_INPUT_FLOAT 32bit floating point
*/
unsigned int inputFormat;
/* block type enforcing -
* (SHORTCTL_NORMAL/SHORTCTL_NOSHORT/SHORTCTL_NOLONG)
*/
int shortctl;
/*
Channel Remapping
Default 0, 1, 2, 3 ... 63 (64 is MAX_CHANNELS in coder.h)
WAVE 4.0 2, 0, 1, 3
WAVE 5.0 2, 0, 1, 3, 4
WAVE 5.1 2, 0, 1, 4, 5, 3
AIFF 5.1 2, 0, 3, 1, 4, 5
*/
int channel_map[64];
} faacEncConfiguration, *faacEncConfigurationPtr;
参数设置示例:
第一步:
faacEncConfigurationPtr pConfiguration;
pConfiguration->outputFormat = 1;
pConfiguration->aacObjectType = LOW;
pConfiguration->bitRate = 48000; // or 0
pConfiguration->bandWidth = 64000; //or 0 or 32000
pConfiguration->inputFormat = FAAC_INPUT_16BIT;
/*下面可以选择设置*/
pConfiguration->allowMidside = 1;
pConfiguration->useLfe = 0;
pConfiguration->useTns = 0;
pConfiguration->quantqual = 100;
pConfiguration->outputFormat = 1;
pConfiguration->shortctl = SHORTCTL_NORMAL;
第二步:
int FAACAPI faacEncSetConfiguration( //设置编码器配置
faacEncHandle hEncoder,
faacEncConfigurationPtr config);
4.进行编码操作(PCM to AAC)
/* 请见步骤1中这部分
int nPCMBufferSize = inputSamples * nPCMBitSize / 8;
unsinged char* pbPCMBuffer = new BYTE[nPCMBufferSize];
unsigned char* pbAACBuffer = new BYTE[maxOutputBytes];
*/
先获取PCM数据,填充到pbPCMBuffer,单次获取长度为nPCMBufferSize。
int FAACAPI faacEncEncode(
faacEncHandle hEncoder,
int32_t * inputBuffer, //pcm输入buffer, pbPCMBuffer
unsigned int samplesInput, //一次输入的样本数(注意不是数据长度 ),samplesInput
unsigned char *outputBuffer, //AAC输出buffer, pbAACBuffer
unsigned int bufferSize);
函数调用成功会返回实际AAC数据大小,从pbAACBuffer中读出即可。
5. 结束关闭编码器退出。
int FAACAPI faacEncClose(faacEncHandle hEncoder);