Sunday, April 25, 2010

Complete Video Geekout

Fair warning -- this entry is not for the faint of heart. This is going to be a whole lot of geeky crap that nobody in our family will really care about. My only purpose in writing it is to document what I've discovered in the past few weeks, and perhaps it will help someone else who's trying to do something similar. You've been warned.

As I mentioned a while back, I've begun streaming shows to our Samsung LED TV, which is DLNA capable. This allows us to easily select a movie on our PC, right click on "Play To" and select the TV. It's great when we need a few minutes to get ready in the morning, and we want the kids to watch a few minutes of something. And it's easier than resetting the PC to output to the TV, using it as a monitor. The DLNA stuff just spits the movie over the network and plays the movie on the TV automatically. No channel changing, no video card settings, nothing. It just works.

This worked so well, that I decided to also do something similar with our TiVo. I wanted a program to stream DVDs to our TiVo without actually downloading the movie to the box. (Downloading is fine, but it's slow and fills up the already tight hard drive on the TiVo.)

I discovered a great piece of add-on software for the TiVo called Streambaby. This allows me to do exactly what I wanted -- stream DVDs and movie files to the TiVo. This is a great find, because it allows us to not need the actual DVD discs for the kids to watch their movies. I can box the DVDs up and never find them on the kitchen floor covered with peanut butter ever again.

So what I did initially was create a DVD image of each movie using DVDFab. I then used either VOB2MPG or VideoReDo to create an MPEG file of the DVD movie. I could then stream this MPEG-2 file (including the Dolby Digital surround sound) to the TiVo, and it worked great with the DLNA on the other TV. I would also use Handbrake to create an H.264/MPEG-4 file with AAC audio for the iPods using the iPod preset. (There's really no way to create one version of each movie which looks good on a 61" TV and a 3" iPod. This doesn't really bother me though, as the iPod files are very small in the end.)

The downside is that this process takes up tons of hard drive space -- several GBs per movie. And while I'd love to keep perfect images of all of our DVDs, I really don't have the money to buy scads of hard drives for our DVDs and CDs. So I need to compress.

I decided to start converting the original MPEG-2 DVD files for the TVs into H.264 files using Handbrake, similar to what I do for the iPods. Only I would use a different level of compression so that the videos still look great on the big screen. I also decided that I still wanted to preserve the Dolby Digital (AC3) surround sound, so I used "AC3 passthrough" mode rather than converting the audio to AAC, as one would usually do in an MPEG-4 file.

Since I started doing this, I've encountered several problems. The first was that I have some DVDs with 2 channel LPCM audio. What I discovered is that the TiVo can't play LPCM audio, so I needed to convert this to something else usable, namely AAC. This worked great.

The second problem I discovered is that I could not play my new MPEG-4 videos with AC3 using the DLNA features of our Samsung TV. In researching this, I discovered that Windows Media Player would play the video, but not the audio in these files. Apparently using AC3 within an MPEG-4 file is a somewhat strange configuration. It was started by Apple who packaged movies in iTunes this way, but now it's becoming more common.

In looking for a way around this, I knew that Streambaby on the TiVo would only look at the first audio track in a file, so this HAD to be the AC3 track if I wanted my surround sound. So I got clever and tried using Handbrake to put the AC3 track first and also add a second AAC audio track to each file to make the DLNA stuff (and Media Player) happy. I thought this had worked great, as the files played fine in Media Player. But unfortunately the Samsung TV still wouldn't accept the file. D'oh.

In the end, what I've decided to do is use AAC audio on DVDs without surround sound -- lots of kids movies are just good old stereo, so this is fine and plays on everything. For the bigger productions which feature surround sound, I'm sticking to my MPEG-4/H.264 with AC3 sound. This works great on the TiVo, and if they want to watch these on the Samsung TV in the other room, they can do so by playing the movie out to the TV using the TV as a monitor. It's not as convenient as using the DLNA connection, but it works.

So for anyone who is interested, here is my basic command line in Handbrake for creating Streambaby-capable movies for the TiVo:

handbrakeCLI -i "Kids Movie.mpg" -f mp4 -O -e x264 -b 2000 -a 1 -E ac3
-x ref=2:bframes=2:me=umh --strict-anamorphic -v -o "Kids Movie.mp4"

Basically this says, "Take the MPEG-2 file, use H.264 to compress it at 2000 kb/s (because the TiVo likes a constant bitrate), optimize it for streaming, pass along the AC3 surround sound, and spit out a shiny, new MPEG-4 file." The only real variations on this are changing the "ac3" to "faac" for the 2-channel stereo movies where I want to use AAC, and if the movie was originally NOT widescreen, I take out the "--strict-anamorphic." I won't go into what that means, but you can read about it here.

In the end, this compresses my movies by more than 50%, and they still look perfect on the TiVo. I could probably even reduce the 2000 kb/s to something smaller, but much like my music, I'd rather not see/hear any reminders that I've compressed my files.

Hopefully eventually the Samsung TV will let me pass an MPEG-4 file using AC3 audio, and this solution will work perfectly for every scenario. But for now, it works with Streambaby on the TiVo, which is where I need it to work 99% of the time.

And the kids can always watch the 2-channel stereo files via DLNA on the Samsung TV, or use the Samsung TV as a monitor for the other files by playing them using a video player (like VLC) which can play MPEG-4 files using AC3 audio. Either way, I can make this configuration work for any movie.

Hopefully some other poor schmuck will find this via Google and save himself some time. And if you read through this looking for pictures of the kids, don't say I didn't warn you.

3 comments:

Rachel said...

Bret... you are a geek with too much time on your hands now. I'm sure I can find you something constructive to do at our home. :)

Katherine said...

Oh boy . . .I hope you find a job soon!

Anonymous said...

Micah loved this post and promptly asked for our Samsung TV model #. peace.