您的位置:首页 > 运维架构 > Linux

java在Linux下将amr转mp3方法

2018-03-01 18:37 489 查看
1. 首先安装系统编译环境
 
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;  
    }  
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  java linux amr mp3