jw-play icon indicating copy to clipboard operation
jw-play copied to clipboard

Using Virtual Cameras for Displaying Photos and Video

Open JoelMon opened this issue 3 years ago • 1 comments

Virtual Cameras

Being able to use a virtual camera for sharing video or images in virtual congregational meetings is beneficial in these ways:

  • Pictures and videos can be shown during talks seamlessly
    • No flipping back and forth from shared screen to webcam
    • No chance of accidentally sliding something into view while sharing desktop
    • Looks more professorial
  • Picture in Picture effects can be accomplished by layering video/photos over each other.
    • Pictures can be shown in the corner
    • Text can be displayed with an alpha mask
  • Hotkeys can be used to display various items quickly
    • Key 1: to play the Watchtower opening scripture
    • Key 2: to show a picture
    • Key 3: to play or show a scripture on screen
    • Key Ctr+b: for blackout screen
    • Key 0: return video feed to speaker's webcam
  • Can use websockets to control what is shown on the screen.
    • Control what is shown on screen via a tablet, phone, or another computer

OBS does all these things and more but it's overkill and becomes unwieldy with large amounts of photos and videos as used in Sign Language congregations. With so many options and capabilities, it's confusing and hard to use for many.

Virtual Cameras in Linux

Accessing real-time camera features under Linux can be done via the V4L2, video for Linux, driver. The V4L2 driver provides a standard API for working with firmware-based cameras and webcams. More information about the V4L2 Linux driver can be found at Kernel.org: Part I - Video for Linux API.

Accessing V4L2 can be done via a Ruby OpenCV wrapper called ruby-opencv but might be simpler by taking advantage of the V4L2Loopback kernel module.

V4L2Loopback

The V4L2Loopback is a Linux kernel module that creates V4L2, loopback devices. In other words, it creates a virtual V4L2 camera that can be used by any programs capable of writing to a v4l2 device to output video or images to any application that can be read by any v4l2-capable application, e.g. Zoom.

This is the method that OBS uses to output a video feed to a virtual webcam. 2021-05-18_19-48

The V4L2Loopback's Github repository lists two feeders as examples that can be used to feed a video stream to v4l2:

  • GStreamer-1.0: using the "v4l2sink" element
  • Gem(>=0.93) using the "recordV4L2" plugin

ffmpeg can also be used.

Virtual Cameras on other systems

I haven't done too much research on other systems but ffmpeg can be used on Linux, macOS, and Windows. With ffmpeg you give it a source or device and you can stream it to another source or device with the format needed.

Implementation

A possible quick and extremely hacky way to implement ~not taking into account the live video feed of the speaker~:

  • Check if V4L2Loopback is loaded modinfo v4l2loopback
    • Prompt user if V4L2Loopback is not loaded.
      • To install via apt under Ubuntu flavors: $ sudo apt install v4l2loopback-dkms

      • To load installed module: $ sudo modprobe v4l2loopback

  • Auto detect all video devices
    • Check dev/v4l/by-id for the index of the devices.
    • Let user input
  • Confirm ffmpeg is installed on the system
    • Output image or video with ffmpeg $ ffmpeg -re -i <video-file.mp4> -f v4l2 /dev/video2
  • Switching to the speaker (webcam)
    • Outputting webcam video: $ ffmpeg -f v4l2 -i /dev/video0 -f v4l2 /dev/video2. video0 being the webcam and video2 being the loopback.

Resources

Examples

Using ffmpeg and v4l2loopback

An example of using ffmpeg and v4l2loopback to stream a video to a virtual cam

JoelMon avatar May 19 '21 01:05 JoelMon

I have added an example of how v4l2loopback can be used with ffmpeg to stream a video file to the virtual camera and shown live on Zoom.

JoelMon avatar Jun 15 '21 13:06 JoelMon