ffmpeg创建并打开AAC编码器
创建并打开编码器API创建编码器: avcodec_find_encoder创建上下文:avcodec_alloc_context3打开编码器:avcodec_open2AVCodecContext* open_encoder(){// 创建编码器// avcodec_find_encoder(AV_CODEC_ID_AAC); // 使用ID创建编码器AVCodec *codec = avcod
·
创建并打开编码器API
- 创建编码器: avcodec_find_encoder
- 创建上下文:avcodec_alloc_context3
- 打开编码器:avcodec_open2
AVCodecContext* open_encoder()
{
// 创建编码器
// avcodec_find_encoder(AV_CODEC_ID_AAC); // 使用ID创建编码器
AVCodec *codec = avcodec_find_encoder_by_name("libfdk_aac"); // 按name创建编码器,按需要修改编码器类型
// 创建codec上下文
AVCodecContext *codec_ctx = avcodec_alloc_context3(codec);
codec_ctx->sample_fmt = AV_SAMPLE_FMT_S16; // 输入音频的采样大小。fdk_aac需要16位的音频输 入数据
codec_ctx->channel_layout = AV_CH_LAYOUT_STEREO; // 输入音频的CHANNEL LAYOUT
codec_ctx->channels = 2; // 输入音频的声道数
codec_ctx->sample_rate = 44100; // 输入音频的采样率
codec_ctx->bit_rate = 0; // AAC : 128K AAV_HE: 64K AAC_HE_V2: 32K. bit_rate为0时才会查找profile属性值
codec_ctx->profile = FF_PROFILE_AAC_HE_V2;
// 打开编码器
if (avcodec_open2(codec_ctx, codec, NULL) < 0)
{
return NULL;
}
return codec_ctx;
}
编码器可以根据需要自行选择修改,上下文参数设置根据选用的编码器设置。
更多推荐



所有评论(0)