php实现amr转成mp3的方法:1、在服务器安装ffmpeg;2、使用“ffmpeg -i”指令来转换amr为mp3格式;3、在网页端使用html5的audio标签来播放mp3文件即可。

思路

  1. 服务器安装ffmpeg
  2. 使用ffmpeg -i 指令来转换amr为mp3格式(这个到时候写在PHP代码中,使用exec函数执行即可)

一、服务器安装ffmpeg以cenos为例

1. 首先安装系统编译环境

yum install -y automake autoconf libtool gcc gcc-c++  #CentOS
  • 1.

2. 编译所需源码包

#yasm:汇编器,新版本的ffmpeg增加了汇编代码
wget http://www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gz
tar -xzvf yasm-1.3.0.tar.gz
cd yasm-1.3.0
./configure
make
make install


#lame:Mp3音频解码
wget http://jaist.dl.sourceforge.net/project/lame/lame/3.99/lame-3.99.5.tar.gz
tar -xzvf lame-3.99.5.tar.gz
cd lame-3.99.5
./configure
make
make install


#amr支持
wget http://downloads.sourceforge.net/project/opencore-amr/opencore-amr/opencore-amr-0.1.3.tar.gz
tar -xzvf opencore-amr-0.1.3.tar.gz
cd opencore-amr-0.1.3
./configure
make
make install


#amrnb支持
wget http://www.penguin.cz/~utx/ftp/amr/amrnb-11.0.0.0.tar.bz2
tar -xjvf amrnb-11.0.0.0.tar.bz2
cd amrnb-11.0.0.0
./configure
make
make install


#amrwb支持
wget http://www.penguin.cz/~utx/ftp/amr/amrwb-11.0.0.0.tar.bz2
tar -xjvf amrwb-11.0.0.0.tar.bz2
cd amrwb-11.0.0.0
./configure
make
make install


#ffmpeg
wget http://ffmpeg.org/releases/ffmpeg-2.5.3.tar.bz2
tar -xjvf ffmpeg-2.5.3.tar.bz2
cd ffmpeg-2.5.3
./configure --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-version3 --enable-shared
make
make install



#加载配置
#最后写入config后,终端运行ffmpeg命令,出现success和已安装的扩展,则运行成功。
ldconfig
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.
  • 56.
  • 57.
  • 58.

3.使用方法

ffmpeg -i 1.mp3 -ac 1 -ar 8000 1.amr  #MP3转换AMR
ffmpeg -i 1.amr 1.mp3                 #AMR转换MP3
  • 1.
  • 2.

 

php使用案例

$root_path = root_path();
$conversion_fileUrl = str_replace('amr','mp3',$fileUrl);
$shell_exec      = "ffmpeg -i {$root_path}public/{$fileUrl} {$root_path}public/{$conversion_fileUrl}";
shell_exec($shell_exec);
$fileUrl = $conversion_fileUrl;
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.