您的位置:首页 > 其它

使用FFMPEG将speex音频格式转为mp3和ogg格式

2016-05-31 22:48 471 查看
场景需要:服务端需要将从客户端APP上传上来的speex格式的语音格式转为mp3和ogg两种格式,这样就可以支持PC所有浏览器(通过html5标签)播放。

软件下载:

1、ffmpeg: wget https://github.com/FFmpeg/FFmpeg/releases/download/n3.0/ffmpeg-3.0.tar.gz

2、lame:wget http://nchc.dl.sourceforge.net/project/lame/lame/3.99/lame-3.99.5.tar.gz(mp3编解码器) 3、libogg:wget http://downloads.xiph.org/releases/ogg/libogg-1.3.2.tar.gz(libvorbis需要依赖) 4、libvorbis:wget http://downloads.xiph.org/releases/vorbis/libvorbis-1.3.4.tar.gz(ogg编解码器)
5、speex:wget http://downloads.xiph.org/releases/speex/speex-1.2rc1.tar.gz(speex编解码)
解压lame、libogg、libvorbis、speex

tar -xvf 对应的包名

eg:tar -xvf  lame-3.99.5.tar.gz

进入对应包目录编译以上4个依赖

eg:

cd lame-3.99.5

./configure --prefix=/usr/local/   --enable-shared

make

make install

以上4个包都编译安装完成后解压ffmpeg

tar -xvf ffmpeg-3.0.tar.gz

cd ffmpeg

./configure --prefix=/usr/local/ffmpeg --disable-yasm --enable-libspeex --enable-libmp3lame --enable-libvorbis --enable-shared
make
make install
ok 全部完成!

说明:ffmpeg 本身有支持了一些音视频格式的编解码器,但是由于版权问题并不是所有的都支持。例如对于mp3,ffmpeg只有解码包,没有编码包。这就意味着只能将mp3转为其他格式,而不能将其他格式的音视频转为mp3,所以我们才需要手动来安装额外的libmp3lame这个包。
查看ffmpeg本身支持编解码格式可以通过./configure --help来查看。
这篇文章对ffmpeg的编译选项有详细的说明(http://www.cnblogs.com/wainiwann/p/4204230.html);
如果需要转为其他格式的,如果ffmpeg默认没安装对应的编解码包,可自行下载安装,再重新编译安装ffmpeg即可。
这篇文章总结了多种格式编解码包(http://www.java123.net/974237.html)

最后验证是否可以转码:./usr/local/bin/ffmpeg -i input.speex output.mp3

注:ffmpeg 2.x版本有重大bug.建议安装3.0

补充:安装中间可能遇到一些问题,

1、speex not found using pig-config
解决办法:
vi /etc/profile
添加
export PKG_CONFIG=/usr/bin/pkg-config
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
保存后执行
source /etc/profile
2、
*** If you have an old version installed, it is best to remove it, although
*** you may also be able to get things to work by modifying LD_LIBRARY_PATH、
configure: error: must have Ogg installed!
解决方法:

vi /etc/ld.so.conf
添加 /usr/local/lib
保存后执行 ldconfig
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息