Uitgangspunt: PI4, Bookworm, ffmpeg en nginx geïnstalleeerd
Diagnostic Steps
Check the service logs first for ffmpeg errors—these will reveal if the RTMP input fails or output writing issues occur.
sudo journalctl -u hls-stream.service -f
sudo systemctl restart hls-stream.service
Look for messages like connection refused to rtmp://127.0.0.1:1935/gopro/live, permission denied on /var/www/html/hls/gopro, or "No more output streams."
Test ffmpeg manually as the pi4 user to isolate systemd problems.
sudo -u pi4 /usr/bin/ffmpeg -loglevel info -fflags +genpts+discardcorrupt -probesize 500000 -analyzeduration 1000000 -i rtmp://127.0.0.1:1935/gopro/live -map 0:v:0 -c:v copy -an -f hls -hls_time 2 -hls_list_size 30 -hls_flags delete_segments+independent_segments+program_date_time+temp_file -hls_segment_type mpegts -hls_segment_filename segment_%05d.ts stream.m3u8
Run this from /var/www/html/hls/gopro; press Ctrl+C after 30 seconds and check for files. Add -re before -i if it races ahead on live input.
Likely Fixes
- Permissions: The ExecStartPre sets ownership correctly, but confirmÂ
ls -la /var/www/html/hls/gopro shows pi4:www-data. If not, runÂsudo chown -R pi4:www-data /var/www/html/hls/gopro.​ - RTMP Availability: Ensure your NGINX RTMP server publishes /gopro/live continuously; ffplay succeeding manually confirms the stream exists.​
- FFmpeg Flags: Your command looks solid for local disk output (
segment_%%05d.ts uses relative path, writing to WorkingDirectory). If manual test fails, tryÂ-hls_segment_filename ./segment_%05d.ts explicitly. RemoveÂ-an only if video stream lacks audio initially.​ - Systemd Tweaks: AddÂ
ProtectHome=no andÂNoNewPrivileges=no under [Service] if SELinux/AppArmor interferes, thenÂsudo systemctl daemon-reload.​
Once segments appear locally, your rsync service should sync them. If logs show input errors, verify the GoPro RTMP publisher runs reliably.
Er is vaak een insteltijd na reboot voordat de RTMP-stream volledig beschikbaar en publiceerbaar is.
Typische Opstartvolgorde
Na reboot start systemd-services in deze volgorde, maar met vertragingen:
- Network-online.target: 10-30 seconden wachttijd tot netwerk echt klaar is (DNS, DHCP)​
- NGINX RTMP server: Moet volledig opgestart zijn metÂ
listen 1935Â voordat ffmpeg kan verbinden - hls-stream.service: Start na network-online, maar RTMP-inputÂ
rtmp://127.0.0.1:1935/gopro/live faalt als NGINX nog niet luistert
Probleem in Jouw Setup
Je services hebben After=network-online.target, maar missen afhankelijkheid van de NGINX RTMP-service:
Fix voor /etc/systemd/system/hls-stream.service:
text[Unit]
Description=GoPro RTMP to HLS
After=network-online.target nginx.service
Requires=nginx.service # Wacht tot NGINX volledig draait
Wants=network-online.target
Controleer NGINX RTMP service naam:
bashsystemctl list-units | grep nginx
# Waarschijnlijk nginx.service of nginx-rtmp.service
Test Opstarttijd
bashsudo reboot
sudo journalctl -u nginx.service -u hls-stream.service -f
Kijk wanneer NGINX “listening on 1935” logt vs wanneer hls-stream start.
Extra Vertragingen (RPi-specifiek
- GoPro publisher: Als dit een aparte service is, moet die ook na NGINX starten
- ffmpeg probesize/analyzeduration: Je hebt 1MB/1s analyse-tijd in command; live streams kunnen langer nodig hebben om keyframe te vinden
Quick fix: Voeg Requires=nginx.service toe, sudo systemctl daemon-reload, sudo systemctl restart hls-stream.service. De map vult binnen 10 seconden na NGINX-ready.