, Online book by Michael B. Karbo

Copyright Michael Karbo, Denmark, Europe.


  • Next chapter.
  • Previous chapter.


    Chapter 25. More about the codecs

    Compression is a technique, which is used a lot in the computer world. 10 years ago, Stacker and Drivespace were the hottest subjects, as hard disks were unbelievably expensive. The volume of a hard disk could be doubled with the help of these programs without any big problems. There are not very many who compress their hard disk today, but on the other hand, you cannot avoid working with the compression of video and audio files.

    We have seen earlier that 18 minutes of film in a ”raw” DV quality fills 4 GB. Hard disks may be big, but they are not big enough to store DV film. If we worked with video without compression, then we would get images with the size of a stamps ... So it is quite natural that we compress the films in one or another way. This is done with the help of the rather mystical codecs, which I am going to get a little closer to in this section.

    Common features for all compression

    Common for all compression is that the data is packed so that it fills less space. This is called encoding data, when we are working with audio and video. And when we have encoded a video sequence, it is stored in a certain format.

    When the recordings are encoded, they can be stored and transmitted. When the recordings are to be shown, the packed data is unpacked into the original uncompressed format. This process is called decoding. Both processes require software, which can be used with the format in question.

    There are many different formats into which audios and videos can be encoded. Some formats can be used on a computer, while others are really intended for completely different devices.

    But it is common for all formats that there has to be suitable software available before a file can be played. A little program, which understands the encoding, which is in the audio or video film and, which can be decode the bit stream to “raw” video or audio. This software is called a codec, and it works almost like a driver for a file format. See also codecs on page 3.

    Figure 189. Codecs are absolutely central when audio and video images are compressed. Here we can see the encoding, but the same codecs are also used for the decoding.

    Encoding requires power

    Both encoding and decoding are software processes, which use a lot of calculations  ­– and I mean really a lot, when it is a matter of compression of video images. Especially when the encoding and decoding is done ”on the fly” and in real time, at the same pace as the film. This requires a tremendous amount of processor power.

    This is, for example, the case when you watch a DVD film, where the films’ images are encoded with MPEG-2. The film is read consecutively from the disk at the same time as it is played of the screen. This means that there is a great amount of computer work going on all the time decoding the data stream.

    If the computer cannot keep up with the data stream being decoded, then it will jump over some frames and the film will be hacked. In fact, it is not very many years since ordinary computers were too weak to be able to play DVD films without hacks. It was necessary to have an extra graphic card (like ”Holly­wood Magic”), which was designed for decoding DVD videos.

    Earlier in the booklet, I described how I prefer to transfer DV recordings to a computer in an AVI format rather than encode them immediately to MPEG. As it is difficult to manage this job in real time, even with a fast Pentium 4 processor.

    Codecs for video images

    A video consists of both audio and image as I have earlier described. When you encode a video to one or another format, then both audio and video codecs are involved. The audio can often be encoded in several ways as can the image too.

     

    Codec

    Used for

    MJPEG

    Older video grabber cards and in many digital cameras with a video function.

    MPEG-1

    VCD

    MPEG-2

    SVCD, DVD Video

    MPEG-4

    DivX, Microsoft Media

    DV

    DV camera and AVI files, which are captured from DV.

    Figure 190. The most often used video codecs.

    I have earlier described several audio codecs, so let us here look closer at the different video codecs. Figure 190 shows the most common codecs used for video with ”good quality”.

    Two forms of compression

    Two sorts of video codecs, which work very differently, are distinguished between:

  • Intra frame, where every frame is compressed individually with JPEG-like algorithms.

  • Non intra frame, where every single frame is compressed in relation to the other frames.

    In the first type, intra frame, every frame is stored individually. This is practical when editing the video, because you can  ”wind forwards”, one frame at a time. The drawback is that the compression isn’t particularly effective; it usually packs the video data with a factor of 5-10. Of the codecs in Figure 190, the older MJPEG and DV use intra frame compression. MJPEG isn’t very effective but is often used when digital cameras record small video films.

    DV camera recordings also take place with intra frame compression and it is this data that you can fetch directly into an AVI file with the use of a FireWire cable.

    Non-intra frame compression is used with the other MPEG codecs and it is much more effective. Key ­frames and various in-between frames are used here. A key frame is a complete JPEG image, while in-between frames only contain the image data that is altered. So video films contain, for example, one key frame followed by 11 in-between frames called a GOP (Group Of Pictures), which is followed by a new key frame.

    The inserted in-between frames (sometimes called delta frames) contain a limited amount of data, because they, as already mentioned, only have to describe the pixels that are changed in relation to the previous frame. This means than the compression can be very effective – typically with factor 25 or more. The drawback is that you cannot edit in all the frames. It is also worthwhile to note that MPEG compression is better, the more still the image is. So always use a tripod when you record serious videos. If the background of the recording doesn’t change, then the images are easy to compress and the quality will be a lot better.

    MPEG-2, MPEG-4 and DivX

    MPEG-2 is used in DVD video and its technique produces excellent video images but requires rather a high band width because MGEP-2 isn’t a ”hard” compression. MPEG-4 is a very much more aggressive compression, which is designed for small band widths and, which uses a number of intelligent techniques which aren’t found in MPEG-2.

    MPEG-4 is strictly speaking patented, so the intention was that royalties should be paid for the use of the codec. The company Microsoft has also developed a version, which was only for use with Win­dows Media files. But all of the established software industry was overtaken on the inside by the international cracker environment, which introduced DivX-formatet. DivX is the name of a number of variants of MPEG-4, which can be fetched from the Internet. These codecs are extremely effective for compressing DVD films. You can, in fact, fetch illegal DivX copies of almost any film on the Internet.

    In reality, DivX is achieving the same status within films, as mp3 has within music. A complete feature film can, in fact, be packed on one CD with DivX. This is happening all over the world, which is a big worry for the film industry. You can, yourself, fetch programs, codecs and much more for DivX from many sites on the net. See, for example, www.divx-digest.com.

    Problems with codecs

    So codecs are necessary for encoding and decoding audio and video files. In practice, codecs can really tease a lot on a normal computer with Windows, and Microsoft hasn’t done very much to make the use of them any easier. A “Codec Manager” would be a good thing, which could tell us, which codecs are found on the computer, where they come from, what they can be used for and when they have been installed. As the system is now, you are completely on your own  - there is, so to say, no system information can be picked up about the individual codecs.

    With a computer with Windows 2000 or XP,  you can look in the System information and get a little bit of insight into the individual codecs – but this is completely insufficient. Try yourself. Look at Components and then Multimedia.

    The problem with codecs is that there are so many of them and they are not compatible. They are usually installed at the same time as the other programs or with drivers for new hardware:

    Figure 191. Here, various video codecs have been installed in connection with a software package.

    Let me give you a little illustration. Back in 1998, I got the earlier mentioned little Logitech web­cam. We had lots of fun with it in the beginning and recorded a large collection of mini videos. While working on the booklet, I activated the camera and fetched the newest collection of software for it from Logitechs website. But it turned out that the codecs weren’t the same in the new package than in the original because I couldn’t play back any of the old recordings!

    But there is a smart answer for this. If you use Windows Media Player for playing a video or an audio file, which contains an unknown codec, the player itself offers to fetch it from the net. Which works fine.

    Figure 192. Windows is updated with new codecs here.

    If you look in Windows under System information, you can under ”Software environment” find a ”List of devices”. You might be able to see some of the codecs you have installed here via downloads:

    Figure 193. System information about a Microsoft codec, which has been downloaded.

    The program VirtualDub

    One of the best programs for working with video formats is the free VirtualDub, which can be fetched from www.virtualdub.org.

    VirtualDub is fully approved and used a great deal. It is quite clear that the program recognises all the various video files. Here below, an AVI file, which has been recorded with my webcam is loaded. I can play the film and I can hop between the individual key frames:

    Figure 194. Hop from the one key frame to the next.

    If I ask for some information, then VirtualDub can tell me, that there are 15 key frames in the 30 seconds of recording (see Figure 196). Virtual­Dub is a comprehensive program, which can edit and manipulate video and audio data. Various video files can be edited and cut together. Single sequences can be adapted with a large number of filters and all in all there are a great deal of tools stored in this small and rather anonymous program.

    Figure 195. Filters in the freeware program VirtualDub.

    VirtualDub is excellent for giving information about video files. It is easy, for example, to see   which codecs have been used for audio and video:

    Figure 196. Information about a video file, as VirtualDub sees it.

    Windows Media Encoder

    Here is another good and free program, which you ought to have on your computer, if you work with video. Micro­soft has put a lot of effort into developing codecs. This effort has been concentrated on supplying formats, which are suitable for web use (streaming media) and which can outsell the popular formats from the companies Ap­ple (QuickTime) and Real. These are, however, still used a lot, for example, for the downloading of television programs in web format.

    Microsofts’ format is called WMA, and is supported by many programs. You can, for example, get Studio 8 to store in WMA, as described on page 3. I prefer, however, to use Micro­softs’ own software, which can be fetched from the address www.microsoft.com. Search for Win­dows Media Encoder in the Download section.

    Figure 197. Free software from Microsoft.

    Media Encoder is used to produce end formats. The video films can be effectively compressed as described on page 3. But you shouldn’t expect to be able to edit in such a WMA file and then be able to compress in again. If it can be done at all, it will result in loss of quality and/or larger files. Which is why it is important to store the original recordings either on a DV tape or on a hard disk in, for example, an MPEG format, where the quality will remain almost the same.

    Figure 198. Effective encoding with MPEG-4 and Windows Media Encoder.


  • Next chapter.
  • Previous chapter.


  • Book overview.