1

I am calling java.lang.Runtime.exec(...) in my Java program to run a command, say:

ffmpeg -i input.mp4 output.mp4.

This is simply passed to my function to run:

    private static void RunCommand(String command) throws InterruptedException {
        try {
            // Execute command
            Process proc = Runtime.getRuntime().exec(command);
}
}

Everything is OK. But my question is to handle cases when the file already exists, so asks if it should replace it:

File 'output.avi' already exists. Overwrite ? [y/N]

What is the simplest way to ignore it (always assume y and replace)? Maybe through Java in code or FFMPEG command itself?

4
  • Through Java in code. Just implement it like that. Problem solved Commented Jul 26, 2017 at 20:17
  • hmm is not the problem of java, you need to check if there is flag for automatic yes of your command Commented Jul 26, 2017 at 20:17
  • @Proxytype You can delete the file in Java so there will not be a prompt Commented Jul 26, 2017 at 20:18
  • @ThomasWeller you just running command like you will done it from command line, if no automatic yes exists you will need to inject it to the process... as keystroke Commented Jul 26, 2017 at 20:22

1 Answer 1

1

Add -y as argument:

ffmpeg -y -i input.mp4 output.mp4

According to the documentation:

  • -y Overwrite output files without asking.

  • -n Do not overwrite output files, and exit immediately if a specified output file already exists.

Sign up to request clarification or add additional context in comments.

6 Comments

Haha! Thanks. I have a question: there is a command which doesn't run in java, but when I copy the exact string and run in command line, it works?
ffmpeg -i "concat:/home/temp10.avi|/home/p2.avi|/home/temp15.avi" -c copy -y /home/output.avi
which is String c4="ffmpeg -i \"concat:"+dir+temp1+"|"+dir+ad+"|"+dir+temp3+"\" -c copy -y "+dir+output;
try to make more simple copy and see if it's works from java... try to listen to the stdio output for errors...
@Ariana That's a completely different issue. I recommend accepting this answer for the -y issue and asking a new question regarding the concat issue.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.