Server:Server Status

Building a Security Cam/Time-Lapse Video/Auto Webcam System on Linux

I left for the weekend, and left my dog at home (he has a doggy door and an auto food/water thing, he's ok). I leave a webcam on so I can check on him; the way I have it set up is that I want a picture copied to my public dropbox folder then embedded in an html page, so I can check on him from anywhere. Also, my family/friends like to look in on him.

To make this work, the dependencies are dropbox, fswebcam, and cheese. fswebcam does the actual picture capturing, cheese is used to auto-calibrate the camera (you can set settings with fswebcam, but it's a pain...I find if you open cheese for 10 seconds then kill it every 30 minutes, its auto-adjust sticks and works great). Here's my script, called autocam.sh:

#!/bin/bash
case "$1" in

recal)
  cheese &
  sleep 10s
  killall cheese
  exit 1
;;

*)
  now=$(/bin/date '+%Y%m%d%H%M')
  mv /Path/To/Dropbox/Public/RygelWatch.jpg /Path/To/Pictures/RygelWatch/RygelWatch.${now}.jpg
  /usr/bin/fswebcam -d v4l2:/dev/video0 -i 0 -r "640x480" --deinterlace --no-banner "/Path/To/Dropbox/Public/RygelWatch.jpg"
  exit 1
esac

This is then called using the following cronjobs:

*/2 * * * * sh /Path/To/Scripts/autocam.sh
1,31 * * * * sh /Path/To/Scripts/autocam.sh recal

Boom, works great!

So, then to turn it into a timelapse, I cd into the ~/Pictures/RygelWatch folder and run:

ls -1tr | grep -v files.txt > files.txt

I then build the video using mencoder with the following command:

mencoder -nosound -noskip -oac copy -ovc copy -o 2013.08.25.RygelWatch.avi -mf fps=15 'mf://@files.txt'

This works great! Finally, I opened that up in openshot, polished it a bit, and submitted it to youtube:

The autocam function is something I've been meaning to expand on. I actually have raspberry pi's in several of the rooms in my house; I'd like to set up about 8 of them and use it as a security cam from a web interface I'd access on an internal web server (over vpn); it'd be very expandable very quickly. By symlinking from shares and cutting out the whole "upload to public dropbox" step, it won't use a ton of bandwidth and if I drop to grayscale I think it could be an adequate security cam system or something. The only obvious limit is that the auto-opening of cheese selects /dev/video0 for the auto-configuration, but I'm sure I can figure that out once it's actually an issue. For now, it's just webcams while we leave the dog home.

Hope you enjoy!

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

My D&D Character Results

I Am A: Chaotic Neutral Human Sorcerer (5th Level)

Ability Scores:
Strength-15
Dexterity-13
Constitution-12
Intelligence-18
Wisdom-15
Charisma-15

Alignment:
Chaotic Neutral A chaotic neutral character follows his whims. He is an individualist first and last. He values his own liberty but doesn't strive to protect others' freedom. He avoids authority, resents restrictions, and challenges traditions. A chaotic neutral character does not intentionally disrupt organizations as part of a campaign of anarchy. To do so, he would have to be motivated either by good (and a desire to liberate others) or evil (and a desire to make those different from himself suffer). A chaotic neutral character may be unpredictable, but his behavior is not totally random. He is not as likely to jump off a bridge as to cross it. Chaotic neutral is the best alignment you can be because it represents true freedom from both society's restrictions and a do-gooder's zeal. However, chaotic neutral can be a dangerous alignment when it seeks to eliminate all authority, harmony, and order in society.

Race:
Humans are the most adaptable of the common races. Short generations and a penchant for migration and conquest have made them physically diverse as well. Humans are often unorthodox in their dress, sporting unusual hairstyles, fanciful clothes, tattoos, and the like.

Class:
Sorcerers are arcane spellcasters who manipulate magic energy with imagination and talent rather than studious discipline. They have no books, no mentors, no theories just raw power that they direct at will. Sorcerers know fewer spells than wizards do and acquire them more slowly, but they can cast individual spells more often and have no need to prepare their incantations ahead of time. Also unlike wizards, sorcerers cannot specialize in a school of magic. Since sorcerers gain their powers without undergoing the years of rigorous study that wizards go through, they have more time to learn fighting skills and are proficient with simple weapons. Charisma is very important for sorcerers; the higher their value in this ability, the higher the spell level they can cast.

Find out What Kind of Dungeons and Dragons Character Would You Be?, courtesy of Easydamus (e-mail)

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Bash Script to Clip Ripped Home Movies

Bash script I wrote to assist in clipping home movies. Still some more to do, but here's a summary.

Particularly useful was the code I used to find the difference under bash between start and end points using date...and keeping the result in a format ffmpeg could understand.

#!/bin/bash

# Title: HomeMoviesClipper.sh
# Description: Use ffmpeg to split raw home movie captures into clips
# Original Author: Joseph Gullo (surfrock66) (surfrock66@surfrock66.com)
#
# This script works with a very specific set of constraints and formats to 
#  take raw video captures and split them into clips of events.  Each of 
#  these movies was captured, using a Dazzle USB video capture device, 
#  into h264 video and mp3 audio, using VLC.  These original tapes were 
#  typically close to 2 hours long, however capture was often left to run, 
#  creating videos that were 8+ hours long.  The capture device produced 
#  video that was 480x480 and audio that only contains 1 channel (recorded 
#  through stereo), and the output video will retain this.  The desired 
#  format is high-bitrate h264 and aac audio, encapsulated in .mp4 files. 
#  This script also works within a predictable directory environment 
#  because of how specific the task is, and because I'm a lazy bastard 
#  that doesn't want to code bunch of directory logic.  The script first 
#  queries the input file, then works on this file recursing the steps 
#  for each clip.  Each clip requires an output name, a start timecode 
#  (formatted hh:mm:ss.nnn) and an ending timecode.  This is part of 
#  some of the headache, as ffmpeg processes clips with a start time 
#  and a duration, meaning you have to do the difference math yourself.  
#  I take care of this in there.  After producing a clip, the script 
#  will ask the user if they want to create another clip from the same 
#  source file, at which it recurses through a prompting loop.  The 
#  script also can be run from the command line...however in CLI mode, 
#  the intent is to NOT allow the script to re-prompt for additional cips 
#  from the same source video.

# The script can optionally take 4 command line arguments:
#  1) The filename for the source video, without extension
#  2) The desired resulting clip name, without extension
#  3) The start timecode for the clip, format hh:mm:ss.nnn
#  4) The end timecode for the clip, format hh:mm:ss.nnn
#
# Variables:
#  INPUTFILE - Input video filename, without extension
#  OUTPUTFILE - Clip output filename, without extension
#  STARTTIME - Clip starting timecode, format hh:mm:ss.nnn
#  ENDTIME - Clip ending timecode, format hh:mm:ss.nnn
#  NANODIFF - Difference between start and end timecode, in milliseconds
#  NUMSECS - Timecoe difference in whole seconds
#  NUMNANO - Timecode difference remainder in milliseconds
#  REPLY - Flag for checking if the script should create another clip
#  CLIFLAG - Flag set if command line mode is detected, to prevent prompting
#

# Prompt the user for all parameters, by asking for the source clip name, then calling
#  the function which prompts for the clip info.  This can safely call the clip-info 
#  prompting function, as this should only be used once per execution, if at all.
PROMPTFULL() {
  echo "---What is the source video name? (No Extension) (Inside /home/surfrock66/Videos/HomeMoviesRaw/):"
  # First point of possible declaration for INPUTFILE
  read INPUTFILE
  # Execute the PROMPCLIP function
  PROMPTCLIP
}

# Prompt the user for the clip name, start time, and end time.  
PROMPTCLIP() {
  echo "---What is the output filename for this clip? (No Extension):"
  # First point of possible declaration for OUTPUTFILE
  read OUTPUTFILE
  echo "---What is the timecode for the start of this clip? (##:##:##.###):"
  # First point of possible declaration for STARTTIME
  read STARTTIME
  echo "---What is the timecode for the end of this clip? (##:##:##.###):"
  # First point of possible declaration for ENDTIME
  read ENDTIME
}

# This function handles the timecode calculations to find the clip duration, 
#  then executes the actial ffmpeg command.
PROCESSVID() {
  # Calculate the actuall difference, in milliseconds (but we'll call them 
  #  nanoseconds, because that's how the date command works) between the 
  #  start time and end time.  This relies heavily on the "date" command.  
  #  It can convert formatted timecodes between different format 
  #  conventions, but to go from something resembling a standard video 
  #  editing timecode to a raw nanosecond count is a PAIN IN THE ASS.  
  #  This strips out the amount of hours in milliseconds, then the number 
  #  of minutes in milliseconds, then the number of seconds in milliseconds, 
  #  then the number of nanoseconds in milliseconds.  It then adds them 
  #  together, creates a full millisecond count for the start an end time, 
  #  and then finds the difference, in milliseconds.
  NANODIFF=$(($(($(($(date -d $ENDTIME +%-H) * 3600000)) + $(($(date -d $ENDTIME +%-M) * 60000)) + $(($(date -d $ENDTIME +%-S) * 1000)) + $(($(date -d $ENDTIME +%-N) / 1000000)))) - $(($(($(date -d $STARTTIME +%-H) * 3600000)) + $(($(date -d $STARTTIME +%-M) * 60000)) + $(($(date -d $STARTTIME +%-S) * 1000)) + $(($(date -d $STARTTIME +%-N) / 1000000))))))
  # Convert the resulting difference, in millisecodns, into seconds
  NUMSECS=$(($NANODIFF / 1000))
  # Convert the reaminder of the resulting difference, in milliseconds,
  #  to milliseconds
  NUMNANO=$(($NANODIFF % 1000))
  # Print out the ffmpeg command that is generated, mostly for debugging
  echo "\nCommand: ffmpeg -i \"/home/surfrock66/Videos/HomeMoviesRaw/$INPUTFILE.mp4\" -ss $STARTTIME -t $NUMSECS.$NUMNANO -vcodec libx264 -b 1500k -s 480x480 -acodec libfaac -ab 192k -ac 1 -threads 8 \"/home/surfrock66/Videos/HomeMoviesRaw/$INPUTFILE/$OUTPUTFILE.mp4\"\n"
  # Execute the ffmpeg command, this is the big kahuna.
  ffmpeg -i "/home/surfrock66/Videos/HomeMoviesRaw/$INPUTFILE.mp4" -ss $STARTTIME -t $NUMSECS.$NUMNANO -vcodec libx264 -b 1500k -s 480x480 -acodec libfaac -ab 192k -ac 1 -threads 8 "/home/surfrock66/Videos/HomeMoviesRaw/$INPUTFILE/$OUTPUTFILE.mp4"
}

# Start of the main script.  Section 1: Input validation
#  Check that there is a first parameter.  If not, Prompt the user for the
#   parameters.  If there is one, validate the rest of the params, then 
#   either prompt the user, or use the passed params.
if [ -z "$1" ]
then
  # Call the prompt function, including asking for the source video
  PROMPTFULL
else
  # Assuming the first parameter exists, check for parameters 2,3, and
  #  4.  I'm not validating these strings, mostly because ffmpeg will 
  #  flip out if there's something wrong with them...as you know, it's
  #  quite verbose.
  if [ -z "$2" -o -z "$3" -o -z "$4" ]
  then
    # If any parameters are invalid, prompt for them all. Even if param 1
    #  is successfully detected, re-ask for it.  
    echo "--Parameters are incomplete, switching to prompt mode."
    PROMPTFULL 
  else
    # Pass all the command line parameters to the variables
    INPUTFILE="$1"
    OUTPUTFILE="$2"
    STARTTIME="$3"
    ENDTIME="$4"
    # Change the flag to indicate later that this initiated by CLI
    CLIFLAG="yes"
  fi
fi

# Create the default output directory, if it's not already created
if [ ! -d /home/surfrock66/Videos/HomeMoviesRaw/$INPUTFILE ]; then
  mkdir /home/surfrock66/Videos/HomeMoviesRaw/$INPUTFILE
fi

# Now...initiate the final video processing
#  Declare and initiate the REPLY flag...can be set to anything byt n/N
REPLY="y"
# As long as the REPLY flag isn't n or N, repeat the loop
while [ "$REPLY" != "n" ] && [ "$REPLY" != "N" ]
do
  # Call the function PROCESSVID
  PROCESSVID
  # Check to see if the script was run with command line parameters,
  #  If not, issue a bunch of logic to see if we want to re-run the
  #  code for new clips
  if [ -z "$CLIFLAG" ]
  then
    # Now that we know the script was run in prompt mode, ask the user
    #  if they want to make another clip, repeating this loop
    echo "---Would you like to create another clip from this input video? {Y/n}"
    read REPLY
    if [ "$REPLY" != "n" ] && [ "$REPLY" != "N" ]
    then
      PROMPTCLIP
    fi
  # If it was run by command line, essentially abort the loop,
  #  and the script.
  else
    REPLY="n"
  fi
done
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Raspberry Pi Shadowbox Case

Come on, no one reads this. However I need a place to show off my Raspberry Pi case, so I will make it go here.

OBJECTIVES:

  • Functional case for the Raspberry Pi as a media player
  • Attractive enough to pass the wife-approval test
  • Can end up near the TV without any furniture around it

So I got this idea...let's mount the thing in a shadow box. It can hang on the wall next to the tv, will have some air in the case to dissipate heat, can have all cables routed out one side, and can have a matte to hide internal wires.

Here's the results!

pi1

This is the mount, before any cabling is done.

pi2

Here it is up on the wall, with some of the cable management. The HDMI cable isn't done yet, so it's just hanging out the bottom.

Pi3

On the wall, with cables in and power on, basically the finished product.

pi4

The finished thing, with raspBMC powered up and running.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Redoing Bathrooms

Thought I'd show some updates to the work Jenn and I are doing to redo our bathrooms in the new house. All three full bathrooms had awful green 70's tile which we're removing and replacing. One bathroom (the master) has a green tub as well...we'll be getting that resurfaced.

The steps have been as follows:

  1. Remove old tile, being very careful to preserve it to donate to habitat
  2. Remove existing rotted drywall
  3. Clean all surfaces
  4. Put up concrete backer board
  5. Cut tile, apply mortar, put tile up (usually 4-5 stages per room)
  6. Grout tile
  7. Seal tile
  8. Apply Caulk
  9. Replace Fixtures
Read more »
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -