Skip to content

Instantly share code, notes, and snippets.

@Pesticles
Created May 16, 2014 00:13
Show Gist options
  • Save Pesticles/43a9ddf6b46a55c22300 to your computer and use it in GitHub Desktop.
Save Pesticles/43a9ddf6b46a55c22300 to your computer and use it in GitHub Desktop.
#!/bin/bash
# The date is assumed to be today, but you can provide an override on the command line.
if [[ ! -z $1 ]]; then
DATE="$1"
DATE2=$( date -d $DATE +'%A %d %B %Y' )
else
DATE=$( date +'%Y%m%d')
DATE2=$( date +'%A %d %B %Y' )
fi
function get_data {
psql -q -t -A -c "\
SELECT ROUND(data) \
FROM point_float \
WHERE source = $1 \
AND taken > (to_timestamp('$2', 'YYYYMMDDHH24MI') - interval '5 minutes') \
AND taken < (to_timestamp('$2', 'YYYYMMDDHH24MI') + interval '5 minutes') \
ORDER BY ABS(EXTRACT(EPOCH FROM taken - to_timestamp('$2', 'YYYYMMDDHH24MI'))) \
LIMIT 1;" env_data datalogger
}
cd /DATA/Timelapse/
# Process images
echo -n > working/files.txt
ls -1tr ${DATE}*.jpg | while read FNAME; do
# Add annotations
DATE3=${FNAME::12}
TEMP=$( get_data 6 $DATE3 )
HUMI=$( get_data 7 $DATE3 )
BARO=$( get_data 46 $DATE3 )
nice ./script/process_image.py $FNAME $TEMP $HUMI $BARO
# Archive hourly images
MIN="${FNAME:10:3}"
if [[ "$MIN" == "000" ]]; then
cp "working/$FNAME" archive/
fi
echo "working/$FNAME" >> working/files.txt
done
# Create raw AVI
nice mencoder -idx -nosound -noskip -ovc lavc -lavcopts vcodec=mjpeg -o working/${DATE}.avi -mf fps=24 'mf://@working/files.txt' >/dev/null || exit 1
# Create compressed MKV
nice avconv -loglevel quiet -i working/${DATE}.avi -c:v libx264 -preset slow -crf 24 complete/${DATE}.mkv || exit 2
# Clear out working files
rm working/${DATE}.avi
rm working/*.jpg
# Clear out old images
find . -maxdepth 1 -name '*.jpg' -mtime +1 -exec rm -f {} \;
# Upload to youtube
cd script/
./upload_video.py --file="/DATA/Timelapse/complete/${DATE}.mkv" --title="Papakura Weather ${DATE2}" --description="Captured with a Raspberry Pi and PiCamera. 3 frames per minute, looking north from Papakura Central" --category="22"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment