使用ffmpeg实现 amr转mp3

参考文章:

http://www.linjie.org/2015/08/06/amr%E6%A0%BC%E5%BC%8F%E8%BD%ACmp3%E6%A0%BC%E5%BC%8F-%E5%AE%8C%E7%BE%8E%E8%A7%A3%E5%86%B3Linux%E4%B8%8B%E8%BD%AC%E6%8D%A20K%E9%97%AE%E9%A2%98/

 

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

使用ffmpeg:
1.  从这里下载 https://ffmpeg.org/download.html
2. 下载linux平台的Linux Static Builds

004104_0EVM_1993939.png

3. 将ffmpeg拷贝到Linux环境下

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

arm和ffmpeg

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

chmod +x ffmpeg

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

./ffmpeg  -i test.amr  test.mp3

 

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

你可能得到的日志如下:

 

19004658_zSrT.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<String> runShell(String shStr) throws IOException, InterruptedException  {
		List<String> strList = new ArrayList<String>();

		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;
	}

}

 

转载于:https://my.oschina.net/jrrx/blog/734877

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值