# 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
=============================================