# Setting Up a Virtual Webcam on Linux

I was testing a web app that involves taking pictures. Once again, my attached webcam wasn't working, and I didn't bother to check this minor issue. Just as 42 is the answer to everything, so is v**4**l**2**loopback.

First, let's summon the video device out of thin air:

```bash
sudo modprobe v4l2loopback
```

Check this [**extensive documentation**](https://wiki.archlinux.org/title/V4l2loopback) \[[**archive**](https://archive.ph/wip/DuWZf)\] for details on the arguments you can use. A newly created video device is now available. In my case, it is at `/dev/video3`.

Now, see how `ffmpeg` takes input from `testrc` and then writes it to `/dev/video3`.

```bash
ffmpeg -re -f lavfi -i testsrc=size=1280x720:rate=30 -f v4l2 /dev/video3
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1759422831106/389a289f-bf51-4a57-9616-a15a4c4627de.png align="center")

Similarly, we can use `ffplay` to show the video.

```bash
ffplay /dev/video3
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1759423008047/fa7b9cb4-0ee2-4948-a3bb-b7018e198df5.png align="center")

At my workplace, I used `ffmpeg` and `gstreamer` to deliver real-time video feeds to our customers. This information might be available online, but it's scattered. While this post serves as my personal note, I hope it will also be useful for you. Ciao!
