April 14, 2008

YouTube Encoding: Locked & Reloaded

By Brian Gary

It's been just over a year since I wrote the "Encoding for YouTube Using Compressor" article for Ken's site and I first want to thank everyone from all parts of the world who sent in comments.

A considerable amount has changed with Internet media in the last year and not just with broadcasting video via YouTube. For example, the entire Flash Video landscape changed when Adobe announced the inclusion of H.264 in Flash Player 9. Now, you marry that with the YouTube/Apple announcement detailing the conversion of YouTube content to H.264 and you've got the ability to broadcast high quality video to computers, mobile devices, and television sets (via Apple TV). Wired magazine even wrote about this convergence last summer. Google is a key player here as well: a major player in fact. I mean, they own YouTube after all. So if you want to keep up with Google via an outsider's viewpoint as opposed to their own propaganda, you can visit this Blog.

If you recall, one of the core goals of my last article was how to deal with, or moreover, outwit the inherent drawbacks of Flash Video re-encoding on YouTube. Therefore the inclusion of H.264 significantly alters the compression strategy.

The changes and additions don't stop there though. Just within the last few months, YouTube has been delivering several platform advancements itself, most notably the inclusion of "High Quality" content streams. As you read in that YouTube Blog post, they are rolling this feature out, "and over time you'll find a greater percentage of the library is available to view in higher quality." So be on the lookout for the higher quality link below a movie...

One main tenet to acknowledge in this discussion is that YouTube is a free service. None of us have to pay to upload video and have it hosted. It's very easy to get caught up with all of these quality and distribution concepts and concerns and completely lose sight of the forest for all the trees. It's a massive undertaking at a considerable expense...just look at DivX's failed HD quality streaming service that just imploded under the sheer weight of bandwidth and demand. DivX is no slouch in any regard. They pretty much dominate PC based internet video and practically all torrent based video is DivX encoded. In fact, the same YouTube help page that I referenced a year ago, and is still up, outlines the "best" settings for encoding videos for the site as DivX MPEG-4 compression. That said, remember that all of us who choose to use YouTube for broadcasting content do so at the complete governance, re-encoding and whim of YouTube/Google with little to no recourse--they are, after all, offering both free storage and unlimited bandwidth. Which is exactly why I use a paid service like Box.net (or even my .Mac account) when I want to broadcast something that I need/want to have total control over.

That pretty much reacquaints us from our year sojourn from this topic, so let's take a look at harnessing these new and evolving features to achieve the best possible quality video on YouTube.

The first major improvement we'll cover is YouTube's exponential increase in upload file size from 100 megabytes to 1 gigabyte per file. Most of the issues that people had with the suggestions in my previous YouTube article were with longer videos that exceeded the 100mb limit when using Photo JPEG. The only solution when using that codec under those upper limit constraints was to decrease video quality. Well, now you can still try all of those methods from the previous article and you've got ten times the upload limit to work with. Remember the encoding maxim: The compromise between size versus quality. YouTube has just conceded a huge amount of file size in the bargain, so naturally quality can increase.

I have a Producer's account so my single uploads can utilize the full 1 gigabyte file limit but, as I'll say many times during this article, things are in flux at YouTube and by the time you read this, regular accounts may be able to upload single files in excess of 100 mb too. And then again, some accounts may continue to be limited to 100 mb files. One thing that seems to be fairly standard now is the ten-minute time limit for movies...except for those accounts that previously could upload movies with durations greater than ten minutes: and that too may change. Who knows?

It's here where you just throw up your hands and realize that you get what you pay for with YouTube. It's true, they can do whatever they want. Period. In fact, in all of my research for the first and now this second article on YouTube, it's apparent that YouTube doesn't really want anybody to know what they are doing behind the scenes. Sure, they post items to their blog that have some information and oblique references to what they are doing, but very little in the how they're doing it department. Mostly I had to troll the web, experiment and just plain stumble across things to figure out the best angle of approach, because even the posts that I referenced above are rather cryptic.

So, to figure out what's going on, you have to go outside the corporate bandwidth and start hacking away at the problem. You can also look to fellow users for ideas. For example, Charles Trippy has postings, a website, and videos that talk about, "YouTube now in HD." It's really not HD, but compared to what it was it sure looks like it. Then there are the hardcore tech sites like VideoHelp.com --which by the way is a treasure trove of all things Digital Video and, that if you only get one thing from these YouTube articles, I hope it's an awareness of this resource. The encoding spelunkers on this site dive deep into the caverns of Blu-Ray encoding, HDV, restoration, compression, conversion, and of course encoding for YouTube. The thread, "YouTube offering higher quality video / Stage6 ends services!" provided both a spirited debate and some really great sleuthing by posters like bayme, Denizzje, reez, and wonderpierrot. So go to VideoHelp, sign up and join the fray.

But I digress...

Back to uploading your videos: as I said before, you should have the ability to upload movies that are ten minutes or less in duration and one gigabyte or less in file size.


As you can see, you can upload single videos directly from your account page. You can also upload directly from your phone by setting your mobile preferences.

But let's say you want to upload several movies at once. YouTube now has a multi-file uploader, which they also say is for "files over 100mb in size," but as you can see from the picture above, my account lets me upload single files greater than 100mb. The huge downside of the uploader is that it only works on PCs. I have Parallels Desktop on my Mac that's running Windows XP Pro. You can also use Fusion or set up Boot Camp to get a PC inside your Intel based Mac. The following screenshots are from Firefox running in Parallels:

Log in to your account on the PC and click the Multi-Video uploader button.

Install the Windows Uploader.

From there you can just add files with the required metadata then upload as a batch. Remember: each movie must be less than ten minutes in duration and less than one gigabyte in size.

**Newsflash** YouTube now has a Mac version of the multi-uploader. Just login on a Mac and click the same Install Uploader button. A DMG will download and then run the YouTube Installer. In the end you'll see this window:

On the Mac side, the uploader is installed as one of the Google apps, but behaves and works just like the PC version above.

Now, let's shift gears toward quality. What's the mojo, what's the magic configuration that will unlock the secrets of this new, high quality video? For starters, you and your intended audience need to have the latest Adobe Flash Player installed because YouTube's new high quality video harnesses this new player and, in fact, it won't work correctly on the audience side without it.

In terms of encoding the video, here's what seems to work best on a Mac:

Codec: H.264
Frame Size: 640x480 (Note the 4:3 aspect ratio)
Frame Rate: 30 fps Progressive (you can also use 24fps or 25fps Progressive)
Audio: AAC, 44.1kHz, 128bps (mono or stereo)

If you're on a PC:
Codec: Windows Media 9 Standard
Coding: 2PassVBR @ 1000kbps
Quality: 80 (more towards sharper than smoother)
Frame Size: 640x480
Frame Rate: 30 fps Progressive (you can also use 24fps or 25fps Progressive)
Audio: WMA 9, 44.1kHz, 128bps

You'll notice that I left out bitrate on the H.264 encoding because I want to cover that more in depth. In Compressor, create a new custom QuickTime movie setting by clicking the Plus Sign pop-up menu in the Settings window and choosing QuickTime Export Components from the list.

With the new setting loaded into the Inspector window click the "Settings" button next to Video:

Set the Compression type to H.264, the Frame Rate to 30 (or 24 or 25). Remember, the goal is to deliver progressive frame video, not interlaced because we're primarily delivering to computers and not to television sets (I say "primarily" because you could be delivering to televisions via Apple TV). Set the Key Frames to "Automatic" and select "Frame Reordering." Now, here's the key: set the Data Rate to "Automatic." Notice that the Compressor slider undims. Set the slider to either High or Best. You'll be hard pressed to chew through one gigabyte of data with a video duration limit of 10 minutes when the slider is set to High. You'll be pushing things though if you set it to Best. For me, I just set it at "High" because I don't feel like uploading massive files to YouTube, especially when I get basically the same quality (for my eyes) as I do with "Best." Lastly, set the encoding option to "Multi-pass" for better encoding but longer encode times, or set it to "Single," for faster encoding at a lower overall quality.

So what's happening here? You're allowing the H.264 encoder to dynamically set the data rate based on the type of source media you're encoding. The Quality slider guides the encoder to either focus on overall quality (High and Best), small output file size (Least and Low) or a compromise between the two (Medium). This, along with automatic key frame placement creates very targeted movies based on the slider setting. In my tests, I've found that the High settings average around 100 mb per minute of video, but can vary greatly depending on the content.

Here are a few more tricks and tweaks to the Compressor setting that I've found add to the overall quality of the output movie:

After clicking the "Settings" button next to Audio, follow this example for the encoding options:

Turn Frame Controls on to employ optical flow for the deinterlacing and frame rate conversion:

A couple of things to note here: first set the Output Fields to "Progressive" and the Deinterlace option to "Better." Now here's the trick: since this movie is bound for computer display, un-check the "Adaptive Details" option. This lets Compressor harness the same fast processing algorithms that DVD Player uses to deinterlace DVD movie playback on the fly. You'll achieve significantly faster encoding times with Adaptive Details turned off.

Lastly, in the Geometry pane set the output frame size and the Pixel Aspect:

If you go to the Flying Chaucer Films channel you'll see I've got two drag racing movies: one was encoded with Windows Media 9 using Flip4Mac in Compressor as a QuickTime Component:

The second movie was encoded with the above H.264 settings.

Now here's where it starts becoming pretty erratic in terms of the audience. We've already covered the fact that in order to watch the new high quality movies, you have to have the latest Flash Player. But it doesn't stop there. By the time you read this article you may or may not see the high quality option at the bottom of those drag racing movies on my channel:


If you click that link (if it's actually there) you get the HQ version of the movie:


You may alternately see the following interface with a small monitor icon below the player skin.

Hovering over the icon displays a pop-up menu that lets you "Change" the video quality from "Standard" to "High."

Just look at the two screen grabs and you can see a marked improvement in the video. But the real juice flows when you start analyzing the media that YouTube is pushing through the Flash Player. Now stand back my Mac brothers and sisters, as I wizard some shadizzle on the PC...but fear not, the Mac is just a command-tab away thanks to Parallels. (And for any PC users reading this...you're probably unimpressed, but slide a Mac Monk his props for trying!)

First we've got to grab the stream and for that, Firefox on the PC does the trick. Go to the page and let the high quality stream fully load in the flash player. Then in the URL field type, "about:cache."

You'll see a whole series of entries, but you're looking for the one that is large in size and is coming from "vp.video.1.google..." Click the link to open the entry:

Right click on the entry and choose "Open link in new tab." It doesn't actually open the link. Instead, Firefox presents a window to save the MP4 video file:

Save the video file and then open it up in MediaInfo. There are Mac apps like MediaInfo Mac that will do pretty much the same thing.

So, what are we looking for? Why bother? Well, to be frank, you don't have to go through this detective work at all...ever. But what it does divulge is that H.264 has finally won the day over Flash Video--at least on YouTube. Notice that the codec is AVC, which is another name for H.264. You can also see that YouTube has upped the total bit rate to around 600 (up from 350) and that they are delivering progressive frames at 480x360. The audio is AAC, 44.1 at 118kbps and it's stereo. From what I've been able to uncover it seems that, no matter what, YouTube is going to re-encode the video. There were encoding methods for Flash video that would bypass the YouTube encoders altogether, but those avenues are pretty much moot at this point because Flash Video is on the way out. Therefore it seems like either PhotoJPEG (for an all "I" frame strategy) or H.264 as outlined above are the ways to go.

Let's cover a few more things before wrapping up. The YouTube re-encoders only deal with 4:3 aspect ratios and will scale any other aspect ratio into that frame. Meaning, if you've got a 16:9 movie, you'll need to manually letterbox it to maintain aspect; otherwise the YouTube encoder will squish and scale into the 4:3 frame. Fortunately, if you're using Compressor there's an easy fix: just add a Letterbox filter from the Filters pane and make sure you choose "Scale" from the Type pop-up menu.

Here's an HDV clip in Compressor's Preview window with the YouTube custom preset (outlined above) applied that also includes the Letterbox filter:

As you can see you are delivering a 4:3 frame, but maintaining aspect ratio much like a DVD would by letterboxing a feature film when played on a Standard Definition television set.

You may still be wondering why I mentioned above, that you may or may not see the high quality link next to your movies. Well, that's because as YouTube is rolling out this feature it really seems hit or miss whether or not a movie gets "blessed" or, more accurately, when a movie gets blessed. My assumption is that they are load testing/balancing this new feature as opposed to just flipping the switch on.

For example you may go to a YouTube page and it still looks like this:

This page is displaying only the low-resolution movie with no option for a high quality version. The good news is that you can force the high resolution media by adding some simple code to the URL...


Therefore, for this drag racing movie instead of just this URL:


You would type this URL:


As of this writing, this additional code seems to force the high quality in about 90% of the cases where the high quality option link is absent. You can also try:


Which seems to produce a mono version of the high quality stream.

What if you want to imbed the YouTube Flash Player on another site, your homepage for example? Very simple: just add the following code to your page:

<object width="480" height="397"><param name="movie" value="http://www.youtube.com/v/XclhUJ3-JBU&ap=%2526fmt%3D18"></param><param name="wmode" value="window"></param><embed src="http://www.youtube.com/v/XclhUJ3-JBU&ap=%2526fmt%3D18" type="application/x-shockwave-flash" wmode="window" width="480" height="397"></embed></object>

Just swap out the red highlighted code with your movie URL. And how do you know what that is? Easy: it's right there in the address bar:

<A HREF = "http://www.youtube.com/watch?v=XclhUJ3-JBU&fmt=18">

The code will embed the player on your page:

Notice the YouTube watermark.

When the movie finishes, the Flash Player becomes even more branded, but also quite interactive:

And as with the YouTube site, embedded players require the latest version of the Flash Player to work properly.

Lastly, YouTube has added some pretty cool analytic tools that display metrics for your uploaded content. Log into your account page and click "Videos, Favorites & Playlists."

Click "About This Video" next to one of your movies. The following page will display both hits and countries of audience origin:

The cutting edge of anything draws its portion of blood, and the almost clandestine operation of attempting to second guess the engineers of YouTube/Google Video falls into that intrigue...just lurk around the VideoHelp.com forums and you'll see both the jocular jibes and the white knuckled keyboard tirades on the subject. But I still come back to the same point I made earlier: YouTube is a free service and they can do whatever they want. Therefore, as a content provider, if I have media that I want displayed in a certain way or at a certain quality or with a certain level of security, then I'll pay for a service that provides me with that level of freedom. If I want a better Flash experience, one that's not branded by YouTube, then I'll create my own and I'll host it myself. Understanding what YouTube is, realizing its niche in a distribution plan (or just for fun) is the key to maximizing the experience and simultaneously reducing the frustration--the inevitable "why do my YouTube movies suck? How can I make them un-suck?" Hopefully, again, with this article I've not just proffered a recipe to copy verbatim, but rather presented some tools and ways to examine an encoding situation so that when YouTube changes again--and they most assuredly will--you'll be better suited to roll with the tide.

YouTube, like the rest of the Internet, is evolving and I'm sure the folks at Google, the proud owners of YouTube, have great plans for the distribution service. And that's generally good for everyone trying to widely distribute content for free. It's just too bad that most of it is more pabulum than provocative, but then again what's not to enjoy (albeit guiltily) in a good old-fashioned skateboarding face-plant, or a tear-filled Leave Brittany Alone! rant. So, what's popular right now as I'm writing at 2:00 AM...Feline Fear Factor? Obama Girl? Chocolate Rain? Nope, Evolution of Dance 80 million views and counting.


YouTube HQ setting for Compressor 3.0.2 or higher

You can download this Compressor YouTube HQ Preset. Install this preset in:
~/Library/Application Support/Compressor

This setting will appear in the Custom folder of the Settings window.

Because this Compressor Preset is licensed free of charge there is NO WARRANTY for the Preset, to the extent permitted by applicable law. Except when otherwise stated in writing the copyright holders and/or other parties provide this Compressor Preset "AS IS" without warranty of any kind, either expressed or implied, including, but not limited to, the implied warranties of merchantability and fitness for a particular purpose. The entire risk as to the quality and performance of this Preset is with YOU. Should the Preset prove defective, you assume the cost of all necessary servicing repair or correction.

Award-winning director, writer, and producer, Brian Gary heads Flying Chaucer Films LLC in Los Angeles. Under that shingle, Gary has directed commercials for clients such as Verizon, Lucky Brand Jeans and Dow Jones./Reuters; independent feature films; television; and new media content. As a film producer, Gary's involvement includes independent fare like LOCAL COLOR and major release features like CLANDESTINE (the prequel to L.A. CONFIDENTIAL). He also actively produces content for television, video and the Internet. Rounding out Gary's multi-hyphenate approach to filmmaking is accomplished editor, where he has cut independent feature films, cable television shows for networks such as ESPN, commercial, industrial and new media/ interactive content. Also, in that vein, Brian Gary is a published author with the Apple Certified texts on Compressor and QuickTime and he produces Compressor related training content for Steve Martin's Ripple Training.


copyright © www.kenstone.net 2008

© 2000 -2008 Ken Stone. All rights reserved. Apple, the Apple logo, Final Cut Pro, Macintosh and Power Mac
are either registered trademarks or trademarks of Apple. Other company and product names may be trademarks of their respective owners.

All screen captures, images, and textual references are the property and trademark of their creators/owners/publishers.