Last active
October 12, 2015 22:58
-
-
Save foghina/4100939 to your computer and use it in GitHub Desktop.
Video Surveillance in Bash
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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