How can I stream my desktop/screen to /dev/video1 as a (fake) "webcam" on Linux?
Solved.
Steps to solve:
- Unload previous v4l2loopback
sudo modprobe -r v4l2loopback
git clone https://github.com/umlaeute/v4l2loopback/
-
make && sudo make install
(if you're using secure boot, you'll need to sign it first https://ubuntu.com/blog/how-to-sign-things-for-secure-boot) sudo depmod -a
- Load the videodev drivers
sudo modprobe videodev
-
sudo insmod ./v4l2loopback.ko devices=1 video_nr=2 exclusive_caps=1
Change video_nr based on how many cams you already got. Zero indexed -
ls -al /dev/video*
Use /dev/video[video_nr] with ffmpeg sudo ffmpeg -f x11grab -r 60 -s 1920x1080 -i :0.0+1920,0 -vcodec rawvideo -pix_fmt yuv420p -threads 0 -f v4l2 -vf 'hflip,scale=640:360' /dev/video2
- Go to https://webcamtests.com and test your dummy cam
- Profit!
If you want this to persist between boots, https://askubuntu.com/a/1024786/721238 should do it.
Related videos on Youtube
![dǝɥɔS ʇoıןןƎ](https://i.stack.imgur.com/jCzX9.png?s=256&g=1)
dǝɥɔS ʇoıןןƎ
Updated on September 18, 2022Comments
-
dǝɥɔS ʇoıןןƎ almost 2 years
I have two commands, one that lets me record my screen to an AVI video file, and another which lets me stream a video file as a (fake) "webcam". This is really useful in apps that doesn't support selecting one screen to share (I'm looking at you Slack).
command #1 (https://askubuntu.com/a/892683/721238):
ffmpeg -y -f alsa -i hw:0 -f x11grab -framerate 30 -video_size 1920x1080 -i :0.0+1920,0 -c:v libx264 -pix_fmt yuv420p -qp 0 -preset ultrafast screenStream.avi
command #2 (https://unix.stackexchange.com/a/466683/253391):
ffmpeg -re -i screenStream.avi -map 0:v -f v4l2 /dev/video1
Why can't I just run both of these in parallel? Well, the second command starts streaming from the beginning of the file, whenever I use my "webcam". So I have to time it really close, otherwise there is latency.
I've tried lots and lots of solutions (including solutions with gstreamer instead of ffmpeg), can't get anything to work. This is my last hope.
How can I stream my desktop/screen to /dev/video1 as a (fake) "webcam" on Ubuntu?
-
Bart almost 5 yearsdid you try v4l2loopback? askubuntu.com/questions/881305/…
-
dǝɥɔS ʇoıןןƎ almost 5 yearsYes, the closest I got with that (after building the latest version from source) was
sudo ffmpeg -f x11grab -r 60 -s 1920x1080 -i :0.0+1920,0 -vcodec rawvideo -pix_fmt yuv420p -threads 0 -f v4l2 -vf 'hflip,scale=640:360' /dev/video1
. It's not detected on Chrome, and Slack, though it does work on Firefox. I found some bug reports about that, but I can't remember where. I can try to find them again if it helps -
dǝɥɔS ʇoıןןƎ almost 5 yearsI should say, I'm using webcamtests.com to test wether my "webcam" is working, rather than calling my collegues every time. If it works on that site on Chrome, the Slack app will probably also work. I know this because I actually had a working solution a few months ago. I no longer have my working solution :/
-
Bart almost 5 yearsweirdly enough, this works on my CentOS 7 Chrome, using this command:
ffmpeg -f x11grab -r 15 -s 1280x720 -i :0.0+0,0 -vcodec rawvideo -pix_fmt yuv420p -threads 0 -f v4l2 /dev/video0
-
Bart almost 5 yearsand am not sure this is still relevant, but see: bugs.chromium.org/p/chromium/issues/detail?id=757399
-
dǝɥɔS ʇoıןןƎ almost 5 yearsVery interesting. I'm running Ubuntu bionic. I get the two cams on Firefox, but on Chrome I only get my itegrated one. See my screenshot of the media devices imgur.com/a/SmDR84b (couldn't take screenshot of webcamtests.com). That bug report is relevent. I'm guessing Skype and Slack both use Electron, which I think is based on Chromium, so it makes sense they're affected
-
dǝɥɔS ʇoıןןƎ almost 5 yearsMight have just solved it using github.com/umlaeute/v4l2loopback/issues/78. Will answer question once I confirm
-
Coder Guy over 3 yearsCombine this with tmtimer.calebgrove.com and you've got a very suitable Toastmasters timer (without the need for Zoom screensharing) for your timer role.
-
-
dǝɥɔS ʇoıןןƎ almost 5 years@Bart, thanks for the help, couldn't have done it without you!
-
pbhj about 4 yearsFor me it wasn't necessary to download from github, just
sudo apt install v4l2loop*
. As I was using generally available modules I just used modprobe where the answer uses insmod. Other than that, very useful. I was able to play a file using-stream_loop -1
as if it were a webcam feed. -
undercat about 4 yearsIn my case (Ubuntu 18.04) it was the old v4l2loop version from the repo that was the problem, as it turns out. This answer explains how to use the latest github version that does work with my distro. Thanks so much!