Lame虽然没有ffmpeg强大,但是也可以做一些事情。转码的步骤:
1.(optional) Get the version number of the encoder, if you are interested.
void get_lame_version(char *strbuf, size_tbuflen, const char *prefix);
2.Error messages. By default, LAME willwrite error messages to stderrusing vfprintf(). For GUI applications,this is often a problem and you need to set your own error message handlers:
lame_set_errorf(gfp,error_handler_function);
lame_set_debugf(gfp,error_handler_function);
lame_set_msgf(gfp,error_handler_function);
3.Initialize the encoder. sets default forall encoder parameters.初始化编码器,设置默认参数
#include "lame.h"
lame_global_flags *gfp;//在lame.h中typedeflame_global_flags *lame_t;
gfp = lame_init();
默认是 44.1khz、128kbps,音质是5,需要的时候设置自己的参数覆盖默认
lame_set_num_channels(gfp,2);/* 默认也是2 */
lame_set_in_samplerate(gfp,44100); /* 采样率 */
lame_set_brate(gfp,128); /* 比特率 */
lame_set_mode(gfp,1); /* mode = 0,1,2,3 = stereo,jstereo,dualchannel(not supported),mono default */
lame_set_quality(gfp,2); /* 2=high 5 = medium 7=low */
4. 检查配置确保返回值ret_code>= 0
ret_code = lame_init_params(gfp);
5 编码: 缓冲区mp3buffer_size大小可以通过 num_samples,samplerate和 encoding rate计算, 最坏的估计是
mp3buffer_size(in bytes) = 1.25*num_samples + 7200.其中num_samples = the number of PCMsamples in each channel.
返回的数字code = 输出到mp3buffer缓冲的大小(number of bytesoutput in mp3buffer),可以为0,但是小于0就出错了
int lame_encode_buffer(lame_global_flags*gfp,
short intleftpcm[],