Skip to content

Instantly share code, notes, and snippets.

@kardysm
Last active September 28, 2021 06:31
Show Gist options
  • Save kardysm/b3544549f5ee90634f951ca5117fffe0 to your computer and use it in GitHub Desktop.
Save kardysm/b3544549f5ee90634f951ca5117fffe0 to your computer and use it in GitHub Desktop.
Stream external dslr/mirrorless camera as webcam on linux
#!/bin/sh
# webcam will be preview quality, not of actual camera capabilities
# prerequisites and source: https://www.crackedthecode.co/how-to-use-your-dslr-as-a-webcam-in-linux/
# alternative: https://hanspinckaers.com/using-a-sony-alpha-camera-as-a-webcam-in-ubuntu
# IF PREREQUISITES ARE MET AND SCRIPT IS FAILING, RESTART MIGHT HELP
# restart v4l2loopback kernel module
sudo modprobe -r dslr-webcam
sudo modprobe dslr-webcam
# detect video0
v4l2-ctl --device=/dev/video0 --all
# detect connected camera
gphoto2 --auto-detect
# uses gpu, for cpu see: source^
# /dev/video0 should be v4l2loopback device
gphoto2 --stdout --capture-movie | ffmpeg \
-hwaccel nvdec \
-c:v mjpeg_cuvid \
-i - \
-vcodec rawvideo \
-pix_fmt yuv420p \
-threads 0 \
-f v4l2 /dev/video0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment