Skip to content

Instantly share code, notes, and snippets.

@Raymo111
Last active November 27, 2021 04:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Raymo111/41d0e4f93dae6757a2c260cabf113d54 to your computer and use it in GitHub Desktop.
Save Raymo111/41d0e4f93dae6757a2c260cabf113d54 to your computer and use it in GitHub Desktop.

1920x1080 HD webcam on Linux

By Raymond Li (Raymo111)

Last updated 8 Sept 2021

So your webcam is giving you a 5:4 low-res video and you can't do anything about it?

  1. Load the v4l2loopback kernel module:
sudo depmod -a
sudo modprobe v4l2loopback devices=1 max_buffers=2 exclusive_caps=1 card_label="VirtualCam"

You can do this persistently by creating a config file like video.conf in /etc/modprobe.d/ with the following in it:

options v4l2loopback devices=1 max_buffers=2 exclusive_caps=1 card_label="VirtualCam"
  1. Check the devices that v4l2 detects:
v4l2-ctl --list-devices
---
Dummy video device (0x0000) (platform:v4l2loopback-000):
        /dev/video2

T2 Webcam: T2 Webcam (usb-0000:0b:00.3-2):
        /dev/video0
        /dev/video1
  1. Check the format and resolution that is supported:
ffmpeg -hide_banner -f v4l2 -list_formats all -i /dev/video0
---
[video4linux2,v4l2] Compressed: mjpeg  : Motion-JPEG: 1920x1080 640x480 1280x720 320x240 1024x768 1280x1024 160x120 576x1024 800x600
[video4linux2,v4l2] Raw       : yuyv422: YUYV 4:2:2 : 640x480 1280x720 320x240 1024x768 1280x1024 160x120 576x1024 800x600

In this case, 1920x1080 is the highest resolution supported, and the type is mjpeg. 4. Use ffmpeg and magic to pipe the video stream to the loopback stream, editing the command to suit your devices, resolutiona nd format:

ffmpeg -hide_banner -f v4l2 -input_format mjpeg -video_size 1920x1080 -i /dev/video0 -vf format=yuyv422 -f v4l2 /dev/video2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment