Created
January 11, 2014 16:42
-
-
Save andrewbolster/8373242 to your computer and use it in GitHub Desktop.
Event Cam Management script
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 | |
BASE="/mnt/eventcam/" | |
COMPRESS=0 | |
RERUN=0 | |
UPLOAD=1 | |
TODAY=`date +%Y%m%d` | |
# Move all jpgs in to per date folder for processing | |
for file in `find $BASE -maxdepth 1 -name '*.jpg' -type f -print`; do | |
newfilename=`echo $file | awk -F '-' '{print $2$3}'` | |
date=`echo $newfilename | cut -c 1-8` | |
if [ ! -d ${BASE}${date} ]; then | |
mkdir -p ${BASE}${date} | |
fi | |
if [ -z "$newfilename" ] || [ "$date" -ge "$TODAY" ]; then | |
echo $file skipped: $newfilename $date $TODAY | |
continue | |
else | |
mv $file ${BASE}${date}/${newfilename} | |
fi | |
done | |
# Auto-upload existing timelapses and rename them pased on date | |
for file in `find $BASE -maxdepth 1 -name '*.mpg' -type f -not -name 'latest.mpg' -print`; do | |
newfilename=`echo $file | awk -F '-' '{print $2}'` | |
date=`basename $file | cut -c 1-8` | |
if [ ! -d ${BASE}${date} ]; then | |
mkdir -p ${BASE}${date} | |
fi | |
if [ -z "$newfilename" ] || [ "$date" -ge "$TODAY" ]; then | |
echo $file skipped: $newfilename $date $TODAY | |
continue | |
fi | |
done | |
# Auto generate high quality time lapses, compress images, and delete | |
for date in `find $BASE -mindepth 1 -maxdepth 1 -type d -exec basename '{}' \;`; do | |
if [ ! -f "${BASE}${date}.mp4" ] || [ $RERUN -eq 1 ]; then | |
rm /dev/shm/timelapselist.txt | |
if [ -f "${BASE}tarfiles/${date}.tgz" ]; then | |
echo "Found Tarfile, should really expand it: $date" | |
else | |
ls -1 ${BASE}${date} | grep .jpg > /dev/shm/timelapselist.txt | |
cd ${BASE}${date} | |
/usr/bin/mencoder -nosound -quiet -ovc lavc -lavcopts vcodec=mpeg4:vme=5:vhq:vbitrate=2000 -o ../$date.mp4 -mf type=jpeg:fps=15 mf://@/dev/shm/timelapselist.txt | |
cd - | |
echo Timelapsed ${date} | |
fi | |
fi | |
if [ ! -f "${BASE}tarfiles/${date}.tgz" ] && [ $COMPRESS -eq 1 ]; then | |
if [ ! -f "${BASE}tarfiles/${date}.tgz" ]; then | |
tar -czf ${BASE}tarfiles/${date}.tgz ${BASE}${date}/*.jpg | |
echo Compressed ${date} | |
cd - | |
else | |
rm -rf ${BASE}${date} | |
echo Cleaned ${date} | |
fi | |
echo "Something went badly wrong with $date" | |
fi | |
if [ -f "${BASE}${date}.mp4" ] && [ $UPLOAD -eq 1 ]; then | |
echo "Uploading $date.mp4" | |
# youtube uploader from https://code.google.com/p/youtube-upload/ | |
/usr/local/bin/youtube-upload --email=admin@farsetlabs.org.uk --password=XXXXXXXXX --title="$date" --category=Tech --private ${BASE}${date}.mp4 | |
if [ $? -eq 0 ]; then | |
mv ${BASE}${date}/$date.mp4 | |
else | |
echo "Something went wrong with $date upload" | |
fi | |
else | |
echo "Already Uploaded $date" | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment