umlaeute / v4l2loopback

v4l2-loopback device
GNU General Public License v2.0
3.61k stars 515 forks source link

CPU usage is too high when clone device by v4l2loopback #549

Open trungthanhnguyen0502 opened 1 year ago

trungthanhnguyen0502 commented 1 year ago

I use v4l2loopback + Gstreamer to clone device. Sometimes Using this plugin results in very high CPU usage.

Step 2: Environment

Step 3: Describe the problem:

Steps to reproduce:

  1. Create virtual devices: sudo modprove v4l2loopback devices=3

  2. Clone the data stream from the original device to virtual devices.

    gst-launch-1.0 v4l2src device=/dev/video0 ! videorate drop-only=true ! "video/x-raw,framerate=(fraction)30/1" ! \ tee name=t ! queue ! v4l2sink device=/dev/video1 sync=false async=true \ t. ! queue ! v4l2sink device=/dev/video2 sync=false async=true \ t. ! queue ! v4l2sink device=/dev/video3 sync=false async=true

Observed Results:

low-cpu

high-cpu

Or worst case like that: Screenshot from 2023-07-20 15-56-46

I've checked and not see any strange programs that can cause this problem. I see that someone else had the same problem, Nvidia supporter said "For CPU usage, it is probably v4l2loopback as well causing high CPU load. high-cpu-usage-for-video-capturing

Screenshot from 2023-07-20 15-06-23

Expected Results:

I want to know why CPU usage is too high and how to fix it. Because this problem affects my system a lot.

umlaeute commented 1 year ago

hmm, well. the high CPU load you see is obviously in user-space (the green bar), which is GStreamer. the load in kernel-space (the red bar), which is where you would see anything done by v4l2loopback, seems to be pretty constant.

so i conclude that the v4l2loopback is not doing any excessive work, but instead GStreamer is. (it could still be a problem with v4l2loopback that makes GStreamer burn your CPU cycles).

so, if I were you, i would do some analysis where GStreamer is spending its time (and see whether something can be done on the v4l2loopback side of things)

trungthanhnguyen0502 commented 11 months ago

I tried some analysis with simple gstreamer command. When I run gst-launch-1.0 v4l2src device=/dev/video0 ! videoconvert ! appsink CPU usage is 17%.

But when I replace appsink with v4l2sink (to a virtual device created by v4l2loopback). CPU usage is 60%.

chrisiberg commented 11 months ago

I think your problem hast to do with missing DMA support, or am I wrong? @umlaeute

501

sanbrother commented 10 months ago

I think your problem hast to do with missing DMA support, or am I wrong? @umlaeute #501

Will copy without DMA consume a lot of CPU? mmap still costs high CPU usage?

angeelalg commented 5 months ago
  • kernel version: 5.10.104-tegra
  • Distribution (+version): Ubuntu 20.04.5 LTS
  • Jetson xavier nx: JetPack 5.0.2.
  • Deepstream and Gstreamer version are 6.1.1 and 1.16.3.

Hello @trungthanhnguyen0502 , good morning.

How did you get v4l2loopback working for you? I'm trying to get my Jetson NX to work, with the same kernel version and it's impossible. I keep getting this error when running modprobe v4l2loopback: modprobe: ERROR: could not insert 'v4l2loopback': Operation not permitted