Create a gist now

Instantly share code, notes, and snippets.

@foghina /bashsurv.sh
Last active Oct 12, 2015

What would you like to do?
Video Surveillance in Bash
#!/bin/bash
OUTPUT_DIR="/var/www/bashsurv"
FFMPEG_INPUT_FLAGS="-rtsp_transport tcp"
FFMPEG_SOURCE="rtsp://192.168.1.123/video.mp4"
FFMPEG_OUTPUT_FLAGS="-r 20 -acodec libspeex"
FFMPEG_OUTPUT_EXT="ogv"
CLIP_LENGTH=600 # seconds
TIMELIMIT=620 # seconds, allows for network timeout over CLIP_LENGTH
KEEP_FILES_FOR=10080 # minutes
while [ true ]; do
avconv -timelimit $TIMELIMIT $FFMPEG_INPUT_FLAGS -i $FFMPEG_SOURCE -t $CLIP_LENGTH $FFMPEG_OUTPUT_FLAGS $OUTPUT_DIR/$(date +%F.%T).$FFMPEG_OUTPUT_EXT
if [ $? -ne 0 ] ;
then
sleep 1m ;
fi
find $OUTPUT_DIR/ -type f -mmin +$KEEP_FILES_FOR -delete
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment