Last active
January 29, 2021 04:28
-
-
Save jranson/ea3efc1c66d07d49a7c1009e926ee35b to your computer and use it in GitHub Desktop.
PiCam Time Lapse Maker w/ ffmpeg
This file contains 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 | |
# PREREQUISITES | |
# | |
# fswebcam (sudo apt-get install fswebcam) | |
# imagemagick (sudo apt-get install fswebcam) | |
# lighttpd (sudo apt-get install lighttpd) | |
# ffmpeg (wget https://johnvansickle.com/ffmpeg/builds/ffmpeg-git-armhf-static.tar.xz) | |
# | |
IMG_DIR=/home/pi/webcam/images | |
if [ ! -d $IMG_DIR ]; then | |
mkdir -p $IMG_DIR | |
fi | |
etime=$(date +%s) | |
RAW_FILE="$IMG_DIR/${etime}_raw.jpg" | |
TXT_FILE="$IMG_DIR/${etime}_text.jpg" | |
GIF_FILE="$IMG_DIR/lapse_out.gif" | |
PUB_FILE="$IMG_DIR/lapse.gif" | |
NEW_FILE="$IMG_DIR/latest.jpg" | |
rm $TXT_FILE >/dev/null 2>&1 | |
echo -n "Capturing ..." | |
while [ ! -f $TXT_FILE ] | |
do | |
fswebcam -r 2560x1960 --no-banner $RAW_FILE >/dev/null 2>&1 | |
if [[ -f $RAW_FILE ]]; then | |
echo | |
echo "Rotating" | |
mogrify -rotate 270 $RAW_FILE >/dev/null 2>&1 | |
echo "Overlaying Text" | |
dtime=$(date +"%H:%M:%S") | |
convert -pointsize 40 -fill black -draw "text 30 50 '$dtime' " $RAW_FILE $TXT_FILE >/dev/null 2>&1 | |
if [[ ! -f $TXT_FILE ]]; then | |
echo -n "." | |
sleep 1 | |
else | |
echo "Publishing Latest Image" | |
cp $TXT_FILE $NEW_FILE.tmp | |
mv $NEW_FILE.tmp $NEW_FILE | |
echo "Deleted outdated images" | |
find $IMG_DIR -mmin +1440 -type f -name "*.jpg" -exec rm -f {} \; | |
rm $RAW_FILE >/dev/null 2>&1 | |
echo "Generating Animation" | |
ffmpeg -framerate 60 -pattern_type glob -i "$IMG_DIR/*_text.jpg" -vf scale=512:-1 $GIF_FILE | |
mv $GIF_FILE $PUB_FILE | |
fi | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment