Tuesday, October 17, 2023

Linux Ubuntu Installing and Using Fake Camera Stream

If you wish to create a virtual camera in Linux and stream "fake" videos during calls:

To install the loopback camera:

sudo apt update sudo apt install v4l2loopback-dkms v4l2loopback-utils

To add the loopback camera module:

sudo modprobe v4l2loopback card_label="My Fake Webcam" exclusive_caps=1


sudo modprobe v4l2loopback devices=1 video_nr=1 card_label='MyWebCam' exclusive_caps=1

Now to stream the video:

First find the list of videos device available:

v4l2-ctl --list-devices

You can check the videos by playing:

ffplay /dev/videoX ffplay Rick_Astley_Never_Gonna_Give_You_Up.mpg

Now you can stream the video to the free one:

ffmpeg -re -i Rick_Astley_Never_Gonna_Give_You_Up.mpg -map 0:v -f v4l2 /dev/videoX


ffmpeg -stream_loop -1 -re -i video.mp4 -vcodec rawvideo -threads 0 -f v4l2 /dev/videoX

To remove the module from the kernel:

sudo modprobe --remove v4l2loopback

Software for streaming:

sudo apt-add-repository ppa:obsproject/obs-studio
sudo apt-get update
sudo apt-get install ffmpeg obs-studio