Linux下配置ffmpeg环境 转AMR为MP3
参考:http://hi.baidu.com/duqingming/item/4adf34337d75b65a81f1a7e5
1. 首先安装系统基础环境
RHEL & CentOS 系列:yum install -y automake autoconf libtool gcc gcc-c++
2. 编译所需源码包(附近中在Linux环境已经可以正常使用)
yasm:http://yasm.tortall.net/Download.html(汇编器,新版本的ffmpeg增加了汇编代码)
lame:http://lame.sourceforge.net/download.php(Mp3音频解码)
OpenCore AMR (fdk-aac-0.1.3 ):http://sourceforge.net/projects/opencore-amr
FFMpeg:http://ffmpeg.org/download.html
yasm、lame、OpenCore 解压后直接使用
#./configure
#make
#make install
命令进行编译安装。
FFMpeg特殊:
#./configure --enable-libmp3lame --enable-version3 --enable-shared
#make
#make install
#ldconfig
终端运行ffmpeg命令,出现success和已安装的扩展,则运行成功。
必须在Linux环境下授权
chmod 777 ffmpeg 或者 chmod 755 ffmpeg
Java代码
private boolean linuxToMp3(String localPath) {
try{
log.warn("************** ffmpeg ****************");
java.lang.Runtime rt = Runtime.getRuntime();
String command = "ffmpeg -i " + localPath + " " + localTargetFilePath;
log.warn("ffmpeg exec command = " + command);
Process proc = rt.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);
log.warn("ffmpeg Process errorInfo: " + sb.toString());
int exitVal = proc.waitFor();
log.warn("ffmpeg Process exitValue: " + exitVal);
return true;
}
catch(Exception e)
{
log.warn("ffmpeg exec cmd Exception " + e.toString());
}
return false;
}