1. 首先安装系统编译环境
yum install -y automake autoconf libtool gcc gcc-c++ #CentOS
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
#加载配置
vi /etc/ld.so.conf
在文件末尾加上:安装目录 例如 /usr/local/lib
执行命令:ldconfig
执行ffmpeg
3.使用方法
ffmpeg -i 1.amr 1.mp3 #AMR转换MP3
核心代码
public static void amrToMP3Linux(String localPath, String targetFilePath){
log.info("执行命令开始");
String command = "ffmpeg -i "+localPath+" "+targetFilePath;
log.info("the command is : "+command);
Runtime runtime = Runtime.getRuntime();
try {
Process proc = runtime.exec(command);
InputStream stderr = proc.getErrorStream();
InputStreamReader isr = new InputStreamReader(stderr);
BufferedReader br = new BufferedReader(isr);
String line = null;
StringBuffer sb = new StringBuffer();
while ((line = br.readLine()) != null)
sb.append(line);
int exitVal = proc.waitFor();
log.info("the exitVal is : "+exitVal);
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
log.info("ffmpeg exec cmd Exception " + e.toString());
}
log.info("执行命令结束");
}