Skip to content

Instantly share code, notes, and snippets.

@bryanjhv
Created May 3, 2020 09:38
Show Gist options
  • Save bryanjhv/1c38a0d10faa425431c8d3e3982227de to your computer and use it in GitHub Desktop.
Save bryanjhv/1c38a0d10faa425431c8d3e3982227de to your computer and use it in GitHub Desktop.
Create fake webcam for Raspberry Pi (3B+ tested)
#!/usr/bin/env sh
# REQUIRES BUILDING+INSTALLING THIS FIRST:
# https://github.com/umlaeute/v4l2loopback#install
NUM=${2:-0}
PIC=${1:-/usr/share/plymouth/themes/pix/splash.png}
if [ ! -r "$PIC" ]
then
echo "ERROR: '$PIC' is not a file."
exit 1
fi
case "$NUM" in
''|*[!0-9]*)
echo "ERROR: '$NUM' is not a number."
exit 1 ;;
esac
DEV="/dev/video$NUM"
if [ -e "$DEV" ]
then
echo "ERROR: device '$NUM' exists."
exit 1
fi
trap ' ' INT # Capture ffmpeg interrupt
sudo modprobe v4l2loopback exclusive_caps=1 video_nr="$NUM" card_label="Fake Webcam $NUM"
echo "INFO: Created fake webcam at '$DEV' using '$PIC'."
ffmpeg -hide_banner -loglevel warning -stream_loop -1 -re -i "$PIC" -f v4l2 -vcodec rawvideo -pix_fmt yuv420p "$DEV"
sudo modprobe -r v4l2loopback
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment