我服了,使用 Java 和 Python 运行 ffmpeg 命令, Java 运行了大半天不出结果, Python 秒出

2020-10-18 11:27:49 +08:00
 qwertty01

大佬们,能不能说一下为什么这样啊 java

public class TestApp {
    public static void main(String[] args) throws IOException, InterruptedException {
        ProcessBuilder processBuilder = new ProcessBuilder("D:\\ffmpeg\\bin\\ffmpeg.exe", "-i", "D:\\test\\test.mp4",
                "-strict", "-2", "-vf", "crop=280:360:0:0", "D:\\test\\out.mp4"
        );
        Process process = processBuilder.start();
        process.waitFor();
    }
}

python

os.system("D:\\ffmpeg\\bin\\ffmpeg.exe -i D:\\test\\test.mp4 -strict -2 -vf crop=280:360:0:0 D:\\test\\out.mp4")

1967 次点击
所在节点    问与答
7 条回复
xl224
2020-10-18 12:25:33 +08:00
把 stdout 和 stderr 读出来,也可以设置转发 err 到 stdout 然后一起读取出来,不读取如果写满缓冲会挂起程序,ffmpeg 我记得会有大量输出信息
paulluis2dev
2020-10-18 12:49:59 +08:00
没用对,说明不了问题
qwertty01
2020-10-18 13:26:08 +08:00
@xl224 大佬这样写行吗?
```
Process process = processBuilder.start();
byte[] bytes = new byte[104];
while (true) {
if (process.getInputStream().read(bytes) != -1) {
System.out.println(bytes.toString());
} else {
break;
}
}
```
lxk11153
2020-10-18 13:27:24 +08:00
-y (global)
Overwrite output files without asking.
chihiro2014
2020-10-18 13:29:16 +08:00
= =说起来,我服务端也是用 Java 调用 ffmpeg,完全没这种问题
lxk11153
2020-10-18 13:40:29 +08:00
-strict 拿来干嘛的?

----
try(InputStream pis=process.getInputStream()){
// org.apache.commons.io.IOUtils#toString(InputStream, Charset)
}
qwertty01
2020-10-18 16:59:32 +08:00
@lxk11153 不知道,我直接在网上抄的命令 😂

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/716072

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX