A-A+
ipcam2rtmp脚本
#!/bin/bash # IPcam2rtmp # Version 1.3 # Look at http://lxy.me/ipcam2rtmp.html for more info # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; either version 2 of the License, or (at your # option) any later version. CAM1_RTSP_URL="rtsp地址" CAM1_RTMP_URL="rtmp地址" CAM2_RTSP_URL="rtsp地址" CAM2_RTMP_URL="rtmp地址" SERVICE="avconv" PIDDIR="/var/run" LOGFILE="/var/log/ipcam.log" DATETIME=`/bin/date +%Y%m%d-%H%M%S` ################################### # FUNCTION start camera (give camid as param) ################################### startcam () { if [[ $1 =~ 'cam1' ]]; then cam='cam1'; RTSP_URL=${CAM1_RTSP_URL}; RTMP_URL=${CAM1_RTMP_URL}; fi if [[ $1 =~ 'cam2' ]]; then cam='cam2'; RTSP_URL=${CAM2_RTSP_URL}; RTMP_URL=${CAM2_RTMP_URL}; fi if [ "$cam" != "" ]; then PIDFILE="$PIDDIR/$cam.pid" DATETIME=`/bin/date +%Y%m%d-%H%M%S` PID=$(cat $PIDFILE) PNAME=$(ps -p $PID -o comm=) if [ "$PNAME"x = "$SERVICE"x ]; then echo $DATETIME "Continue tream cam" $cam >> $LOGFILE touch $PIDFILE else /usr/bin/mkfifo $PIDFILE.fifo 1>/dev/null 2>/dev/null nohup avconv -rtsp_transport tcp -i ${RTSP_URL} -vcodec copy -an -f flv ${RTMP_URL} 1>/dev/null 2>&1 <$PIDFILE.fifo & echo $! > $PIDFILE # Write process ID in the pid file echo > $PIDFILE.fifo # Need this to start ffmpeg process echo $DATETIME "Start rtmp cam" $cam "PID" $(cat $PIDFILE) >> $LOGFILE fi fi } case "$1" in startcam) cam=`echo $2 | sed -ne 's/.*\(cam[0-9]\).*/\1/p'` startcam $cam ;; *) echo "Usage: $0 {startcam id}" exit 1 ;; esac exit 0
脚本不完善,需要先建立cam的pid和pid.fifo文件。