PHP converts AMR audio files to MP3 format

Source: Internet
Author: User
Tags bz2

The whole idea

1, Server Installation FFmpeg

2, Use the FFMPEG-I directive to convert AMR to MP3 format (this will be written in PHP code, using the EXEC function can be executed)

3. Use the HTML5 audio tag to play the MP3 file on the web side

Here are the details of the operation:

first, Server Installation FFmpeg take Cenos as an example

Reference Here: http://my.oschina.NET/ethan09/blog/372435

It is important to note that in the following method, the installation of Amrnb and AMRWB to the make link will request a URL of 3gp, which is generally not requested, you can cancel his process with crtl+c, and these two do not need to be able to convert the format

Received the need to convert AMR to mp3,windows under the Linux environment directly using the third party jar package Package EXE method can be, but does not support linux, the internet climbed the data said to be using FFmpeg plus AMR plug-in can be achieved, according to the tutorial to try a bit:

1. Install the system compilation environment first

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

2. Compile the required source code package

1 #yasm: assembler, new version of ffmpeg adds assembly code
  3 wget
  5 tar -xzvf yasm-1.3.0.tar.gz
  7 cd yasm-1.3.0
  9 ./configure
 11 make
 13 make install
 17 #lame: Mp3 audio decoding
 19 wget
 21 tar -xzvf lame-3.99.5.tar.gz
 twenty two 
 23 cd lame-3.99.5
 twenty four 
 25 ./configure
 27 make
 29 make install
 33 #amr support
 35 wget
 37 tar -xzvf opencore-amr-0.1.3.tar.gz
 39 cd opencore-amr-0.1.3
 41 ./configure
 43 make
 45 make install
 49 #amrnbSupport
 51 wget
 53 tar -xjvf amrnb-
 55 cd amrnb-
 57 ./configure
 59 make
 61 make install
 65 #amrwbSupport
 67 wget
 69 tar -xjvf amrwb-
 71 cd amrwb-
 73 ./configure
 75 make
 77 make install
 81 #ffmpeg
 83 wget
 85 tar -xjvf ffmpeg-2.5.3.tar.bz2
 87 cd ffmpeg-2.5.3
 89 ./configure --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-version3 --enable-shared
 91 make
 93 make install
 97 #Load Configuration
 99 # After writing the config, the terminal runs the ffmpeg command, and the success and installed extensions appear, and the operation succeeds.
101 ldconfig

3. How to use

1 ffmpeg -i 1.mp3 -ac 1 -ar 8000 1.amr #MP3 convert AMR
3 ffmpeg -i 1.amr 1.mp3 #AMR convert MP3

Appendix 1. FFmpeg default installation directory is "/usr/local/lib", some 64-bit systems under the Software directory is "/usr/lib64", the compilation process may appear
"ffmpeg:error while loading shared open Shared object file:no such file or directory" The solution to such a similar error is to establish a soft link:
# ln-s/usr/local/lib/

Appendix 2. If the following prompt appears: Ffmpeg:error while loading shared open Shared object file:no such file or Directory
You can view Ffmpeg's dynamic link libraries in the following ways which are not found:

1 ldd `which ffmpeg`
 3 => not found
 5 => not found
 7 => not found
 9 => not found
11 => not found
13 => not found
15 => not found
17 => /lib64/ (0x00002ab7c0eb6000)
19 => /lib64/ (0x00002ab7c100b000)
21 => /lib64/ (0x00002ab7c1125000)
twenty two 
23 /lib64/ (0x00002ab7c0d9a000)
twenty four 
25 #If similar to the above output, look for the above class library, you will find all under /usr/local/lib/
27 find /usr/local/lib/ | grep -E "||"
29 /usr/local/lib/
31 /usr/local/lib/
33 /usr/local/lib/
35 /usr/local/lib/
37 /usr/local/lib/
39 /usr/local/lib/
43 #View Link Library Configuration File
45 more /etc/ | grep /usr/local/lib
47 # If not included, you need to edit this article to add:
49 vi /etc/
51 /usr/local/lib
53 /usr/local/lib64
55 #Run Configuration Command
57 ldconfig


About FFmpeg introduction:

FFmpeg is an open source, free Cross-platform video and audio streaming solution that belongs to free software, with a LGPL or GPL license (depending on the component you choose). It provides a complete solution for recording, converting, and streaming audio and video. It contains a very advanced Audio/video codec library libavcodec, in order to ensure high portability and codec quality, Libavcodec Many codec are developed from Scratch. Its official website is:

finally, Some of the contents refer to Http://

Ii. use of the FFMPEG directive

After the first step, you can use FFMPEG--HELP to see if the installation is correct, if not, please check if you forgot make install

The instructions to use the conversion are ffmpeg-i 1.AMR 2.mp3

Will convert the 1.AMR to 2.mp3

third, use PHP to execute Linux instructions ffmpeg

The conversion of the file is certainly not self-kept to the server running Linux instructions, so we use PHP to execute the Linux instructions to process the AMR file

Use the EXEC function to perform

1 $amr = ‘./‘.$vo[‘voice‘];
2 $mp3 = $amr.‘.mp3‘;
4 if(file_exists($mp3) == true){
5 // exit (‘no conversion ‘);
6 }else{
7 $command = "/usr/local/bin/ffmpeg -i $amr $mp3";
8 exec($command,$error);
9 }

Take a closer look at the code, I use The/usr/local/bin/ffmpeg to execute, because I use PHP can not directly run FFmpeg instructions, If your instructions are not in this directory, you can use locate or find to find the FFmpeg directory

PHP converts AMR audio files to MP3 format

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.