【问题标题】:Open ffplay & execute command with ProcessBuilder not working使用 ProcessBuilder 打开 ffplay 并执行命令不起作用
【发布时间】:2015-10-18 01:58:34
【问题描述】:

我尝试使用 ProcessBuilder 打开 ffplay.exe 并将命令执行到 ffplay。然而它并不成功。我怎么能那样做?

代码:

ProcessBuilder pb = new ProcessBuilder();

pb.command("C:\\Windows\\System32\\cmd.exe", "/c",
"C:\\ffmpeg\\bin\\ffplay.exe", "tcp://192.168.1.1:5555"); 

pb.start();

【问题讨论】:

    标签: java cmd ffmpeg


    【解决方案1】:

    尝试使用Runtime.getRuntime().exec() 并这样做:-

    String[] command = {"ffplay.exe", "tcp://192.168.1.1:5555"}; // add in String array in sequence, the commands to execute
    Process process = Runtime.getRuntime().exec(String[] options, null, new File("C:\\ffmpeg\\bin"));
    int returnVal = process.waitFor(); // should return 0 for correct execution
    try {
                final BufferedReader reader = new BufferedReader(
                        new InputStreamReader(process.getInputStream()));
                String line = null;
                while ((line = reader.readLine()) != null) {
                    System.out.println(line); //check for the inputstream & see the output here
                }
                reader.close();
            } catch (final Exception e) {
                e.printStackTrace();
            }
    

    【讨论】:

    • 您好,请问如何按顺序添加数组来执行?谢谢!
    • @DennisQT 我的意思是在String 数组中添加完整的命令,用空格分隔。比如如果命令是ffmpeg -i input.flv output.mp4,那么数组就是{"ffmpeg", "-i", "input.flv", "output.mp4"}
    • 所以我添加了:String[] command = {"C:\\ffmpeg\\bin\\ffplay.exe", "ffplay tcp://192.168.1.1:5555"} ;它返回值 0。但我仍然无法打开 ffplay。完全没有错误。
    • 我想进入ffplay程序并执行“ffplay tcp://192.168.1.1:5555”的命令。那怎么可能呢?我做的对吗?
    • @DennisQT 尝试编辑后的代码来检查inputstream 以及输出
    猜你喜欢
    • 2015-06-18
    • 2019-04-10
    • 1970-01-01
    • 2014-02-10
    • 2011-04-16
    • 2014-03-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多