I have a couple Logitech C920 webcams, and I wanted to see if I could use them while streaming and/or recording clips at 1080p... the problem is "it's complicated", and unlike macOS where there are literally a dozen or so free options with fancy/simple GUIs for the purpose, on Linux/RPi, it's a lot more complex.
The most reliable way to capture video is with ffmpeg
, but its usage is inscrutable for beginners. And maybe not impossible for me, but it still requires a lot of futzing around.
After reading this article about streaming 1080p content to YouTube directly (without killing your Pi's poor CPU), it was apparent I was in luck that my Logitech C920 has a built-in H.246 encoder that puts out a pre-compressed stream.
Using this incantation gets the video and dumps it into an mp4 file, with minimal CPU usage:
ffmpeg -f v4l2 -codec:v h264 -framerate 30 -video_size 1920x1080 -itsoffset 0.5 -i /dev/video0 -copyinkf -codec:v copy -codec:a aac -ab 128k -g 10 -f mp4 test.mp4
Using a simpler/more standard example from ffmpeg's documentation, however, results in the Pi's CPU struggling to maintain 5 fps:
ffmpeg -f v4l2 -framerate 30 -video_size 1920x1080 -i /dev/video0 output.mkv
You might wonder, 'how do you know the webcam is at /dev/video0
? Well, find it with:
$ v4l2-ctl --list-devices
bcm2835-codec-decode (platform:bcm2835-codec):
/dev/video10
/dev/video11
/dev/video12
bcm2835-isp (platform:bcm2835-isp):
/dev/video13
/dev/video14
/dev/video15
/dev/video16
HD Pro Webcam C920 (usb-0000:01:00.0-1.2.3):
/dev/video0
/dev/video1
Now, onto finding a way to get my audio interface into the stream...