Skip to content

Instantly share code, notes, and snippets.

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 agusalex/031ae2401c191f4a74bbbaf3e2242384 to your computer and use it in GitHub Desktop.
Save agusalex/031ae2401c191f4a74bbbaf3e2242384 to your computer and use it in GitHub Desktop.
Test your AR or any other webcam dependant software easily using a virtual webcam with static image or video

How to use a virtual webcam with static image or video

How To

First you’ll need to install Ffmpeg and v4l2loopback and v4l-utils.

For Ffmpeg is easy as it comes bundled with most distros and so does v4l2-ctl.

sudo apt-get install ffmpeg v4l-utils

For v4l2loopback you need to first clone from their repository and do make install as follows

sudo make && make install

once installed we need to copy the module to our modules folder

sudo cp v4l2loopback.ko /lib/modules/`uname -r `

sudo depmod -a

sudo modprobe v4l2loopback

once the module is loaded we can check that our dummy camera is installed and find out it’s name

v4l2-ctl --list-device

in my pc the output is as follows

Dummy video device (0x0000) (platform:v4l2loopback-000): /dev/video1 Laptop_Integrated_Webcam_1.3M: (usb-0000:00:1a.0-1.5): /dev/video0

As you can see the dummy camera has been installed and it is on dev/video1. Finally can well tell ffmpeg to grab an image and stream it to our virtual webcam.

ffmpeg -loop 1 -re -i testsrc.png -f v4l2 -vcodec rawvideo -pix_fmt yuv420p /dev/video1

Note that we used video1 for our dummy camera but yours may differ. Testsrc is the file that you will stream. For video you can also do

ffmpeg -re -i testsrc.avi -f v4l2 /dev/video1

Now you should be able to see your image shown in any app that uses webcam, for example you can test it with this handy online tool

I want to clarify that this method does not work on chromium, I tested it on Firefox.

References

This gist was created following this nice tutorial from linuxgamecast for desktop capturing

And v4l2loopbacks’s wiki

For more information check their wiki.

sudo apt-get -y install ffmpeg v4l-utils;
git clone https://github.com/umlaeute/v4l2loopback.git;
cd v4l2loopback;
sudo make && make install;
sudo cp v4l2loopback.ko /lib/modules/`uname -r`
sudo depmod -a
sudo modprobe v4l2loopback;
cd ..;
ffmpeg -loop 1 -re -i testsrc.png -f v4l2 -vcodec rawvideo -pix_fmt yuv420p /dev/video1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment