用java在windows上运行的ffmpeg

时间:2013-12-24 06:08:39

标签: java ffmpeg

我有简单的测试类

public static void main(String[] args) throws IOException {

         String[] line = {"ffmpeg -i D:\\hadoop-video\\testVideo\\xyz.mp4 %d.png"};
         Runtime.getRuntime().exec(line);

    }

当我尝试运行时,我正在

Exception in thread "main" java.io.IOException: Cannot run program "ffmpeg -i D:/hadoop-video/testVideo/xyz.mp4 %d.png": CreateProcess error=2, The system cannot find the file specified
    at java.lang.ProcessBuilder.start(Unknown Source)
    at java.lang.Runtime.exec(Unknown Source)
    at java.lang.Runtime.exec(Unknown Source)
    at ImageTest.main(ImageTest.java:13)
Caused by: java.io.IOException: CreateProcess error=2, The system cannot find the file specified

但是我的windows7机器上存在文件位置

D:\hadoop-video\testVideo\xyz.mp4

我尝试删除.mp4然后运行也无法正常工作。请建议可能出现的问题

1 个答案:

答案 0 :(得分:1)

安装ffmpeg.exe的位置?尝试使用完整路径来执行ffmpeg.exe

e.g。

d:\ ffmpeg的\ BIN \ ffmpeg.exe

然后

String cmd[] = {"D:\\ffmpeg\\bin\\ffmpeg","-i","D:\\ffmpeg\\hadoop.mp4","D:\\ffmpeg\\img%d.png"};
Runtime.getRuntime().exec(cmd);

Process process = new ProcessBuilder(Arrays.asList(cmd)).start();