Using ffmpeg to manage video

This is going to be a quick and dirty how-to on ffmpeg and you can find this stuff all over the net (well except the slow motion trick, I couldn't find that anywhere). Here goes:

Where to get ffmpeg
Ubuntu - sudo apt-get install ffmpeg
Windows - Install ImageMagick or Use a binary someone has built

Mac - Aren't you using Final Cut anyway? [Edit: Use this guide to build ffmpeg on the Mac]


Easiest way to convert video

 ffmpeg -i video.wmv -sameq video.mpg

Create video from a series of images
Assuming your images are named like this - IMG_0001.JPG, IMG_0002.JPG...
Also, I'm setting the frame rate low here.
ffmpeg -r 15 -b 1800 -i IMG_%04d.JPG movie.mpg

Create a time lapse from a regular video
movie.mpg is the original, and I'm going to save every 5th frame. Then we stitch them back together.
ffmpeg -i movie.mpg -r 5 -f image2 %d.jpg
ffmpeg -b 1800 -i %d.jpg tt_movie.mpg

Make a video slow motion (kind of a hack, but I couldn't find another way)
This will make images from every frame in the clip. Then you stitch them back together with a different frame rate. The lower the rate, the slower the vid.
ffmpeg -i movie.mpg %d.jpeg
ffmpeg -r 10 -b 1800 -i %d.jpg tt_movie.mpg

Add audio to a video
ffmpeg -sameq -ar 22050 -ab 32k -i song.mp3 -i video.mpg videoWithMusic.mpg

Make an image into a video clip (for an intro or credits or something)
This will play for 10 seconds
ffmpeg -loop_input -i image.jpg -t 10 -r 30 -qscale 2 vid.mpg

Trim a video
This will clip the first 30 seconds of the video
ffmpeg -i video.mpg -sameq -ss 00:00:00 -t 00:00:30 trim.mpg

Stitch clips together (no ffmpeg needed)
This only works with a few formats. I tend to always work with mpeg, so this works great for me
cat video.mpg video2.mpg video3.mpg > finalVid.mpg



Geotagging photos with your iPhone

Ever since I starting using my iPhone to take photos and upload them to the net, I've really become interested in geotagging my photos. I didn't realize how cool it is to be able to see your photos on a map (or Google Earth) until all my photos started showing up tagged (thanks to the GPS in the iPhone). Having low res photos tagged is cool and all, but I want to tag them with my SLR. You could buy an adapter for you camera from Amazon or you could just use the GPS you're carrying with you every where you go. Here's how:

First, get an app from the app store that logs GPS data points. There are a ton of them, and one app specifically tailored to this called GeoLogTag. Anything that allows you to export your data in a GPX file with times should work. I just use MotionX GPS because it's super cheap for what you get, I use it for hiking as well, and it makes it super easy to share/get the GPX file.

Next you'll need an app that allows you to tie your GPS location and timestamps to your photos. There is a ton of software that does this, but I chose to use a perl script because I wanted something cross platform and any time I can use the command line, I'm happy. You can find the handy dandy perl script called gpsPhoto here. You'll need to install two more perl packages if you don't already have them installed. The site goes over how to install them if you don't already know how.

So let's go step by step:

0. Make sure the time is set correctly on your camera.
1. Turn on MotionX GPS and start logging.
2. Walk around and take pictures like a mofo.
3. When you're done taking pictures, stop MotionX, save the track, and email yourself the GPX log (called sharing in MotionX)
4. Go home and dump the pictures from your camera into a folder.
5. Fire up a command window and change into the directory where you pictures are.
6. Run the perl script. Here is the command I used:

./ --dir geotag --gpsfile Track.gpx --timeoffset 21600

There are a ton of options that you can use, but these 3 should get you by. The first two args are pretty self explanatory, but the third isn't at first. The timeoffset is the UTC offset in your timezone in seconds. I live in Denver, and my offset is 7 hours, minus 1 hour since we are on daylight savings. Just google the local time in your city if you don't know what your offset is, and then multiply that by 60 minutes and 60 seconds.

Anyway, this should get you started, and I was able to get this to work on Windows, Mac OSX, and Ubuntu, so you should be able to follow my instructions on any OS that supports perl. Lastly, you can use any old GPS to get the GPX file, it's just a matter of having your GPS with you as well as the ease of getting the GPX file to your computer.


Some Perl code for the Nike+iPod serial adapter

The other day, I came across a nice tutorial on using a Nike+iPod adapter as a kind of active RFID to unlock your car doors. I immediately thought of a need that I have to be able to open my garage door while pulling up on my motorcycle. It's kind of a hassle to reach in my pocket and open the door, and why should I have to do that? Anyway, I had a Nike+iPod kit at home that I don't really use, as well as an Arduino, so all I needed to do was buy the adapter from Spark fun electronics in Boulder (my favorite place to spend money). So I put in the order, and in a few days I had the adapter that came with a nice VB app that allows you to immediately plug the adapter into your computer and start listening for "foot pods". The next thing I wanted to do was create a Perl script to listen for the pods so that I could use the adapter on Linux and maybe my Mac. So after a few hours, I have a script that works on Windows, and has successfully worked on my girlfriends Ubuntu laptop, but to date is not working on my Intel Mac mini or my Ubuntu server.

Here are the steps you need to follow to get the script up and running:

1. On Linux/Mac - Install Device::SerialPort using CPAN
a. On Windows - Install Win32::SerialPort using CPAN (make sure to follow all directions. On Windows, it's a little more involved)
b. And install Win32-API using PPM (I use ActiveState, so it has PPM)
2. On the Mac, I needed to install the UART driver from here. It seems as of Kernel 2.6 the driver is included in Linux.

You can download the Perl script (called from here

After you get the script, you may need to edit the port that your adapter is running on, and you can figure that out by going to the device manager in Windows, using dmesg on Linux, or using the System Profiler on Mac OS X.

Then just fire up the script, and it will start listening for "foot pods" and dumping out the ID as well as the raw data received from each pod.

I'll be using the adapter with my Arduino soon, and I'll post details on that project, as well as any updates I have on getting the adapter to work on the Mac.

Update: Just wanted to let everyone know that if Python is your thing, there is a nice writeup about using Python to do the same thing.


Solar powered Mac Mini

A little backgound
I live in a ~750 sq. foot apartment with my girlfriend and dog, and my utility bill was ~$100. That seemed a little high, so I went to work on bringing down the bill. I first replaced all the light bulbs with either compact florescent or L.E.D bulbs as well as set my Mac to turn off at night and back on in the morning, on a schedule. These two actions alone, brought the bill down to ~$75. This was nice, and we've been living with this bill since Christmas, but I knew we could do better. I'm sure that most of the bill is made up of the dryer and my server that I run 24 hours a day, but things like the laptops we both have, the phone/camera chargers, and my Mac could be run completely off of solar power.

What you'll need
Before this project, I knew nothing about solar power, batteries, how to measure power consumption, or how to hook it all up. After some research, I was able to piece it all together, and I now have a working solar system.

So, how do you build it? It all breaks down to the following materials:

1. Solar panels
2. A charge controller
3. A battery or batteries
4. A power inverter
5. Wiring

First things first, the panels. There are a ton of places to get panels, but since I'm new to this, and I love Amazon, I felt I probably couldn't go wrong just getting them online at Amazon. The first thing I did was search Amazon for "Solar Panels". I got a ton of hits, that ranged from 5 watts, to a few hundred watts. I wasn't sure how many watts I needed, so I didn't just want to buy anything. I took a look at the Google, and figured out how to calculate the watt/hours your electronic uses. The quick and dirty is this:

Take a look at the back of your equipment for a tag that has info about the power output. You'll see something like "writing... 100v ~ 2.5a ...more writing". To figure out the watt/hours, you take the Volts x the Amps. So the above calculation, would be 100v X 2.5a = 250w. Now add up all the watts from all the appliances you want to run, and then you'll know how much power you need to run your equipment. I figured my Mac takes around 40Watts and if I wanted to run it for 8 hours, I need to be able to make 320Watts of power. I was conservative and figured I'd only have about 5 - 6 hours of good sun a day. That means I could probably get away with a 60w system. So I went back to Amazon, and I after browsing, decided on a Sunforce 60w kit. This kit came with the panels, and it also came with an inverter, charger controller, and wiring. And best of all, I got it for $300.

So, all I needed now, was a battery. You'd think I could just buy any old car battery, and I'd be set. This is probably true, but there are some things to take into consideration. First, and most important is safety. You need to remember, that standard lead acid batteries will leak flammable gases when charged as well as become pretty hot. That being said, if you have a dry, ventilated, fire-walled area, you can build a nice battery cluster for a good price. This is not the case for me, so I needed to explore other avenues. If you plan on running your system in your house, you'll probably want to look into agm sealed batteries. These batteries don't leak gases, but do still get hot. There is a premium to pay for no gases though, and if you can use standard lead acid batteries, you should.

Because I practice agile, I believe in building a vertical slice of the system before I build in bells and whistles. Because of this, I went with a simple charge controller, and I am starting with a one battery system. As you search for batteries, you'll notice that there are a lot to choose from and they range from pricey to expensive. I decided on a Duracell powepack 600 (for $130) not because it's the best battery for the job, but because it is not just a battery (it had a built in 600w inverter), and if I decided that I don't have room for my panels and system, I'd be able to use my battery for many other things. Plus, when I have my vertical slice complete and have work out the kinks, I'll build a true battery cluster.

Putting it all together

The first thing I did was lay all my panels out:

4 15W solar panels

You'll want to build a frame to hold your panels. The Sunforce kit came with a PVC frame, but you could easily build this yourself.

PVC rack/stand for my solar panels

Next I attached the panels to the frame.

4 15W solar panels

I then laid out all the wires, and examined the mess.

Various wiring for my solar panel generator kit

It's important to keep in mind that you need to maintain a 12v system. That means when adding panels, or batteries to the system, everything needs to be in parallel (positive to positive, negative to negative). As long as you keep that in mind, you should be pretty safe and not damage anything. My panels came with a four way connector that wires them in parallel, but when I add more panels, I'll need to figure out how to splice the new panels in. Also important to note, is that the inverter that came with the panels, is only a 200w inverter. If you plan on running anything bigger than a laptop computer, you may want to think about investing in a bigger inverter. I am using a 600w inverter.

Once my batter came in, I just needed to hook it all up. I first charged my battery from AC over night, to get it topped off.

The battery and inverter

Then I mounted the solar panels on the outside of my second story apartment balcony.

I used 10 inch house clamps and hung the panels from the top rail. This allows them to swing out and catch more sun.

I also bundled all the wiring with zip ties.

Here is what they look like from the ground.

My solar panels are installed

Here is what they look like making free power.

My charge controller

I've been running the system for about a week now, and I love it. I charge my phone on it every day, run my laptop off it every night, and I've had the TV and Mac hooked up to it. I'll be rearranging my entertainment system, so that the Mac can use the battery everyday as well. I've run the battery all the way down once (we've had a few days of rain, that didn't allow the battery to charge all the way), but otherwise it's charged and ready to go everyday when I get home. When using my laptop, I get about 7 hours off the battery. When using the TV, I get about 3 hours.

The future of the system

The next thing I will be doing, is building a Tweet - a - watt and attaching it to the inverter, so see exactly how much power I'm using from the sun.

A few months down the road, I'd like to buy a two or three stand alone lead acid batteries, and build a cluster and put it in a box on the balcony. After that, I'll probably buy a few more panels, as I'd like to ultimately have a 100w system.


Finding people who do stuff instead of just talk about it

Over the last few months, I've been more and more interested in tinkering with things, building stuff just for the hell of it, and making my life more efficient. Most of the time when I talk about my projects to the people I work with (like my current solar powered Mac mini project), I get an odd look and then the inevitable, "but why?". Why is it so hard to find people that like to build shit just for the experience of learning something?

I follow a ton of blogs, news, and other random feeds, and I just don't hear that much about things going on in Denver. But, after a little searching, I managed to find a few things. First was an Autonomous Vehicle Competition put on by Spark Fun Electronics in Boulder:

It took place on a Thursday, so I had to dip out of work for a bit, but it was well worth it. There were a ton of people all interested in building things, how stuff works, and sharing their ideas about stuff. I talked to a few people, and because I was Twittering the event, I had five new Boulder area Makers following me on Twitter by the time I got back to the office. It's nice to have a few friends on Twitter, that you know IRL BTW.

I left that event inspired, and really ready for more. And, as luck would have it, the first Denver area maker meet up was scheduled on April, 23. I found out about this on the Make blog. This was in the evening, so I rode down there and checked it out. John Maushammer was the guest speaker, and he gave an excellent presentation on his home made pong watch:

My jaw was literally on the floor listening to this guy. He's definitely a top notch maker.

I was able to meet a few more people, and I realized that some of the people at the Sparkfun event were here too. I'm pretty excited about meeting new people, and learning as much as I can.