将amr文件转成mp3
2016-04-06 09:40
561 查看
package com.ericlin.dongjing.util; import it.sauronsoftware.jave.AudioAttributes; import it.sauronsoftware.jave.Encoder; import it.sauronsoftware.jave.EncodingAttributes; import java.io.File; import java.io.IOException; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; /** * 将amr文件转成mp3 * 不同操作系统使用不同方式 * linux服务器需要安装ffmpeg, 将手机语音amr转为mp3格式 * 安装参考: * centos yum install ffmpeg ffmpeg-devel * Ubuntu apt-get install ffmpeg * 参考:https://www.ffmpeg.org/ * * @author Ericlin */ public class Mp3Util { private static Log log = LogFactory.getLog(Mp3Util.class); /** * 将amr格式转成mp3格式 * @param amrFilePath amr文件 * @return mp3文件路径 */ public static String convertAmr2Mp3(String amrFilePath) { File source = new File(IConstants.UPLOAD_FILE_PATH + amrFilePath); String extension = amrFilePath.substring(amrFilePath.lastIndexOf(".")); String targetFilename = amrFilePath.replace(extension, ".mp3"); String os = System.getProperties().getProperty("os.name").toLowerCase(); if (os.startsWith("win")) { File target = new File(IConstants.UPLOAD_FILE_PATH + targetFilename); Encoder encoder = new Encoder(); EncodingAttributes attrs = new EncodingAttributes(); attrs.setFormat("mp3"); AudioAttributes audio = new AudioAttributes(); audio.setCodec("libmp3lame"); attrs.setAudioAttributes(audio); try { encoder.encode(source, target, attrs); } catch (Exception e) { log.error("convert amr to mp3 error", e); } } else { String command = "ffmpeg -i " + IConstants.UPLOAD_FILE_PATH + amrFilePath + " " + IConstants.UPLOAD_FILE_PATH + targetFilename; try { Runtime.getRuntime().exec(command); } catch (IOException e) { log.error("convert amr to mp3 error", e); } } return targetFilename; } public static void main(String[] args) { String a = Mp3Util.convertAmr2Mp3("/223400017.amr"); System.out.println(a); } }
相关文章推荐
- java对世界各个时区(TimeZone)的通用转换处理方法(转载)
- java-注解annotation
- java-模拟tomcat服务器
- java-用HttpURLConnection发送Http请求.
- java-WEB中的监听器Lisener
- Android IPC进程间通讯机制
- Android Native 绘图方法
- Android java 与 javascript互访(相互调用)的方法例子
- 介绍一款信息管理系统的开源框架---jeecg
- 聚类算法之kmeans算法java版本
- java实现 PageRank算法
- PropertyChangeListener简单理解
- c++11 + SDL2 + ffmpeg +OpenAL + java = Android播放器
- 插入排序
- 冒泡排序
- 堆排序
- 快速排序
- 二叉查找树