linux下ffmpeg实现wav转mp3,原来的9秒声音变成了一秒,该怎么处理
发布时间:2011-06-27 19:29:19 文章来源:www.iduyao.cn 采编人员:星星草
linux下ffmpeg实现wav转mp3,原来的9秒声音变成了一秒
#include "libavcodec/avcodec.h"
#include "libavformat/avformat.h"
#include <stdio.h>
#include "libavutil/avutil.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
main(int argc,char **argv)
{
const char *input_file_name="test.wav";
av_register_all();
AVFormatContext *ic;
ic=avformat_alloc_context();
if(av_open_input_file(&ic,input_file_name,NULL,FFM_PACKET_SIZE,NULL)!=0)
{
printf("can't open the file %s\n",input_file_name);
exit(1);
}
if(av_find_stream_info(ic)<0)
{
printf("can't find suitable codec parameters\n");
exit(1);
}
dump_format(ic,0,input_file_name,0);
int i;
int audioindex=-1;
for(i=0;i<ic->nb_streams;i++)
{
if(ic->streams[i]->codec->codec_type==CODEC_TYPE_AUDIO)
{
audioindex=i;
break;
}
}
if(audioindex==-1)
{
printf("can't find audio stream\n");
exit(1);
}
AVCodecContext *aCodecCtx;
aCodecCtx=ic->streams[audioindex]->codec;
AVCodec *aCodec;
aCodec=avcodec_find_decoder(aCodecCtx->codec_id);
if(aCodec==NULL)
{
printf("can't find suitable audio decoder\n");
exit(1);
}
if(avcodec_open(aCodecCtx,aCodec)<0)
{
printf("can't open the audio decoder\n");
exit(1);
}
const char *output_file_name="out.mp3";
AVOutputFormat *fmt;
AVFormatContext *oc;
AVCodecContext *oAcc;
AVCodec *oAc;
AVStream *audio_st;
fmt=guess_format(NULL,output_file_name,NULL);
if(!fmt)
{
printf("could not deduce output format from outfile extension\n");
exit(0);
}
oc=avformat_alloc_context();
if(!oc)
{
printf("Memory error\n");
exit(0);
}
oc->oformat=fmt;
strncpy(oc->filename,output_file_name,sizeof(oc->filename));
audio_st=av_new_stream(oc,oc->nb_streams);
if(!audio_st)
{
printf("could not alloc audio stream\n");
exit(0);
}
avcodec_get_context_defaults2(audio_st->codec,CODEC_TYPE_AUDIO);
oAcc=avcodec_alloc_context();
oAcc=audio_st->codec;
oAcc->codec_id=CODEC_ID_MP3;
oAcc->codec_type=CODEC_TYPE_AUDIO;
oAcc->bit_rate=aCodecCtx->bit_rate;
oAcc->sample_rate=aCodecCtx->sample_rate;
oAcc->channels=1;
oAcc->block_align=0;
if (av_set_parameters(oc, NULL) < 0)
{
printf( "Invalid output format parameters\n");
exit(0);
}
strcpy(oc->title,"music of c/c++");
strcpy(oc->author,"yzg");
strcpy(oc->copyright,"linux");
strcpy(oc->comment,"fedora");
strcpy(oc->album,"test");
oc->year=2011;
oc->track=1;
strcpy(oc->genre,"dota");
dump_format(oc,0,output_file_name,1);
友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。
其他相似内容:
-
DSHOW push
推模式,ConnectDirect 的,为什么我一直反回错误
下级级用的是HAALI的一个东西,用CMemStream拉模式的时候是可以连接的
...
-
ffmpeg编码后视频速度不正确,质量也不好,求助,求助,求助,求助啊
对采集到得摄像头图像进行编码保存,发现得到的视频质量不好,而且速度不...
-
请问怎么在live555中接收jpeg
请问,我现在想接收一个服务器发送的jpeg 不知道怎么用live555做一个客户端, 接收它并显示。
请问应...
-
XP SP3 YUV420 的fiter依赖 在线等答案……
链接时媒体类型为WMMEDIASUBTYPE_I420
有的XP可以播放出来
有的就不行,请问不能播放...
-
如何获取通过麦克风来获取当前说话的音量?
使用Wave系统API采集音频输入的数据,当数据缓存区满了后,收到消息取得数据后,如何根据这里...
-
RFC3984 有没有完整的中文版本呢?
搜了几个 都是一半英文一半中文的。哎 郁闷!
------解决方案--------------------
英文的凑合...
-
介绍一个学习directshow和com、atl技术的网站
有一个学习directshow和com、atl技术的网站,还可以下视频教程,共享给大家: http://www...
-
攻击帖:jrtplib、live555是个垃圾,刚开始搞流媒体就用这玩意就是找s
不解释~
来丢我砖头吧~~
我分太多了用不完~ 支持的散分~~~
...
-
50分,寻找《Visual C++音频/视频处理技术及工程实践》的随书光盘?
急于使用其中的几个例程。若哪位好心人能够提供,非常感谢!!我的QQ:52...
-
h264的高宽比怎么获取?
我看标准里面只有样点的高宽比啊。
还有,bit rate可以读出来吗?
------解决方案--------------------
是要...