java在Linux下将amr转mp3方法
2018-03-01 18:37
489 查看
1. 首先安装系统编译环境
2. 编译所需源码包
#yasm:汇编器,新版本的ffmpeg增加了汇编代码
3.使用方法
4.java代码 :
public class ChangeAudioFormat {
public static void main(String[] args) throws Exception {
String path1 = "/opt/1519895395744.amr";
String path2 = "/opt/1519895395744.mp3";
amrToMp3(path1, path2);
}
public static boolean amrToMp3(String localPath, String targetFilePath) {
try {
System.out.println("************** ffmpeg ****************");
java.lang.Runtime rt = Runtime.getRuntime();
String command = "ffmpeg -i " + localPath + " " + targetFilePath;
System.out.println("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);
}
System.out.println("ffmpeg Process errorInfo: " + sb.toString());
int exitVal = proc.waitFor();
System.out.println("ffmpeg Process exitValue: " + exitVal);
return true;
} catch (Exception e) {
System.out.println("ffmpeg exec cmd Exception " + e.toString());
}
return false;
}
}
yum
install
-y automake autoconf libtool
gcc
gcc
-c++
#CentOS
2. 编译所需源码包
#yasm:汇编器,新版本的ffmpeg增加了汇编代码
3.使用方法
4.java代码 :
public class ChangeAudioFormat {
public static void main(String[] args) throws Exception {
String path1 = "/opt/1519895395744.amr";
String path2 = "/opt/1519895395744.mp3";
amrToMp3(path1, path2);
}
public static boolean amrToMp3(String localPath, String targetFilePath) {
try {
System.out.println("************** ffmpeg ****************");
java.lang.Runtime rt = Runtime.getRuntime();
String command = "ffmpeg -i " + localPath + " " + targetFilePath;
System.out.println("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);
}
System.out.println("ffmpeg Process errorInfo: " + sb.toString());
int exitVal = proc.waitFor();
System.out.println("ffmpeg Process exitValue: " + exitVal);
return true;
} catch (Exception e) {
System.out.println("ffmpeg exec cmd Exception " + e.toString());
}
return false;
}
}
相关文章推荐
- Linux下将CD音乐提取为mp3的方法和中文乱码问题的解决
- Linux下将CD音乐提取为mp3的方法和中文乱码问题的解决
- Linux下将CD音乐提取为mp3的方法和中文乱码问题的解决
- Linux下将CD音乐提取为mp3的方法和中文乱码问题的解决
- Linux下将CD音乐提取为mp3的方法和中文乱码问题的解决
- Linux下将CD音乐提取为mp3的方法和中文乱码问题的解决
- linux&UNIX下WebSphere数据源连接出现java.lang.UnsatisfiedLinkError: SQLConnect问题的解决方法
- Linux操作系统下的三种Java环境配置方法
- Linux操作系统下的三种Java环境配置方法
- Java调用C(Linux下实现Java本地方法)
- java开发中linux常用方法
- 找到linux获得java线程ID的方法
- 关于JNI的使用(实战linux平台下java调用本地c语言方法)
- Linux下JAVA使用Graphics解决方法
- Linux下将CD音乐提取为mp3的方法和中文乱码问题的解决
- 纯Java通过SSH执行Linux命令的方法及代码
- Linux下将CD音乐提取为mp3的方法和中文乱码问题的解决
- Java调用Linux命令的方法
- Linux下将CD音乐提取为mp3的方法和中文乱码问题的解决
- Linux下将CD音乐提取为mp3的方法和中文乱码问题的解决