Apr 04 2008

HD Video - A Primer

Published by Jonathan Wise under Articles

This weekend I spent an exorbitant amount of time trying to deal with HD video in the same way I manage my digitized DVD collection. By that I mean, attempting to figure out how to get ripped HD movies into a format that I can play over my network, with the XBox 360, the Mac in our room and a PC as the target players. Things have not gone well, and while some people may have worked out a system they can live with, I’ve not found a solution that can be applied efficiently enough to make it worth the effort. Nonetheless, I’ll document what I’ve learned, in case its useful to anyone. There is no new information here — all of it is on the web somewhere — I’m just hoping to pull it into a coherent form…

 

MPEG4

For starters, high def content is invariably distributed in MPEG4-10 format. The different ways it can be bundled into a file will be discussed later on, but its important to first understand that not all MPEG4 is created equal.

MPEG4-2, or Part 2, is very common, and not really suitable for HD content. DivX and XVid are both implementations of MPEG4-2. DivX is MPEG4-2 with a couple extra features added. XVid is an independent re-implementation of DivX that, while usually compatible, is definitely a different beast. A player with DivX stamped on it can probably play any MPEG4-2 content, and probably play any XVid content. In cannot, however play MPEG4-10 content.

MPEG4-10, or Part 10, is relatively new and most commonly known as H.264. Its based on the same technology as its older cousin, but includes improvements to color handling, and allows higher quality content at lower bit rates.

Bit Rate: Loosely defined, the Bit Rate is the number of bits of data that go into showing 1 second of video. The higher the bit rate, the more information making up the image you see on the screen. Higher bit rates = better quality video.

H.264 can do better picture, with less artifacting, and less “chunkiness” (if you don’t know what I mean by chunkiness, watch a dark scene in any DivX movie) at a lower bit rate. A 2GB MPEG4-10 video will look better than a 4GB MPEG4-2 video.

 

Containers

All video, regardless of the codec (be it MPEG2, MPEG4-2, H.264, etc…) is typically distributed inside a container, bundling up the video track with an audio track, and possibly other features such as alternate audio tracks (containing a different language) or subtitles. Wikipedia has a good entry comparing the different container formats, but here are the common ones you’ll see for HD Video:

Quicktime (.MOV)
Quicktime is an incredibly flexible container that can hold virtually any collection of files, by using plug-in codec support. A .MOV container can hold an H.264 video track plus a DTS 5.1 surround sound audio track without any problem.

Limitations: There’s not many devices with full Quicktime support. Basically you’re stuck with something from Apple. The XBox does have basic support for .MOV containers, but doesn’t have the ability to plug-in codecs to extend its limited offering.

Windows Media File (.WMV)
Windows Media is actually very fully featured, with support for containing high bit-rate HD video and audio tracks with 5.1 surround sound.

Limitations: Its a fantastic format, despite being from Microsoft, but there aren’t many devices that support it, and I frankly hate Windows Media Player. You’ll rarely find any content distributed in a WMV container.

MP4 (.MP4)
By far the most popular, and infuriatingly limited container for H.264 (MPEG4-10). Do not confuse “MPEG4″ for “MP4″ — one is the video track, one is the container it travels in. MP4 supports H.264 video at all bit rates (but not all bit rates can be played on all devices, read about levels here) and can hold an AAC-LC audio track (probably more than one.) But herein lies the biggest problem with MP4: AAC-LC means “Low Complexity” or in other words “no digital surround sound.” You can encode Dolby Pro Logic II into the stereo track and thus get surround sound that way, but it won’t be DTS and it’ll basically suck.

Matroska (.MKV)
The Matroska container is the most common one you’ll see — both from ripped optical media, such as Bluray or HD-DVD discs, and online. Its very flexible, and can hold super high bit-rate H.264 video tracks as well as multiple audio tracks, including DTS (Digital Theater Surround).

Limitations: Apparently its a poorly defined standard and there are lots of different interpretations on how to implement it. No OS or media player software supports Matroska out-of-the-box. Few set-top devices can support Matroska. The XBox 360 does not.

 

Useage

None of these containers formats are really mature enough to be considered ready for consumer use. Different devices can handle different containers — but each with restrictions on what’s inside the container. Here’s a list of what the XBox 360 can handle.
The best standardized container, MP4, is missing a pretty critical piece of the home theater puzzle: digital surround sound. This is not a new feature here, folks. It needs to be supported for MP4 to be useful. The other containers, which do support surround sound, are either too proprietary or too disorganized to be useful yet.

If you were to obtain a MKV file with HD video inside (H.264) and a surround sound audio track, and you wanted to play it on your XBox, you’d basically have two choices on how to proceed:

Extraction and Re-bundling
Using an array of poorly-made tools and hacks available online, which I won’t cover here out of disdain for them and the hours of time I wasted on them, you can extract both the H264 video stream and the AC3 (digital surround sound) audio track into separate files. Then you can modify them to be playable on your target device, and re-contain them in a supported container.

For example, you could drop the bit rate on the H264 stream down to at least level 4.1, outputting it to a new, slightly more compressed, but certainly still “Hi-Def” file. Then you could pare the audio track down to Stereo, with Dolby PL2 intact. Finally you could combine the two files together into an .MP4 container and play them on your XBox 360, PS3, etc…

A friend claims to have this process down to a few clicks done in less than 10 minutes (he says 6 minutes or less, but I’ll chalk that up to bragging.) Using a Mac with Windows running in a VM, then later, after much frustration and waiting, using a well-equipped physical Windows PC after sneaker-netting the files, I was unable to complete all the steps of the process after 5 hours. The “software” is buggy, has poorly documented dependencies and 0 troubleshooting information if anything goes wrong.
My friend calls this operator error and says I’m technologically inept. I call it really bad software being used to do something it wasn’t really intended for. I finally gave up.

Down-sampling
The less attractive, but much easier option, is to simply down-sample the whole contained file into a MPEG4-2/DivX file. If you have a Matroska file, you might still want to do some conversion first — Quicktime Pro can ‘Save As’ a MKV file into a MOV in a couple seconds.

From there, many mature applications, like Handbrake or FFMPEGx on the Mac, will be able to convert the whole thing into something playable for you. It may take some time, and you’ll want to compress at a high bit-rate to keep as much of the video quality as possible (and don’t fool yourself — you will loose quality), but it’ll be a usable, decent-looking file that can play on a wide-range of devices, AND it can contain DTS 5.1 audio.

 

Conclusions

HD Video is the biggest screw-up in consumer technology history. We’ve been waiting for this for years… Waiting while they sort out 720p, 1080i, or 1080p as the resolution we’re supposed to buy. Waiting while the cable companies struggle to get a trickle of 720p content to our sets (then screw their customers around trying to save money on it.) Waiting while big companies publically fight over which optical format we’re supposed to go out and re-buy all our movies on…

In fact, “HD” video (eg: 1080p) describes only the resolution. You can have a 268kbps bit-rate video in 1920×1080 and call it “HD” if you want. It’ll look like crap, but it’ll be big!

Learning about the different container formats and how they’re still a fractured mess of incompatible technologies only makes me angrier. Here I stand, ready to jump on the Hi-Def band wagon, with my brand-new TV, my brand-new XBox 360, cash in my hand… and the only reasonable and affordable way to get HD content is the now-defunct $50 HD-DVD add-on player I bought on clearance.
Bluray is ridiculously expensive. No one offers 1080p downloads or subscription content. Even the pirate world can’t figure out how to distribute content playable on any common device…

Its a disaster. I spent the better part of a day trying to make it useful, and I’ve decided that, for now, I’ll be storing my content in high bit-rate DivX with my surround sound intact, thank you very much. I’ll re-visit this again sometime in 2009, and hope they’ve got their crap together…

Anyone have any corrections to this, or suggestions to make this space more understandable and usable?

4 responses so far

Mar 07 2008

Possibly the most elite home network ever…

Published by Jonathan Wise under Articles, Toys

Once we move back to Ontario, I’ll be working from a home office. Add that to the fact that we’re not using anything more than basic cable, but digital distribution (both the paid and the found-automatically-on-the-internet-and-you-can’t-convince-me-I-shouldn’t-have-it kind) for our entertainment, and I think I have some unusual problems to solve. Here’s what I’m dealing with:

  • I want a reliable and dedicated “business” connection with no WiFi access so that my company’s source code is secure.
  • But I want access to my stuff from my iPhone and my Craptop, and visitors and passers-by should have free access to Internet, because that’s the spirit of the thing, but they shouldn’t have fee access to my files and documents, so I want both a secure and an open WiFi network.
  • The XBox 360’s method of getting shared content is incredibly noisy and resistant to QoS. The sharing program, in my case Connect360, uses broadcast messages to toss bits all over the network. The only way I’ve found to ensure Quality on this is to have a dedicated network just for sharing between the computer and the XBox.
  • My media is going to be stored in different places depending on primary usage. High quality movie rips (legally obtained, of course) shouldn’t be transcoded by Connect360. Daily TV downloads and recordings using EyeTV (and can be transcoded since they’re already pretty low quality), MP3s and Photos will be frequently revolved and updated and should be managed from a PC (manually, or by script.) All of these files need to be available from anywhere in the house.

The solution to all of these problems can be seen in this diagram (click for a larger version):

As you can see, there will be no less than 3 individual networks, with bridge points between each, where appropriate.

  • The green network represents the dedicated XBox network, allowing us to stream content from a PC regardless of the activity of other devices. We’ll open it up for free WiFi since there’s really nothing accessible on that network, but QoS all other devices as low priority.
  • The blue network is the primary home network, your typical file/print sharing setup. Living on that network is a sweet little LaCie Mini NAS drive, which will share all our high quality movies and will also have a direct USB connection to HDTV via the XBox to avoid transcoding. Other media: recordings, downloads, MP3s and photos will be shared from the home Mac to all devices over this pipe. Two touch points in the home office will allow me to listen to my music while I’m at work, and sync my calendars and e-mail with the home Mac.
  • Both the blue and the green network will be coming off a standard home Cable Internet connection, but each router will have its own public IP.
  • The purple network is a dedicated 7+ MBPS DSL connection (shooting for 10MBPS, but we’ll see what’s available) used only for connecting my home office to the Internet. It will have no wireless connection, and won’t leave my office in any way. The Blue network connection into the home office will be firewalled and won’t be set-up for Internet — SMB file sharing only, but if something goes wrong with my DSL, I can re-configure for Cable over the blue network and still do my job. The purple network will allow communication between my work computers, both of them running Synergy so I only need one keyboard and mouse. And the little iMac will by my jukebox/Photoshop/personal mail rig.
  • The two work computers will run up to 4 Virtual Machines each, but my primary VMs (represented by the monitors — and yes I’ll have 4!) will be: an e-mail/IM computer for connecting to work, a development workstation with occasional VPN access to sync source code, and a test server and client — more added as my current project dictates.

    My newest work computer will be running Microsoft’s new Windows Server 2008 with Hyper-V virtualization, allowing incredible performance of the Guest machines.

  • Any capable device can also get VPN access from any network, since its secure by nature, but only 3 machines will be configured to do it most of the time. My touch points with the physical office will be fairly limited, since I’ll be able to have local VMs of current server builds that I’ll refresh whenever I’m in the office for meetings.

I think that’s ambitious enough… but if you have a better home network, or ideas to improve this, I’d love to hear about them!

5 responses so far

Dec 20 2007

Question From A Reader: Mirroring an iTunes Library

Published by Jonathan Wise under Hacks

Shawn writes…

…i’m looking all over these internets, and I have a feeling you can point me in the right direction.

Short short version: how can I mirror/sync the itunes database file (just the database, not the song files themselves) between two macs on the same home network, so that any changes made on one mac will show up when itunes is opened on the other mac? Foldershare doesn’t seem to be working…

I’m looking to:

  • Store my itunes library (the files) on my mac mini, storing no mp3’s on my macbook pro (this is done, easily, by sharing the mini’s itunes folder and pointing the mbp to it…got that done already…it’s the sharing of the database file that I’m having trouble with)
  • Either NAS or external fw/usb drives for saving music/movies/photos attached to mini (raid 1 or 5…I’d love to hear suggestions of why a NAS or external would be a better bet…I’m leery about capability of NAS to stream high quality handbrake rips through my elcheapo linksys wrt54g router…would love to get lacie Ethernet RAID, but I don’t think it will cut it)
  • Use that repository of files on the mini/nas/external drive whenever i’m on my home network…rip a cd on the mbp, consolidate, it shoots over to the mac mini, and occasionally clean off the mbp so it’s got no MP3’s stored on it
  • Reference either the same library database file or have a mirrored library file on my macbook that updates/syncs regularly, so I can access the library (add new podcasts, new music from cd’s, etc.) even if I’m not on my home network

Advantages:

  • if i’m out and about, and add a cd to the mbp, or a podcast, I can still sync my ipod…the easiest solution of just pointing the MBP to the itunes library database on the mini is problematic, because if I’m off the network, I can’t use that library database, and I’ll get a blank itunes library, and not be able to sync the ipod. If, however, I set it up like I’m wanting to, whenever I’m out and open up itunes, I’ll just get the ‘grey exclamation point’ by all of the songs (because the actual files are still housed on the mini/external drive). Then, when I get back home and onto the home network, any changes I made to the itunes library (playcounts, playlists, etc.) would be mirrored back to the mini…and vice versa, if I happened to change the playlists on the mini…though I’m not so worried about changes from the mini being mirrored back to the MBP…that won’t happen all that often.

Problems:

  • I can’t get the damned itunes database file to mirror. I’ve tried foldershare to link folders between the two computers, and it *will* copy the itunes database over into each folder, but it loses some file information along the way: somehow, whenever it’s copied, the itunes database “turns into” a ‘unix executable file’, and is no longer recognized by itunes as a valid database file…I’ve looked at rsyncx (for about 15 minutes), but couldn’t figure out how to use it to do what I needed automatically.

Great question, Shawn. As you’ve found, this is much harder than it should be. I do have some tips you might try, but I never got all the way to a solution myself, and eventually settled with a one-way solution. I’ve posted everything I’ve discovered in the comments below. I’d love to keep this discussion going and see if we can’t find a way to get this done right…

9 responses so far

Sep 11 2007

Automagic

Published by Jonathan Wise under Code Snippets

Well my previous post on Symlinks was only partially right. It turns out iTunes doesn’t work very well when it has to share its library. If either computer decides it needs to write anything to the library database, it locks the other out. I had other problems with symlinking iCal’s database — it seems to keep a cache somewhere that I can’t find. So I had to resort to some AppleScripting — maybe the most elite AppleScript I’ve ever written. Here’s everything, some scripted, some not, that our computers do automatically for us…

Media Synchronization

TVShows, the amazing little OS X app, watches the Internets for shows we like and sends them to Transmission, my favorite BitTorrent client, to download. Transmission has a speed-limit in effect during the day so as not to disrupt normal Internet use, and ramps up to full speed after we go to bed.

My uber-script runs at 1:00am on the iMac. It starts by cleaning out the downloads folder, deleting any downloaded TV shows over 21 days old, then moves any downloaded music into the appropriate folder and adds it to the local iTunes library. Then it gets really clever, and logs into the remote Home Theater Mac over SSH and begins sending it instructions. It shuts down the remote iTunes, deletes its Library (which is a data island, because we do all our media maintenance on the iMac) and copies over the iMac’s iTunes Library. Note that it copies the Library only — the music remains on a network share that both computers have access to.
Then, once both iTunes are in sync, it starts up the remote iTunes which triggers a sync with my iPhone, getting me a playlist of my most recent music, plus my favorites (I only have a 4GB so I have to manage well) and does something similar locally to sync Nic’s iPod.

Both computers use the network shared Videos folder to populate FrontRow with our movies and TV content.

Calendar Synchronization

I failed to get WebDAV up and running on my new host, and Symlinks didn’t work out. But a wonderful and free service called iCalX came to the rescue. Microsoft finally added WebDAV publishing to Outlook 2007, so I publish my work calendar from there, my personal calendar syncs from my iPhone with the Home Theater Mac and from there to iCalX, and Nic publishes her calendar from the iMac. Any WebDAV client can subscribe to them and iCalX provides a nice little PHP iCalendar view online.

Address Book Synchronization

The OS X Address Book doesn’t complain too much about sharing its library between two computers, and provides little other utility for syncing or sharing (unless you want to pay $99 a year for .Mac — an otherwise useless service). I explored lots of options, but the only unattended one is Exchange syncing (or Kerio), and I don’t want to run a mail server any more. So I finally just decided to let Address Book share. The only caveat is that to make sure Address Book’s on multiple machines match up you have to quit Address Book to dump its in-memory cache and force it to re-read the database. It was easy enough to add some quit, open and hide commands to my uber-script, and that seems to solve the problem. Putting those commands in before each iTunes syncs with its connected portable device makes sure that both the iPhone and iPod have the latest contacts.

Nic’s cell phone is still a non-Apple device, but it syncs nicely over Bluetooth. A little app called Proximity detects when she comes into range of the Home Theater Mac, and fires a tiny AppleScript that does an automatic sync for her. A little blue light on her phone is the only indicator that its even happening.

Document Backup

This is actually another potentially useful service of .Mac, but I’m too cheap to be sold that easily. A really nice online service called Mozy provides free back-ups up to 2GB, and unlimited back-up for $5 a month (sign-up with that link and get me more free space!) We just eeked in under the 2GB mark backing up all our documents. This happens automatically every Sunday night at 1:00am, in place of the usual media sync.
I’ll be taking a semi-annual physical back-up of our document, music and pictures — pictures are copied between both Macs anyway. I have yet to figure out a way to back up 280GB of videos, save for having a second hard drive stored elsewhere, but I think, in case of a fire, we can live with only losing our movie collection.

Cleaning up

After either scheduled task (media sync or back-up, depending on the night of the week) the iMac goes to sleep until 9:00am, or until called for, while the Home Theater Mac studiously downloads things it thinks we might want to watch.

My script is likely pretty unique to our set-up, but I had to search long and hard to find the various parts that make it work — sending script instructions to a remote Mac over SSH was particularly tricky — so I’m posting it here for anyone who’s interested in picking it apart.

One other thing to be aware of, much of the script works against a shared drive, so it needs to be mounted for this to work. I use a little app called Automount Maker to get my media share to mount on boot, but its possible for the volume to get dismounted during the day (our microwave interferes with our wireless, for example, because there are so many wireless networks around, and that can kill the connection). I’d love to hear any ideas on how to make sure a volume stays mounted!

3 responses so far