Ffmpeg loads CPU

Which system do you use? Android, Ubuntu, OOWOW or others?

Ubuntu 22.04

Which version of system do you use? Please provide the version of the system here:

vim4-ubuntu-22.04-gnome-linux-5.15-fenix-1.6.9-240618

Please describe your issue below:

I use the simplest ffmpeg action - transferring an RTSP stream from a webcam to an RTSP server.
The processor will load from 50% to 400% depending on the video resolution (320x240 … 1280x720).

ffmpeg -f v4l2 -i /dev/video0 -f rtsp rtsp://localhost:8554/mystream
khadas@khadas:~$ ps -p 5510 -o %cpu,%mem,cmd
%CPU %MEM CMD
42.0  0.8 ffmpeg -f v4l2 -i /dev/video0 -f rtsp rtsp://localhost:8554/mystream

If I use encoding, the processor load increases to 400%!
Is it possible to somehow use Mali-G52 for ffmpeg to unload the CPU?

@igorhoop instead of ffmpeg you can use gstreamer, which supports encoding by VPU.

https://docs.khadas.com/products/sbc/vim4/applications/hardware-encoding

Can you try this?

@Electr1
I tried it. Indeed, with gstreamer + amlvenc, the CPU load has become 50% with RTSP streaming, and in the console you can see the following log:

[amvenc_multi_load_Module:40] amvenc_ports multi loadModule!, load_count:0

It’s like normal.

But if I kill the process (press CTRL + C) and start the process again, the load becomes 100%, and in the output you can see the following log:

[amvenc_multi_load_Module:40] amvenc_ports multi loadModule!, load_count:1

Was load_count = 0 and became load_count = 1

If I reboot the VIM4 and start the process, then the load CPU is 50% again.

I don’t really understand how everything works at a low level, but is it possible to somehow reset this load_count to zero?

Hello @igorhoop

We will check this issue, @Electr1 could you reproduce this issue ?

Cheers.

1 Like

I’m afraid I don’t fully understand how the author of the mentioned topic (@RichardPar) achieved hardware encoding/decoding via ffmpeg.

If you need information on how to reproduce my problem, I am ready to provide it.

I achieved an RTSP stream with a CPU load of 15% through Gstreamer :rocket:, but there remains a problem with restarting the process (when the load_count becomes = 1).

@igorhoop can you share how you launched your pipeline ?
I wasn’t able to see any issue of CPU usage or load_count.

RTSP server:

Steps:

$ wget https://github.com/bluenviron/mediamtx/releases/download/v1.8.2/mediamtx_v1.8.2_linux_arm64v8.tar.gz
$ tar xvf mediamtx_v1.8.2_linux_arm64v8.tar.gz

Start RTSP server:

$ ./mediamtx & 

Gstreamer RTSP packages:

$ sudo apt install libgstrtspserver-1.0-0 gstreamer1.0-rtsp

My pipeline:

$ gst-launch-1.0 v4l2src device=/dev/video50 io-mode=mmap ! amlvenc ! h264parse ! rtspclientsink location=rtsp://localhost:8554/test

Hi. Yes, when using gst-launch-1.0 + mediamtx, I also have everything okay.

Problem if I don’t want to use mediamtx. In this case, I use gst-rtsp-server (based on Gstreamer). It needs to be collected through meson.

Next, in the examples folder will have the test-launch binary file. I run it and specify the following pipeline:

./test-launch "( v4l2src device=/dev/video0 ! image/jpeg,width=640,height=480,framerate=30/1 ! amlv4l2jpegdec! amlvenc ! h264parse ! rtph264pay name=pay0 pt=96 )"

Such a pipeline allows me (for my webcam) to get a load of 15%, but it will increase if you restart the program.

To watch the video stream, use:
gst-launch-1.0 rtspsrc location=rtsp://127.0.0.1:8554/test latency=300 ! decodebin ! autovideosink