ffmpeg-android-java
ffmpeg-android-java copied to clipboard
Handling Multiple Commands
I'm trimming mp4 files and noticed if I ran another command while one was running, I get this error.
com.github.hiteshsondhi88.libffmpeg.exceptions.FFmpegCommandAlreadyRunningException: FFmpeg command is already running, you are only allowed to run single command at a time
at com.github.hiteshsondhi88.libffmpeg.FFmpeg.execute(FFmpeg.java:66)
at com.github.hiteshsondhi88.libffmpeg.FFmpeg.execute(FFmpeg.java:79)
at drivespotter.com.continuousrecordcam.api.s3.S3MediaAPI.sendMediaSegment(S3MediaAPI.java:55)
at drivespotter.com.continuousrecordcam.ContinuousRecordActivity.stopRecorder(ContinuousRecordActivity.java:199)
at drivespotter.com.continuousrecordcam.ContinuousRecordActivity.access$200(ContinuousRecordActivity.java:41)
at drivespotter.com.continuousrecordcam.ContinuousRecordActivity$2.onClick(ContinuousRecordActivity.java:171)
at android.view.View.performClick(View.java:4466)
at android.view.View$PerformClick.run(View.java:18542)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5097)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
I would think that because it is running on a separate thread it would be fine. What is the recommended way to run multiple commands?
Have you resolved this issue?
No, I have not
I've been using this library for over a year too and haven't found any workaround for this, the library manages threading (or rather the lack thereof) on it's own, so calling execute() from another thread is of no use.
My suggestion: Manage your own 'pool' of commands. A simple queue of tasks that you do one after another. This way you can move up the elements in onFinish()
and simply append to the queue whenever another task comes up and they'll get done one by one.
@AdityaAnand1 My issue is that I get this error "FFmpeg command is already running" even after the command is done. I can't run a command one after the other?
@HD-AD That's weird. Are you absolutely certain you're waiting for onFinish() before firing off the second command?
Are you able to run multiple commands using the sample apk?
@AdityaAnand1 yes I'm sure the command completes in onFinish(). The processing I do doesn't take long so I haven't tried running multiple commands as the command doesn't take long to finish. At the moment I have to destroy the application/activity in order to run a new command. I don't know if the issue could be because I'm calling loadFFmpeg() in onCreate(), but the example does the same, this is a big issue for my application so I really hope someone can help me out. Thanks for taking the time to reply.
@AdityaAnand1 I can also downvote, I'm asking for help, no need to be an ass!
The last task was left unfinished。
@steveLYL yes I got it working, thank you for answering.
@HD-AD very good.
trying to mFFmpeg.killRunningProcesses()
mFFmpeg.killRunningProcesses() 这个不起作用
but I don't want to kill my running progress.