Well... it cost's me a complete evening to realise, that only the older C920's have h264/mp4 encoding. Logitech decided to drop this feature a while ago:
According to Wikipedia, there are not many Webcam's with mp4 left:
https://en.wikipedia.org/wiki/List_of_cameras_with_onboard_video_compression
But nontheless I've found a way for me to make it work on my Raspberry Pi 4 running OctoPi 0.17.0 with OctoPrint 1.4.00: Restreamer (https://datarhei.github.io/restreamer/
). Here's what I did:
- disabled/stopped
webcamd
and wait till port 8080 is free, check withnetstat -tulpen
sudo service webcamd stop sudo systemctl disable webcamd.service
- installed Restreamer via Docker (ARM version) on the Pi:
https://datarhei.github.io/restreamer/docs/guides-usb-camera.html
using port 8080 (e.g.) and/dev/video0
- installed @jneilliii's WebCamIframe-Plugin:
https://community.octoprint.org/t/load-video-stream-instead-of-usb-camera/9772/19
- Started streaming via Restreamers Webinterface in
h264
mode. If your Webcam supports nativeh264
you can simply usecopy
in the encoding options - changed Octoprint's Stream-URL to:
http://<network-ip-of-pi>:8080/player.html
- changed Octoprint's Snapshot-URL to:
http://127.0.0.1:8080/images/live.jpg
- Configured and started restreamers Encoding on
rtmp://127.0.0.1/live/usbcam.stream
accordong to the guide.
I'm at 30-40% CPU with 720p@25fps (superfast, 4MBit/s) as I can't find anything on how to use the Pi's hardware mp4 unit for this.
But maybe some of you can help me out, as there is a second ffmpeg process eating up cpu time. I think this must be something from Octoprint itself. I don't know it this also blocks Port 8080, as I've disabled mjpeg_streamer by stopping webcamd.
Edit: Both ffmpeg processes are from Restreamer. One to fetch /dev/video0
and put it to /dev/video
, the second to encode the video to h264.
Edit^2: Obviously I've not waited long enough to let free up mjpeg_streamer port 8080 after stopping it.
Before that I've fidled around with ffserver (https://trac.ffmpeg.org/wiki/ffserver
), which is not maintained anymore. I've switched to Restreamer before I came to the conclusion, that my camera is lacking h264.
All in all it's kind of a mess. Every information you find regarding v4l2 is mostly from 2014/2015 and things like ffserver are discontinued. Don't get me wrong, I'm very thankfull for the work people put into this. But maybe I'm oversaw something as I went on the wrong path...
Would be great to get your input on my unsolved issues:
Disabling Octoprint's ffmpegFree up port 8080Employ hardware encoding on the Pi
As the hardware encoding bit has to do something with Restreamer in my setup, I've openend up an issue there:
https://github.com/datarhei/restreamer/issues/148 - solved Hardware encoding of the usbcam stream on the Pi. Now max 10% cpu load.
Keep in mind, restreamer always reencodes the webcam to h264, so on the settings page you only need to use "copy" to get mp4.
Cheers,
Patrik
(As a new user I'm only allowed to put two links in a post, thus the links in parenthesis)