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 :
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