ffmpeg api pcm转aac

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

编码流程:


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();   

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值