I have a 1080p webcam connected to a Raspberry Pi 4B over USB. The camera supports the following formats:
Raw : yuyv422 : YUYV 4:2:2
Compressed: mjpeg : Motion-JPEG
I would like to use ffmpeg to stream the footage to file, using hardware-accelerated encoding, so I'm attempting to use the h264_v4l2m2m codec.
Problem is, if I want 1080p to work at a decent frame rate, I need to use the mjpeg stream from the camera. But this makes the output codec complain.
Here's my command:
$ ffmpeg -y -f v4l2 -framerate 24 -video_size 1920x1080 -input_format mjpeg -i /dev/video0 -c:v h264_v4l2m2m -r 24 -b:v 2386092 lmao.mp4
And the relevant output:
...
[h264_v4l2m2m @ 0xf4c2d0] Using device /dev/video11
[h264_v4l2m2m @ 0xf4c2d0] driver 'bcm2835-codec' on card 'bcm2835-codec-encode' in mplane mode
[h264_v4l2m2m @ 0xf4c2d0] requesting formats: output=YU12 capture=H264
[h264_v4l2m2m @ 0xf4c2d0] Encoder requires yuv420p pixel format.
Error initializing output stream 0:0 -- Error while opening encoder for output stream #0:0 - maybe incorrect parameters such as bit_rate, rate, width or height
Conversion failed!
What's the deal?! This seems very limiting.
Does anyone know of alternative solutions? I've tried using the h264_omx codec, but at least on stock Raspberry Pi OS, it just complains about missing libraries, so I imagine I'd have to compile ffmpeg myself.
I'm on Raspberry Pi OS Bullseye, using ffmpeg version 4.3.4-0+deb11u1+rpt1.