#!/bin/bash

# ANPVIZ 摄像头推流到 Cloudflare Stream (WHIP 协议)
# 摄像头 IP: 192.168.0.96
# 账号: admin / 123456
# 编码: H.265 (需要转码为 H.264)
# RTSP 路径: /Streaming/Channels/101

RTSP_URL="rtsp://admin:123456@192.168.0.96:554/Streaming/Channels/101"
# 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 3.1 -pix_fmt yuv420p \
    -preset veryfast -tune zerolatency \
    -vf "scale=1280:720" \
    -r 25 \
    -g 25 -keyint_min 25 \
    -b:v 2000k -maxrate 2000k -bufsize 4000k \
    -an \
    -f whip \
    "$WHIP_URL"
