Join Lee Brimelow for an in-depth discussion in this video Video compression basics, part of Flash Professional 8 Video Integration.
>>In this chapter I'm going to be showing you all the various ways in which you can encode your source video files into the FLV format. I thought before that it would be a good idea just to go over some video compression basics so we're all on the same page when it comes to all of the terminology, the buzz words and the acronyms that you're going to be seeing in the Encoding Tool. So one of the biggest buzz words that you hear all the time is codecs, video codecs. So what is a codec? It stands for compressor/decompressor and is basically an algorithm that controls how video files are compressed during encoding and then decompressed during playback.
So in the graphics world you can think of GIF and JPEG as graphics codecs. Now when it comes to Flash video there are two codecs that we're going to be dealing with , the Sorenson Spark and the new On2 VP6 codec. In the next tutorial I'm going to be explaining the differences between the two and also their compatibility with different versions of the Flash player. So there are essentially two types of video compression. Spacial video compression, which is also known as intraframe compression, is applied to a single frame of data independent of any surrounding frames.
So you can think of it as a sequence of images that you're using JPEG compression on. You compress each image individually and you don't take into account the other images that are in the sequence. Now the other type of compression is temporal compression. This is also known as interframe compression. It identifies the differences between frames and stores only those differences. Frames are described based on their difference from the preceding frame only and it can compress the video file really well.
So that is why I was talking to you before about acquiring your video footage with less movement. The less movement there is in your video, the less that has to be stored when it compresses the video file. The more movement there is in it the less space it can really save because it has to encode every frame almost as a full frame. So it definitely helps to minimize the amount of motion in your frame. Compression methods are how the encoder compresses your file. The first is constant bit rate or CBR.
With CBR the video's bit rate remains constant regardless of the complexity of the content. So essentially you tell it which bit rate to encode at. It's going to encode every frame at that bit rate regardless of whether there's no motion in the video or a lot of motion. It doesn't take motion into account. It just stays at the data rate which you told it to. Now this can be good if you're encoding for streaming video using Flash Media Server because, when you're relying on a certain video file being able to be viewed by a person with a certain bandwidth, it can be good to have a constant bit rate in your file.
The encoding is also faster when you use CBR. So variable bit rate, or VBR, is where the bit rate changes are based on the complexity of the content. So simple frames with a little motion are given a lower bit rate than complex frames that are given a higher bit rate. This is definitely the optimal method in most cases. If you have just a talking head video the encoder will recognize that and assign that piece of the video a lower bit rate.
Then when it comes to video with high motion content it has more bit rate in reserve that it can apply it to the complex frames. So this definitely will make the quality of your final video much higher. Encoding passes are how many times the encoder will actually go through and analyze your video footage. In one pass encoding the encoder goes through the video one time to analyze and encode the video. Oviously this is the fastest encoding method.
It basically goes through one time and does everything. With two pass encoding the encoder analyzes the video two times producing a much higher quality compression and bit rate distribution. You should always aim to use two pass encoding whenever possible. So it's analogous to rush doing your taxes and then ,without even checking the numbers and the calculations, sending it to the IRS. That would be an example of one pass encoding. With two pass encoding you would do it and then double check all your numbers to make sure you had it right before you sent it.
So it's kind of the same thing here. Now keyframes are particularly confusing for people coming from Flash because they are not the same kind of keyframes that you're used to using on the time in Flash. When it comes to Video Compression keyframes, they are complete video frames that are inserted in consistent intervals into the video clip, or when the codec detects a significant change in the video. They serve as the main point of reference for the frames that follow it. So they're whole video frames and the frames that come after it use them as a reference to build any parts that have been left out through compression.
I've put a note here that video with high motion may require more keyframes since there are more differences from frame to frame. So if you have a lot of motion in your video you definitely want to consider adding more keyframes. Now another reason why keyframes are important when building your video player is that, when you want to create a scrubber or a seek bar in Flash, it can only seek to keyframes. The more keyframes that are in your FLV file the more responsive your video scrubber will be.
So that's also something to keep in mind. Here's a simulated compression example. This is very simplified and is just a video of me shot in front of a green screen. So here would be the keyframe, the first frame of the video. Now for the next couple of frames it will recognize that, 'Hey, I don't need to encode this green background again.' So I'm only going to encode the parts of the video that are changing which are my expression and hands.
These frames are known as interframes or delta frames. They use the information from the keyframe, as well as the information from the frame before it, to build itself up. So here we save data because it doesn't have to encode the green background on every frame. Frame rates are the number of frames that appear every second. That number is known as the frame rate and it's measured in frames per second, or fps for short. Higher frame rates achieve smoother movement and animation but they also result in a larger file size and are more processor intensive for the people viewing it.
So it only makes sense that the more frames you have in the video the better it's going to look but the more data there will be. So if you have a video at 30 fps and another video at 15 fps per second,the video at 15 fps is half the size and uses half as much processor power in order to view it. So here are some common frame rates. So for NTSC, which is the TV standard in the United States, it's 29.97 fps. For PAL, which is the European TV standard, it's 25 fps.
In film, most film is shot at 24 fps. When reducing the frame rate, while you're encoding, the best results come using a number that evenly divides into the native frame rate. So that's very important. Here is a sample frame rate reduction. If the source was at NTSC frame rate, 29.97, the best results are achieved by cutting it exactly in half which would be 14.98; or cutting it again to 7.49 for a quarter of the source frame rate.
For NTSC a lot of people just take it as 30 fps and then take half of that as 15 fps. That will work fine but not using an exact factor of the source frame rate can result in audio syncing issues and longer video files. So when possible always use an exact factor of the source frame rate. Interlacing, you see that word a lot. In broadcast TV, and video shot with a camcorder, the video's known as interlace video.
Only half of a frame is shown at a time when you're viewing it on a T.V. set. It's alternating between the odd and even fields. Now computer displays and film are known as progressive and show only full frames. So definitely wherever possible you want to de-interlace any interlaced video sources if you can. We'll be looking at doing that and some encoding tools. Pixel aspect ratio; not all video uses square pixels. DVD and DV video use rectangular pixels instead.
Most video applications will automatically adjust to these pixel differences when you're switching between pixel aspect ratios and you definitely want to keep that in mind if you're using video from a DVD or a DV camera. Once converted to square pixels, DVD and DV will have a 4:3 three aspect ratio. So let's look at frame size and aspect ratio. The frame size represents the width and height of your video. The aspect ratio represents the ratio between the width and height.
So a common size for Flash video for the web is 320x240. Which has an aspect ratio of 4:3. It's probably the most common aspect ratio out there. Another popular ratio is 16:9 which is used for wide screen video. So here are some common frame sizes in both of those aspect ratios. These are very approximate but for 4:3, you'd be looking at maybe 640x480 for a user on a corporate LAN.
You can see they go down to 320x240, maybe a modem user would have 160x120, and then there you see some examples of 16x9 frame sizes. So let's talk now about the data rate. The data, or bit rate, represents the quality of the compressed video. It measures how many kilobits per second, kps, need to be transferred in order to view the file. Higher data rates mean much better quality but also much larger file sizes.
Again larger files are more taxing on the user's computer when viewing them. So here are some common data rates. Again, these are very approximate, but a high quality data rate would be 700 kbps, medium would be 400 kbps, low quality like a 56K modem would be 40 kbps. With a lot of people having high bandwidth this could go even higher. I put a note here that, when it comes to choosing the correct data rate, experimentation is the key because no two video files are going to be the same.
Every file has a unique amount of motion in it. So you really want to do some little experiments on every video file, to dial it down to just the right data rate and the right trade off between bandwidth and quality. So next audio compression. If your video has music in it you should be encoding it in stereo and it should probably be 64 kbps or higher. Video's with speech can only be encoded in mono at even lower bit rates than that. When you're dealing with Flash video you're almost always going to be encoding the audio using MP3 and we'll talk about when we get into actually encoding some files.
So here's a little example of the extremes of video compression. Here is a video of me in front of a green screen. You can see there's really a small amount of movement in this frame. Only my head and my arm is moving a little bit. So it's easy for the encoder to compress this because they can disregard most of this background because it's not moving. Now over here is the other extreme. This is a high speed shot of a barrier on a highway And almost every pixel and frame is changing.
So this would be the extreme case of a file that would be hard to compress. Finally I've put this here because, if you want to learn more about the things that I just mentioned, and want to go into a lot of detail and learn more about digital video, I definitely recommend this title here at Lynda.com by Larry Jordan called, "Digital Video Principles". He goes into all of these things in great detail and it's really a great foundation if you want to really get into video.