This is a short introduction to Video Compression techniques by using free software tools. These include video codecs and VirtuaDub.

Here is another Tutorial for HandBrake [>>] (easy to use, less technical jargon).

What do we call Video Compression

Video Compression refers to the methods for reducing the quantity of data used to represent video. It is a straight forward combination of image compression and motion compensation. To compress a video file we need two things: a video codec and a video editing tool.

What is a codec

A codec is short for COder/DECoder and is basically a small piece of software that is used to Encode and Decode video. In order to compress a video file you need to download and install the relevant codecs on your system. In our case, download and install a codec-pack that includes all of the codecs that will will need for the rest of this tutorial. The recommended codec-pack is k-lite mega codec-pack.

Install with the standard settings but ensure to select XviD, x264, theora and DivX from the codec list.

Xvid

This is one of the most used codecs. The Official Page is http://www.xvid.org/. Most people have it installed, so by using this codec it is almost certain that your videos will be playable everywhere. It is supported by Linux, MacOS and Windows.

x264

x264 is a free software library for encoding H.264/MPEG-4 AVC video streams. As of May 2007, x264 is one of the most advanced publicly available AVC encoders. It is supported by Linux, MacOS and Windows.

Theora

Theora is a video compression technology being developed by the Xiph.Org Foundation as part of their Ogg project. Based upon On2 Technologies’ VP3 codec, and christened by On2 as the successor in VP3’s lineage, Theora is targeted at competing with MPEG-4 video (e.g., the x264, Xvid and DivX codecs), RealVideo, Windows Media Video, and similar lower-bitrate video compression schemes. Xiph and Theora are considered the most promising projects for video compression. mainly supported by linux/unix operating systems. It supports playback for Linux, MacOS and Windows. You can use this player: VLC

DivX ;-)

This is also one of the best-known free codecs, although nowadays it is confused with DIVX an advanced commercial codec created by DivX, Inc. The DivX codec uses lossy MPEG-4 Part 2 compression, also known as MPEG-4 ASP, where quality is balanced against file size for utility. Many newer “DivX Certified” DVD players are able to play DivX encoded movies. For more history visit the wikipedia pages for DivX. Today, because of the licensing issues this codec’s use is limited (windows vista do not support it).

For the purposes of this tutorial we will be using the Xvid Codec. I consider this the most decent codec in terms of reliability, speed, features, support and popularity.

Tutorial Video editing tool: VirtualDub

VirtualDub is a video capture and linear video editing tool, written by Avery Lee. Depending on your processor (CPU), download and install the appropriate VirtualDub version. For instance if you have Intel 32bit get 32bit version. If you have a n amd64 then download the AMD 64bit version.

VirtualDub has many advanced features, is able to use plugins to add different video processing techniques, and can process *.avi files, if the required video and audio codecs are installed, so pay attention to the installation of the codecs as mentioned on the previous paragraph.

Tools we need

VirtualDUB

K-Lite Mega Codec Pack

Download both programs and install them.

A good alternative and easy to use is HandBrake for Windows, Linux and Mac users. Here is a Tutorial for HandBrake [>>].

Encoding a video

We need to know: 1) Where is the video file we plan to compress, 2) the codec we plan to use: Xvid and 3) how to launch VirtualDub.

First of all run VirtualDub. Then drag and drop (or file->open) the video file that you want to compress. It should look something like this:

 

virtualbud interface

To re-compress your video file do the following: Video->Fast recompress

 

fast recompress

Next step is to enable the compression algorith that is to be used during the compression process: Video->Compression

 

Video compression

From the menu list we must select the Xvid codec and then click on the Configure button. If you select a different codec then the configuration settings will be different. Here we focus on the Xvid:

 

codec menu

Xvid configuration menu should look like this:

 

xvid options

The settings are as follows:

Profile @ Level: These profiles correspond to the MPEG-4 standard and selecting a profile will limit the codec and produce output that is playable by other devices, for instance standalone DVD players. There are plenty of ready made profiles you can pick. For instance you can select Home Theatre PAL if you want your resolution and quality to much a home cinema (i.e. 720×576 25fps with a relatively good compression level).

There are other several profiles with different name. More specifically, simple is the MPEG-4 simple profile, which is limited to VCD-like resolutions (352x) and bitrates up to 384 kbit/s. ARTS means advanced real time streaming and is useful for streaming video content. Obviously, streaming also means you cannot have too high a bitrate and use too many complex features, so the resolution is once again limited at 352x but the bitrate can go up to 4 mbit/s.

AS means Advanced Simple and that’s what you want to use in most cases. Advanced simple profiles support multiple quantization types and advanced features like b-frames, QPel and GMC. Then there are the DXN profiles that correspond to the DivX hardware profiles. They can be used to create content that works on DivX certified standalone players. However, they are somewhat restricted in comparison to the Advanced Simple profiles, and with new MediaTek based XviD capable standalones, it is actually safe to use the Advanced Simple profile. Last but not least there is the (unrestricted) profile which imposes no constraints whatsoever.

After selecting a profile and level, press more to the right of the profile selection. This gives us more settings regarding the selected preset.

  1. Adaptive quantization is the formerly called lumi-masking, which tries to give less bitrate to scenes that the human eye can’t see very well.
  2. Interlacing can be checked to improve performance when encoding interlaced content.
  3. Quarterpel, which enables quarter pixel motion estimation – a more accurate motion estimation. Quarterpel can be useful especially for lower resolutions. Note that you need a MediaTek based standalone player in order to handle QPel.
  4. Global Motion Compensation can be useful to save bits on panning scenes. Note that there is currently no standalone player that can handle XviD’s GMC. If you decide to use it, make sure the VHQ option is used (and you can go higher than VHQ level 4 with GMC).
  5. Reduced resolution is only applicable for streaming and would make XviD use a lower resolution that the source video has.
  6. BVOPs are B-frames. You can use the Maximum B-frames option to set the number of consecutive B-frames. Unlike DivX5 you can go higher than 1, though it’s suggested that you do not go higher than 3. B-frame quantizer ratio indicates the additional compression a B-frame gets as compared to a P-frame. Quantizer offset is the offset which gets added to each quantizer. So if the surrounding P-frames have quantizer 2 and both ratio and offset are 1.0, the b-frame would get a quantizer of 3.
  7. Checking Packet bitstream creates a bitstream that can be decoded delay-free (as introduced with DivX5.01, in VDub you’ll no longer be a number of frames behind due to B-frame decoding).
  8. Finally we have Closed GOV, which ensures that a p-frame is used befor every new I-frame. This option should always be checked (otherwise you might end up with a frame sequence like PBIP where the B frame has a forward reference to an I-frame which makes no sense)

 

xvid profile settings

In the Aspect Ratio tab you can configure the aspect ratio of the input video.

 

xvid aspect ratio

The next thing you want to set is the encoding type, for instance select:

 

xvid encoding options

Single pass encodes the movie at a constant given bitrate which you can configure.

Twopass – 1st pass: analyzation pass for 2 pass encoding. The codec will write a text file containing a suggested bitrate for each frame, which we call bitrate curve.

Twopass – 2nd pass: is the internal 2nd pass encoding mechanism. The codec will scale the bitrate curve in accordance with a couple of settings.

To start with select a Twopass – 1st pass as the encoding type. Also make sure the Discard first pass option is selected. Otherwise, the codec will create a pretty useless AVI file during the first pass (and writing that AVI also slows the process down).

Select OK and then File->Save avi

This will seek the video file and it will create a video.pass statistics file.

When it finishes , then go back to the compression settings and select a Twopass – 2nd pass encoding type to compress your video file. Then as we did earlier File->Save AVI. This time it will save the final version of your video.

In my case the original video file size was 50MB and the final was 16MB (most of its size is because of the sound!). The image quality of each of the two videos is as follows (click to see before & after):

 

armoire

This is not an easy process, but it gives us access to features that will greatly improve the quality of our final video.

good luck

μο.

Video:

the video is from the Masters of Russian Animation Volume 8 VHS – ANDREI KHRJANOVSKY + ALFRED SCHNITTKE Collection [>>]

you can watch it here [>>]

References:

http://en.wikipedia.org/wiki/Comparison_of_video_codecs

http://en.wikipedia.org/wiki/Theora

http://en.wikipedia.org/wiki/VLC_media_player

http://www.doom9.org/index.html?/xvid-vdub-final.htm