`

把ffmpeg放到后台自动运行

阅读更多

最近一个项目,需要用ffmpeg把rtsp流转成ts流。由于rtsp服务器有可能关闭,需要自动的重启ffmpeg去连接rtsp服务器

1、编写一个用ffmpeg转TS流的脚本rtsp2ts.sh

ffmpeg -i "rtsp://xx.xx.xx.xx:554/xxx?tcp" -vcodec mpeg2video -b 2048k -acodec libmp3lame -ab 128k -f mpegts udp://127.0.0.1:1234?pkt_size=1316 2> /dev/null &

URI中?tcp表明音视频数据采用tcp传输,而不是rtp/udp


2、编写一个检测ffmpeg是否挂掉的脚本check.sh

#!/bin/sh 
num=`ps -ef | grep ffmpeg | grep -v grep | wc -l`
if [ $num -lt 1 ]
then
 /root/rtsp2ts.sh
fi


3、把脚本添加crontab

crontab -e 
*/1 * * * *  /root/check.sh

每分钟检查一次

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics