【问题标题】:ffmpeg running on windows with javaffmpeg 使用 java 在 windows 上运行
【发布时间】:2014-01-12 09:25:43
【问题描述】:

我有简单的测试类

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,然后运行也无法正常工作。请提出可能的问题

【问题讨论】:

    标签: java ffmpeg


    【解决方案1】:

    ffmpeg.exe 安装在哪里?尝试使用完整路径执行ffmpeg.exe

    例如

    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();
    

    【讨论】:

    • 我添加了完整路径如下 String[] line = {"C:\\Program Files\\ffmpeg\\bin\\ffmpeg.exe -i D:\\hadoop-video\\testVideo \\xyz.mp4 %d.png"}; Runtime.getRuntime().exec(line);还是不行。
    • 我得到的错误是无法运行程序“C:\Program Files\ffmpeg\bin\ffmpeg.exe -i D:\hadoop-video\testVideo\xyz %d.png”:CreateProcess错误=2,系统找不到在 java.lang.Runtime.exec(Unknown Source) at java.lang.Runtime.exec(Unknown Source) at ImageTest 的 java.lang.ProcessBuilder.start(Unknown Source) 指定的文件。主(ImageTest.java:14)
    • String[] line = {"C:\\Program Files\\ffmpeg\\bin\\ffmpeg", "-i", "D:\\hadoop-video\\testVideo\\ xyz", "%d.png"}; Runtime.getRuntime().exec(line);现在没有错误出现,但是图像也没有生成
    • 在 Eclipse 工作区中检查你的项目目录,这将包含所有生成的图像;)
    • 嘿,谢谢 .. 它在 Eclipse 中。我试图在视频文件夹中搜索..我们可以自定义位置吗?再次感谢 :) 干杯
    猜你喜欢
    • 2017-10-29
    • 1970-01-01
    • 2012-05-10
    • 1970-01-01
    • 2010-11-19
    • 1970-01-01
    • 2017-08-04
    • 2012-10-27
    • 1970-01-01
    相关资源
    最近更新 更多