Instead of showing yourself in the conference, we can show video or static images
We don’t always want to include a camera during the conference, so we found a way to display video or static images instead. The means of OS or browser doesn’t provide this out of the box. I found this article and, indeed, created a virtual camera module that is recognized by browsers as an ordinary camera 😄
Below is a script with detailed comments. The only argument to it is the path to the file or image that should be transmitted in the stream.
#!/usr/bin/env sh
set -e
# label for the new webcam as it will be seen in browserLABEL="VirtualCam #0"# module insertion in case if it was not inserted during this bootif ! lsmod | grep -qE '^v4l2loopback';then# camera is being created during the module loading sudo modprobe v4l2loopback devices=1exclusive_caps=1max_buffers=2card_label="$LABEL"# wait for a while to finish module initialization sleep 1fi# path to media fileF="${1:?File is not passed}"# getting path to newly created camera deviceDEV="$(v4l2-ctl --list-devices 2>/dev/null | grep -A1 "$LABEL"| grep -oE '/dev/video[0-9]+')"if[ ! -f "$F"];then# check in case if media file path does not existsecho"error: file $F does not exists" >&2exit1fi# get file type and use proper streaming commandcase"$(file --mime-type --brief "$F"| cut -d/ -f1)" in
video)# in case if file is video ffmpeg -re -i "$F" -f v4l2 -vcodec rawvideo -pix_fmt yuv420p "$DEV";; image)# in case if file is picture ffmpeg -loop 1 -re -i "$F" -f v4l2 -vcodec rawvideo -pix_fmt yuv420p "$DEV";; *)# in case if file is something elseecho'error: unknown mime type' >&2exit2;;esac
So, in the end, we were able to stream Rick Ashley - Never Gonna Give You Up.
One notable drawback is that FFmpeg consumes almost an entire core. Additionally, we are, of course, only transmitting the image, without any sound.