0
点赞
收藏
分享

微信扫一扫

rust学习(tokio协程分析二)

fbd4ffd0717b 03-05 12:30 阅读 4

针对Linux环境下如何安装ffmpeg请看上一篇文章Linux上搭建并使用ffmpeg(Java)-CSDN博客

public static void voiceChangeFormat(String localPath, String targetPath) {
        List<String> command = new ArrayList<>();
        command.add("ffmpeg");
        command.add("-i");
        command.add(localPath);
        command.add("-ar");
        command.add("8000");
        command.add("-ab");
        command.add("12.2k");
        command.add("-ac");
        command.add("1");
        command.add(targetPath);
        commandStart(command);
    }

/**
     * 调用命令行执行
     *
     * @param command 命令行参数
     */
    public static void commandStart(List<String> command) {
        command.forEach(v -> System.out.print(v + " "));
        System.out.println();
        System.out.println();
        ProcessBuilder builder = new ProcessBuilder();
        //正常信息和错误信息合并输出
        builder.redirectErrorStream(true);
        builder.command(command);
        //开始执行命令
        Process process = null;
        try {
            process = builder.start();
            //如果你想获取到执行完后的信息,那么下面的代码也是需要的
            String line = "";
            BufferedReader br = new BufferedReader(new InputStreamReader(process.getInputStream()));
            while ((line = br.readLine()) != null) {
                System.out.println(line);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
举报

相关推荐

0 条评论