diff --git a/squashkiwi-streaming/config/docker-compose.yml b/squashkiwi-streaming/config/docker-compose.yml index 41a2af2..4f70179 100644 --- a/squashkiwi-streaming/config/docker-compose.yml +++ b/squashkiwi-streaming/config/docker-compose.yml @@ -18,18 +18,45 @@ services: MTX_PATHS_COURT_MAIN_RECORDFORMAT: fmp4 MTX_PATHS_COURT_MAIN_RECORDSEGMENTDURATION: 1h MTX_PATHS_COURT_MAIN_RECORDDELETEAFTER: 24h - # Sub stream configuration + # Sub stream configuration (usually H264) MTX_PATHS_COURT_SUB_SOURCE: ${MTX_PATHS_COURT_SUB_SOURCE} MTX_PATHS_COURT_SUB_SOURCEPROTOCOL: tcp - # Legacy court path - use substream for better compatibility - MTX_PATHS_COURT_SOURCE: ${MTX_PATHS_COURT_SUB_SOURCE} + # Legacy court path - original H265 stream + MTX_PATHS_COURT_SOURCE: ${MTX_PATHS_COURT_SOURCE} MTX_PATHS_COURT_SOURCEPROTOCOL: tcp + # Force all paths to start immediately + MTX_PATHDEFAULTS_SOURCEONDEMAND: "no" + # Disable all authentication + MTX_PATHDEFAULTS_PUBLISHUSER: "" + MTX_PATHDEFAULTS_PUBLISHPASS: "" + MTX_PATHDEFAULTS_READUSER: "" + MTX_PATHDEFAULTS_READPASS: "" healthcheck: test: ["CMD", "wget", "-q", "-O", "-", "http://localhost:9997/v2/paths/list"] interval: 30s timeout: 10s retries: 3 + # FFmpeg transcoder for H265 to H264 + transcoder: + image: linuxserver/ffmpeg:latest + container_name: ${PROJECT_NAME}-transcoder + restart: unless-stopped + network_mode: host + command: > + -re + -rtsp_transport tcp + -i rtsp://localhost:8554/court + -c:v libx264 + -preset ultrafast + -tune zerolatency + -b:v 2M + -f rtsp + -rtsp_transport tcp + rtsp://localhost:8554/court_h264 + depends_on: + - mediamtx + # Score overlay and recording service overlay-service: build: ./overlay @@ -58,8 +85,7 @@ services: image: nginx:alpine container_name: ${PROJECT_NAME}-nginx restart: unless-stopped - ports: - - "${HOST_PORT}:80" + network_mode: host volumes: - ./nginx.conf:/etc/nginx/nginx.conf:ro - ./web:/usr/share/nginx/html:ro diff --git a/squashkiwi-streaming/config/mediamtx.yml b/squashkiwi-streaming/config/mediamtx.yml index 70f624f..43b0199 100644 --- a/squashkiwi-streaming/config/mediamtx.yml +++ b/squashkiwi-streaming/config/mediamtx.yml @@ -4,9 +4,13 @@ logLevel: info logDestinations: [stdout] +# Authentication - disable for public access +authMethod: none + # API Configuration api: yes apiAddress: :9997 +apiAllowOrigin: '*' # Metrics metrics: yes @@ -31,6 +35,7 @@ webrtcAddress: :8889 webrtcAllowOrigin: '*' # Path Configuration -# Paths are configured entirely via environment variables in docker-compose.yml -# This allows dynamic configuration without modifying this file -paths: {} \ No newline at end of file +paths: + # Transcoded H264 stream + court_h264: + # This path will receive the transcoded stream from ffmpeg \ No newline at end of file diff --git a/squashkiwi-streaming/config/nginx.conf b/squashkiwi-streaming/config/nginx.conf index 6bf8dbd..8603159 100644 --- a/squashkiwi-streaming/config/nginx.conf +++ b/squashkiwi-streaming/config/nginx.conf @@ -16,7 +16,7 @@ http { proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=hls_cache:10m max_size=1g inactive=60m use_temp_path=off; server { - listen 80; + listen 8880; server_name _; root /usr/share/nginx/html; @@ -37,7 +37,7 @@ http { # HLS streams proxy location /hls/ { - proxy_pass http://localhost:8888/; + proxy_pass http://[::1]:8888/; proxy_http_version 1.1; # CORS headers @@ -54,22 +54,36 @@ http { proxy_request_buffering off; } - # WebRTC signaling + # WebRTC signaling (WHEP) location /webrtc/ { - proxy_pass http://localhost:8889/; + proxy_pass http://[::1]:8889/; proxy_http_version 1.1; - proxy_set_header Upgrade $http_upgrade; - proxy_set_header Connection "upgrade"; + + # CORS headers for WebRTC + add_header Access-Control-Allow-Origin * always; + add_header Access-Control-Allow-Methods "GET, POST, OPTIONS, PATCH, DELETE" always; + add_header Access-Control-Allow-Headers "Authorization, Content-Type, If-Match" always; + add_header Access-Control-Expose-Headers "Link" always; + + # Handle OPTIONS preflight + if ($request_method = OPTIONS) { + return 204; + } + proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + proxy_buffering off; + proxy_request_buffering off; proxy_read_timeout 86400; proxy_send_timeout 86400; } # MediaMTX API location /api/mediamtx/ { - proxy_pass http://localhost:9997/; + proxy_pass http://[::1]:9997/; allow 127.0.0.1; allow 172.16.0.0/12; deny all; diff --git a/squashkiwi-streaming/config/web/index.html b/squashkiwi-streaming/config/web/index.html index f768041..7c90a9c 100644 --- a/squashkiwi-streaming/config/web/index.html +++ b/squashkiwi-streaming/config/web/index.html @@ -170,7 +170,7 @@ + + + \ No newline at end of file diff --git a/squashkiwi-streaming/config/web/webrtc.html b/squashkiwi-streaming/config/web/webrtc.html new file mode 100644 index 0000000..3e93efe --- /dev/null +++ b/squashkiwi-streaming/config/web/webrtc.html @@ -0,0 +1,254 @@ + + + + + + SquashKiwi Court Stream - WebRTC + + + +
+
+

🎾 SquashKiwi Court Stream (WebRTC)

+
+ +
+
+ +
+
+
+ Connecting... +
+
+ + +
+
+
+ + + +
+

WebRTC Stream

+

This player uses WebRTC for lower latency streaming. It should work with H265/HEVC streams.

+
+
+ + + + \ No newline at end of file diff --git a/squashkiwi-streaming/install.sh b/squashkiwi-streaming/install.sh index a553e48..e6e964c 100755 --- a/squashkiwi-streaming/install.sh +++ b/squashkiwi-streaming/install.sh @@ -30,7 +30,7 @@ cat > "${LOCAL_DATA_FOLDER}/config/.env" <&1 | head -20 + +echo "" +echo "Note: The substream (subtype=1) on Dahua cameras is typically H264" +echo "while the main stream (subtype=0) is H265" \ No newline at end of file