ffmpeg-android-java icon indicating copy to clipboard operation
ffmpeg-android-java copied to clipboard

isFFmpegCommandRunning() not working

Open SebSob opened this issue 8 years ago • 18 comments

When i run a command with ffmpeg.execute() inside the FFmpegExecuteResponseHandler onProgress() method when i call ffmpeg.isFFmpegCommandRunning() it's returning false.

Also killRunningProcesses() is not working, because when i execute and run this method it always return false

Could you please conside a fix please? Thanks

SebSob avatar Mar 14 '16 00:03 SebSob

Hey, you could try using this code. I have tried this, and it works successfully. for example - you can make toast in catch block ," that ffmpeg is Already running". Hope this helps.

FFmpeg ffmpeg = FFmpeg.getInstance(context); try { // to execute "ffmpeg -version" command you just need to pass "-version" ffmpeg.execute(cmd, new ExecuteBinaryResponseHandler() { @Override public void onStart() {}

@Override
public void onProgress(String message) {}

@Override
public void onFailure(String message) {}

@Override
public void onSuccess(String message) {}

@Override
public void onFinish() {}

}); } catch (FFmpegCommandAlreadyRunningException e) { //Do somthing }

JayParikh20 avatar Mar 18 '16 09:03 JayParikh20

Ok yes, that could be a possible workaround thanks. But what if i want to stop the current process (for example in the onDestroy() method)?

SebSob avatar Mar 18 '16 10:03 SebSob

Let's assume the ffmpeg command was executed and was in progress

OnProgress function will be called again and again (try adding toast , to cross check) So workflow around this can be you add a if statement inside Onprogress function(to check kill conditions ) Now if condition is true you call

ffmpeg.killRunningProcesses();

JayParikh20 avatar Mar 19 '16 09:03 JayParikh20

I'm having the same issue, that workaround will not work, as the issue is in killRunningProcesses() itself (don't work no matter what or where is called)

sam7700 avatar Mar 20 '16 10:03 sam7700

well,that's weird.let me check!

JayParikh20 avatar Mar 21 '16 05:03 JayParikh20

I manage to have it work by recompiling the aar from the sources - this means the patch is actually already there but not in the gradle or the public build on the site ( it's actually in this state from quite a while: https://github.com/WritingMinds/ffmpeg-android-java/issues/3 )

sam7700 avatar Mar 21 '16 11:03 sam7700

@sam7700 Nice Catch!

How did you manage to get master source in android studio and get same result as Compiling Gradle? i mean compiling with gradle is easy, how can i download it from Github and then add it in android Studio?

JayParikh20 avatar Mar 22 '16 05:03 JayParikh20

Just get the source, import in android studio and then run a build, you will find the aar generated under FFmpegAndroid/build/outputs/aar/ - I was prepared to get some some dependency hell but all went smooth

sam7700 avatar Mar 22 '16 11:03 sam7700

haha, thanks!

JayParikh20 avatar Mar 22 '16 13:03 JayParikh20

Version 0.2.5. FFmpeg.java @Override public boolean isFFmpegCommandRunning() { return ffmpegExecuteAsyncTask != null && ffmpegExecuteAsyncTask.isProcessCompleted(); }

ruha9005 avatar Apr 08 '16 15:04 ruha9005

@sam7700 can you provide the aar ?

akashpopat avatar Apr 18 '16 11:04 akashpopat

Is this issue still in 0.3.2? I'm trying to re run my command multiple time but it always end up with FFmpeg already running.

I'm trying to run this command:

private int count = 0;
private void seekToPosition(long currentVideoPosition){

    String[] cmd = {"-ss", String.valueOf(currentVideoPosition), "-i", "/storage/emulated/0/Videos/01.mp4",
                    "-frames:v", "1", "/storage/emulated/0/Videos/out"+ count +".jpg"};

    final FFmpeg ffmpeg = FFmpeg.getInstance(this);
    try {
        // to execute "ffmpeg -version" command you just need to pass "-version"
        ffmpeg.execute(cmd, new ExecuteBinaryResponseHandler() {

            @Override
            public void onStart() {
                isSeekable = false;
            }

            @Override
            public void onProgress(String message) {}

            @Override
            public void onFailure(String message) {
                Log.d(TAG, "FFmpeg cmd failure");
            }

            @Override
            public void onSuccess(String message) {
                Log.d(TAG, "FFmpeg cmd success");
                count++;
                isSeekable = true;
                ffmpeg.killRunningProcesses();
                Log.d(TAG, "FFmpeg kill running process: " + ffmpeg.killRunningProcesses());
            }

            @Override
            public void onFinish() {
                Log.d(TAG, "FFmpeg cmd finished: is FFmpeg process running: " + ffmpeg.isFFmpegCommandRunning());

            }
        });
    } catch (FFmpegCommandAlreadyRunningException e) {
        // Handle if FFmpeg is already running
        Log.d(TAG, "FFmpeg exception: " + e);
    }
}

I can replicate this with the demo as well. Try running this command:

-ss 00:00:05 -i whateverVideo.mp4 -frames:v 1 out1.jpg

Then re run with a different output's name:

-ss 00:00:05 -i whateverVideo.mp4 -frames:v 1 out2.jpg

It behave as expected with 2 different output files. But if you accidentally run any of those command twice then nothing happen for the next run even if you change the output's name.

vxhviet avatar May 10 '16 01:05 vxhviet

I am also facing the same problem like vxhviet mentioned.

shubhamvishnoi-kiwi avatar May 12 '16 11:05 shubhamvishnoi-kiwi

Just using sam7700 solution:

Just get the source, import in android studio and then run a build, you will find the aar generated under FFmpegAndroid/build/outputs/aar/

And that's the release.aar

For the "accidentally running it twice" just need to pass -y to the command (-y means overwriting file, consult ffmpeg document for better example).

vxhviet avatar May 12 '16 12:05 vxhviet

Hi vxhviet,

using -y option solved my problem

Thanks.

shubhamvishnoi-kiwi avatar May 12 '16 12:05 shubhamvishnoi-kiwi

I think still a problem on gradle today. Need to resort to compile from source code option.

mikexing2010 avatar May 12 '17 18:05 mikexing2010

@sam7700 @JayParikh20 I am having the same issue with killRunningProcesses(), and following what you two discussed also didn't help me. Please guide me on this.

Whenever I execute a process it ends up moving in the catch block where I have written this:

catch (FFmpegCommandAlreadyRunningException e) {
            if (ffmpeg.isFFmpegCommandRunning()) {
                ffmpeg.killRunningProcesses();
            }
}

When killRunningProcesses() gets called, my app crashes:

Error running FFmpeg
java.lang.IllegalThreadStateException: Process has not yet terminated: 16893
at java.lang.ProcessManager$ProcessImpl.exitValue(ProcessManager.java:275)
at
com.github.hiteshsondhi88.libffmpeg.CommandResult.getOutputFromProcess(CommandResult.java:18)
at com.github.hiteshsondhi88.libffmpeg.FFmpegExecuteAsyncTask.doInBackground(FFmpegExecuteAsyncTask.java:44)
at com.github.hiteshsondhi88.libffmpeg.FFmpegExecuteAsyncTask.doInBackground(FFmpegExecuteAsyncTask.java:10)
at android.os.AsyncTask$2.call(AsyncTask.java:295)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
at java.lang.Thread.run(Thread.java:818)

@hiteshsondhi88 Can you please help me on this please?

Ashutosh-Tiwari avatar Jan 09 '18 15:01 Ashutosh-Tiwari

Is there any workaround is available for this problem?

tutysathish avatar Oct 03 '18 12:10 tutysathish