5

Wondering if it would be possible to use ffmpeg w/ v4l2 support (on say Ubuntu Linux) to create a virtual webcam device, that presents a transformed version of real webcam's output. The idea would be that the virtual webcam device could then be used by popular video conferencing applications like Teams, Zoom, Google Talk etc.

The nature of transformations I am looking at is cropping on few of the edges, applying overlay text, applying chroma-keying, background replacement etc. I am looking for a mechanism that has least system overhead as well, which is why considering ffmpeg.

2

1 Answer 1

6

Yes, this is possible.

  1. Get the v4l2loopback module
    apt-get install v4l2loopback-dkms
    
  2. Load the module
    modprobe v4l2loopback exclusive_caps=1 card_label="Virtual Webcam" max_buffers=2
    
  3. Run ffmpeg(1) reading from the actual/physical webcam and writing to the “virtual” webcam. For instance, I got some old webcam that only supports 640 pixels × 480 pixels @ 30.00 FPS (among other modes), but I like to have it cropped to a 16 : 10 aspect ratio:
    ffmpeg -f v4l2 -i /dev/video0 -pix_fmt yuyv422 -vf crop=h=400 -f v4l2 /dev/video1
    
    Pay attention to the order of parameters. E. g. here it was crucial to specify ‑pix_fmt before (any) ‑vf.
  4. If you’ve changed the resolution:
    v4l2-ctl -d /dev/video1 --set-fmt-video=width=640,height=400,pixelformat=yuyv422
    
  5. Use the virtual camera from your application and celebrate.

I presume it wasn’t worth mentioning, but for the sake of completeness: apt‑get(8) and modprobe(8) need to be executed with root privileges, whereas ffmpeg(1) and v4l2-ctl(1) are run as a regular user usually (also) being a member of the video group. Confer the group ownership of /dev/video*.

PS: Some duplicate questions/answers are OK, especially if you can’t merge them because they are on different sites.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .