#!/bin/bash # Test camera RTSP connection # shellcheck disable=SC1091 source "${AGENT_PATH}/common.sh" _check_required_env_vars "CAMERA_IP" "CAMERA_USER" "CAMERA_PASSWORD" "CAMERA_RTSP_PORT" "LOCAL_DATA_FOLDER" echo "Testing camera connection..." echo "Camera IP: ${CAMERA_IP}" echo "Camera User: ${CAMERA_USER}" echo "RTSP Port: ${CAMERA_RTSP_PORT}" # URL-encode the password if it contains special characters ENCODED_PASSWORD=$(echo -n "${CAMERA_PASSWORD}" | sed 's/!/%21/g; s/@/%40/g; s/#/%23/g; s/\$/%24/g; s/&/%26/g') RTSP_URL="rtsp://${CAMERA_USER}:${ENCODED_PASSWORD}@${CAMERA_IP}:${CAMERA_RTSP_PORT}/cam/realmonitor?channel=1&subtype=0" echo "" echo "Testing RTSP URL (password hidden): rtsp://${CAMERA_USER}:****@${CAMERA_IP}:${CAMERA_RTSP_PORT}/cam/realmonitor?channel=1&subtype=0" # Test with ffprobe echo "" echo "Testing with ffprobe..." docker run --rm --network host \ linuxserver/ffmpeg:latest \ ffprobe -v error -show_streams -select_streams v:0 \ "${RTSP_URL}" 2>&1 | head -20 if [ $? -eq 0 ]; then echo "✓ Camera connection successful!" else echo "✗ Camera connection failed" echo "" echo "Trying alternative RTSP paths..." # Try without subtype parameter ALT_URL="rtsp://${CAMERA_USER}:${ENCODED_PASSWORD}@${CAMERA_IP}:${CAMERA_RTSP_PORT}/cam/realmonitor?channel=1" docker run --rm --network host linuxserver/ffmpeg:latest \ ffprobe -v error "${ALT_URL}" 2>&1 | head -5 # Try simple path SIMPLE_URL="rtsp://${CAMERA_USER}:${ENCODED_PASSWORD}@${CAMERA_IP}:${CAMERA_RTSP_PORT}/" docker run --rm --network host linuxserver/ffmpeg:latest \ ffprobe -v error "${SIMPLE_URL}" 2>&1 | head -5 fi echo "" echo "Checking MediaMTX container logs..." docker logs "${PROJECT_NAME}-mediamtx" --tail 20 2>&1 | grep -E "(ERR|WARN|connected|disconnected|error)"