Efficiency of the MPEG-2 (H.262), MPEG-4 Part 2 and H.264 codecs

The following post is quite dated and reflects a 2001 era worflow using ancient technology. These are the hoops we had to jump through.


Around 2001, I conducted a technology review comparing the coding efficiency of the MPEG-2, MPEG-4 Part 2 and H.264 (MPEG-4 Part 10) codecs in order to pick an effective and efficient compression algorithm to be used in a new satellite directv-to-home DBS system. The goal of these tests was to achieve the highest quality video at the lowest possible bit rate, thus allowing a large number of video channels to be placed into a single satellite transponder.

We were hoping to fit upwards of 25 full screen Standard Definition (SD) video channels into a transponder by encoding each channel at an average of 1.2Mbps. All channels would be stat muxed within a transponder. Stat muxing channels allows an encoder to maintain video quality by varying the bit rate for that channel above or below the 1.2Mpbs average, as dictated by the source material. In a nutshell,

the objective of statistical multiplexing is to dynamically distribute the
available channel bandwidth among the video programs in order to maximize
the overall picture quality of the system

The difference in video quality at 1.2Mbps between the older MPEG-4 Part 2 algorithm and the new H.264 algorithm is quite marked, as can be seen in the following screen shots.

source mpeg4 2 1200
Figure 1. "Uncompressed SD Source" | "MPEG-4 Part 2"
source mpeg4 10 1200
Figure 2. "Uncompressed SD Source" | "H.264"
mpeg4 2 mpeg4 10 1200
Figure 3. "MPEG-4 Part 2" | "H.264"
mpeg4 2 mpeg4 10 2000
Figure 4. "MPEG-4 Part 2" | "H.264"

I downloaded several uncompressed clips[1][2] in Berkley YUV format and, using netPBM,[3] converted these to Windows AVI. Each clip was encoded at an average of 2Mbps and 1.2Mbps using the Microsoft ISO MPEG-4 Part 2 encoder and the MPEG committee H.264 reference encoder.

The processor power required by the new H.264 algorithm is an order of magnitude greater than the older MPEG-4 Part 2 algorithm. Using a 2Ghz Pentium 4 with 768MB RAM, encoding an 8-second sequence using the Microsoft MPEG-4 Part 2 encoder took under 60-seconds. Encoding the same sequence using the reference H.264 encoder took two hours. Note that the reference H.264 encoder is a proof of concept and is not yet optimized.



Here is the workflow that I used in order to convert a H.264 compressed video to AVI format so that it can be viewed in a media player in MS Windows (e.g. Windows Media Player).

  1. Convert the video sequences to 4:2:0 Berkley YUV, suitable for encoding:

    • Use yuv2avi from NetPBM to convert the 4:2:2 source material to an avi file. This conversion process also decimates the video from 4:2:2 to 4:2:0. It is essential to convert whatever video you want to encode into a base format, like ppm. So if you are unable to use yuv2avi, then use an application like VirtualDub to save your video to a sequence of images in .BMP ` format (e.g. `image_0001.bmp, image_0002.bmp, image_0002.bmp.)

      yuv2avi.exe src19_ref__525.yuv src19_ref__525.avi 525 UYVY
  2. Use VirtualDub to:

    1. Crop the x/y video resolutions to multiples of 16, e.g 720×480, 352×288 etc.

    2. Split the video into separate .BMP images.

  3. Use bmptoppm in the Netpbm package to convert each .BMP image to a .PPM image.

  4. Use ppmtoeyuv in the Netpbm package to convert each .PPM image to a corresponding Berkley yuv image(*)

    for i in image*.bmp; do bmptopnm.exe $i | ppmtoeyuv.exe >`basename $i .bmp`.yuv; done
  5. Use the MSDOS copy command to create a single eyuv video file from the individual images:

    copy.exe /b *.yuv video.yuv
  6. Encode your source video (4:2:0) using the H.264 encoder. The H.264 codec (at least the version I used) does not support 4:2:2 video. This may have changed.

  7. Decode the compressed file using the H.264 decoder. This results in a Berkley EYUV encoded file.

  8. To convert the H.264 encoded file into an .AVI file that can be viewed in Windows:

    1. Use eyuvtoppm in the Netpbm package to convert the Berkley yuv encoded video to a single ppm file containing the video frames.

    2. Use pnmsplit in the Netpbm package to write out the individual frames from the ppm sequence(*):

      eyuvtoppm.exe -w $WIDTH -h $HEIGHT < decoded_file.yuv | pnmsplit.exe
    3. Convert each .PPM image to a .BMP image(*)

      for i in image*; do ppmtobmp.exe $i >`basename $i `.bmp; done
  9. Use VirtualDub to create an avi file from the sequence of .bmp images

If you want to view a file you have encoded using H.264, you must first decode it to uncompressed EYUV format and then either view the uncompressed video in an application capable of playing this format, or convert the file to AVI. In my case, I took an 8 second clip of 177 Megabytes in size and compressed it down to around 2 Megabytes. To watch it I had to decompress it (back to 177 Megabytes) and then convert it to AVI format.