Entries in video (9)


Happy Mother's Day

Lunch at Kim's mom's house:

I love you mom, and I think about you every day.  Thanks for everything you did for me.

- - Rob


Perl script for creating time lapse videos from a GoPro HD camera

A few months ago, I bought a GoPro HD helmet cam. It takes 1080p video at 30fps, and is basically bomb proof. Video is not the only thing this little beast does, however. It has a mode to take continuous still pictures at given intervals ( 2,5,30,60 seconds ). Because it has a rather nice glass, wide angle lens, you can capture a lot in a single shot. This camera basically does all the hard work for you, so all you have to do is stitch the pictures back together. If you remember correctly (and you probably don't, because let's face it, who reads this blog?), I did a post on how to use ffmpeg to do stuff. In there I showed how you could use ffmpeg to create time lapse videos from stills. Basically you just do the following:

ffmpeg -r 15 -b 1800 -i IMG_%04d.JPG movie.avi

Anyway, this works for the GoPro as well (except the regex for the image name), but you get a cropped square picture, and pretty poor compression. So how do we fix that? Like so:

ffmpeg %d.JPG -r 12 -croptop 180 -cropbottom 180 -s hd720 -vcodec ffv1 movie.avi

Again, the name regex is incorrect in this case, but I'm just using this for demonstration. So, this solves the problem of formatting the video to your liking, but there are two other issues that need to be accounted for:

1. When taking more >1000 images the GoPro makes a new folder and starts the image count over again. So your images end up in folders like 100MEDIA, 101MEDIA, so on and so forth.

2. You now have images with the same name in multiple folders.

The problem with this is the way ffmpeg handles the input of still images. It would be nice if you could just input *.jpg, but you can't. Because you have to have your images named sequentially, you can't delete pictures out of the sequence either.

Because of these problems, I wrote a perl script that grabs all the images in any of the MEDIA folders, resizes and renames them, by modified time, and then puts then in a single folder. It then creates the movie for you.

Download the script here (Update: I added a line to escape spaces in the file names before piping it to ImageMagick)

 To make this script run on Windows:

1. Install Perl from ActiveState - ActivePerl
2. Install ImageMagick - Windows Bins
3. Save the above script into a file called "makeMovie.pl"
4. Copy all the MEDIA folders from your GoPro to a folder on your machine once you've captured your images
5. From the command line, switch into the folder with your MEDIA folders and copy the perl script into the folder
6. Run the perl script

To run this on Linux (Ubuntu):

1. Install imagemagick - sudo apt-get install imagemagick
2. Copy the above script into a file called "makeMovie.pl"
3. From the command line chomod the file - chmod +x makeMovie.pl
4. Copy your MEDIA folders from your GoPro to a folder
5. Copy your perl script into the same folder as the MEDIA folders
6. Run the perl script

Here's a few examples of what you get:

And one from skiing:


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



Cheap time lapse with a webcam, VLC, and ffmpeg

I've always been fascinated with time lapse videos of all sorts. Recently I've had the urge to do a little time lapse myself. My ultimate goal is to do something with my DSLR, but I guess you have to crawl before you walk right?



1. Get a webcam

2. Get VLC from Videolan.org (Windows, Mac, and Linux)

      * if using Ubuntu type the following: sudo apt-get install vlc

3. Get ffmpeg from ffmpeg.mplayerhq.hu

      * if using Ubuntu type the following: sudo apt-get install ffmpeg

      * You can find Windows binaries for ffmpeg from Google

4. Capture your stills using VLC

      * cvlc v4l2:// :v4l2-dev="/dev/video0" -V "image" --image-out-prefix img --image-out-format jpg --image-out-ratio 10 --v4l-fps 30

This means you'll save every 10th image from /dev/video0. You'll want to replace that with where ever your webcam is. It'll most likely be under /dev/video, but you can use dmesg to find your cam.

5. Let your video run as long as you'd like (or until your hard drive fills up)

6. Stitch your images back together using ffmpeg

      * ffmpeg -b 1800 -i img%06d.jpg video.mpg

After that you'll have a video named video.mpg that looks similar to the one above. You'll want to play with the number of images you grab with the image-out-ratio and you may want to explore varying the play back speed by taking a look at the options ffmpeg has to offer.

Although I had to figure out the VLC command by reading and just trying stuff, I found the ffmpeg command from: Catswhocode.com

It's also worth mentioning that I found a good article about extracting time lapse from a video. This sounds good for shooting video with my camcorder and then getting different types of time lapse from the video. You can find that article at: wp.pr0gr4gr4mm3r.com

Page 1 2