ffmpeg处理amr转mp3
# wget http://www.tortall.net/projects/yasm/releases/yasm-1.2.0.tar.gz
# tar -xvzf yasm-1.2.0.tar.gz
# cd yasm-1.2.0
# ./configure && make && make install
# wget http://sourceforge.net/projects/lame/files/lame/3.99/lame-3.99.5.tar.gz/download
# tar -xvzf lame-3.99.5.tar.gz
# cd lame-3.99.5
# ./configure && make && make install
# wget http://sourceforge.net/projects/opencore-amr/files/opencore-amr/opencore-amr-0.1.3.tar.gz/download
# tar -xvzf opencore-amr-0.1.3.tar.gz
# cd opencore-amr-0.1.3
# ./configure && make && make install
# wget http://ftp.penguin.cz/pub/users/utx/amr/amrnb-11.0.0.0.tar.bz2
# tar -xvjf amrnb-11.0.0.0.tar.bz2
# cd amrnb-11.0.0.0
# ./configure && make && make install
# wget http://ftp.penguin.cz/pub/users/utx/amr/amrwb-11.0.0.0.tar.bz2
# tar -xvjf amrwb-11.0.0.0.tar.bz2
# cd amrwb-11.0.0.0
# ./configure && make && make install
# yum install -y git
# git clone git://source.ffmpeg.org/ffmpeg.git ffmpeg
# cd ffmpeg/
# ./configure –enable-libmp3lame –enable-libopencore-amrnb –enable-libopencore-amrwb –enable-version3 –enable-shared
# make && make install
# ldconfig
[root@test about_ffmpeg]# ffmpeg
ffmpeg version N-56717-gface578 Copyright (c) 2000-2013 the FFmpeg developers
built on Sep 29 2013 11:53:49 with gcc 4.1.2 (GCC) 20080704 (Red Hat 4.1.2-50)
configuration: –enable-libmp3lame –enable-libopencore-amrnb –enable-libopencore-amrwb –enable-version3 –enable-shared
libavutil 52. 46.100 / 52. 46.100
libavcodec 55. 33.101 / 55. 33.101
libavformat 55. 18.104 / 55. 18.104
libavdevice 55. 3.100 / 55. 3.100
libavfilter 3. 88.100 / 3. 88.100
libswscale 2. 5.100 / 2. 5.100
libswresample 0. 17.103 / 0. 17.103
Hyper fast Audio and Video encoder
usage: ffmpeg [options] [[infile options] -i infile]… {[outfile options] outfile}…
Use -h to get full help or, even better, run \’man ffmpeg\’
[root@test username]# ffmpeg -i 0929121000.amr 0929121000.mp3
ffmpeg version N-56717-gface578 Copyright (c) 2000-2013 the FFmpeg developers
built on Sep 29 2013 11:53:49 with gcc 4.1.2 (GCC) 20080704 (Red Hat 4.1.2-50)
configuration: –enable-libmp3lame –enable-libopencore-amrnb –enable-libopencore-amrwb –enable-version3 –enable-shared
libavutil 52. 46.100 / 52. 46.100
libavcodec 55. 33.101 / 55. 33.101
libavformat 55. 18.104 / 55. 18.104
libavdevice 55. 3.100 / 55. 3.100
libavfilter 3. 88.100 / 3. 88.100
libswscale 2. 5.100 / 2. 5.100
libswresample 0. 17.103 / 0. 17.103
[amr @ 0x9a34d40] Estimating duration from bitrate, this may be inaccurate
Input #0, amr, from \’0929121000.amr\’:
Duration: 00:00:18.41, bitrate: 5 kb/s
Stream #0:0: Audio: amr_nb (samr / 0x726D6173), 8000 Hz, mono, flt, 5 kb/s
Output #0, mp3, to \’0929121000.mp3\’:
Metadata:
TSSE : Lavf55.18.104
Stream #0:0: Audio: mp3 (libmp3lame), 8000 Hz, mono, fltp
Stream mapping:
Stream #0:0 -> #0:0 (amrnb -> libmp3lame)
Press [q] to stop, [?] for help
0929121000.amr: Input/output error
size= 18kB time=00:00:18.43 bitrate= 8.2kbits/s
video:0kB audio:18kB subtitle:0 global headers:0kB muxing overhead 1.405039%
============================================================
[root@Rr ffmpeg]# ffmpeg
ffmpeg: error while loading shared libraries: libavdevice.so.55: cannot open shared object file: No such file or directory
[root@Rr ffmpeg]# ldconfig
[root@Rr ffmpeg]# ldd `which ffmpeg`
linux-gate.so.1 => (0x00907000)
libavdevice.so.55 => not found
libavfilter.so.3 => not found
libavformat.so.55 => not found
libavcodec.so.55 => not found
libswresample.so.0 => not found
libswscale.so.2 => not found
libavutil.so.52 => not found
libpthread.so.0 => /lib/libpthread.so.0 (0x00965000)
libm.so.6 => /lib/libm.so.6 (0x00933000)
libc.so.6 => /lib/libc.so.6 (0x00110000)
/lib/ld-linux.so.2 (0x007b9000)
================================
查看链接库配置文件
# vi /etc/ld.so.conf添加:
/usr/local/lib
/usr/local/lib64
然后,再次运行
# ldconfig
如果有报错:
cannot restore segment prot after reloc: Permission denied
就把selinux关闭:
- /usr/sbin/setenforce 0
================================================================
http://hi.baidu.com/duqingming/item/4adf34337d75b65a81f1a7e5
Linux下使用ffmpeg将AMR转成MP3
最近公司一款基于移动互联网的产品有个短暂的录音(留言)功能,因为录音需要传输到服务器上,所以为了用户体验及节省用户流量,我们采用了AMR的语音格式。
AMR格式是智能手机上的常用音频文件格式,比MP3格式的压缩比大。同样时长的AMR文件大概是MP3的十分之一,所以在移动互联项目中应用比较广泛。
但目前AMR格式在个人电脑上应用较少,所以目前大部门播放器都不支持AMR,为了解决这个问题我们打算在服务器端将AMR转成MP3,以便在个人电脑上通过浏览器的方式进行播放。
目前并没有找到合适的支持AMR转MP3的java的开发包,服务器环境为CentOS 6.2,所以我们采用了ffmpeg。
FFmpeg是一个开源免费跨平台的视频和音频流方案,属于自由软件,采用LGPL或GPL许可证(依据你选择的组件)。它提供了录制、转换以及流化音视频的完整解决方案。它包含了非常先进的音频/视频编解码库libavcodec,为了保证高可移植性和编解码质量,libavcodec里很多codec都是从头开发的。
其官方网址为:http://www.ffmpeg.org/
1. 首先安装系统基础环境
RHEL & CentOS 系列:yum install -y automake autoconf libtool gcc gcc-c++
Debian & Ubuntu 系列:apt-get install automake autoconf libtool gcc gcc-c++
2. 编译所需源码包
yasm:http://yasm.tortall.net/Download.html(汇编器,新版本的ffmpeg增加了汇编代码)
lame:http://lame.sourceforge.net/download.php(Mp3音频解码)
OpenCore AMR:http://sourceforge.net/projects/opencore-amr
AmrNB:http://www.penguin.cz/~utx/amr
AmrWB:http://www.penguin.cz/~utx/amr
FFMpeg:http://ffmpeg.org/download.html。
分别解压缩并编译上述源码包
#tar xzvf *.tar.gz
#tar xjvf *.tar.bz2
解压后直接使用
#./configure
#make
#make install
命令进行编译安装。
编译FFMpef的时候稍微特殊一点:
#./configure –enable-libmp3lame –enable-libopencore-amrnb –enable-libopencore-amrwb –enable-version3 –enable-shared
#make
#make install
#ldconfig
最后写入config后,终端运行ffmpeg命令,出现success和已安装的扩展,则运行成功。
3.使用方法
MP3转换AMR: ffmpeg -i 1.mp3 -ac 1 -ar 8000 1.amr
AMR转换MP3: ffmpeg -i 1.amr 1.mp3
可能遇到的问题
1.ffmpeg默认安装目录为“/usr/local/lib”,有些64位系统下软件目录则为“/usr/lib64”,编译过程中可能会出现
“ffmpeg: error while loading shared libraries: libmp3lame.so.0: cannot open shared object file: No such file or directory”等类似的错误,
解决办法是建立软链接:
#ln -s /usr/local/lib/libmp3lame.so.0.0.0 /usr/lib64/libmp3lame.so.0
2.此时如果出现以下提示:
ffmpeg: error while loading shared libraries: libavdevice.so.54: cannot open shared object file: No such file or directory
可以通过如下方式查看ffmpeg的动态链接库哪些没有找到:
# ldd `which ffmpeg`
libavdevice.so.54 => not found
libavfilter.so.3 => not found
libavformat.so.54 => not found
libavcodec.so.54 => not found
libswresample.so.0 => not found
libswscale.so.2 => not found
libavutil.so.51 => not found
libm.so.6 => /lib64/libm.so.6 (0x00002ab7c0eb6000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x00002ab7c100b000)
libc.so.6 => /lib64/libc.so.6 (0x00002ab7c1125000)
/lib64/ld-linux-x86-64.so.2 (0x00002ab7c0d9a000)
如果类似于上面的输出内容,查找以上类库:
# find /usr/local/lib/ | grep -E “libavdevice.so.54|libavfilter.so.3|libavcodec.so.54”
/usr/local/lib/libavfilter.so.3.17.100
/usr/local/lib/libavcodec.so.54.59.100
/usr/local/lib/libavdevice.so.54
/usr/local/lib/libavcodec.so.54
/usr/local/lib/libavfilter.so.3
/usr/local/lib/libavdevice.so.54.2.101
会发现全部在/usr/local/lib/下
查看链接库配置文件
# more /etc/ld.so.conf | grep /usr/local/lib
如果不包含的话,需要编辑此文添加:
/usr/local/lib
/usr/local/lib64
运行配置命令
# ldconfig
=============================================