bramp / ffmpeg-cli-wrapper

Java wrapper around the FFmpeg command line tool
BSD 2-Clause "Simplified" License
1.69k stars 413 forks source link

How to stop FFMPEG process gracefully with ffmpeg-cli-wrapper ? #282

Open mertakkartal opened 1 year ago

mertakkartal commented 1 year ago

Hi folks ,

I wrote a simple UDP stream recorder application with using this library in Java 11. Everything works fine except stopping FFMPEG record process before the duration time. (i.e The duration time is 60 seconds but want to stop FFMPEG process like in 30th second.)

What should I do for solving this problem ? Any ideas would be appreciated .

Thanks, Mert

curiousurick commented 11 months ago

I'm having the same issue. I think I'm going to just call on the shell to kill any process with the name ffmpeg. It's not ideal, but it'll work for my project.

bramp commented 11 months ago

You'll have to execute ffmpeg manually and get a Process object that you can then read streams or kill as needed. Similar to what https://github.com/bramp/ffmpeg-cli-wrapper/blob/e47b3e9bd009c9aafd765610948b8dd1cd582cbc/src/main/java/net/bramp/ffmpeg/FFcommon.java#L100 and https://github.com/bramp/ffmpeg-cli-wrapper/blob/master/src/main/java/net/bramp/ffmpeg/RunProcessFunction.java do.

curiousurick commented 11 months ago

Yeah, that's working for me. If there was a way to get the PID for the ffmpeg job, then I could narrow the kill command to that.

bramp commented 11 months ago

The current API doesn't make it easy to get the Process object / PID. So that's why I suggest executing ffmpeg yourself.

curiousurick commented 11 months ago

Meh, I'm queuing up tasks anyway so there will only be one ffmpeg process running at a time. My personal project is just shrinking video files from blu-ray quality to x265 and moving them to a new folder so not exactly needing production quality.

I appreciate this cli wrapper! Thanks for your work making this.