编码流程:
avformat_alloc_output_context2(); //打开输出音频上下文句柄;
avcodec_find_encoder(); //查找编码器
avcodec_alloc_context3(); //创建编码器上下文
//初始化编码器参数
codecCtx->channels = 2; //通道数量
codecCtx->channel_layout = AV_CH_LAYOUT_STEREO; //通道类型
codecCtx->sample_rate = 8000; //采样率
codecCtx->sample_fmt = AV_SAMPLE_FMT_FLTP; //采样数据格式
if (!check_sample_fmt(codec, codecCtx->sample_fmt))
{
fprintf(stderr, "Encoder does not support sample format %s",
av_get_sample_fmt_name(codecCtx->sample_fmt));
exit(1);
}
codecCtx->bit_rate = 64000; //码率
codecCtx->flags |= AV_CODEC_FLAG_GLOBAL_HEADER; //公共头部
avcodec_open2(); //打开编码器
avformat_new_stream(); //创建AVstream语音通道
avcodec_parameters_from_context(); //从编码器上下文获取编码参数
avio_open(); //创建并初始化AVIOContext
avformat_write_header(); //写文件头
av_frame_alloc();

本文详细介绍了使用FFmpeg进行PCM格式音频文件到AAC编码的完整流程,包括打开输出上下文、选择编码器、设置参数、音频重采样、编码并写入AAC文件。关键步骤包括配置通道数、采样率、编码器选择及处理不支持的采样格式。
最低0.47元/天 解锁文章
2108

被折叠的 条评论
为什么被折叠?



