JAVA-文件格式转换工具webmToWav

音频文件格式转换工具类

public class CmdUtil {

    public static final Logger LOGGER = LoggerFactory.getLogger(CmdUtil.class);

    public static int webmToWav(String input, String output) {
        LOGGER.info("webmToWav the param is, url is {}, outPut is {}", input, output);
        // 构建FFmpeg命令
        String commandSb = "ffmpeg -y -i " + input + " -c:a pcm_s16le -f wav -ac 1 -ar 16000 " + output;
        LOGGER.info("【webmToWav】 命令是:{}", commandSb);
        // 执行命令
        Process process;
        int exitCode = -1;
        try {
            process = Runtime.getRuntime().exec(commandSb);
            // 处理进程的输出流
            BufferedReader errorReader = new BufferedReader(new InputStreamReader(process.getErrorStream()));
            String errorLine;
            while ((errorLine = errorReader.readLine()) != null) {
                LOGGER.info(errorLine);
            }
            // 等待进程结束
            exitCode = process.waitFor();
            LOGGER.info("webmToWav the param is, url is {}, outPut is {}, exitCode is {}", input, output, exitCode);
            return exitCode;
        } catch (Exception e) {
            LOGGER.error("[getFirstPicFromVideo] met error", e);
            throw new BusinessException("webmToWav error");
        }
    }
}

猜你喜欢

转载自blog.csdn.net/caryeko/article/details/141321863