Batch Handbrake video file conversion with Python

April 11, 2014 Leave a comment

I needed a quick little piece of code that would go recursively iterate through a folder and its subfolders and convert all of the video files to H.264, so I took advantage of the Handbrake command line interface (CLI) and Python 2.7.x to do the work for me. This code snippet is not long or elaborate, but does the job, so hopefully it will be helpful to others.

Note that the Handbrake CLI options are defined in runstr. As-is, the script will convert videos with AVI, DIVX, FLV, M4V, MKV, MOV, MPG, MPEG, and WMV extensions to H.264 MP4s with the following options:

Here’s the code:

import os
import subprocess
import sys
 
fileList = []
rootdir = raw_input("Root Dir: ")
for root, subFolders, files in os.walk(rootdir):
    for file in files:
        theFile = os.path.join(root,file)
        fileName, fileExtension = os.path.splitext(theFile)
        if fileExtension.lower() in ('.avi', '.divx', '.flv', '.m4v', '.mkv', '.mov', '.mpg', '.mpeg', '.wmv'):
            print 'Adding',theFile
            fileList.append(theFile)
 
runstr = '"C:\Program Files\Handbrake\HandBrakeCLI.exe" -i "{0}" -o "{1}" --preset="Normal" --two-pass --turbo'

print '=======--------======='

while fileList:
    inFile = fileList.pop()
    fileName, fileExtension = os.path.splitext(inFile)
    outFile = fileName+'.mp4'
 
    print 'Processing',inFile
    returncode  = subprocess.call(runstr.format(inFile,outFile))
 
    print 'Removing',inFile
    os.remove(inFile)

Read more…

GoPro SuperView-like adaptive aspect ratio

March 16, 2014 Leave a comment

For Christmas, my parents got me a fantastic gift for photographers and outdoors enthusiasts, a GoPro Hero3+ Silver Edition digital camera (Amazon). If you are not familiar with GoPros, they are small action cameras that have a very wide-angle lens and come with a water-resistant case. It’s a fantastic little camera that packs a lot of punch for such a compact package.

There are a number of GoPro editions, but the newest one are the Hero3+ Silver and Black. The Silver Edition is very similar to the GoPro Hero3+ Black Edition (Amazon), but omits a few features, including some very high-resolution video recording modes and a feature that GoPro calls “Superview”. This post talks about a way that I attempted to emulate their Superview mode in MATLAB and put together an adaptive aspect ratio function that allows one to change the image’s aspect ratio while maintaining “safe regions” with minimal distortion.

This function allowed me to resize 4:3 images and video, like this one:

To a wider aspect ratio, for example 16:9:

Click through for info on how I implemented the code.
Read more…

Cinnamon Buns

March 15, 2014 Leave a comment

Here’s a short video of some cinnamon buns I made. The video was set to music by Jill Zimmerman – Earthbound (CC BY-NC-SA 3.0).

Click through for the recipe.
Read more…

WiFi-Enabled Arduino Fio using the WiFly RN-XV (RN171XV)

October 20, 2013 Leave a comment

The Arduino Fio is a nice little Arduino board designed specifically to interface with XBee devices. I think it’s a great little board and have used it quite a bit in the past. BUT, I haven’t talked too much about the XBee interface, so for this post, I wanted to demonstrate an example utilizing the XBee socket to get an Arduino Fio onto the web. This is a simple example, just demonstrating communication with the Microchip RN171XV (previously Roving Networks RN-XV) wifi module.

WiFlyTimeWithConsole Example

Click through the break for information on the setup and source code to get the Arduino Fio onto the web.
Read more…

Chocolate & Hazelnut Chip Cookies

October 7, 2013 Leave a comment

Here’s a short video of cookies I made this weekend. They turned out really well, so I wanted to share the delicious recipe (based upon the classic Nestlé® Toll House® chocolate chip cookie recipe). Here’s a little time-lapse set to music by Jill Zimmerman – Tunnel Vision (CC BY-NC-SA 3.0).

Click through for the recipe.
Read more…

Magic Lantern HDR video to tonemapped video with MATLAB scripts

October 5, 2013 Leave a comment

I have a Canon T3i with a Canon EF 50mm f1.4 lens that I use for the gross majority of my day-to-day photography these days. I’ve been using a custom firmware for the Canon called Magic Lantern that provides a some interesting (and useful!) functions. One of them is HDR video. Here’s a beautiful example of what can be done:

I tried my hand at processing the HDR video output and was able to get a reasonably nice tone-mapped video:

After the break, you’ll find how I processed the initial Magic Lantern video using MATLAB and exiftool and tone-mapped the output using Luminance HDR.
Read more…

Preparing a “Blobby” Object for Printing with Shapeways

October 5, 2013 1 comment

I have been working with a 3D blobby object for some of my pilot studies on shape from shading and texture that I would like to 3D print. Back at Rutgers University, we had a MakerBot Cupcake, but now that I am in Germany, I need to find alternatives. I have been looking into getting the 3D object printed using Shapeways.com but there have been a few hiccups along the way, so I wanted to describe my experiences in the hopes that it might help someone else avoid these issues in the future. The object was generated in MATLAB using a simple script (see 3D “Potato” Generation using Sinusoidal Pertubations) and rendered in our 3D environment:

3D-Blobby-Object---Solid-(Seed--0431630057)

So the question is: What do I need to do to get this 3D object printed at Shapeways? Click through to see the steps that I took to get this 3D model printed economically.
Read more…

University of Giessen (Justus-Liebig-Universität Gießen) Timelapse

September 14, 2013 1 comment

I seem to be on a video-posting roll with some of these videos from day-to-day life here in Germany (see previously: Johannisbeeren (red currant) Pastries and Puff Pastries with Blueberry Compote). The latest video is a time-lapse from my office at the University of Giessen (officially Justus-Liebig-Universität Gießen) that I took with my HTC Rezound using Lapse It.


Read more…