#!/bin/bash

# 海康威视 摄像头
# 默认账号: admin
# 默认密码: Wxc767718929
# 默认端口: 554
# 默认通道: 101
# 默认流媒体服务器: rtsp://admin:Wxc767718929@192.168.0.64:554/Streaming/Channels/101
# 默认推流地址: https://customer-pj89kn2ke2tcuh19.cloudflarestream.com/8c108b4025d3278b188b443e8a6c5503kb51e49994b6fd9e56b6f1fdfcd339fe6/webRTC/publish
# 默认推流密钥: ZrpMoQ15dCCe6rX0pKINzcb0eNdakSih-TmQrbq-

RTSP_URL="rtsp://admin:Wxc767718929@192.168.0.64:554/Streaming/Channels/101"
WHIP_URL="https://customer-pj89kn2ke2tcuh19.cloudflarestream.com/8c108b4025d3278b188b443e8a6c5503kb51e49994b6fd9e56b6f1fdfcd339fe6/webRTC/publish"
BEARER_TOKEN="ZrpMoQ15dCCe6rX0pKINzcb0eNdakSih-TmQrbq-"

/usr/local/ffmpeg-whip/bin/ffmpeg \
    -rtsp_transport tcp \
    -i "$RTSP_URL" \
    -map 0:v:0 -map "0:a?" \
    -c:v libx264 \
    -preset veryfast \
    -tune zerolatency \
    -profile:v baseline \
    -level 3.1 \
    -pix_fmt yuv420p \
    -g 30 -keyint_min 30 \
    -b:v 2500k -maxrate 2500k -bufsize 5000k \
    -c:a opus -strict -2 -ar 48000 -b:a 128k \
    -f whip "$WHIP_URL" \
    -headers "Authorization: Bearer $BEARER_TOKEN"
