欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

使用ffmpeg实现 amr转mp3

程序员文章站 2022-07-13 13:23:59
...

参考文章:

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

使用ffmpeg实现 amr转mp3

3. 将ffmpeg拷贝到Linux环境下

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

使用ffmpeg实现 amr转mp3

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

chmod +x ffmpeg

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

./ffmpeg  -i test.amr  test.mp3

 

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

你可能得到的日志如下:

 

使用ffmpeg实现 amr转mp3

 

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

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