java ffmpeg amr mp3_使用ffmpeg实现 amr转mp3

参考文章:

备注:使用博主提供的jar包,在linux下试验不成功。最后使用shell命令调用ffmpeg实现。

使用ffmpeg:

1.  从这里下载 https://ffmpeg.org/download.html

2. 下载linux平台的Linux Static Builds

72e46984b82d5646dd0ab715cc9d3b9e.png

3. 将ffmpeg拷贝到Linux环境下

4. 准备一个amr文件,将两个文件都拷贝到同一个目录下,进行测试。如果准备好了,如图:

c87e35138541f39b44af055a05456ea9.png

5. 接着先给ffmpeg加个执行权限

chmod +x ffmpeg

6. 接着调用 ffmpeg 执行转换下

./ffmpeg -i test.amr test.mp3

然后你会看到一堆的日志,并且可能还有提示,“test.amr: Input/output error”,但不要担心,先不管,你查看下这个目录下是否多了一个test.mp3 文件。如果有了,恭喜你,转换成功了,尝试播放下MP3

你可能得到的日志如下:

fbd51de9bc827cbe6be5b4b99f9e872a.png

----------------------------------

shell调用

public class ShellUtil {

/**

* 运行shell脚本

*

* @param shell

* 需要运行的shell脚本

*/

public static void execShell(String shell) {

try {

Runtime rt = Runtime.getRuntime();

rt.exec(shell);

} catch (Exception e) {

e.printStackTrace();

}

}

/**

* 运行shell

*

* @param shStr

* 需要执行的shell

* @return

* @throws IOException

* @throws InterruptedException

*/

public static List runShell(String shStr) throws IOException, InterruptedException {

List strList = new ArrayList();

Process process;

process = Runtime.getRuntime().exec(new String[] { "/bin/sh", "-c", shStr }, null, null);

InputStreamReader ir = new InputStreamReader(process.getInputStream());

LineNumberReader input = new LineNumberReader(ir);

String line;

process.waitFor();

while ((line = input.readLine()) != null) {

strList.add(line);

}

return strList;

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值