In side the AVI file. by Johnny Norre (FlickerFree) & Nigel Aves (Video At Home)
Introduction.
This dissertation has been written with the professional and new user alike. AVI files (or any movie file format) is a much miss-understood format. We are hoping that after reading this short write up you will have a much better understanding as to what is happening and why you are not getting the results that you expect, or this will help you fine tune to get the results that you do expect. Movie formats require moving large amounts of data in very short time spans (called bandwidth). At the end you will also find a short write up on streaming video over the Internet another very hard task.
You might have seen the term "RDR" already, it stands for "Recommended Data Rate"
AVI files and beyond
To obtain a reasonable quality from an AVI file, the file must have enough bandwidth (data rate) with respect to its size and frame rate. As a rule of thumb, a 320x240 at 15 fps movie must have a data rate of 150 kb/sec (it will be bad to fair at 100 kb/sec, fair to good at 150 kb/sec and good to excellent at 200 kb/sec.). Do not get confused here, this has nothing to do with the AVI file it self, this is the transfer rates needed to show the AVI file on the screen in front of you. The path of the AVI file is from the medium it is on, via a data buss to the CPU , another data buss to the Video Card and finally from the Video Card to the screen it self. Any of the "components" that the data has to go through can be a "bottle neck" to the speed or quality of the final display.
Another rule says, that when you increase the picture size 4 times (as the difference between 320x240 and 640x480) you should double the data rate, or in general increase the data rate by the square root of the increased number of pixels per second. Huhh .. well think of it this way. If I had a matrix of 10x10 then the number of items that I have is 100 .. but strange things happen when ever the famous squaring factor is thrown in. Here we go . 11x11=121 12x12=124 13x13=169 14x14=196 so 320x240=76,800 640x480=307,200 ; The bottom line here is that a small increase in picture size can lead to a dramatic increase in data size and this will require more "bandwidth" to carry the picture
So far we have only looked at this from a 2d (or flat) perspective. i.e. the size of the picture is only a relationship of the matrix I wish to look at. If only it was this simple, but we also need to throw into the equation COLOUR. You will have noticed that the PC you are running on comes with many different options for number of colours verses the screen resolution and depending on the amount of on-board memory your Video card has will reflect in the maximum resolution and number of colours that can be displayed. If your Video Card has 2 meg of memory on it you will be able to work at 640x480 in True Colour mode but you will not be able to work in 1024x768 in True Colour mode. The following table shows the resolutions verses colours that my Video Card can display. (I am only showing Maximums)
Diamond VIPER 330 with 4 Megabytes of Video Ram
| Resolution V # of Colours | 65536 Colours | 16772216 Colours | True Colour |
| 640 X 480 | YES | YES | YES |
| 800 X 600 | YES | YES | YES |
| 1024 X 768 | YES | YES | YES |
| 1152 X 864 | YES | YES | YES |
| 1280 X 1024 | YES | YES | NO |
| 1600 X 1200 | YES | NO | NO |
| 8 bits = 256 colours | 16 bits = 65536 colours (High Colour) | 24 bits = 16772216 colours | 32 bits = True Colour |
So to summarize each point in our matrix is called a pixel and each pixel has a depth that will set the number of colours that the pixel can display so 320x240x8=614400 bits or 76800 bytes of memory OR 320X240X24=230400 bytes of memory
Where is this taking me you inquire? Well it leads us into the next topic, A codec.
The CODEC
Simplistic view : A codec gives you the advantage to "compressing" the video file. So rather than dealing with raw data this will compress the file and turn it into something a little more manageable. (Please remember that the memory needed by each frame effects the bandwidth needed to display that frame so the smaller we can make it the faster it will display and the more frames / second we can use for better quality)
The codec typically comes with user defined options that you can set. These options will vary the amount of compression or the type of compression that will be used. The option that you as a user will be using the most will be the Quality option.
As you can see here is the FlickerFree Project options dialog box. The Quality of the output is set by the slider and this is defaulted to 75%. Different Codec will use a different default.
To obtain the best quality output to available bandwidth is a fine line and will require you to spend time adjusting the percentage of quality to output.
From the programmers desk Tweaking the "quality" setting should only be done, after setting the correct data rate (by following the description earlier in the document) - if the data rate is to low, the codec will recompress at a lower quality (using more time) until it can meet the data rate setting or until it absolutely can't compress the picture any more ("Microsoft RLE" will even compress the picture to ONE! color - with no details at all!).
The only things with higher priority than the "data rate" is the picture size, color depth, frame rate and codec - anything else can be changed to obtain the data rate. The reason this is important is, that the default quality setting is calculated from the default expected picture type and expected data rate. Indeo default to 65%, which makes it possible to produce an Indeo movie in 320x240x24, 15 fps at 150 kb/sec.
If you increase the quality, Indeo will need more data rate (bandwidth) to cope with the increased quality. Cinepak, on the other hand, can pack a little more than 75% into a 320x240x24, 15 fps movie at 150 kb/sec (75% was the default under Windows 3.1), so it defaults to 100% (for which our experiments shows, that it need a data rate of 195 kb/sec) and let the encoder adjust the quality dynamically (Cinepak is the best codec to adjust the quality, i.e. it does not take significant longer to compress at to high a data rate - Indeo does!). So if the user wants to tweak for higher image quality, I would suggest the following steps:
Examples on the use of the formula:
For a 320x240 sized movie at 15 fps with 11 kHz mono sound:
RDR = SQRT(320*240)*15/30+11 = 149 kb/sec.
For a 640x480 sized movie at 15 fps without sound:
RDR = SQRT(640*480)*10/30+0 = 277 kb/sec.
Where's the calculator you ask? Well here it is
Please Note.
You must remember who your target audience is. It will be a waste of time producing a great video and then using a codec that can not be used by the "end user". A good example of this is; you down load the codec from the Indeo™ site that will compress your video for Pentium's™ with the MMX™ extensions. You send your final result to your customer and they have not yet upgraded to the Pentium with MMX. All your hard work was for nothing because they will not be able to display your video. Another problem is using a codec that is not widely available. I (Nigel) was caught here. My son downloaded a game that had a MPEG codec compressor delivered with the game. Because this is a codec it will automatically be added to your system as a valid codec to use. I used this codec and no one else could find it. As they say in the United Kingdom "I had egg all over my face" !!
Adding Sound / Audio
The good news is that adding sound is a one time hit and does not greatly increase the size of your AVI file, UNLESS (as you can see from the formula above) you are going to use CD Quality . Of course the over variable is the size of the (Height and Width) of the AVI. An 11 kHz mono sound track in a 20x20 movie will be considered large but a 44Khz stereo sound track in a 4096x4096 will be small, or as Johnny correctly states "A Mere Drop in the Ocean". (An acronym is born, from now on anything that is proportionally smaller than the whole will be called a "MDO")
The compression of the audio tracks are not handled by the codec but by PAE itself. You can now output audio at 11 kHz or 22 kHz depending on the quality of the sound that you wish to achieve. There is one thing that you must remember, by using stereo you will be doubling the amount of data that is required for the sound track
Streaming Video and the Internet.
Streaming a video over the Internet is a complex procedure that adds the true bottleneck into the equation. The speed of the Internet at any one time, the number of servers that the data must pass through and last but not least the speed of your modem.
Many companies have produced software that aid in the streaming of video over the Internet and the most common algorithm (An algorithm is programmers language for a block of code that is defined to does a specific task) used is that the compressor software will first send the entire frame and from that point on will only send the "pixels" that have changed until a new scene is required. (This approach has also been used by companies that have written Internet phones, though now a days the more common approach is to send at a much reduced frame rate)
The quality of streaming video over the Internet is getting better day as new algorithms are coming into play but the best break through has been in the speed of modems.
Conclusion.
We hope that this write up has been of use to you. If you have any comments on this page please do not hesitate to send e-mail to Nigel Aves.
This page and the contents of this page are copyrighted © by Nigel Aves and Johnny Norre and may not be reproduced by any means without the prior consent of the owners. FlickerFree™ and Video At Home™ 1999