Accepting suggestions, just create a new issue. 🤝
Simple guide for setting up webcam streaming from your PiKVM system. Tested on PiKVM V4 Plus. Useful for setting up BIOS settings on laptops, or completely reinstalling the OS. Keyboard input function of kvmd works even if the HDMI input is not connected.
pikvm-update
- update the system, probably reboot requiredrw
- enable writing to filesystempacman -S ffmpeg
- install ffmpeg
Copy download link for latest release of mediamtx (linux_armv7), you can find the download link here: https://github.com/bluenviron/mediamtx/releases
wget <download link>
tar -xvf <downloaded archive>
mv mediamtx /usr/local/bin/
mv mediamtx.yml /usr/local/etc/
nano /etc/systemd/system/mediamtx.service
[Unit]
Wants=network.target
[Service]
ExecStart=/usr/local/bin/mediamtx /usr/local/etc/mediamtx.yml
[Install]
WantedBy=multi-user.target
nano /usr/local/etc/mediamtx.yml
At the end of file modify the "paths" section as:
paths:
cam:
runOnDemand: ffmpeg -f v4l2 -input_format mjpeg -s 1920x1080 -r 10 -i /dev/webcam -c:v h264_v4l2m2m -pix_fmt yuv420p -b:v 6M -f rtsp rtsp://localhost:$RTSP_PORT/$MTX_PATH
runOnDemandRestart: yes
cam-lq:
runOnDemand: ffmpeg -f v4l2 -input_format mjpeg -s 1280x720 -r 5 -i /dev/webcam -c:v h264_v4l2m2m -pix_fmt yuv420p -b:v 2M -f rtsp rtsp://localhost:$RTSP_PORT/$MTX_PATH
runOnDemandRestart: yes
cam-hq:
runOnDemand: ffmpeg -f v4l2 -input_format mjpeg -s 1920x1080 -r 20 -i /dev/webcam -c:v h264_v4l2m2m -pix_fmt yuv420p -b:v 20M -f rtsp rtsp://localhost:$RTSP_PORT/$MTX_PATH
runOnDemandRestart: yes
all_others:
This is to mount the webcam consistently to a single /dev mapping point. You can find name and index attributes for your exact webcam using udevadm info -a -p $(udevadm info -q path -n /dev/videoX)
, where /dev/videoX
is current mapping of your webcam.
nano /etc/udev/rules.d/99-webcam.rules
SUBSYSTEM=="video4linux", ATTR{index}=="0", ATTR{name}=="Logitech Webcam C925e", SYMLINK+="webcam"
sudo systemctl daemon-reload
sudo systemctl enable mediamtx
reboot
Stream quality switch takes ~20 seconds. Multiple streams are possible only in single quality. If webcam USB is disconncted/reconnected just refreshing the stream page should get it running again.
You can access the stream through a web browser supporting WebRTC, access to UDP is required.
<IP>:8889/cam/
= normal quality (1920x1080, 10fps, 6Mbit max, ~3Mbit avg)<IP>:8889/cam-lq/
= low quality (1280x720, 5fps, 2Mbit max, ~500kbit avg)<IP>:8889/cam-hq/
= high quality (1920x1080, 20fps, 20Mbit max ~10Mbit avg)
For TCP only environments you can use RTSP stream through VLC:
rtsp://<IP>:8554/cam/
= normal quality (1920x1080, 10fps, 6Mbit max, ~3Mbit avg)rtsp://<IP>:8554/cam-lq/
= low quality (1280x720, 5fps, 2Mbit max, ~500kbit avg)rtsp://<IP>:8554/cam-hq/
= high quality (1920x1080, 20fps, 20Mbit max ~10Mbit avg)
Be sure to set up network caching parameter when connecting to the stream according to the latency and stability of your network for lower latency stream.