Last active
April 25, 2018 04:18
-
-
Save aclud/8155494 to your computer and use it in GitHub Desktop.
Script to take videos FTP'ed from my D-Link DCS-5010L, compile the 15 second clips into one video, upload it to YouTube and email the URL to me.Requires: mencoder mailx youtube-upload (https://code.google.com/p/youtube-upload/)Run via cron
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 | |
#setup variables | |
x="/share/cam" #base dir to search | |
age="1" #minimum age in minutes of file to include in processing | |
date=$(date +"%Y%m%d%H%M") #date used throughout script | |
fileprefix="YT-5010L-" #output file name prefix | |
ytemail="youremail" #your youtube email account | |
ytpassword="password" #your youtube password | |
emailfrom="youremail(Your Name)" #your email address and from name | |
emailuser="youremail" #your gmail address | |
emailpassword="password" #your gmail password | |
emailto="youremail" #email to send message to | |
emailsubject="Security Camera Video Recorded" #email subject | |
#make list of files to work with that are at least x minutes old | |
for i in $(find $x/ -amin +"$age"|grep DCS|grep avi|sort) ; do echo $i >> $x/$date.lst ; done | |
#proceed if there are any videos | |
if [ -a $x/$date.lst ] | |
then | |
#create one video from all files | |
mencoder -oac copy -ovc copy $(cat $x/$date.lst) -o $x/$fileprefix$date.avi | |
#determine how long the new video is, thank you http://www.linuxquestions.org/questions/linux-software-2/getting-movie-length-from-shell-195938/ | |
LEN=$(mplayer -vo null -ao null -frames 0 -identify $x/$fileprefix$date.avi 2>/dev/null | grep "^ID_LENGTH" | sed -e 's/ID_LENGTH=//g') | |
HR=$(echo "$LEN/3600"|bc) | |
MIN=$(echo "($LEN-$HR*3600)/60"|bc) | |
SEC=$(echo "$LEN%60"|bc) | |
LENGTH=$(printf "%02.0f:%02.0f:%02.0f" $HR $MIN $SEC) | |
#upload video | |
if [ -a $x/$fileprefix$date.avi ] | |
then | |
result=$(/usr/local/bin/youtube-upload --email=$ytemail --password=$ytpassword --private --api-upload --title="$fileprefix$date" --description="$LENGTH" --category="People" --unlisted $x/$fileprefix$date.avi) | |
fi | |
#check to make sure that the upload returned a video URL | |
if [[ $result == *http* ]] | |
then | |
#send email with video URL | |
echo -e "File: $fileprefix$date\nTime: $LENGTH\nURL: $result\nFiles contained:\n$(cat $x/$date.lst)"|mailx -v -s "$emailsubject" -S smtp-use-starttls -S ssl-verify=ignore -S smtp-auth=login -S smtp=smtp://smtp.gmail.com:587 -S from="$emailfrom" -S smtp-auth-user="$emailuser" -S smtp-auth-password="$emailpassword" -S ssl-verify=ignore -S nss-config-dir=~/.mozilla/firefox/yyyyyyyy.default/ "$emailto" | |
#rename video to prevent processing it again | |
for i in $(cat $x/$date.lst); do mv "$i" "${i/DCS/YOUTUBE}"; done | |
fi | |
#delete helper files | |
if [ -a $x/$date.tmp ] | |
then | |
rm -f $x/$date.tmp | |
fi | |
if [ -a $x/$date.lst ] | |
then | |
rm -f $x/$date.lst | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment