Video Compression

(BMAS Website 2003-2005)

With raw video which has been digitised at 25 frames per second and 24 bitplanes of 768 by 576 pixels (the standard size for full frame PAL video on DVD) the resulting data can occupy a vast amount of space.

768 * 576 * 24 * 25 = 265,420,800 bits

= 33,177,600 8bit bytes

or around 31 MBytes of video data to be transferred per second

So some form of compression is required to be able to transfer the video over almost all but the highest bandwidth data links. To achieve this for a more restricted bandwidth, some compromises will have to be made on things like:

  • framesize,
  • framerate,
  • bitplanes

If you have ever watched digital TV (either via satellite; cable or digital terrestrial), then you have seen a compressed video stream in action. Digital TV uses a variation of the MPEG-2 (MPEG = Motion Picture Experts Group) standard for video encoding. Feature films on DVD are also presented in another variation of the MPEG-2 standard. In a typical DVD movie of around 90 minutes duration, this can still occupy around 5 Gigbytes of data. The actual video data in a DVD is less than this as the MPEG-2 data can include several soundtracks and/or several subtitle tracks, but it still means around 1MByte of data per second.

Whilst the high bandwidth data links can manage this level of data rate, the lower bandwidth data links (2 - 10Mbit) would still have problems so something more agressive is required.

Video CD

Before the advent of MPEG-2 video, a VCD (Video CD) used MPEG-1 as a base. The quality of VCD video is similar to that of an average quality VHS (Video Cassette) recording, and should be viewable over a 2 - 10Mbit data link. With this format, it is possible to pack an hour of PAL format TV video into around 650MBytes (i.e: space for two episodes of Coronation Street on a 700MByte CD-R.. - God forbid!). The framesize is limited to 352 by 288 at 25 frames per second for PAL format VCD to remain within the MPEG-1 VCD standard. It is possible to use larger framesizes but with unpredictable results - for example: a video file of 512x384 can look fine on a computer screen, but a domestic DVD player squashes the vertical and the audio will probabably drop out of sync.

There are three basic VCD MPEG-1 formats, two of which cater for NTSC (American TV format) and the other for PAL (Mainly European TV format).

 

352x240 pixels29.97 fpsNTSC
352x240 pixels23.98 fpsFILM
352x288 pixels25 fpsPAL

MPEG-4

More recently Apple have been pushing a new version of Quicktime incorporating the MPEG-4 audio/video codecs. MPEG-4 video itself has been around for quite some time and is often used as the video codec in the infamous DivX format.

DivX is capable of a 10:1 compression ratio while still retaing most of the original quality, so a 5GByte DVD feature film will be compressed down to around 500MBytes which a much easier size to handle. DivX achieved a lot of its reputation along with the 'defunct' (?) Napster P2P (peer to peer) network as a large quantity of pirated video (including unreleased feature films) became available over the internet. DivX is a combination of two codecs - one for video and one for audio. The video codec is usually a variation of MPEG-4 whilst the audio codec is normally MPEG-1 layer III (MP3).

(Napster in its original form has bee closed down, but the concept is still alive and well under several other P2P systems, we aren't going to reveal what is available as that could be construed as approving of P2P piracy.)

 

To illustrate the conversion from a DVD title to a DIVX file, a sample DVD was encoded using mencoder/mplayer on a Apple G4 and secondly using the same software on a Home-Built Celeron system. The two systems where running a standard software setup, Mac OS-X in the case of the Apple and Debian Linux 2.4.20 in the case of the PC. MPlayer 1.0pre1 was used on both systems.

The procedure described below is actually a 4 pass system with the real 1st/2nd passes combined and with the real 3rd/4th passes combined.

Pass 1 (1/2)

2divx dvd 11 0 0 0 0

Here a zero in the last position causes 2divx to do the following, the other zeros are ignored.

Read title 11 from the DVD and dumps the complete audio/video data to stream.dump, then scans through this file to produce frameno.avi which is and audio only copy of the stream. This stage also reports back with the bitrates to use in the next pass for each of the target sizes (650MB, 700MB, 800MB and double of each)

 

 867MHz G4
640MB mem
Mac OS-X
1.4GHz Celeron
512MB mem
Debian Linux
start_at:19:11:3214:09:24
intermed:19:59:2014:21:00
finish_at:23:18:4014:55:42

Pass 2 (3/4)

2divx dvd 11 gq 640 640:272:0:44 834

Using a bitrate of 834 to correspond to a final DIVX of just less than 700MB, and inserting the other parameters:

gq
output filename prefix, the .divx suffix is appended by the script
640
total scaled width of the output
640:272:0:44
<cropped_width>:<cropped_height>:<left_offset>:<top_offset>
these values are chosen to crop the black border from the top/bottom from a 16:9 original down to a 2.35:1 DIVX

The first stage of this pass is to produce the target DIVX file along with a log of data for each frame, the second and final stage is to recreate the DIVX but with fine tuning helped by the log data.

 

 867MHz G4
640MB mem
Mac OS-X
1.4GHz Celeron
512MB mem
Debian Linux
start_at:23:40:3515:18:11
intermed:02:40:3816:44:00
finish_at:05:40:0118:10:42

Files produced:

stream.dump (5826826240 bytes)
The complete stream dump of the DVD title produced in Pass 1 (1/), including all the audio and subtitle tracks
frameno.avi (121126348 bytes)
The audio only copy produced in Pass 1 (/2), which in this case is an MP3 audio track encapsulated in an AVI file
gq.log (18257554 bytes)
The log produced in Pass 2 (3/)
gq.divx (733152202 bytes)
The final DIVX file produced in Pass 2 (/4), which is a 7.948:1 reduction for a bitrate of 834 - reducing the bitrate would reduce the size of the DivX file as well. As it is the DivX will just fit onto a 700MB CD-R

PLEASE NOTE: IT IS ILLEGAL TO COPY DVD's


Do NOT ask for the 2divx script as this procedure is only meant to illustrate the stages involved in creating a DivX file from a DVD, and NOT a tutorial

For really low bandwidth data links you could resort to the RealMedia or Windows Media format which allow video to be compressed and streamed over links as slow as a 14.4k modem although the quality is non-existant.

 

 
© 2010 John Heaton, G1YYH
Joomla! is Free Software released under the GNU/GPL License.