java.io.IOException : Cannot run program "usr/bin/ffmpeg ": error=2, 没有那个文件或目录

标签 java linux ubuntu ffmpeg

我在 Ubuntu 服务器中从 java 程序执行 ffmpeg 命令时遇到错误。当我在 putty 中执行时,它执行成功但从 java 中它给了我

的异常
java.io.IOException: Cannot run program "/usr/bin/ffmpeg ": 
error=2, No such file or directory

我的代码如下:

public String convert3gpTomp4(File contentFile, String filename) {
    String[] cmd = new String[6];
    filename = StringUtils.substringBefore(filename, ".");      
    cmd[0] =  "/usr/bin/ffmpeg ";
    cmd[1] = "-y ";
    cmd[2] = "-i ";
    cmd[3] = contentFile.getPath();
    cmd[4] = "  -acodec copy ";
    String myfilename = filename +"eg.mp4";
    cmd[5] = contentFile.getParent() + "/" + myfilename;        

    if (execute(cmd)){
            return myfilename;
    }else{      
        return null;
    }

   }
}

public boolean execute(String[] cmd){
    try{
        Runtime rt= Runtime.getRuntime();

        Process proc = rt.exec(cmd);

        StreamGobbler errorGobbler = new StreamGobbler(proc.getErrorStream(), "ERROR");
        StreamGobbler outputGobbler = new StreamGobbler(proc.getInputStream(), "OUTPUT");
        errorGobbler.start();
        outputGobbler.start();

        int exitVal = proc.waitFor();
        String sb = outputGobbler.sb.toString();
        String eb = errorGobbler.sb.toString();

        System.out.println("Command Exceute Exit value: " + exitVal);

        proc.destroy();

        return true;
    }
    catch(java.io.IOException e ){System.out.println("IOException "+e);e.printStackTrace();}
    catch(java.lang.InterruptedException e){}

    return false;

}

ffmpeg命令的输出:

/usr/bin/ffmpeg -y -i /mydata/clip1.3gp -acodec copy /mydata/clip1eg.mp4

当我在 putty 中运行上面的命令时,它成功执行但来自 Java 程序。

在程序中,我也尝试了以下但没有成功。

usr/bin/ffmpeg
/bin/ffmpeg
ffmpeg
/root/usr/bin/ffmpeg

请告诉我哪里做错了。

谢谢,

最佳答案

要找到 ffmpeg 的完整路径,请从您的 putty 运行以下命令:

  which ffmpeg

如果通过 rpm 包安装,默认路径是 /usr/bin/ffmpeg

关于java.io.IOException : Cannot run program "usr/bin/ffmpeg ": error=2, 没有那个文件或目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28632100/

相关文章:

c - GDB 和核心转储问题

linux - 使用 Shell 脚本递归删除 Linux 中的所有备份文件

apache - 使用 htaccess 将子域重写到子文件夹

java - 如何在Java中解析css文件

java - 无法导入servlet类

java - 如何重写实例/具体类的方法运行时? (例如反射、cglib)

c++ - GCC - 多个预编译头文件和特定路径

java - HashMap - 正确用法?

c++ - Linux守护进程中的shell命令

php - 如何在 ubuntu 上安装 PECL 扩展?