Discreet Cosine Transform

A few thoughts on ruby, video and other things

Scaling Video for Widescreen DVDs

There are lots of reasons you might be burning your own DVD video today - your vacation footage, a project at work, or archiving some of your favorite shorts from the internet. If you are coming from a background in computers and computer graphics, or are simply new to video, you might find some of the aspects (pun intended) of video a little confusing - it often does not work like traditional computer graphics. I thought I would share some specific math you need if you are working with widescreen (also called 16:9 aspect ratio) DVDs. If you are creating menus and titles, trying to burn a video you downloaded in a computer format (such as Windows Media), or want to create custom curtains (more on what that means later) for your video, you have to do a little mathematical acrobatics to make your DVD come out right.

Non-Square Pixels

So why is video hard for people that have worked all their lives with computer graphics? Because all us computer geeks grew up thinking pixels were always square, and in standard-definition video, they are not. Luckily, that has all been fixed in high-definition video. But, for everyone out there eager to burn their own DVDs, standard-definition video is still an important format. So what is a non-square pixel?

Just as it sounds, a non-square pixel is longer than it is tall. Or, viewed another way, the image has more resolution in its vertical axis than in its horizontal axis (when thought of as pixels-per-inch, for example). The ratio of pixel resolution in one axis compared to the other is called Pixel Aspect Ratio, or PAR. If you search around on the web you will find several explanations of PAR and why it exists in standard-definition video. I would like to focus on the proper scaling for widescreen DVDs however, so I will leave the background story out of this post.

Anamorphic DVDs

The original DVD specification dictates that a DVD can only hold 720 x 480 resolution video (for NTSC). However, using anamorphic widescreen, a DVD can still hold a widescreen (16:9 aspect ratio) picture. The anamorphic picture is compressed, horizontally, into 720 pixels across, then stretched back out by the display when played. This makes its PAR a little different than the PAR of a traditional 4:3 video, since in traditional 4:3 the pixels are shrunk down, meaning the PAR usually reduces the stated horizontal resolution. However, with anamorphic widescreen, the PAR actually stretches the resolution.

This is all a lot easier to understand when you are actually looking at the math, so let’s look at that.

The Math

Traditional 4:3 aspect ratio video, when displayed as square pixels (PAR 1:1), is 640 x 480. It is easy to tell that this video is truly 4:3, as 640/480 (640 divided by 480) = 1.33333, and 4 divided by 3 is 1.33333 as well.

So what aspect ratio is traditional video if its resolution is 720 x 480? 720/480 = 1.5, so you might think it is 3:2 video, but of course it is not, it is 4:3 video. How is that possible? Because its PAR is not 1:1, like square pixels. Traditional video has a PAR of 1125:1000, or 1.125. You won’t see the PAR stated this way very often though, more often the two axis are reversed, so you will see it stated as 1000:1125, or more commonly 0.88888 (or even 0.9, which is the rounded figure). What this means is that for every unit of resolution that a vertical line occupies, the same horizontal line occupies 1.125 times as much space. Look at this a simpler way though: (720 x 1000) / 1125 = 640, which is the same as saying 720 x 0.88888 = 640. In other words, 720 x 480 is really the same resolution video as 640 x 480, but its pixels are not square, they are long rectangles that take up more horizontal space than vertical.

Some video is 704 x 480, and this works exactly the same way, it just has a slightly different PAR, of 11:10 or again stated the more common way, 0.909090. Again, this is really 640 x 480 video, just stored using pixels that are wider than they are tall.

So, for 4:3 aspect ratio video, the PAR reduces the stated resolution. For anamorphic widescreen though, it works the other direction, stretching video to fill a 16:9 space.

Before we start the math for 16:9 video though, I need to explain one more complexity. There is no exact resolution, using 480 vertical lines, that is exactly 16:9. As you might guess, this doesn’t make all video hardware happy. Using 486 lines of vertical resolution though, there is. 720 x 486 is a valid resolution for standard-definition video. So what is the difference between 720 x 486 and 720 x 480? Absolutely nothing. Analog standard-definition video actually has more vertical lines of resolution that either of these statements, but much of it is black or contains data not intended for viewing (this area is called the blanking area). When you turn analog video into digital video, you can choose to keep or throw-away this blanking area, and different digital formats over the years have made different decisions regarding it. Jump ahead to MPEG 2, the compression algorithm used on DVDs, and you find that the algorithm itself requires heights and widths that are divisible by 16, because it looks at 16 x 16 chunks of the video to do its compression. So when working with MPEG 2, we are always working with 480, which is divisible by 16, and not 486, which is not. The 6 lines difference is insignificant - because of traditional blanking area, no display (except special professional displays capable of under scanning) actually displays beyond 480 lines, and most display even less than that. This slight difference of how much of the image really gets shown on the display is why we have title safe areas in video, another topic you will find plenty of information about online. The bottom line, the math below ends up with a few remainders and exceptions due to this slight discrepancy between 480 and 486, but I think you will follow it with no problem.

So what is the resolution of standard-definition widescreen video? The best number to use is 864 x 486, which is exactly 16:9 (864 x 486 = 1.77777 and 16/9 = 1.77777). This resolution, if displayed completely pixel for pixel, is sometimes called EDTV. So in anamorphic video, you are stretching the 720 pixels of stored resolution to make 864. To do this, you stretch each pixel by 1.2. 720 x 486 stretched by exactly 1.2 times is 864 x 486, as you can see: 720 x 1.2 = 864. Remember however, DVDs specify 480 vertical resolution video - so, DVDs use 480 which throws off this math just a bit. But, in almost all programs you work with, you will still see widescreen anamorphic PAR stated as 1.2.

So lets review the final math:

Standard Definition 4:3 640/480 = 1.33333 or 4:3 (720 x 1000) / 1125 = 640 720 x 0.88888 = 640

Standard Definition 16:9 864/486 = 1.777 or 16:9 720 x 1.2 = 864 pixels

Working With a 1.2 PAR

Great, so what does all that have to do with you? Well, let’s say you are designing a title for your widescreen DVD. You go look up the resolution of a widescreen DVD and find that it is 720 x 480, so great, you make your title in Photoshop, Paint Shop Pro, or another program and make it 720 x 480. You import that into your DVD software and burn the disc, but when you play it, the font looks stretched out and more squat than it did on your computer screen. Well, now you can see exactly why - your program did not compensate for PAR, and so it just stored the 720 x 480 image you provided it. However, on the DVD disc, it marked the right flags to tell the player this is widescreen material, so the player and your TV stretched the image by 1.2 times and now it looks squat and stretched out.

So how do you fix that? Well, the answer varies slightly depending on what programs you are using, depending on in if your program understands PAR or not. I will warn you upfront, very few programs do, but some pro and pro-sumer tools do, such as the latest version of Photoshop and Adobe Encore.

Let’s start with the more common scenario, your graphics program has no idea what PAR is, and your DVD burner just knows how to mark the widescreen flag on your DVD, not correct your images for you.

Programs That Do Not Understand PAR

If your program does not understand PAR, you have to compensate for this yourself. The easiest way to do that is to simply work in a 16:9 aspect ratio, then as a last step use the resize function in your graphics program to “squish” your image.

For example, you might make a graphic that is 864 x 480, placing all the type and graphics you want just as they will appear. Then, when you are ready to save this image for use in your DVD program, go to your graphic program’s resize function and resize the image to 720 x 480. You will often have to disable any constrained proportions check to do this, as you are literally squishing the image, you are discarding some pixel data to do this. This can seem confusing to graphics professionals, who are used to preserving all the resolution of an image they can, but video is simply a less precise world. Your image should now look squished the other way, that is, fonts should look too skinny.

Now, import this image to your DVD program and burn it as a widescreen image. When played back on a widescreen display, you should see the fonts and other shapes exactly as you prepared them, restored to their proportional size. The image has been re-stretched and that removes the skinniness you see when viewing the image before the PAR is applied.

Programs That Do Understand PAR

A few programs though do understand PAR, for example, Photoshop CS 2. It has a Pixel Aspect Ratio submenu under the Image menu. When you select the Anamorphic Widescreen PAR (1.2), it displays the image as 864 x 720 pixels, even though under the hood it knows there are only 720 pixels across. This can be confusing, specifically in Photoshop, for example if you have a pixel ruler enabled on the image. PS will still show the horizontal pixels as 720, even though on your monitor it is using 853 pixels to display the image.

This feature makes for an easy way to see PAR in action though. Start an image, set to 720 x 480, and tell PS it is an Anamorphic Widescreen image. Next, use one of PS’s drawing tools, like the circle or font tool. Draw on the image, then change its PAR back to Square Pixels (1:1). Before your eyes the shape or letter will get skinny - Photoshop has really only drawn the appropriate number of pixels underneath, even though it displays more to you when you have the PAR turned on. You can prepare your whole graphic this way, then save out the 720 x 480 image for import into your DVD program.

640 x 480 Video and Anamorphic PAR

One last trick you may find a need to do is render video that contains curtains - the black or grey bars on the left or right that frame a 4:3 image into a 16:9 area (the opposite of letterboxing). Usually, you just let your TV draw the curtains, and you can probably just burn your DVD as a 4:3 DVD and do just that, if you have 4:3 video but a 16:9 display. But sometimes you want to customize the curtains, for example inserting a logo or other graphic into the curtain (as you see sometimes on HDTV channels when they are showing 4:3 footage). Here again, you have either use a program that understands PAR, or compensate for PAR yourself. More likely, you need to compensate for PAR yourself.

So how wide should your 640 x 480 video be in the 720 x 480 frame? And how wide should each curtain be? Before you understood PAR, you might have just placed the 640 x 480 video into a 720 x 480 project, for example in After Effects, and thought that covered things. Now we see though that this video will get stretched, just like your font in the example of creating a graphic for your DVD, above. The 640 video will actually get displayed as about 768 pixels in the 864 x 486 space, which is incorrect, because really the video should be 640. To make the video 640, even after the PAR is applied, you again need to shrink it horizontally.

640 / 1.2 = 533.3333 pixels, so you have to squeeze your video into 533 x 480, when placed in a 720 x 480 project. This leaves 167 pixels to split between your two curtains, or about 93 pixels for each curtain. However, once displayed properly, these curtains wil expand to about 111 pixels each. The 533 video will expand to 640, and so 640 + 111 + 111 = 862 (again, there is some rounding inaccuracy here) which is what we are after.

So squeeze your video to 533, and if you are designing a custom curtain, start with a 111 x 480 image and then resize it to 93 x 480 image prior to placing it on either side of the 533 video.

A Note on HD

You may also be upscaling a standard definition video to be displayed in HD, for example, 720p or 1080i, with custom curtains. Here though, things get easier, since as I mentioned, HD throws away the non-square pixel idea and uses just square pixels. So, for example, 720p is 1280 x 720 and is actually stored as exactly that, no funny math required. If you are scaling your video to be in the center of this space, scale your 640 x 480 video up to 720 vertical resolution, keeping the aspect ratio, so 480 x 1.5 = 720 and 640 x 1.5 = 960. This new, 960 x 720 video is what you would place on your 1280 x 720 workspace, thus giving you two curtains of 160 x 720 each.

Conclusion

This post doesn’t tackle the reasons why SD video uses pixels that aren’t square, but hopefully it provides concrete enough math examples for you to have success with your project when working with anamorphic widescreen DVDs.