转载:http://blog.youkuaiyun.com/sanshipianyezi/article/details/78742621
转载:http://blog.youkuaiyun.com/szfhy/article/details/50441162
在linux下进行wav和amr的相互转换,如果是amr转为wav只需要ffmpeg即可 但是若wav转为amr则需要依赖ffmpeg和opencore_amrnb库。
完整下载地址:http://download.youkuaiyun.com/download/sanshipianyezi/10149789
1.Linux下安装ffmpeg
ffmpeg下载地址:https://www.johnvansickle.com/ffmpeg/
release: 3.4 也是免安装版(只需解压) 只需要下载放到/usr/local/目录下
//解压ffmpeg
tar -xvf ffmpeg-release-64bit-static.tar.xz
- 1
- 2
2.安装opencore-amr
opencore-amr库下载地址:https://sourceforge.net/projects/opencore-amr/
把下载的opencore-amr-0.1.5.tar.gz放到/usr/local/目录下
//编译方法
chmod 755 opencore-amr-0.1.5.tar.gz //改变文件操作权限 tar -xzvf opencore-amr-0.1.5.tar.gz //解压文件 cd opencore-amr-0.1.5 //进入到opencore-amr文件夹内 ./configure --enable-shared=no --enable-static=yes //配置 make //编译 make install
- 1
- 2
- 3
- 4
- 5
- 6
- 7
3.进入ffmpeg下实现wav转amr和amr转wav
1.wav转amr
//wav转amr
#pwd
/usr/local/ffmpeg-3.4-64bit-static/ [root@localhost ffmpeg-3.4-64bit-static]# ./ffmpeg -i hello1.wav -c:a libopencore_amrnb -ac 1 -ar 8000 -b:a 7.95k -y 1.amr
- 1
- 2
- 3
- 4
- 5
2.amr转wav
//amr转wav
./ffmpeg -i 1.amr 1.wav
- 1
- 2
4.java调用
import java.io.IOException;
/**
* wav文件转amr工具类
* @author sanpianyezi
*
*/
public class Wav2AmrUtil { //ffmpeg执行目录 private final static String FFMPEG_PATH ="/usr/local/ffmpeg-3.4-64bit-static/ffmpeg"; /** * 将一个wav文件转换成amr文件 * * @param wavPath * @param amrPath * @throws IOException * @retuen boolean */ public static boolean Wav2Amr(String wavPath,String amrPath) throws IOException { try{ String shellContent = FFMPEG_PATH + " -i " + wavPath + " -c:a libopencore_amrnb -ac 1 -ar 8000 -b:a 7.95k -y "+amrPath; System.out.println("wav2amr执行命令行为:"+shellContent); Runtime.getRuntime().exec(shellContent); System.out.println("wav2amr执行成功"); return true; }catch(Exception e){ System.out.println("wav2amr执行失败:"+e.getMessage()); return false; } } }
- 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
//异常说明
我在安装过程中出现configure: error: C++ compiler cannot create executables问题
这后来查了一下相关资料后才发现是gcc的组件没有装全,我之前安装gcc时是通知yum方式:
yum install gcc gcc++
这样的话还是有组件没有安装完整的。再执行一下这个命令就可以解决问题。
yum install gcc gcc-c++ gcc-g77
这下应该没有什么问题了。
引用参考:http://blog.youkuaiyun.com/u010018421/article/details/71280099