Skip to content

Linux Picture in Picture

jayeye edited this page Mar 22, 2020 · 10 revisions

I needed a picture-in-picture camera feed, the main picture pointing at my (paper) notebook, the "in-picture" picture pointing at my face. Here is how to do it (tested in Ubuntu LTS; YMMV).

  • Assume /dev/video0 will be the "in-Picture" camera and /dev/video1 will be the "main" camera.

  • As root: modprobe v4l2loopback exclusive_caps=1

  • Verify /dev/video2 exists and is readable by you.

  • Kill whatever application you will be using with this setup (probably your browser).

  • As you:

    pip_dev=/dev/video0
    main_dev=/dev/video1
    v_dev=/dev/video2
    pip_res=320x240
    main_res=1600x1200
    ffmpeg \
      -f v4l2 -c:v mjpeg -fflags nobuffer -fflags flush_packets -video_size ${main_res} -i ${main_dev} \
      -f v4l2 -c:v mjpeg -fflags nobuffer -fflags flush_packets -video_size ${pip_res} -i ${pip_dev} \
      -filter_complex \
        "nullsrc=size=${main_res} [bg];
         [0:v] setpts=PTS-STARTPTS [main];
         [1:v] setpts=PTS-STARTPTS [pip];
         [bg][main] overlay [ovly];
         [ovly][pip] overlay" \
      -c:v rawvideo -pix_fmt yuyv422  -f v4l2 ${v_dev}
    
  • Restart the browser and go to whatever videoconferencing site you are using. Select the dummy camera from the camera selection settings.

  • Profit!

This is what it looks on the other side:

For the main camera, I used a cheap ELP USB camera I had lying around, mounted on a coolant pipe:

Which, in turn, is mounted on something I 3D-printed a long time ago:

Clone this wiki locally