3

I am trying to split, convert and merge an audio. I used writingMinds FFmpeg build for Android. But it is taking to much time for long duration audios.

To speed it up I tried using the "thread -4" command on a phone having 8 cores but it didn't improve the performance.

So then I split the audio into 4 parts (to use 4 threads) and then called FFmpeg.execute() inside separate threads for multithreading. But FFmpeg library processes the files sequentially. Is it possible for ffmpeg to parallelly process these 4 parts in 4 threads? If so how?

UPDATE
see alex cohn's answer. In this case, it was also because of the calling method of FFmpegExecuteAsyncTask as execute method of Asynctask class only allows one instance to run at a time in modern APIs. a workaround was using this checks.

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { // Android 3.0 to
                    // Android 4.3
                    // Parallel AsyncTasks are not possible unless using executeOnExecutor
                    ffmpegExecuteAsyncTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
                } else { // Below Android 3.0
                    // Parallel AsyncTasks are possible, with fixed thread-pool size
                    ffmpegExecuteAsyncTask.execute();
                }
priojeet priyom
  • 899
  • 9
  • 17

1 Answers1

2

You are right. This Java wrapper makes sure all calls to ffmpeg are sequential. If you drop this harness and load the binary yourself, you can run multiple ffmpeg processes in parallel. Note that they are not threads, but full-blown processes, so the cost of doing this may be higher than you expect.

Alex Cohn
  • 56,089
  • 9
  • 113
  • 307
  • Thank you for your comment.it explained a lot. But in my case, it was also because of the calling method of FFmpegExecuteAsyncTask as execute method of Asynctask class only allows one instance to run at a time in modern APIs. a work around was using this checks. `code` – priojeet priyom Jul 10 '18 at 17:36