About stopping a running ffmpeg process #372
-
Hi again. I'm been struggling with java/Spring and Jaffree in order to understand how to implement a way to stop a ffmpeg running process at any moment. I've carefully reviewed the StopExample.java that's available in the repo, but I've failed to adapt it to my context. I've also searched extensively through the Spring documentation for any related example. The problem is that I was not sure exactly what I was looking for. Maybe I'll have more luck here. Here's my last try:
What's the objective of this?. I have an The code I've shared it's not working as is (no image on the browser player). But with some minor changes it works:
The problem is that this way I can't access any Ffmpeg* object and, as you may guess, I can't stop the process. Any advice?. I'm not asking for code but for a clue or concept to know what I have to look for in java/Spring docs. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
Never use OutputStream with Controllers. It's never a good idea. You don't know how and when outputstream will be read. There is no guarantee that content will actually be streamed (and not fully buffered first) by Spring/Tomcat/Netty/etc. Regarding you question: at what moment you want to stop Jaffree? 10 seconds? 1 minute? Or may be when a user closes a browser? With HTTP (at least HTTP 1.1) the only way to stop downloading is closing a connection. What is your final goal? If you want allow a user to download "fixed" file - the easiest way is to read RTSP and store fixed file on local disk. Then to serve the file from local disk. If you want to provide live streaming functionality - check HLS-related examples/issues/discussions. |
Beta Was this translation helpful? Give feedback.
-
Hi again. As you suggested I tried with HLS and it worked, but with some changes. The process is somewhat similar to the one I use to download a file: A controller method launches the ffmpeg process by ajax request. That ajax request starts an interval to another js function that asks for a m83u file. When the file is created, another controller method serves the files (m3u8 and ts). The FFmpegResultFuture is stored in a global class map variable and called when the user clicks the stop button. Thank you very much for your help! (Is there any way to contribute to the project?). The code is like this:
|
Beta Was this translation helpful? Give feedback.
Hi again. As you suggested I tried with HLS and it worked, but with some changes. The process is somewhat similar to the one I use to download a file: A controller method launches the ffmpeg process by ajax request. That ajax request starts an interval to another js function that asks for a m83u file. When the file is created, another controller method serves the files (m3u8 and ts). The FFmpegResultFuture is stored in a global class map variable and called when the user clicks the stop button. Thank you very much for your help! (Is there any way to contribute to the project?). The code is like this: