How to limit FFMPEG CPU usage on Android

249 Views Asked by At

I am recording video on Android and saving it to mp4 files using MediaMuxer. This works great but a few times I also need to proccess these mp4 files to cut/combine them into a new mp4 while still recording. The speed of this proccessing is not vital.

For cutting and combining I use FFMPEG, specifically https://github.com/tanersener/ffmpeg-kit. com.arthenica:ffmpeg-kit-full-gpl:4.5

The problem is that this sometimes causes 100% CPU usage and the recording to freeze. I have set maximum priority on the thread handling recording and minumum priority on the one starting FFMPEG. But the problem still occurs. The ffmpeg command seams to start many threads (despite me trying to limit it to one) as seen in the Android studio inspector.

The command I use:

FFmpegKit.execute("-threads 1 -hide_banner -loglevel error -y"
                        + " -ss " + convertMSToString(startTimeMs)
                        + " -t " + convertMSToString(lenghtMs)
                        + " -i " + inputFilePath
                        + " -c copy " + outputFilePath)

enter image description here

Any ideas how I can limit the CPU usage of ffmpeg, or ensure that the camera thread/threads get higher priority so they do not freeze?

0

There are 0 best solutions below