Skip to content

Instantly share code, notes, and snippets.

@gerasiov
Created April 3, 2015 18:58
Show Gist options
  • Save gerasiov/81af0841c16c1d0eed71 to your computer and use it in GitHub Desktop.
Save gerasiov/81af0841c16c1d0eed71 to your computer and use it in GitHub Desktop.
The smallest video monitoring daemon ever
#!/bin/sh
DEVICE=/dev/video0
RESOLUTION="width=1024:height=768"
FRAMES_SKIP=3
ROTATE=1
REMOTE_HOST=lvk.cs.msu.su
REMOTE_DIR=public_html/webcam
INTERVAL=300
WORK_DIR=$(mktemp -d)
trap "rm -rf $WORK_DIR;exit" INT QUIT
cd $WORK_DIR
while true; do
mplayer -cache 128 -tv driver=v4l2:$RESOLUTION:device="$DEVICE" -vo jpeg:quality=100 -frames $FRAMES_SKIP tv://
test $ROTATE -ne 1 && cp 0000000${FRAMES_SKIP}.jpg result.jpg || jpegtran -rotate 180 -perfect 0000000${FRAMES_SKIP}.jpg > result.jpg
date=$(date +%F-%T)
scp result.jpg $REMOTE_HOST:"$REMOTE_DIR"/$date.jpg
ssh $REMOTE_HOST "ln -sf $date.jpg $REMOTE_DIR/0.jpg"
sleep $INTERVAL
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment