Stuck getting hardware H264 USB cam working with Octoprint on RasPi4


I've have two Octoprint instances running in Docker containers (so, I'm not using OctoPi... just plain Raspbian) using plain old USB cameras through mjpg-streamer, but I wanted to start using hardware H264 encoding to lower the load on my Pi, so I bought some generic H264 USB cams and am trying to get going with those.

Camera model

lsusb reports:

32e4:9422 H264 USB Camera H264 USB Camera

while v4l2-ctl on the four device files report:

v4l2-ctl -d /dev/v4l/by-id/usb-H264_USB_Camera_H264_USB_Camera_2020032801-video-index0 --list-formats
Type: Video Capture
[0]: 'MJPG' (Motion-JPEG, compressed)
[1]: 'YUYV' (YUYV 4:2:2)

v4l2-ctl -d /dev/v4l/by-id/usb-H264_USB_Camera_H264_USB_Camera_2020032801-video-index1 --list-formats
Type: Video Capture

v4l2-ctl -d /dev/v4l/by-id/usb-H264_USB_Camera_H264_USB_Camera_2020032801-video-index2 --list-formats
Type: Video Capture
[0]: 'H264' (H.264, compressed)

v4l2-ctl -d /dev/v4l/by-id/usb-H264_USB_Camera_H264_USB_Camera_2020032801-video-index3 --list-formats
Type: Video Capture

What is the problem?

What did you already try to solve it?

I read a lot of Low-Latency H264 Streaming Support w/ WebRTC to try to make sense of it, but it's unclear what service I'm supposed to run in order to achieve this. I've looked for WebRTC daemons for raspi, and found one, but it seems to be aimed at video-conferencing and streaming of various non-camera sources.

I also found camera-streamer, and I was able to get that to stream from the non-H264 device, but I can't get it to just do plain pass-through of the H264 stream to a web client.

Have you tried running in safe mode?

No. This isn't even to the step where I point OctoPrint at a stream URL. I'm just trying to get my system to stream the hardware H264 stream in a way that OctoPrint could even consume. I realize that this isn't technically an OctoPrint issue, but it's a problem that I'm sure counteless OctoPrint users have solved and must have a standard solution, but, for the life of me, I can't find it.

Systeminfo Bundle

You can download this in OctoPrint's System Information dialog ... no bundle, no support!) (37.2 KB)

Additional information about your setup

OctoPrint 1.9.3 on a RasPi 4b running Raspbian bookworm on kernel 6.1.63

In general most streaming software doesn't have an option to use h264 outputted directly from the camera, because it is much harder to make work on a wide range of devices. Instead, on something like the Pi, which has a hardware H264 encoder, something like camera-streamer is able to use that to encode the video without taxing the Pi. I am not aware off the top of my head of generally available streaming software for passing through h264.

The other dimension of the problem would be viewing it in OctoPrint. For a webrtc stream, you need a viewer specific to the streaming server because, although a standard is being developed, most of them stream differently. For camera-streamer, this exists already, but for something else it would not.

My suggestion would be to use camera-streamer and the hardware encoding of the Pi if you want an h264 stream.

1 Like