umlaeute / v4l2loopback

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

Chromium cannot read camera: Dequeued v4l2 buffer contains invalid length #561

Closed hackermondev closed 1 year ago

hackermondev commented 1 year ago

I installed the v4l2loopback kernel module on my machine and ran it with sudo modprobe v4l2loopback exclusive_caps=1.

I created a camera on /dev/video0 with the rust bindings and starting piping a static image to the camera (command from the wiki):

sudo ffmpeg -loop 1 -re -i 60828015.jpg -f v4l2 -vcodec rawvideo -pix_fmt yuv420p /dev/video0

I'm running this on a VPS with no desktop environment so I quickly spun up a Docker container with noVNC and a desktop environment to test everything (sudo docker run --rm -it --device /dev/video0 --privileged -p 8090:8080 theasp/novnc). Everything looks fine and if i run ffplay /dev/video0, I can successfully view the image in the camera. The problem now is with other applications

Cheese doesn't even detect the camera. Chromium detects the camera but cannot use it:

[15749:15755:1024/025614.520951:ERROR:v4l2_capture_delegate.cc(1138)] Dequeued v4l2 buffer contains invalid length (11441 bytes).

Not sure what I'm doing wrong and why Chromium cannot read from the camera.

FFmpeg pipe logs:

ffmpeg version 4.2.7-0ubuntu0.1 Copyright (c) 2000-2022 the FFmpeg developers
  built with gcc 9 (Ubuntu 9.4.0-1ubuntu1~20.04.1)
  configuration: --prefix=/usr --extra-version=0ubuntu0.1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --arch=amd64 --enable-gpl --disable-stripping --enable-avresample --disable-filter=resample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libjack --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librsvg --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-lv2 --enable-omx --enable-openal --enable-opencl --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-nvenc --enable-chromaprint --enable-frei0r --enable-libx264 --enable-shared
  libavutil      56. 31.100 / 56. 31.100
  libavcodec     58. 54.100 / 58. 54.100
  libavformat    58. 29.100 / 58. 29.100
  libavdevice    58.  8.100 / 58.  8.100
  libavfilter     7. 57.100 /  7. 57.100
  libavresample   4.  0.  0 /  4.  0.  0
  libswscale      5.  5.100 /  5.  5.100
  libswresample   3.  5.100 /  3.  5.100
  libpostproc    55.  5.100 / 55.  5.100
Input #0, image2, from 'input.jpg':
  Duration: 00:00:00.04, start: 0.000000, bitrate: 1854 kb/s
    Stream #0:0: Video: mjpeg (Baseline), yuvj420p(pc, bt470bg/unknown/unknown), 360x287 [SAR 96:96 DAR 360:287], 25 fps, 25 tbr, 25 tbn, 25 tbc
Stream mapping:
  Stream #0:0 -> #0:0 (mjpeg (native) -> rawvideo (native))
Press [q] to stop, [?] for help
[swscaler @ 0x55b19c9fab80] deprecated pixel format used, make sure you did set range correctly
Output #0, video4linux2,v4l2, to '/dev/video0':
  Metadata:
    encoder         : Lavf58.29.100
    Stream #0:0: Video: rawvideo (I420 / 0x30323449), yuv420p, 360x287 [SAR 1:1 DAR 360:287], q=2-31, 30996 kb/s, 25 fps, 25 tbn, 25 tbc
    Metadata:
      encoder         : Lavc58.54.100 rawvideo
frame= 2277 fps= 25 q=-0.0 size=N/A time=00:01:31.08 bitrate=N/A speed=   1x   
hackermondev commented 1 year ago

@umlaeute Any chance you know what's going on here?

hackermondev commented 1 year ago

The issue was with the size of the image I was sending with ffmpeg (87x87). I'm assuming there's a minimum webcam frame size in Chromium and I wasn't aware of it. I started sending a larger image with ffmpeg (2880x1800) and it no longer logs that error and the webcam works.

umlaeute commented 1 year ago

Depending on the colour encoding, odd-sized frames can be problematic (eg YUV420p requires that the U and V planes are downsampled by a factor of 2, which works best if the width and height can be divided by 2)

hackermondev commented 1 year ago

@umlaeute Yep, looks like that was the issue. Maybe add that to the wiki?

umlaeute commented 1 year ago

Sure, please go ahead!