ffmpeg 转换语音(部分参考)

#pragma warning(push)
#pragma warning(disable : 4101 4244)
int ConverAudio(const char* input_file, const char* output_file, int samples_rate, int channel)
{
AVFormatContext *infmt_ctx;
unsigned int i = 0;
初始化
//     avcodec_register_all();
//     avdevice_register_all();
av_register_all();
infmt_ctx = av_alloc_format_context();
//打开输入文件
if(av_open_input_file(&infmt_ctx, input_file, NULL, 0, NULL)!=0)
{
//debug_string("can't open input file/n");
return -1;
}
//取出流信息
if(av_find_stream_info(infmt_ctx) <0)
{
//debug_string("can't find suitable codec parameters/n");
return -2;
}
//dump_format(infmt_ctx, 0, input_file, 0); //列出输入文件的相关流信息
// 查找音频流信息
int audioindex=-1;
for(unsigned int j = 0; j < infmt_ctx->nb_streams; j++)
{
if(infmt_ctx->streams[j]->codec->codec_type == CODEC_TYPE_AUDIO)
{
audioindex=j;
break;
}
}

if(audioindex == -1) //没有找到音频流
{
//debug_string("can't find audio stream/n");
return -3;
}
AVCodecContext *incode_ctx;
AVCodec *incodec;
incode_ctx = infmt_ctx->streams[audioindex]->codec;
//找到合适的音频解码器
incodec = avcodec_find_decoder(incode_ctx->codec_id);
if(incodec == NULL)
{
//debug_string("can't find suitable audio decoder/n");
return -4;
}

//打开该音频解码器
if(avcodec_open(incode_ctx, incodec) < 0)
{
//debug_string("can't open the audio decoder/n");
return -5;
}

输出  
/* 解析输出文件的格式 */   
AVOutputFormat *outfmt = guess_format(NULL, output
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值