Im looking for a driver and tutorials to use my kinect 2 as a webcam on obs and skype

Hello.

Im looking for a driver for linux (I prefer an ubuntu one),that can allows me to use my kinect 2 as a webcam on obs and skype. I would like that the kinect 2 camera is recognized by obs and skype. I would like to know if your tool can offer this feature. If yes,how to do that ? can u suggest some documentation ? thanks.

While Psychtoolbox does support the Kinect 1, it is for scientific use cases like depth sensing / 3d object capture, not for use as a regular wecam in other applications, only inside Psychtoolbox. I don’t think our driver supports the Kinect v2 though. Also not tested since over 5 years due to lack of access to a Kinect 1.

So the “use as a regular webcam for skype etc.” question is off-topic for this forum, but sufficiently nerdy for myself to do a quick google for you while i wake up and have my morning coffee. The following advice is obviously untested and i hold no responsibility if this breaks your system, and also won’t give further advice - but those repos have issue trackers:

Linux has a builtin driver for the Kinect 1. For a Kinect 2, i’d try building and setting up a driver from one of these Github repos:

Original repo, seems outdated or unmaintained:

Network graph of versions building on top of the original:

For easy webcam setup i’d probably got for this one:

DKMS support, but no automatic setup as standard webcam:

Have a playful and nerdy weekend,
-mario

yes,you have evaluated my question well as nerdy. This is only an intermediate project. At the end I want to try to compile and load the driver on freeBSD using the linux emulator. I want to install and run skype or zoom inside the linux / ubuntu emulator chroot using the linux driver to place video calls with skype and or zoom. Unfortunately I’m freezed at some point :

Looking at that install script, the system has been setup, but not activated.

You can either systemctl start v4l2-kinect in a terminal, or reboot your machine - this will autostart at reboot.

Then /dev/video10 would be the videodevice that provides video in a color/pixelformat that skype, obs etc. may find better to handle.

However, this is a Linux kernel driver, so if you wanted to use it on FreeBSD, you’d have to port the driver to whatever the FreeBSD kernel uses. Haven’t used FreeBSD in almost 20 years, but i doubt the chroot or emulator will handle this.

good luck,
-mario

Nope,it does not work,even with OBS :

root@marietto-BHYVE:/home/marietto/Scrivania/gspca-kinect2/gspca-kinect2-tduck973564# systemctl enable v4l2-kinect

root@marietto-BHYVE:/home/marietto/Scrivania/gspca-kinect2/gspca-kinect2-tduck973564# systemctl start v4l2-kinect

root@marietto-BHYVE:/home/marietto/Scrivania# v4l2-ctl --list-devices

Dummy video device (0x0000) (platform:v4l2loopback-000):
/dev/video0

root@marietto-BHYVE:/home/marietto/Scrivania# sudo /sbin/rmmod gspca_main

root@marietto-BHYVE:/home/marietto/Scrivania# sudo /sbin/modprobe videodev

root@marietto-BHYVE:/home/marietto/Scrivania# sudo /sbin/insmod gspca_main.ko

root@marietto-BHYVE:/home/marietto/Scrivania/gspca-kinect2/gspca-kinect2-tduck973564# sudo /sbin/insmod ./gspca_kinect2.ko

root@marietto-BHYVE:/home/marietto/Scrivania/gspca-kinect2/gspca-kinect2-tduck973564# v4l2-ctl --list-devices

Dummy video device (0x0000) (platform:v4l2loopback-000):
        /dev/video0

Xbox NUI Sensor (usb-0000:00:04.0-1):
        /dev/video1
        /dev/video2

root@marietto-BHYVE:/home/marietto/Scrivania/gspca-kinect2/gspca-kinect2-tduck973564# ffmpeg -framerate 30 -video_size 640x480 -i /dev/video1 test.avi
ok

obs with :

Xbox NUI Sensor (usb-0000:00:04.0-1)
Xbox NUI Sensor (usb-0000:00:04.0-1)

= Black Screen

and these errors :

error: v4l2-input: /dev/video1: select timed out
error: v4l2-input: /dev/video1: failed to log status
error: v4l2-input: /dev/video1: select timed out
error: v4l2-input: /dev/video1: failed to log status
error: v4l2-input: /dev/video1: select timed out
error: v4l2-input: /dev/video1: failed to log status
libv4l2: error got 4 consecutive frame decode errors, last error: v4l-convert: libjpeg error: End Of Image
error: v4l2-input: /dev/video1: failed to dequeue buffer
info: v4l2-input: /dev/video1: Stopped capture after 0 frames
info: v4l2-input: Found device 'Xbox NUI Sensor' at /dev/video1
info: v4l2-input: Found device 'Xbox NUI Sensor' at /dev/video2
libv4l2: error getting pixformat: Argomento non valido
info: v4l2-input: Unable to open /dev/video0
info: v4l2-input: Found input 'kinect2' (Index 0)
info: v4l2-input: Pixelformat: JFIF JPEG (unavailable)
info: v4l2-input: Pixelformat: RGB3 (Emulated) (unavailable)
info: v4l2-input: Pixelformat: BGR3 (Emulated) (available)
info: v4l2-input: Pixelformat: YU12 (Emulated) (available)
info: v4l2-input: Pixelformat: YV12 (Emulated) (available)
info: v4l2-input: Pixelformat: JFIF JPEG (unavailable)
info: v4l2-input: Pixelformat: RGB3 (Emulated) (unavailable)
info: v4l2-input: Pixelformat: BGR3 (Emulated) (available)
info: v4l2-input: Pixelformat: YU12 (Emulated) (available)
info: v4l2-input: Pixelformat: YV12 (Emulated) (available)
info: v4l2-input: Stepwise and Continuous framerates are currently hardcoded
info: v4l2-input: Found input 'kinect2' (Index 0)
info: v4l2-input: Pixelformat: Y11B (unavailable)
info: v4l2-input: Pixelformat: RGB3 (Emulated) (unavailable)
info: v4l2-input: Pixelformat: BGR3 (Emulated) (available)
info: v4l2-input: Pixelformat: YU12 (Emulated) (available)
info: v4l2-input: Pixelformat: YV12 (Emulated) (available)
info: v4l2-input: Stepwise and Continuous framesizes are currently hardcoded
info: v4l2-input: Start capture from /dev/video2
info: v4l2-input: Input: 0
error: v4l2-input: Selected video format not supported
error: v4l2-input: Initialization failed
info: ==== Shutting down ==================================================
info: All scene data cleared
info: ------------------------------------------------
error: X Error: GLXBadDrawable, Major opcode: 152, Minor opcode: 26, Serial: 16704
error: Failed to make context current.
error: X Error: GLXBadDrawable, Major opcode: 152, Minor opcode: 26, Serial: 16706
error: Failed to make context current.
error: X Error: GLXBadDrawable, Major opcode: 152, Minor opcode: 26, Serial: 16708
error: Failed to make context current.
error: Failed to fetch parent window geometry!
error: X Error: BadDrawable (invalid Pixmap or Window parameter), Major opcode: 152, Minor opcode: BadLength (poly request too large or internal Xlib length error), Serial: 16710
error: X Error: GLXBadDrawable, Major opcode: 152, Minor opcode: BadAlloc (insufficient resources for operation), Serial: 16711
error: X Error: GLXBadDrawable, Major opcode: 152, Minor opcode: 26, Serial: 16713
error: Failed to make context current.
error: X Error: GLXBadDrawable, Major opcode: 152, Minor opcode: 26, Serial: 16715
error: Failed to make context current.
error: X Error: GLXBadDrawable, Major opcode: 152, Minor opcode: 26, Serial: 16717
error: Failed to make context current.
error: Failed to fetch parent window geometry!
error: X Error: BadDrawable (invalid Pixmap or Window parameter), Major opcode: 152, Minor opcode: BadLength (poly request too large or internal Xlib length error), Serial: 16719
error: X Error: GLXBadDrawable, Major opcode: 152, Minor opcode: BadAlloc (insufficient resources for operation), Serial: 16720
error: X Error: GLXBadDrawable, Major opcode: 152, Minor opcode: 26, Serial: 16722
error: Failed to make context current.
error: X Error: GLXBadDrawable, Major opcode: 152, Minor opcode: 26, Serial: 16724
error: Failed to make context current.
error: X Error: GLXBadDrawable, Major opcode: 152, Minor opcode: 26, Serial: 16726
error: Failed to make context current.
info: [Scripting] Total detached callbacks: 0
info: Freeing OBS context data
info: == Profiler Results =============================
info: run_program_init: 4199,19 ms
info:  ┣OBSApp::AppInit: 140,78 ms
info:  ┃ ┗OBSApp::InitLocale: 114,67 ms
info:  ┗OBSApp::OBSInit: 2760,39 ms
info:    ┣obs_startup: 4,624 ms
info:    ┗OBSBasic::OBSInit: 2590,01 ms
info:      ┣OBSBasic::InitBasicConfig: 1,008 ms
info:      ┣OBSBasic::ResetAudio: 0,379 ms
info:      ┣OBSBasic::ResetVideo: 378,752 ms
info:      ┣OBSBasic::InitOBSCallbacks: 0,006 ms
info:      ┣OBSBasic::InitHotkeys: 0,073 ms
info:      ┣obs_load_all_modules: 1781,31 ms
info:      ┃ ┣obs_init_module(decklink-captions.so): 0,033 ms
info:      ┃ ┣obs_init_module(decklink-ouput-ui.so): 1,47 ms
info:      ┃ ┣obs_init_module(frontend-tools.so): 281,773 ms
info:      ┃ ┣obs_init_module(image-source.so): 0,022 ms
info:      ┃ ┣obs_init_module(linux-alsa.so): 0,01 ms
info:      ┃ ┣obs_init_module(linux-capture.so): 0,831 ms
info:      ┃ ┣obs_init_module(linux-decklink.so): 1,153 ms
info:      ┃ ┣obs_init_module(linux-jack.so): 0,007 ms
info:      ┃ ┣obs_init_module(linux-pulseaudio.so): 0,007 ms
info:      ┃ ┣obs_init_module(linux-v4l2.so): 0,319 ms
info:      ┃ ┣obs_init_module(obs-browser.so): 0,523 ms
info:      ┃ ┣obs_init_module(obs-ffmpeg.so): 64,611 ms
info:      ┃ ┃ ┗nvenc_check: 64,005 ms
info:      ┃ ┣obs_init_module(obs-filters.so): 0,089 ms
info:      ┃ ┣obs_init_module(obs-libfdk.so): 0,011 ms
info:      ┃ ┣obs_init_module(obs-outputs.so): 0,011 ms
info:      ┃ ┣obs_init_module(obs-transitions.so): 0,032 ms
info:      ┃ ┣obs_init_module(obs-vst.so): 0,01 ms
info:      ┃ ┣obs_init_module(obs-x264.so): 0,007 ms
info:      ┃ ┣obs_init_module(rtmp-services.so): 28,91 ms
info:      ┃ ┣obs_init_module(text-freetype2.so): 0,065 ms
info:      ┃ ┗obs_init_module(vlc-video.so): 170,626 ms
info:      ┣OBSBasic::ResetOutputs: 37,564 ms
info:      ┣OBSBasic::CreateHotkeys: 0,104 ms
info:      ┣OBSBasic::InitService: 6,589 ms
info:      ┣OBSBasic::InitPrimitives: 2,285 ms
info:      ┗OBSBasic::Load: 62,771 ms
info: obs_hotkey_thread(25 ms): min=0,048 ms, median=0,382 ms, max=79,248 ms, 99th percentile=4,278 ms, 99,8394% below 25 ms
info: audio_thread(Audio): min=0 ms, median=0,041 ms, max=3,19 ms, 99th percentile=0,319 ms
info: obs_graphics_thread(33,3333 ms): min=0,146 ms, median=4,04 ms, max=302,453 ms, 99th percentile=24,263 ms, 99,2639% below 33,333 ms
info:  ┣tick_sources: min=0 ms, median=0,01 ms, max=4,63 ms, 99th percentile=0,029 ms
info:  ┣output_frame: min=0,066 ms, median=0,468 ms, max=5,769 ms, 99th percentile=2,296 ms
info:  ┃ ┗gs_context(video->graphics): min=0,066 ms, median=0,467 ms, max=5,768 ms, 99th percentile=2,293 ms
info:  ┃   ┣render_video: min=0,005 ms, median=0,134 ms, max=2,24 ms, 99th percentile=0,247 ms
info:  ┃   ┃ ┗render_main_texture: min=0,003 ms, median=0,105 ms, max=2,216 ms, 99th percentile=0,193 ms
info:  ┃   ┗gs_flush: min=0 ms, median=0,026 ms, max=4,991 ms, 99th percentile=1,163 ms
info:  ┗render_displays: min=0,04 ms, median=2,701 ms, max=210,367 ms, 99th percentile=19,353 ms
info: =================================================
info: == Profiler Time Between Calls ==================
info: obs_hotkey_thread(25 ms): min=25,106 ms, median=25,743 ms, max=104,445 ms, 17,7653% within ±2% of 25 ms (0% lower, 82,2347% higher)
info: obs_graphics_thread(33,3333 ms): min=5,143 ms, median=33,333 ms, max=302,46 ms, 83,4737% within ±2% of 33,333 ms (8,21053% lower, 8,31579% higher)
info: =================================================
info: Number of memory leaks: 0

The /dev/video0 from the kernel driver only supports one video output format, and the ffmpeg service here is used to reencode into a different video format on those other /dev/video devices, a format which may be more commonly supported by things like skype or obs.

My guess would be that obs or skype or whatever doesn’t understand the pixelformat output by the ffmpeg driven video loopback device – that’s the -pix_fmt yuyv422 line in the ffmpeg call in that script, asking for a yuyv422 format. You could try other supported formats, maybe check if there is a list somehwere of what obs understands, then restart that service with systemctl or machine reboot.

But at this point you should ask for help in the issue tracker of that github repo, or on obs mailing lists etc. This topic is mostly off topic for the Psychtoolbox forum.

Have a nice weekend,
-mario

ffmpeg works only with /dev/video1,not with video0 or video2. I don’t know which dev OBS and skype are choosing. Infact OBS detect “usb-0000:00:04.0-1” ; but I don’t know if it belongs to video0,video1 or video2. Skype for the web detects "Xbox nui sensor (045e:02c4) ; the skype client for linux detects only the dummy dev (0000:0000) maybe it is the loopback dev. Anyway none of these work. I don’t see a direct correlation between what ffmpeg needs to work (/dev/video1) and what’s needed by OBS and Skype. Is there a method to redirect /dev/video1 to /dev/video0 and /dev/video2 ? Maybe doing this,it will force obs and skype to grab the right device. If they don’t accept video1,I can do the same with video0 and video2. In this way I will understand what device OBS and Skype want to use. I’ve already asked in a lot of places,but no one replied in a useful way until now.

If you look at the /etc/systemd/system/v4l2-kinect.service systemd service defintion file, you will find the ffmpeg command that gets exectued at system boot or service start. That command takes input from the kernel and converts it into a format suitable for more other clients and feeds it into one end of the video loopback device.

This is what that setup script created:
ExecStart=ffmpeg -i /dev/video0 -vsync drop -filter:v fps=30,scale=1280:-1,hflip -pix_fmt yuyv422 -color_trc bt709 -color_primaries bt709 -color_range tv -f v4l2 /dev/video10

So you can see from -i /dev/video0 that ffmpeg tries to read from /dev/video0, which is apparently something else on your systm. Maybe your machine already has a builtin webcam as /dev/video0? Anyway, you need to change that to -i /dev/video1 to feed the Kinect camera data to ffmpeg. Then you see that ffmpeg tries to feed the video which was converted from MotionJpeg to YUYV422 into the video4linux loopback device at /dev/video10 - also setup by the installation script and configured in /etc/modprobe.d/v4l2loopback.conf. If you edit the files so ffmpeg gets input from the Kinect and feeds converted input into the loopback device, and reboot the machine for good measure, then there should be another device, probably /dev/video10 that obs/skype etc. may be able to read. The setup script assumed the real Kinect color camera on video0, but that seems to be not the case on your setup, hence one reason for failure.

Anyway, that’s my guess. For further questions, ask the people on that Github repo. Also make sure that if you find a solution that you post it on the places you asked for help, so others can benefit.

-mario