I recently bought a new webcam, because my laptop screen broke down, and the replacement screen that the Fujitsu people had on stock did not have a webcam anymore -- and, well, I need one.

One thing the new webcam has which the old one did not is a sensor with a 1920x1080 resolution. Since I've been playing around with various video-related things, I wanted to see if it was possible to record something in VP9 at live encoding settings. A year or so ago I would have said "no, that takes waaay too much CPU time", but right now I know that this is not true, you can easily do so if you use the right ffmpeg settings.

After a bit of fiddling about, I came up with the following:

ffmpeg -f v4l2 -framerate 25 -video_size 1920x1080 -c:v mjpeg -i /dev/video0 -f alsa -ac 1 -i hw:CARD=C615 -c:a libopus -map 0:v -map 1:a -c:v libvpx-vp9 -r 25 -g 90 -s 1920x1080 -quality realtime -speed 6 -threads 8 -row-mt 1 -tile-columns 2 -frame-parallel 1 -qmin 4 -qmax 48 -b:v 4500 output.mkv

Things you might want to change in the above:

  • Set the hw:CARD=C615 bit to something that occurs in the output of arecord -L on your system rather than on mine.
  • Run v4l2-ctl --list-formats-ext and verify that your camera supports 1920x1080 resolution in motion JPEG at 25 fps. If not, change the values of the parameters -framerate and -video_size, and the -c:v that occurs before the -i /dev/video0 position (which sets the input video codec; the one after selects the output video codec and you don't want to touch that unless you don't want VP9).
  • If don't have a quad-core CPU with hyperthreading, change the -threads setting.

If your CPU can't keep up with things, you might want to read the documentation on the subject and tweak the -qmin, -qmax, and/or -speed parameters.

This was done on a four-year-old Haswell Core i7; it should be easier on more modern hardware.

Next up: try to get a live stream into a DASH system. Or something.