#!/bin/sh
FFMPEG_PATH="/usr/bin/ffmpeg"
RTSP_URL="rtsp://$2/h265/ch1/main/av_stream"

echo "Starting 10-second recording: $1"

#"$FFMPEG_PATH" \
#    -rtsp_transport tcp \
#    -t 10 \
#    -i "$RTSP_URL" \
#    -vf "scale=480:480,drawtext=fontfile=/usr/share/fonts/dejavu/DejaVuSans-Bold.ttf:text='%{localtime\:%Y-%m-%d %H\\\\\:%M\\\\\:%S}':x=10:y=10:fontsize=24:fontcolor=white:box=1:boxcolor=0x00000099" \
#    -vcodec libx264 \
#    -preset slower \
#    -crf 28 \
#    -b:v 1000k \
#    -g 50 \
#    -bf 2 \
#    -an \
#    -vsync 0 \
#    -loglevel error \
#    "$1"

"$FFMPEG_PATH" \
    -t 10 \
    -rtsp_transport tcp \
    -i "$RTSP_URL" \
    -vf "scale=480:480,drawtext=fontfile=/usr/share/fonts/truetype/msttcorefonts/segoeui.ttf:text='%{localtime}':x=10:y=10:fontsize=24:fontcolor=white:borderw=2:bordercolor=black" \
    -vcodec libx264 \
    -preset slower \
    -crf 28 \
    -b:v 1000k \
    -g 50 \
    -bf 2 \
    -an \
    -vsync vfr \
    -loglevel error \
    "$1"

echo "Recording finished: $1"