1. 服务器安装ffmpeg
2. 执行命令 ffmpeg -i {amr_file_path} -f mp3 -acodec libmp3lame -y {mp3_file_path}
public static boolean changeAmr2Mp3(final String ffmpegPath, final String amrFilePath, final String mp3FilePath) { if (!Mp3TranslateUtils.checkfile(amrFilePath)) { Mp3TranslateUtils.LOGGER.error(amrFilePath + " is not file"); return false; } final List<String> command = new ArrayList<String>(); command.add(ffmpegPath); command.add("-i"); command.add(amrFilePath); command.add("-f"); command.add("mp3"); command.add("-acodec"); command.add("libmp3lame"); command.add("-y"); command.add(mp3FilePath); try { final ProcessBuilder builder = new ProcessBuilder(); builder.redirectErrorStream(true); builder.command(commend); final Process process = builder.start(); try { process.waitFor(); } catch (final InterruptedException e) { e.printStackTrace(); Thread.currentThread().interrupt(); } process.getErrorStream().close(); return true; } catch (final Exception e) { e.printStackTrace(); return false; } }
时间: 2024-11-04 09:38:52