-1

My Java program is running under a hosted server (not mine), the program is using ffmpeg as a video processing library, on my localhost installation I had no trouble while using my program and executing ffmpeg, the program extract the ffmpeg.exe somewhere and run it, but when its used on another server I had the following error while executing ffmpeg :

  java.io.IOException: Cannot run program "softwares/player/libraries/ffmpeg.exe": error=13, Permission denied
    at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1143)
    at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1073)
    at com.albert4224.player.Loader.run(TaskAsyncLoadVideo.java:83)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
    at java.base/java.lang.Thread.run(Thread.java:833)
  Caused by: java.io.IOException: error=13, Permission denied
    at java.base/java.lang.ProcessImpl.forkAndExec(Native Method)
    at java.base/java.lang.ProcessImpl.<init>(ProcessImpl.java:314)
    at java.base/java.lang.ProcessImpl.start(ProcessImpl.java:244)
    at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1110)

I tried to change permissions on the ffmpeg.exe file, through Java code such as ffmpegFile.setExecutable(true), File.setReadable(true), File.setWritable(true) but unsuccessfully, also tried to change file permission via my FileZilla software to 777, but again unsuccessfully :

enter image description here

What is strange is like permission goes back to 750 after server reboot, but even before restart it doesn't work.

Maybe related to : Permission denied error in Java for chmod command, I tried running other program that uses .exe library and resulted in a java.io.IOException: Cannot run program "/bin/chmod": error=13, Permission denied

Here is my code :

            String[] videoCommand = {new File(softhware.getFolder() + "/libraries/", "ffmpeg.exe").getAbsoluteFile().getAbsolutePath(), "-hide_banner", "-loglevel", "error", "-i", video.getVideoFile().getAbsolutePath(), "-q:v", "0",
                    "-start_number", String.valueOf(framesCount), new File(video.getFramesFolder().getPath(), "%d.jpg").getAbsolutePath()};
            
            ProcessBuilder videoProcessBuilder = new ProcessBuilder(videoCommand);
            
            try {
            Process process = videoProcessBuilder.inheritIO().start();
                process.waitFor();
            }catch (IOException | InterruptedException e) {
                e.printStackTrace();
            }

So, I was wondering if there can be any work around to use the library, give the needed permissions, or running it in a certain way that will not trigger permission check. Thanks you.

EDIT:

Thanks for your replies, I followed the answers, the server is running under unix and now my program looks like :

    try {
        
        Runtime.getRuntime().exec("chmod -R 777 " + FilenameUtils.separatorsToSystem(new File(softhware.getFolder() + "/libraries/", "ffmpeg.exe")).getAbsolutePath())).waitFor();
        
             
        Runtime.getRuntime().exec(FilenameUtils.separatorsToSystem(new File(softhware.getFolder() + "/libraries/", "ffmpeg.exe").getAbsolutePath()) + " -hide_banner " + "-loglevel " + "error" + " -i " + video.getVideoFile().getAbsolutePath() + " -q:v " + "0 " +
                    "-start_number " + String.valueOf(framesCount) + " " + new File(video.getFramesFolder().getPath() + "%d.jpg").getAbsolutePath()).waitFor();
        }catch (InterruptedException | IOException e) {
              e.printStackTrace();
        }

But now I have an strange output when I execute the .exe and I don't know what is :

>/home/container/softwares/Player/libraries/ffmpeg.exe: 1: 
MZ����@���: not found
�.ome/container/softwares/Player/libraries/ffmpeg.exe: 2: �
%D����@8: not found
/home/container/softwares/Player/libraries/ffmpeg.exe: 3: Syntax 
error: "(" unexpected
Albert4224
  • 73
  • 1
  • 7
  • FWIW, setting write permission to others on an exe file is not a good idea. Unless you like getting hacked. – passer-by Dec 19 '21 at 15:46
  • ffmpeg.exe looks from the filename that it is a Windows program. The stack trace gives the impression you're running on a Linux/Unix machine. Please clarify. – passer-by Dec 19 '21 at 15:49
  • Are you running on a server with extra security like SELinux? – Thorbjørn Ravn Andersen Dec 19 '21 at 16:08
  • The servers where I have the problems are more likely running under Linux OS, My localhost installation runs under Windows. I tested my program on others hosted servers but still have the same issue. – Albert4224 Dec 19 '21 at 16:36
  • Your problem probably stems from using different OSs as you know from basic java the / and the \ are not the same there is File.separatorChar to be used - "softwares/player/libraries/ffmpeg.exe": where is this sitting somewhere in the air?? - i see a lot of problems in your program and a good debugging is not out of the question- Given that we cannot be at your server you have to perform it yourself!! – gpasch Dec 19 '21 at 19:15
  • Thanks for your replies, I have made an edit on my post. – Albert4224 Dec 20 '21 at 14:17

1 Answers1

1

Thanks for you replies, I figured out how to solve the problem, and why I had problems, for any one coming down here, here is the solution, follow those steps;

  1. The server isn't running under Windows, as @gpasch said / and the \ are not the same, to get a valid path I had to use apache method, for instance FilenameUtils.separatorsToUnix(new File(softhware.getFolder() + "/libraries/", "ffmpeg").getAbsolutePath()) as a String path to ffmpeg.

  2. The second error that I had (see edit post), comes from the usage of an Windows ffmpeg instead of a Linux/Unix one, so removed it and replaced it by a new one from https://ffbinaries.com/downloads. That made me change my program to :

        try {
            Runtime.getRuntime().exec("chmod -R 777 " + FilenameUtils.separatorsToUnix(new File(software.getFolder() + "/libraries/", "ffmpeg").getAbsolutePath())).waitFor();
        } catch (InterruptedException | IOException e) {
            e.printStackTrace();
        }

        String[] videoCommand = {
            FilenameUtils.separatorsToUnix(new File(softhware.getFolder() + "/libraries/", "ffmpeg").getAbsolutePath()),
            "-hide_banner",
            "-loglevel",
            "error",
            "-i",
            FilenameUtils.separatorsToUnix(video.getVideoFile().getAbsolutePath()),
            "-q:v",
            "0",
            "-start_number",
            String.valueOf(framesCount),
            FilenameUtils.separatorsToUnix(new File(video.getFramesFolder().getPath(), "%d.jpg").getAbsolutePath())
        };

        ProcessBuilder videoProcessBuilder = new ProcessBuilder(videoCommand);

        try {
            Process process = videoProcessBuilder.inheritIO().start();
            process.waitFor();
        } catch (IOException | InterruptedException e) {
            e.printStackTrace();
        }
  1. Becarfull I got my server deleted, 15 minutes after sucessfully running ffmpeg.
Albert4224
  • 73
  • 1
  • 7