Quick and dirty post that pulls together a couple of sources. I might improve the post at some point. I might not…
Initial set-up:
Source https://www.youtube.com/watch?v=TsuY4o2zLVQ
Additional code to specify which video device to create.
sudo apt update && sudo apt install gphoto2 v4l2loopback-utils ffmpeg echo 'dslr-webcam' | sudo tee -a /etc/modules echo <<EOT | sudo tee -a /etc/modprobe.d/dslr-webcam.conf alias dslr-webcam v4l2loopback options v4l2loopback exclusive_caps=1 max_buffers=2 video_nr=69 EOT
Hardware acceleration set-up:
Source https://www.cyberciti.biz/faq/how-to-install-ffmpeg-with-nvidia-gpu-acceleration-on-linux/
I’ll assume you have nvidia drives installed
sudo apt install nvidia-cuda-toolkit mkdir ~/nvidia/ && cd ~/nvidia/ git clone https://git.videolan.org/git/ffmpeg/nv-codec-headers.git cd nv-codec-headers && sudo make install cd ~/nvidia/ git clone https://git.ffmpeg.org/ffmpeg.git ffmpeg/ sudo apt install build-essential yasm cmake libtool libc6 libc6-dev unzip wget libnuma1 libnuma-dev cd ~/nvidia/ffmpeg/ ./configure --enable-nonfree --enable-cuda-nvcc --enable-libnpp --extra-cflags=-I/usr/local/cuda/include --extra-ldflags=-L/usr/local/cuda/lib64 make -j $(nproc)
Combined to pull video from the camera to a video device:
echo 'alias start-gphoto2-webcam="gphoto2 --capture-image && gphoto2 --stdout --capture-movie | ~/nvidia/ffmpeg/ffmpeg -hwaccel cuda -i - -vcodec rawvideo -pix_fmt yuv420p -threads 0 -f v4l2 /dev/video69"' >> ~/.bashrc
Finally:
- Logout/in
- Plug the camera into the computer
- Turn the camera on
- Run: start-gphoto2-webcam
- Use in an application that uses a webcam