Digital Video and Full HD TVs are becoming widespread. While ripping DVDs, downloading DivX torrents, or recording DVB, I ran into lots of interesting oddities. This page tries to summaries Digital Video for my own information, and for me to refer back to when encoding digital video. This is not a definitive guide, but my own personal guide. If it helps other people great.
First it is important to understand the resolutions offered by new High Definition Digital TVs.
| Format | Resolution | Display Aspect Ratio |
|---|---|---|
| HD Ready DTV | 1280 × 720 | 16:9 (1.77:1) |
| Full HD DTV | 1920 × 1080 | 16:9 (1.77:1) |
What is quickly evident here that a Standard Definition (SD) Digital TV (DTV) broadcast that is shown on a Full HD TV needs to be resized (upscaled) otherwise it will play as a small box in a window in the centre of the screen. The same is true for DVDs. More of this later.
| Format | Resolution | Display Aspect Ratio | Bit Rate |
|---|---|---|---|
| SD DTV PAL | 720×576 | 16:15 (1.25:1) | Variable 2 - 5 Mbps |
| SD DTV NTSC | 720×480 | 8:9 (1.5:1) | Variable 2 - 5 Mbps |
Standard Definition Pixel Ratios are not always what you see. PAL SD DTV broadcasts are sometimes 704x756. Also broadcasters resize the actual image to 4:3 or 16:9 by adding black bars to the top and bottom of the picture.
A Standard Definition (SD) Digital TV (DTV) broadcast that is shown on a Full HD TV needs to be resized (upscaled) otherwise it will play as a small box in a window in the centre of the screen.
When you upscale a SD DTV resolution broadcast of (720x576) to display on a Full HD TV (1920x1080) the number of pixels increases but not the amount of information. This is very similar to a digital zoom on a camera, or resizing an image in a graphics application. The processor in the HD TV guesses what should be in the missing pixels by looking at the neighbouring pixels. HD TVs offer a nmber of upscaling options such as Wide, Smart, Zoom, etc.
DTV is broadcast as an MPEG2 Transport Stream (TS). The processor in the Digital TV (or set top box) takes this MPEG-2 TS and decodes it. MPEG-2 is a lossy compression algorithm and the quality of the compression depends on the bandwidth used. Interestingly different channels use different bandwidth. This is because broadcasters attempt to balance their needs to show high quality pictures and to generate revenue by using a fixed bandwidth allocation for more channels. Simply put they try to pack as many channels into the bandwidth available on the MUX as possible. This means dropping the bandiwdth available, and therefore quality to some channels.
The website http://dtt.me.uk provides an interesting snapshot of bitrates currently being used by UK Digital TV broadcasters. Ever wondered why BBC1 looks beter than most other channels? Thats becuase it has a high minimum bitrate for the MPEG-2 encoding.
This means if you sit too close to an SD DTV picture on a Full HD TV you will notice the quality is not great. The effects of limited bandwidth and upscaling mean the quality of the picture shown on screen is actually quite poor.
This is why you need to pay attention living room sizes and LCD TV sizes. If your brand new 42" LCD TV is too big for your living room the picture will look a lot worse than your old bulky 28" CRT TV!!
If you can live with SD TV on a Full HD TV then the difference between DVD and BluRay will be lost on you!
DVD offers similar resolution to SD TV. But there is one big difference - the Bitrate is higher. Therefore quality of MPEG2 encoding is better:
| Format | Resolution | Storage Aspect Ratio | Bit Rate |
|---|---|---|---|
| DVD PAL | 720×576 | 16:15 (1.25) | Up to 9 Mbps |
| DVD PAL | 720×480 | 8:9 (1.5) | Up to 9 Mbps |
When you upscale a DVD playback (720x576) to display on a Full HD TV (1920x1080) the number of pixels increases but not the amount of information. This is very similar to a digital zoom on a camera, or resizing an image in a graphics application. The processor in the HD TV guesses what should be in the missing pixels by looking at the neighbouring pixels.
Another difference between DVD and SD TV is that DVD has a Display Aspect Ratio (DAR) paramter as well as a Pixel Aspect Ratio (PAR).
The Storage Aspect ratio (SAR) is simply the x and y dimensions of the video in pixels.
SAR = X / Y
The Pixel Aspect Ratio (PAR) defines the width to height aspect ratio of the pixels of the video. Computer monitors, and LCD TVs have a PAR of 1:1 which means they are square. But other devices like 4:3 TVs have non-square pixels. Generally you do not have to worry about the PAR because the PAR is mathematically related to the DAR.
SAR = DAR / PAR
The Display Aspect Ratio (DAR) defines the width to height aspect ratio of the physical display screen (as physically measured, not in pixels). The DVD format only supports DAR of 1.33:1 (4:3) for older squarer televisions and 1.78:1 (16:9) for widescreen televisions.
| Old Square CRT TV | 1.33:1 | 4:3 |
| New LCD TVs | 1.78:1 | 16:9 |
| 35 mm US and UK widescreen standard. | 1.85:1 | 37:20 |
| 70 mm standard. | 2.20:1 | 11:5 |
| 35 mm anamorphic, used by CinemaScope. | 2.35:1 | 47:20 |
| 35 mm anamorphic, used by Panavision. | 2.40:1 | 48:20 |
An important point to note here is that even though you have a big Widescreen HD TV with a Display Aspect Ratio of 16:9 you will still get black bars at the top and bottom of many movies from DVD. The reason for this is because the big Hollywood studios shoot in ratios wider than 1.78:1 (16:9) !
So the big question is, why when most movies are 2.35:1 and 2.40:1 why are HD TVs only 1.78:1. The reason is that the studios want to protect the cinema market, and need to keep the cinema experience better than the home experience.
Also when the 16:9 aspect ratio was proposed by Kerns H. Powers, nobody was creating 16:9 video. The popular choices in 1980 were 4:3, 15:9, 1.85, 2.20 and 2.35. Powers discovered that all of those aspects would fit within a 1.78:1 outer rectangle and when over-lapped, all shared a common 16:9 inner rectangle. Hence, any of the "common 5" can be neatly cropped or matted to fill a 16:9 screen.
Typical video aspects which are wider than 1.78:1 (16:9) are accommodated by the DVD format by doing the following:
|
The DAR is set to 1.78:1 (16:9) the widest supported by the DVD format. |
|
|
The video is squeezed horizontally into the frame (without any cropping of the left and right sides of the image). |
|
|
The video is padded vertically by adding black bars at the top and bottom of the frame. |
If you played this video back using its native resolution (SAR) you would get lots of tall thin people. Here is an example from the 300 DVD which is 2.40:1
The SAR = 720x576. But when we look at a frame it has black bars encoded into the DVD and people are tall and skinny. The viewable picture is actually 720x428.
But when it is played back on a DVD Player, the player uses the DAR (and the PAR) information to strectch the video horizontally (x-axis) to fill the widescreen television with a DAR 1.78:1 (16:9).
If you have a HD TV you have to be careful because the TV and DVD player may both be doing scaling. I have an old DVD player which is almost certainly squashing the y-axis to 720x400 to display this via a SCART output because it knows nothing about HD TVs. The TV on receiving the 720x400 input is upscaling this to 1920x1066. This is the worst of both worlds. Firstly my DVD player throws away pixels, and then the HD TV puts them back in and more by guessing what they were! A strong argument for upgrading my DVD Player!
As explained above the DAR parameter is used to tell the DVD player how to handle streching of the video. When converting a DVD to DivX the video aspect ratio with DivX should be based exclusively on the resolution of the video. Although DivX supports PAR, a PAR other than 1:1 (square pixels) is not widely supported by standalone players. Therefore PAR should always be 1:1 and the video resized to so the SAR is equal to the DAR.
Therefore it is necessary to do some resizing of the DVD when encoding to DivX. This is very similar to the resizing that a DVD Player does explained above.
We have a number of choices here. To preserve aspect ratio we can either stretch the x axis, or squash the y axis. Another alternative is to crop information but this is not an option I want to explore. From a purist point of view it would be better to stretch the x axis because this way we do not loose any information.
However lets say we have the film 300 which is shot in 2.40:1
The SAR = 720x576. But when we look at a frame it has black bars encoded into the DVD and people are tall and skinny. The viewable picture is actually 720x428.
1024x576 by stretching the 720x576 x-axis to get the correct aspect ratio. Here we have added infirmation by guessing the missing pixels.
720x400 by squashing the 720x576 y-axis to get the correct aspect ratio. Here we have lost information by throwing away some pixels on the y-aixs.
Given that no HD TVs or Computer Monitors have native resolutions of 7240x400 or 1024x576 when either of these videos are played back the playback device would have to do some scaling. The guide here is to use the DivX/Xvid profiles which are used by cetified players.
| Mobile Profile | Portable Profile | Home Theatre Profile | High Definition Profile | |
|---|---|---|---|---|
| Max Resolution | 352x240 30fps 352x288 25fps | 640x480 30fps | 720x480 30fps 720x576 25fps | 1280x720 30fps |
| Max BitRate | 1 334 850 | 4 854 000 | 4 854 000 | 9 708 400 |
| Max B-frames | 5 | 5 | 5 | 5 |
| Quarterpel | Yes | Yes | Yes | Yes |
| Quantization method | H.263/ MPEG/ CQM | H.263/ MPEG/ CQM | H.263/ MPEG/ CQM | H.263/ MPEG/ CQM |
| Adaptive Quantization | Yes | Yes | Yes | Yes |
| 4MV Mode | Yes | Yes | Yes | Yes |
| Interlaced Coding | No | Yes | Yes | Yes |
| GMC | No | No | 3 warp-point (concealment) | 3 warp-point (full) |
| Pixel Aspect Ratio (PAR) | 1:1 | 1:1, 4:3, 16:9 | 1:1, 4:3, 16:9 | 1:1, 4:3, 16:9 |
Therefore we should pick a rescaling option which fits in with our intended devices.
If DVD DAR = 1.33:1 (4:3): The following typical resolutions (after resizing) are exact integrals of 16 and have been rounded up or down based on the closest to 1.33:1 (4:3).
| Resize | SAR |
|---|---|
| 720 x 544 | 1.32:1 |
| 640 x 480 | 1.33:1 |
| 320 x 240 | 1.33:1 |
If DVD DAR = 1.78:1 (16:9): The following typical resolutions (after resizing) are exact integrals of 16 and have been rounded up or down based on the closest to 1.78:1 (16:9).
| Resize | SAR |
|---|---|
| 720 x 400 | 1.80:1 |
| 640 x 352 | 1.82:1 |
| 320 x 176 | 1.82:1 |
Note is would be possible to crop the black bars before resizing and encoding DVD to DivX, but because encoding black bars takes little effort it is easier to leave them in.
The final video resolution before being passed to the DivX encoder (after resizing and cropping) should always be a multiple of 16 in both width and height since XviD uses 16 x 16 macroblocks.
Before you can re-encode DVDs to DivX on Linux you need to install libdvdcss2.
wget http://www.medibuntu.org/sources.list.d/hardy.list -O /etc/apt/sources.list.d/medibuntu.list apt-get update apt-get install medibuntu-keyring apt-get update apt-get install w32codecs libdvdcss2 |
Use vobcopy -I to identify the main movie. Then use trusty mplayer to pull out the main movie. 1st title in this example.
mplayer dvdnav://1 -dumpstream -dumpfile dump.vob -v |
This dumps the unencrypted VOB to the hard drive. A two pass mencode can then be used to encode it to DivX.
First Pass:
mencoder -ffourcc DIVX -forceidx -vf scale=704:-2 -ovc xvid
-xvidencopts "quant_type=mpeg:pass=1:bitrate=1500:nopacked"
-oac mp3lame -lameopts cbr:br=192 dump.vob -o /dev/null
|
Second Pass:
mencoder -ffourcc DIVX -forceidx -vf scale=704:-2 -ovc xvid
-xvidencopts "quant_type=mpeg:pass=2:bitrate=1500:nopacked"
-oac mp3lame -lameopts cbr:br=192 dump.vob -o dump.avi
|
And now you have a region free backup of your leagally purchased DVD which can now be streamed from my NAS to my PS3.