環境依賴說明:
1、在服務器安裝ffmpeg
2、使用ffmpeg -i 命令來轉換amr為mp3格式
# php代碼 command = "/sbin/ffmpeg -y -i {#amrPath} {#mp3Path} 2>&1"; exec(#command, #out, #exitval);
cenos6系統下安裝ffmpeg,具體安裝步驟如下:
① 首先安裝系統編譯依賴環境 [root@localhost /]# yum install -y automake autoconf libtool gcc gcc-c++ ② 編譯所需源碼包 #yasm:匯編器,新版本的ffmpeg增加了匯編代碼 [root@localhost /]# wget http://www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gz [root@localhost /]# tar -xzvf yasm-1.3.0.tar.gz [root@localhost /]# cd yasm-1.3.0 [root@localhost /]# ./configure [root@localhost /]# make && make install #lame:Mp3音頻解碼 [root@localhost /]# wget http://jaist.dl.sourceforge.net/project/lame/lame/3.99/lame-3.99.5.tar.gz [root@localhost /]# tar -xzvf lame-3.99.5.tar.gz [root@localhost /]# cd lame-3.99.5 [root@localhost /]# ./configure [root@localhost /]# make && make install #amr支持 [root@localhost /]# wget http://downloads.sourceforge.net/project/opencore-amr/opencore-amr/opencore-amr-0.1.3.tar.gz [root@localhost /]# tar -xzvf opencore-amr-0.1.3.tar.gz [root@localhost /]# cd opencore-amr-0.1.3 [root@localhost /]# ./configure [root@localhost /]# make && make install #amrnb支持 [root@localhost /]# wget http://www.penguin.cz/~utx/ftp/amr/amrnb-11.0.0.0.tar.bz2 [root@localhost /]# tar -xjvf amrnb-11.0.0.0.tar.bz2 [root@localhost /]# cd amrnb-11.0.0.0 [root@localhost /]# ./configure [root@localhost /]# make && make install #amrwb支持 [root@localhost /]# wget http://www.penguin.cz/~utx/ftp/amr/amrwb-11.0.0.0.tar.bz2 [root@localhost /]# tar -xjvf amrwb-11.0.0.0.tar.bz2 [root@localhost /]# cd amrwb-11.0.0.0 [root@localhost /]# ./configure [root@localhost /]# make && make install #ffmpeg [root@localhost /]# wget http://ffmpeg.org/releases/ffmpeg-2.5.3.tar.bz2 [root@localhost /]# tar -xjvf ffmpeg-2.5.3.tar.bz2 [root@localhost /]# cd ffmpeg-2.5.3 [root@localhost /]# ./configure --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-version3 --enable-shared [root@localhost /]# make && make install #加載配置 #最后寫入config后,終端運行ffmpeg命令,出現success和已安裝的擴展,則運行成功 [root@localhost /]# ldconfig ③ 使用方法 [root@localhost /]# ffmpeg -i 1.mp3 -ac 1 -ar 8000 1.amr #MP3轉換AMR [root@localhost /]# ffmpeg -i 1.amr 1.mp3 #AMR轉換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"等類似的錯誤,解決辦法是建立軟鏈接:
[root@localhost /]# 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的動態鏈接庫哪些沒有找到:
[root@localhost /]# ldd `which ffmpeg` [root@localhost /]# 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) # 如果類似於上面的輸出內容,查找以上類庫,會發現全部在/usr/local/lib/下 [root@localhost /]# find /usr/local/lib/ | grep -E "libavdevice.so.54|libavfilter.so.3|libavcodec.so.54" [root@localhost /]# /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 #查看鏈接庫配置文件 [root@localhost /]# more /etc/ld.so.conf | grep /usr/local/lib #如果不包含的話,需要編輯此文添加: [root@localhost /]# vi /etc/ld.so.conf [root@localhost /]# /usr/local/lib [root@localhost /]# /usr/local/lib64 #運行配置命令 [root@localhost /]# ldconfig
