The Shape of Days

A whimsical assortment of things that totally jack my shit


Blog

Wednesday, May 11, 2005, 2:15 pm

A demonstration of H.264 encoding

First things first: If you don’t have a Mac with QuickTime 7, this post will not be interesting to you. I’m sorry about that, but until Apple ships QuickTime 7 for Windows (any day now, they say), you Windows users are just gonna have to wait. Don’t blame me; not my call. Complain to Apple for leaving you out in the cold … the way Windows-oriented companies have historically left Mac users out in the cold for the past twenty years. Heh.

I’ve written about H.264 twice previously, here and here. My take on the subject has been … well, “gushing” wouldn’t be too strong a word. I really like H.264. I like it a lot.

For those of you who are new to the party, H.264 is the latest MPEG compression standard. Once upon a time there was MPEG, then came MPEG-2. MPEG-2 is used today in standard- and high-definition digital television and in DVDs. There was going to be an MPEG-3, but the people who were working on MPEG-3 decided to just extend MPEG-2 instead, so MPEG-3 never happened. What came next was MPEG-4, and the latest addition to MPEG-4 is a compression algorithm called H.264. It’s also known as AVC for “Advanced Video Coding.” Both names stink, but at least H.264 isn’t yet another three-letter acronym.

Each compression algorithm that’s come down the pike has been incrementally better than the ones that came before it. We’re kind of in the dark ages when it comes to this kind of stuff. We’re still figuring out how to do it. So it makes sense that what we have today should be a little bit better than what we had yesterday.

But H.264 isn’t a little bit better than the other compression algorithms out there. It’s not incrementally better. It’s dramatically better. It’s a whole world better. It’s really mind-blowing.

What I’m gonna do here is show you a side-by-side comparison of two pieces of video encoded from the same source, one encoded with the industry-standard Sorenson 3 codec and the other with H.264. The difference is gonna blow you away.

First, the source. I wrote back in March about the project I did over a weekend just for the fun of it. I took footage from the DVD release of Star Wars and music from the soundtrack album and created a little movie trailer. The total length of the piece is one minute and seventeen seconds. The MPEG-2 source material on the DVD was converted to 4:2:2 video, edited, then encoded for delivery via the Web. If you didn’t follow the jargon there, suffice it to say that this video is pretty clean. It was DVD-quality right up to the point where I clicked the “encode” button to turn it into the samples you see here. So whatever artifacts or imperfections you see are almost certain to be a result of the encoding, rather than junk that was in the source material.

The Sorenson 3 version of this video was created back in March using a piece of software called Cleaner with the Sorenson 3 Pro two-pass codec. I set the bit rate to something suitable for delivery over broadband Internet: one megabit per second. In order to get decent picture quality, I scaled the video down to 480 pixels wide by 204 pixels high. With the audio, the data rate of the movie came out to be 1,022 kilobits per second, or just about exactly one megabit per second. The finished clip was about nine and a half megabytes.

Here’s the result. Click to play.

As you can see, this clip looks pretty darned good. There’s an awful picture break-up when the FOX studio logo is fading in between 00:00:02.22 and 00:00:02.25 — dissolves are really tough for the Sorenson codec to handle — but other than that, it’s pretty clean. In particular, notice the part of the clip between 00:00:31.29 and 00:00:33.27 where Luke Skywalker and Princess Leia are swinging across the Death Star chasm. Shots where the background moves rapidly are really hard for most codecs to deal with. Sorenson 3 acquits itself admirably. It’s the industry standard for near-broadcast-quality Web video for a reason.

What you’re going to see next, you will not believe. I created the darned thing, and I don’t believe it myself.

The first thing you’ll notice about this next clip is that it’s bigger. A lot bigger. At a size of 850 by 366 pixels, this second clip has more than three times the resolution of the first clip. This isn’t near-broadcast-quality, either. It’s actual broadcast quality. A widescreen standard-definition TV picture is 850 pixels across by 480 pixels down. This clip has a wider, more cinematic aspect ratio as is common to movie trailers, so if it aired on TV the top and bottom would be filled out by black bars — ”letterboxing,” in industry jargon. This clip is the correct resolution, minus the letterboxing, to be broadcast on standard-definition television.

When you increase the resolution by a factor of three, it’s common practice to increase the bit rate of the encoded file by a factor of three. So rather than this being a one-megabit-per-second clip, it’s gotta be a three-megabit-per-second clip, right?

Wrong. This clip, this one you see right here at broadcast resolution, is encoded at 768 kilobits per second. With audio — which you’ll notice sounds substantially better since I used the MPEG-4 AAC audio encoder — it comes to exactly 980 kilobits per second, or just hair over nine megabytes total. Yeah, I know. This file is bigger and smaller than the other clip. More pixels, fewer bits used to describe them. And check out the quality. Again, click to play.

Yes, there are places where, if you look for it, you can clearly see the evidence of compression. Pretty much any time there’s a foreground object (like droids) in front of a monotone background (like sand), you can see evidence of compression in the background. If I wanted to get rid of that, I could take the bit rate up to one megabit, or maybe even one-and-a-half megabits, and that mild distortion would disappear. In this case, the artifacts are so minor that I’m happy to live with them in return for having a really amazingly small file on my Web server.

Let’s sum this little exercise up, shall we? The H.264 codec blows the doors off of the previously best-in-class Sorenson 3 codec. It doesn’t improve on it incrementally. It leaves it completely in the dust.

There’s a trade-off, of course. You don’t get this amazing new codec for free. You have to pay for it with time. It took about two minutes to encode my first clip, the Sorenson 3 clip. To encode the second clip, the H.264 one, took more than half an hour. It’d be significantly faster on a G5, of course, but whatever computer you use, it’s going to take a lot longer to encode with H.264 than it takes to encode with anything else. If you want your clips to both look good and be small, you’re going to have to wait for them.

Of course, most people won’t encode that much video. Instead, they’ll just play back video that others have encoded previously. To those folks, H.264 is a huge leap forward.

Update

O’Reilly’s Chris Adamson also puts H.264 through its paces with an emphasis on lower-bit-rate video, a megabit and under. Check out his article. (The H.264 stuff is on page two.)


Posts that might or might not be related to this one

Comments


  1. […] The Shape of Days: A demonstration of H.264 encoding How to encode H.264 video. (tags: codecs video) […]

    links for 2007-08-18 at Chris Dalby Untangles Networks

    Saturday, August 18th, 2007, 7:30 pm


  2. […] while reducing the bandwidth requirement by an order of magnitude, as exemplified by encoding the same video clip twice. This has made H.264 very popular, initially with mobile phones for very low bandwidth video, but […]

    .:bac:. Bulletin "Tech Savvy News" - Page 61 - bac-Community Forum

    Tuesday, August 21st, 2007, 11:14 am


  3. […] iPod touch and the iPhone offer 480×320 — so twice as many usable pixels — with H.264 support. I expect quality to be three times as good as what I currently […]

    Extra Pepperoni » iPod touch ordered

    Thursday, September 6th, 2007, 12:58 am


  4. […] square, so 1/4 of the Treo’s pixels are completely unused for video) — with H.264 support. I expect quality to be three times as good as what I currently […]

    Extra Pepperoni » iPod touch ordered

    Monday, September 10th, 2007, 12:41 am


  5. […] then turned my attention to H.264 in the search for better quality at lower file sizes, having decided that Vimeo, rather than […]

    Vista’s Video Nasties #2 « Hasta la vista, Vista!

    Friday, November 16th, 2007, 6:45 am


  6. [If you’re going to spam my blog with your advertising, at least go to the trouble of checking your spelling. It’s “artifact,” you moron. —J.]

    Kevin Lichtman

    Wednesday, November 21st, 2007, 8:20 am


  7. […] can be done via compressor in Final Cut Studio 2 or in Quicktime Pro 7. Some say that the H.264 is dramatically better than the previous best, Sorenson Video 3 codec, however, […]

    Best video compression format « Hongwei Yu’s Weblog

    Friday, November 30th, 2007, 12:58 pm


  8. Hi I need advice to help me make better quality dvd’.

    After i export my timeline into a quicktime movie of lets say 8GB, the quality is good. but once i write it to dvd the quality drops allot. this happens to my dvd’ that include menu’s and those that don’t have menu’s.

    Please could you help me on this. THANK YOU!!! Rudi

    rudi

    Tuesday, April 1st, 2008, 3:29 am


  9. you can email advice to dirk@dmcp.co.za

    rudi

    Tuesday, April 1st, 2008, 3:30 am


  10. Reading this rather late in the day, but really, the last comments sort of make it clear (or more clear) why Robert X. Cringely’s recent speculations (http://www.pbs.org/cringely/pulpit/2008/pulpit_20080801_005339.html) about Apple regearing to add hardware-based H.264 encoding to new machines (including those at the low end) is such a priority — and probably a very smart business move for Apple.

    Right now I’m using what was a month ago a nearly top of the line HP machine and Vegas Pro 8 for encoding. While it could probably render the clips above in a matter of a few minutes now, software-based encoding IS very demanding on a machine and it pretty much still demands that you shut down all other processes whenever it comes time to render even the most trivial few minutes of video.

    Hopefully, though, other computer-makers will soon be compelled to follow suit as well.

    Saroyan

    Wednesday, August 6th, 2008, 3:07 pm


Post a comment


Sidebar

Buy my book

The Glacier with Her Name Carved in It
and Other Stories

On sale now

Subscribe

Subscribe to my feed

Search

Tip Jar

This site does not accept advertising.
Please show your support
by sending me all your money.

The fine print

Copyright © 2000-2008
by Jeff Harrell except where noted.

Colophon