Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose the pid to be able to kill the process manually. #383

Open
HenriquePassarelli opened this issue Dec 26, 2023 · 15 comments
Open

Expose the pid to be able to kill the process manually. #383

HenriquePassarelli opened this issue Dec 26, 2023 · 15 comments

Comments

@HenriquePassarelli
Copy link

Describe the issue
When I lose connection to the internet, the process sometimes doesn't close by itself, so I would like to get the pid for each process I run FFMpeg to close/kill/verify manually.

To Reproduce
Steps to reproduce the behavior:
While running the RTSP stream, stop the connection with the internet, and you will see that the process will still run even though no one is consuming it.

Expected behavior
Close the process after losing connection or add a way to close it.

Additional context
Linux Ubuntu 20.04

@kokorin
Copy link
Owner

kokorin commented Dec 26, 2023

Have you checked force stop example?

@HenriquePassarelli
Copy link
Author

I'm using it, but even calling it sometimes doesn't stop the process.

@kokorin
Copy link
Owner

kokorin commented Dec 26, 2023

Sometimes? Could you be more specific? Does force stop work in case you described in this issue?

@HenriquePassarelli
Copy link
Author

HenriquePassarelli commented Dec 26, 2023

The messages when the force is called, are being shown, however, when I check the processes the ffmpeg execution is still there. I'm running with executeAsync providing the executor.

@kokorin
Copy link
Owner

kokorin commented Dec 26, 2023

Could you post debug logs? For that you need to configure both ffmpeg log level and java log level (logback or whatever you use)

@HenriquePassarelli
Copy link
Author

  • With an internet connection calling an endpoint to kill.
Peek.2023-12-26.16-34-working.mp4
  • Without an internet connection calling an endpoint to kill.
Peek.2023-12-26.16-33.mp4

@HenriquePassarelli
Copy link
Author

I implemented a workaround that reads all ffmpeg processes on my machine and checks the command to see if they match the arguments, if so, I keep the pid and then I can kill it. That's why I wanted the pid exposed to be used or an internal call to it besides canceling the future.

@kokorin
Copy link
Owner

kokorin commented Dec 27, 2023

Please, provide logs as requested.

@HenriquePassarelli
Copy link
Author

Here I'm logging the stop call that comes from my code that calls the future forceStop

4380793 INFO [qtp1643944254-970] FFMpegHelper: Kill rtsp jobs - 1 
4380794 INFO [qtp1643944254-970] FFMPEGRunner: STOP FFMPEGRunner
4380794 INFO [qtp1643944254-970] FFMPEGRunner: Future status before - false
4380794 INFO [qtp1643944254-970] FFMPEGRunner: Future status - true

So as you can see the future was cancelled but the process is still running.

My stop method

 public void stop() {
        if (isStopping.getAndSet(true)) return;
        LOGGER.info("STOP FFMPEGRunner");
        isRunning.set(false);
        connections.set(0);
        reference.get().clear();
        if (future != null) {
            LOGGER.info("Future status before - {}", future.isCancelled());
            future.forceStop();
            LOGGER.info("Future status - {}\n\n\n\n\n", future.isCancelled());
        }
        onClose.run();
    }

@kokorin
Copy link
Owner

kokorin commented Dec 28, 2023

Could you post debug logs? For that you need to configure both ffmpeg log level and java log level (logback or whatever you use)

Please, provide logs as requested

@HenriquePassarelli
Copy link
Author

The logs aren't providing much.

The basics. A call to stop the process.

stop-call

It had to be closed using the Ubuntu UI
ending-process-via-linux-ui

Reloading without connection no action needs to be taken.
error-reloading-stream

Common user flow, start and stop stream, working.
image

The full log is a not working example.
stop-no-connection

The full log is a working example.
full-working

@HenriquePassarelli
Copy link
Author

HenriquePassarelli commented Dec 28, 2023

I used a workaround to deal with it that could be added to the code, which is the https://github.com/profesorfalken/jProcesses lib to handle to close the process. It is really handy cause it deals with UNIX and Windows systems.

@kokorin
Copy link
Owner

kokorin commented Dec 29, 2023

Please, notice that I asked for debug logs both ffmpeg and Jaffree.

@Speiger
Copy link

Speiger commented Oct 20, 2024

@kokorin If FFmpeg doesn't abide by the force request of the stopper then you are effectively leaving a process alive even if the JVM shuts down. So exposing the Process instance itself would be nice. Especially if you have a highly multithreaded application that doesn't require a lot of Processing power but a lot of traffic on your Storage drives.
Having to go to taskmanager and having to cancel these tasks while the taskmanager isn't responding well because your PC is overloaded for some reason, kinda makes this more important too.

So i highly suggest that there is a way where you can configure a bit more control over it.
(Started using the library when i was using the command line directly before because i wanted a nicer interface, and this is the first thing i realized)

@HenriquePassarelli
You can solve this yourself temporary, by creating your own FFmpeg/Probe class that extends the original one and implement a custom Stopper interface that just wraps around the existing one. Because that gets the process info :) Meaning you can even do that without async then :)

@Speiger
Copy link

Speiger commented Nov 9, 2024

@HenriquePassarelli
FYI on the current state:
I made a PR, got it relatively clean, but the guy here has an excessive amount of requirements to get a basic patch going and is insistent on the PR creator to 100% uphold it.

After seeing how specific the requirements are, and how little interest on meeting half way through he was, I decided to withdraw my PRs, and make my own version now that fit my needs instead of contributing to this project.

Having Code style requirements is fine. Having excessive requirements and 0 leniency of meeting halfway is not fine IMO.

So yeah lets see how long it will take @kokorin to get the feature in.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants