gspca-kinect2
gspca-kinect2 copied to clipboard
Fix device_caps error -22 (EINVAL) on Linux 5.4+
torvalds/linux@3c13505 broke this driver, requiring the video device's device_caps be set in advance.
Set the same device caps that are reported from vidioc_querycap()
.
Fixes #7.
Thanks for your contribution. Thanks to you, I can successfully load the driver.
After inserting the module/plugging in the camera, dmesg reports
[ 515.585237] gspca_main: kinect2-2.14.0 probing 045e:02c4
[ 515.585690] usbcore: registered new interface driver gspca_kinect2
which sounds very good, but when reading the video devices /dev/video0
and /dev/video1
(that are indeed present), I can find these errors in dmesg for which I don't know where they originate from.
[ 578.426371] gspca_main: usb_submit_urb() ret -1
[ 578.426404] gspca_kinect2 2-8:1.1: urb status: -2
[ 578.426407] gspca_main: usb_submit_urb() ret -1
[ 578.426443] gspca_kinect2 2-8:1.1: urb status: -2
[ 578.426446] gspca_main: usb_submit_urb() ret -1
I'm grateful for any input you can provide on this issue.
@thamma: I geht the same output, but I can still use the Kinect and get RGB video out. Is that not the case for you?
Sadly no. I can neither read from /dev/video0 nor from /dev/video1.
Neither mpv (which usually can immediately read from video devices) nor OBS or applications accessing webcams immediately read any data successfully.
Mpv reports
$ mpv /dev/video0
Failed to recognize file format.
Exiting... (Errors when loading file)
I will double check if I loaded all required kernel modules, but I am very certain I always do. I am running my Kinect on rather low amperage (1A instead of 2-3A which some people reccommend), however Protonect (the example program from the libfreenect2 project) can read all video channels as it is supposed to.
Using v4l-utils yields some more info on the devices. In particular, For the Streaming Parameters Video Capture
I get 0fps which might lead to further culprits.
$ v4l2-ctl --list-devices
Xbox NUI Sensor (usb-0000:00:14.0-8):
/dev/video0
/dev/video1
$ v4l2-ctl --all
Driver Info:
Driver name : kinect2
Card type : Xbox NUI Sensor
Bus info : usb-0000:00:14.0-8
Driver version : 5.6.15
Capabilities : 0x85200001
Video Capture
Read/Write
Streaming
Extended Pix Format
Device Capabilities
Device Caps : 0x05200001
Video Capture
Read/Write
Streaming
Extended Pix Format
Priority: 2
Video input : 0 (kinect2: ok)
Format Video Capture:
Width/Height : 1920/1080
Pixel Format : 'JPEG' (JFIF JPEG)
Field : None
Bytes per Line : 1920
Size Image : 2073600
Colorspace : JPEG
Transfer Function : Default (maps to sRGB)
YCbCr/HSV Encoding: Default (maps to ITU-R 601)
Quantization : Default (maps to Full Range)
Flags :
Streaming Parameters Video Capture:
Frames per second: invalid (0/0)
Read buffers : 2
I can look into this tomorrow, but maybe copy the info here into a new issue, which mentions usb_submit_urb()
-- so that others can find it, and if someone solves it be properly closed. This PR here solves what it was meant to solve. Thanks!
The command I use to show Kinect2 output is:
mpv av://v4l2:/dev/video0 --untimed --profile=low-latency
The command I use to show Kinect2 output is:
mpv av://v4l2:/dev/video0 --untimed --profile=low-latency
This actually shows the footage. Thanks for your effort and your great contribution in the first place!
In order to use the Kinect2 (which uses the MotionJPG/mjpg codec) with other programs that mostly don't support mjpg, say, as a webcam, I convert with ffmpeg in the background. You do need a v4l2loopback device for this!
ffmpeg \
-i /dev/video0 \
# don't do vsync, for less delay
-vsync drop \
# drop half the frames, and scale to 720p -- good enough for webcam use
# also mirror horizontally for webcam use -- other cams do this intrinsically but we need to do it ourselves
-filter:v fps=30,scale=1280:-1,hflip \
# good general-purpose pixel format supported by many apps
-pix_fmt yuyv422 \
# convert the colorspace, so the colors look better (not blown out too much)
-color_trc bt709 \
-color_primaries bt709 \
-color_range tv \
# output device format
-f v4l2 \
# output device
/dev/video2
(remove the comments)
/dev/video0
is the kinect rgb input.
/dev/video2
is the v4l2loopback device.
All options except -i ...
, -f v4l2
and the output device are optional but recommended, if you want smaller delay. I still have quite a huge delay sometimes, but it can be good as well -- sadly really random when it works and when not.
I keep this running in the background, and can then use /dev/video2/
as webcam.