


However, the perils in using Runtime.exec() are discussed in many posts here. I have some example code using Runtime.exec() with stdout/ stderr processing on GitHub.

After this the question is only in wrapping the whole thing in the for loop and doing all the files at once. Command-line - Compress and Convert MP4 to Webm for YouTube, Ins, Facebook. ffmpeg -i input.mp4 -vcodec libx265 -crf 28 output.mp4. Command-line - Compress and Convert H.264 to H.265 for Higher Compression. This will produce a 15 second cut from 0:45 to 1:00. Ive switched to avconv a while ago, i believe that the options should be the same, and if not, it should be trivial to rewrite them as needed. Here we take some typical command-line examples to show you how to compress MP4 /MOV/4K/MKV video size using FFmpeg. ffmpeg -t 1:00 -i input.mpg -ss 45 output.mpg. You probably need a Process.waitFor() after the exec() if you want to wait. To cut based on start and end time from the source video and avoid having to do math, specify the end time as the input option and the start time as the output option. It won’t even necessarily look in the same places for executables as a shell will.Īnother problem you’re likely to have is that your Java program might complete before the process spawned by exec() does. Not only will the process block if it produces output and nothing consumes it, you really need to collect stderr to see any errors.īear in mind that Runtime.exec() is not a shell, and it won’t necessarily parse command lines the way a shell would. The output needs to be collected up and processed, even it it’s only copied to the terminal. A particular problem with ffmpeg is that it’s likely to produce output - to stdout or stderr or both - and take some time to complete. Runtime.exec() is fraught with difficulties.
