bravobit / FFmpeg-Android

FFMpeg/FFprobe compiled for Android
https://bravobit.nl/
MIT License
741 stars 176 forks source link

Any way to send "q" to stop the recording gracefully? #4

Closed diegoperini closed 6 years ago

diegoperini commented 6 years ago

https://github.com/diegoperini/ffmpeg-android-java/issues/3 This issue remains here as well.

Hi, I need to record a RTSP stream for a while, I don't know how much time i'll be recording when i start. So if i just stop using the killRunningProcesses the recording seems to be unusable. How can i stop it gracefully. I stumbled upon this code on the internet, but seriously I dont know how to compile the whole project, Im using it as a library

        try {

            if (!ffmpeg.Util.isProcessCompleted(process)) {

                int pid = -1;
                Field f = process.getClass().getDeclaredField("pid");
                f.setAccessible(true);
                pid = f.getInt(process);
                f.setAccessible(false);

                if (pid != -1) {
                    android.os.Process.sendSignal(pid, 15); // 15 is the value for SIG_TERM
                }
            }

        } catch (Exception e) {

        }

I have two suggestions. Either we can expose the pid for advanced use cases and/or we can encapsulate Process.sendSignal in an easy to use interface with good naming.

vxhviet commented 6 years ago

I would like to express my thank you to all of you guys for the hard work you've put into this. I've been trying to rebuild the inFullMobile's FFmpeg library to a newer version without much success. Part of that is because that library have better performance than the WritingMinds' FFmpeg library. I would assume that's because of all the optimization in the newer FFmpeg version (3.2.4 vs 3.0.1).

However, inFullMobile's library seem to be abandoned and there's no way to properly kill a running process which can bring a lot of issues based on my experience with the original WritingMinds' library. I've been playing around with @diegoperini fork for a while, but then again killRunningProcesses() doesn't seem to work properly as well (no disrespect mate).

I believe the proper way to kill the process is by keeping the communication with the running FFmpeg process in order to send the q signal to stop it. The AsyncTask's cancel() method is not a guaranteed way to kill the thread because there's no implementation on the C part of the library to stop the process.

Brianvdb commented 6 years ago

This feature has been integrated in version 1.1.0

dependencies {
    implementation 'nl.bravobit:android-ffmpeg:1.1.0'
}

Checkout the wiki: Send 'Q' signal to FFmpeg/FFprobe process

joshuapinter commented 5 years ago

I think this is a fairly common use case so I'm going to make a PR with an addition to the README so people don't have to go hunting for it...