Encoding videos for high definition screens

back arrow icon

assembly date

2007, September 7.

author(s)

Balla Krisztián

keywords

  • video
  • math
  • multimedia applications

The trend of achieving a higher and higher resolution in video entertainment is up to this writing still active. The term "high definition" or simply high-def got a new hype since another media is about to enter our homes. You guessed it, those are the "HD DVD" and "Blue-ray Dics" discs.

So in the future we are going to gain the possibilty to watch movies in an even higher resolution than the resolution the DVD is offering us (720x576 for PAL and 720x480 for NTSC). Probably new aspect ratios are going to appear extending the already confusing list of available aspect ratios. But since HD DVD and Blue-ray Disc are no standard yet, because the standardization war is up to this writing still going on, this article is going to focus on high definition video encoding of DVDs.

The DVD uses the MPEG-2 video codec for storing video data. Officially a DVD disc can contain video data with a display aspect ratio of 4:3 (used by old low definition screens) and 16:9 (used by newer high definition screens) as written in this text about DVD MPEG-2 aspect ratios. If you are asking yourself now: "But how 4:3 and 16:9? PAL 720x576 is not 4:3 and neither is it 16:9." this article is going to help you out for sure. But before we are going to focus on some more technical stuff, let's do some definitions to have a clear point of view what we are talking about.

PAL and NTSC
These are television system standards. They for instance define the resolution and framerate a television signal or input must have in order to be compatible with television devices. PAL stands for "Phase Alternating Line" and is widely used in Europe and South Asia. NTSC stands for "National Television System Comitee" and is mainly used in Northern America. PAL usually requires for a high resolution but a lower framerate than NTSC. There are also other television system standards like SECAM that is used in Russia and several parts of Africa. Take a look at this picture showing the television system standards used around the world to find out which standard is used in your country.
resolution aspect ratio
The resolution aspect ratio defines the ratio between the width and the height of the video signal´s image. 1:1 would mean that the video is as wide as tall. This could be a resolution of 300x300 or 1820x1820 or whatsoever. Note that the aspect ratio thus doesn´t tell you anything about the resolution of the video data.
display aspect ratio
The display aspect ratio defines the ratio between the width and the height that is used to display the video input. Common display aspect ratios are 4:3 (= 1,3333:1) and 16:9 (= 1,7777:1). They are usually equal to the width and height ratio of your television screen. This information tells you how the video images that are sent to the television device are stretched.
pixel aspect ratio
This is where things get complicated. The AVI container format allows only codecs that use square pixels (like used on the monitor you are reading this page now) which means a pixel aspect ratio of 1:1. Other standards like MPEG-1 and MPEG-2 allow any kind of pixel aspect ratio. This means that the pixels doesn´t have to be squares. Since most of the videos are encoded with XviD or other codecs inside an AVI container to reduce their size before they are burned onto a DVD, this article is going to ignore the pixel aspect ratio. If you want to encode a 16:9 video from a video which is already in the MPEG-1 or MPEG-2 format you must pay attention to the pixel aspect ratio as well. A very usefull article that is going to help you out can be found in the related links box above.
anamorph widescreen
This terminus technicus means that the video data is intentionally stretched vertically so that the horizontal stretching of the high definition screen or widescreen (= display aspect ratio) is going correct the image. This technique is used on 16:9 (= widescreen) DVDs. For detailed explanation of this term read this text about anamorphic widescreen videos.
TMPEGEnc
TMPEGEnc is short for Tsunami MPEG Encoder. It is a software application created by Pegasys Incorporated, a Japenese company dealing with software development and marketing. TMPEGEnc is a tool for encoding videos of any format into MPEG (1 or 2) output that can be used on Video CDs, Super Video CDs and DVDs. It is straight forward to use, outputs high quality videos and is free.

We are going to focus on the 16:9 display aspect ratio, because it is the one used for high definition screens. Have you ever watched television on a high definition screen noticing that the image is stretched horizontally? This is because the television channel you were watching was broadcasting the image with a display aspect ratio of 4:3. The image was stretched by your high definition screen to fit. This is as you should already know, because 16:9 is wider (and thus sometimes also referred to as widescreen) than 4:3.

widescreen image on 16:9 and 4:3 screens Figure 1: A widescreen video on screens with a 16:9 and 4:3 display aspect ratio

16:9 has a major advantage in comparison to 4:3. This advantage is that it is displayed correctly on old (4:3) and newer (16:9) screens. If you own an older television there are two things that can happen. Firstly your television is clever and notices that the display aspect ratio of the video data is different from the display aspect ratio of the screen itself. It therefore automatically inserts a black bar (letterbox) above and below the image so that it is displayed correctly. Secondly your television is not so clever and ignores or cannot notice the different display aspect ratio of the image. The image hence looks vertically stretched and you have to press the button that switches your television device into "16:9 display mode" as shown in Figure 1. So this is the reason why there is such a button on the remote control of older televisions. Since widescreen television devices seem to be the future it doesn't really make sense to create DVDs with a display aspect ratio of 4:3.

Now we are going to focus on the encoding of videos for DVDs with a display aspect ratio of 16:9 using the PAL television system standard and the TMPEGEnc application. I´m using PAL, because it is the standard used in Europe where I am from. If your country uses another television system standard, you will have to replace the height in the calculations below. You can get TMPEGEnc using the link provided in the related links box above. Note: I won't show you how to author a DVD (= creating menus and such things). This chapter only focuses on the converting of AVI videos to MPEG-2 files with a display aspect ratio of 16:9.

720x576 is the highest possible resolution for PAL DVDs. The display aspect ratio is simply an additional information written into the header of the MPEG-2 file. The only thing we have to do is stretching the video vertically so that the horizontal scretching of our widescreen television displays the video correctly. Note: Probably the video would also display correctly on a widescreen television if you do the stretching and encode with a display aspect ratio of 4:3. But it is not the correct way to do it, since in this case the video would contain wrong meta information in its header. So don't do it.

selecting the 16:9 DVD option in the project wizard of TMPEGEnc Figure 2: The first step of TMPEGEnc´s Project Wizard

First of all start TMPEGEnc and choose the "PAL (16:9)" option at the first screen of the wizard as shown in Figure 2. The Project Wizard explains everything pretty well. If you click next and proceed to the second step, you are going to see the controls visible in Figure 3. Here you have to choose your AVI video file as the source. If you demultiplexed your audio into an additional file you have to select it just below the video file. The Wizard should automatically fill in the controls inside the "Expert Setting for Source" group box. The "Aspect ratio" (which in this case means the pixel aspect ratio) should be "1:1" for every AVI video file for instance.

selecting the video and audio source files in the project wizard of TMPEGEnc Figure 3: The second step of TMPEGEnc´s Project Wizard

If everything is set to your convenience click next and than open the "Clip frame" dialog by clicking on the appropriate button. If you do so the dialog visible in Figure 4 is going to pop up. Go to the "Arrange settings" and choose "Center (custom size)" as "Arrange method". This allows you to stretch the video horizontally and vertically as you wish. It is clear that we stretch the video to 720 pixels horizontally, but what do we enter into the height textfield? This is the time when some math and logic comes quite handy.

the clip frame dialog of TMPEGEnc Figure 4: The "Clip frame" dialog of TMPEGEnc

You can see that I entered 552 into the textfield. But why? The formula needed is visible in Figure 5. The figure also covers the equiation I used to receive the formula. I assume that you know how to solve an equation so I´m not going to cover this part. Let´s take a closer look at the logic behind the equation instead.

formula for calculating the correct encoding height Figure 5: Formula for calculating the correct encoding height Y(w,h)

The equation can be seen on the left side in Figure 5. 1,422 is the amount the video gets stretched horizontally by a widescreen television. 1,422 equals 16 over 9 divided by 720 over 576. This means 1,422 is the amount the resolution aspect ratio of a PAL DVD (720 over 576) gets stretched on a widescreen (16 over 9) television. What this equation does is to find out the height that is needed during the encoding to get an inverse resolution aspect ratio change of 1,422. This means that we stretch the image vertically by 1,422 so that the widescreen is able to display the video correctly. The formula you need is the one inside the red rectangle in Figure 5. You have to insert the height and width of your input AVI video to receive the value you need. For NTSC DVDs you have to replace 1,422 with 1,185 (assuming that you are using a resolution of 720x480).

I hope it is clear. If not let's take a look at an example that is also going to prove that the formula is correct. Let´s say you have an AVI video with a resolution of 640x360. 640 over 360 equals 1,7777... This means that the resolution aspect ratio of the video is already 16:9. If you insert 640 as w and 460 as h into the formula, you are going to receive 576 as Y. This is quite logical. It means that since the video already has a resolution aspect ratio of 16:9 (640x360) you must encode it with a resolution of 720x576 (without any letterbox). Your widescreen television is going to restretch the video and display it correctly for you. Note: If your input video doesn´t have a resolution aspect ratio of 16:9 you are going to receive a number smaller than 576 as Y. This means that you are going to add a letterbox to the movie itself. This can be seen in Figure 5. I marked the artifical letterbox with the color red.

After the encoding is finished you can check your video using a player that is capable of interpreting the display aspect ratio inside the header of an MPEG file. Such a player is the VideoLAN VLC media player. It is available for free. You can find a link to its download page in the related links box above. VideoLAN is going to stretch the video as your widescreen television will. That´s it. You have successfully encoded an anamorphic widescreen video.

back arrow icon