xcms_beixiaocai/003推流指定文件夹下所有mp4文件.sh

35 lines
975 B
Bash
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env bash
VIDEO_DIR="/home/admin-root/haotian/康达瑞贝斯机器狗/data_video" # 你的 .mp4 文件目录
RTSP_SERVER="rtsp://10.0.0.17:8554/camera_test"
# 捕获 SIGINTCtrl+C和 SIGTERM触发 exit进而触发 EXIT trap
trap "exit" INT TERM
# EXIT 触发时,终止当前进程组(包括所有子进程)
trap "kill 0" EXIT
for filepath in "$VIDEO_DIR"/*.mp4; do
[ -e "$filepath" ] || continue
filename=$(basename "$filepath" .mp4)
RTSP_URL="${RTSP_SERVER}/${filename}"
(
while true; do
echo "$(date): 推流 -> $RTSP_URL"
ffmpeg -re -stream_loop -1 -i "$filepath" \
-vf "scale=1920:1080" \
-c:v libx264 -preset veryfast -tune zerolatency \
-c:a aac -b:a 128k \
-muxdelay 0 -muxpreload 0 \
-f rtsp -rtsp_transport tcp \
"$RTSP_URL"
echo "$(date): 推流中断5 秒后重启 -> $RTSP_URL"
sleep 5
done
) &
done
# 等待所有后台任务
wait