Skip to content

Instantly share code, notes, and snippets.

@foghina
Last active October 12, 2015 22:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save foghina/4100939 to your computer and use it in GitHub Desktop.
Save foghina/4100939 to your computer and use it in GitHub Desktop.
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