#!/bin/bash

# SVBC 摄像头 (SD10POE-5MP) 推流到 Cloudflare Stream (WHIP 协议)
# 摄像头 IP: 192.168.0.246
# 账号: admin / admin
# 编码: H.265 (2560x1920，需要转码为 H.264)
# RTSP 路径: /1

RTSP_URL="rtsp://admin:admin@192.168.0.246:554/1"
# WHIP URL 已包含认证密钥，无需额外 Bearer Token
WHIP_URL="https://customer-pj89kn2ke2tcuh19.cloudflarestream.com/8c108b4025d3278b188b443e8a6c5503kb51e49994b6fd9e56b6f1fdfcd339fe6/webRTC/publish"

# 注意: ffmpeg WHIP muxer 目前不支持同时发送音视频 (SDP mid 冲突)
# 暂时只发送视频流
/usr/local/ffmpeg-whip/bin/ffmpeg \
    -rtsp_transport tcp \
    -i "$RTSP_URL" \
    -map 0:v:0 \
    -c:v libx264 \
    -profile:v baseline -level 4.1 -pix_fmt yuv420p \
    -preset veryfast -tune zerolatency \
    -vf "scale=1280:960" \
    -g 50 -keyint_min 50 -sc_threshold 0 \
    -b:v 2500k -maxrate 2500k -bufsize 5000k \
    -an \
    -f whip \
    "$WHIP_URL"
