Home / Articles / Adobe Creative Suite / Video with Adobe Flash CS4 Professional: Compression and Encoding Primer

Video with Adobe Flash CS4 Professional: Compression and Encoding Primer

Article Description

Learn how to make the right decisions when it comes time to compress digital video and audio into Flash-compatible video files.
Understanding Video File Bit Rates

Understanding Video File Bit Rates

The bit rate of any video is the amount of data transmitted in a given unit of time, usually expressed in kilobits per second (Kbps) or kilobytes per second (KBps). The term data rate is synonymous with bit rate. Every video file on your computer has a specific bit rate. DV clips, for example, have a data rate of 30 megabits per second (Mbps), whereas a broadband-quality Web video clip can have a data rate of 500 to 1000 Kbps. The total bit rate of a video clip is divided between the video track and the audio track. The bit rate of the video track is referred to as the video bit rate, whereas the bit rate of the audio track is referred to as the audio bit rate.

The video bit rate of a given clip largely determines the visual quality of the video image. No matter how you slice it, a clip encoded with a lower bit rate shows less detail compared to the same source clip encoded with a higher bit rate. However, each video codec can utilize the same bit rate differently. One codec may be able to store more information per kilobit than another codec.

Variations within clip properties

Video bit rate is a unit of measure used to quantify how much information is stored within one second of video. You can use that quantity any way you want. Think of data rate like a specific length of material—you can have 3 feet of high-quality rope or 3 feet of low-quality binder’s twine. How well you use the bit rate of a video clip can determine the quality of the video a viewer experiences. Three primary factors determine how the video bit rate is utilized:

  • Frame rate: The frequency of video frames in your clip determines its frame rate, expressed as frames per second (fps). Higher frame rates have a lower bit rate per frame of video, whereas lower frame rates allow more data to be allocated per frame. Higher frame rates have smoother motion, and lower frame rates can exhibit jerky and unnatural-looking motion. Your content largely determines how much you can reduce the frame rate without destroying the flow of the clip.
  • Frame size: The width and height of your video clip determine the number of pixels in each video frame. You can think of video pixels like an allotment of grass seeds for a yard. For any given bit rate, you have only so many seeds. If you spread those seeds over a large area, your yard will be splotchy with large gaps between the blades of grass. If you concentrate the seeds, the yard will be smaller, but the grassy area will be rich.
  • Codec compression: Each video codec has its own method of compressing data. For Web video formats especially, two types of compression are usually applied: spatial (intraframe) and temporal (interframe). Spatial compression is similar to JPEG image compression: Redundant color information is thrown away to reduce storage requirements. Temporal compression stores only the changed information from frame to frame. More efficient codecs require less storage and deliver higher quality but usually require more processing power and computer memory (RAM) for video playback.

Every codec has an ideal bit rate after you’ve determined which frame size and frame rate you want to use. The following formula can help you determine whether your bit rate is acceptable as a starting point for encoding tests. For a list of each Flash Player–supported video codec’s divisor, refer to Table 3.1.

(Width x Height x Frame rate)  Compression = Bit rate (Kbps)

Table 3.1 Video Codec Compression Divisor

Codec

Compression divisor

Sorenson Spark (H.263)

6000

On2 VP6-E

7500

On2 VP6-S

7000

AVC/H.264 Base profile

6500

AVC/H.264 Main profile

8000

AVC/H.264 High profile

8250

If you want to compress a video file at 320 by 240 at 29.97 fps, the following formula is a good starting pointing as the average video bit rate for the Sorenson Spark codec (based on the H.263 codec), where 6000 indicates the compression divisor for Spark:

(320 x 240 x 29.97)  6000 ? 384 Kbps

Because the On2 VP6-E codec, or the VP6 codec using the E profile, requires less data rate for the equivalent quality, you can use a compression divisor of 7500:

(320 x 240 x 29.97)  7500 ? 300 Kbps

Flash Player 9 Update 3, or 9.0.115, added more video and audio codecs, including On2 VP6-S. The On2 VP6-S codec, or the VP6 codec using the S profile, requires a little more bit rate than VP6-E for the equivalent quality:

(320 x 240 x 29.97)  7000 ? 330 Kbps

The powerful AVC/H.264 codec was also added to Flash Player 9.0.115. Three profiles—Base, Main, and High—are now supported in Flash Player. The Base profile on average can achieve better compression than the Sorenson Spark codec but less than the VP6 family of codecs:

(320 x 240 x 29.97)  6500 ? 350 Kbps

On average, the Main profile of the AVC/H.264 codec can achieve better compression than all of the aforementioned codecs. The Main profile requires more processor power, though, than the Base profile:

(320 x 240 x 29.97)  8000 ? 290 Kbps

The High profile of the AVC/H.264 codec can achieve the best compression of all Flash Player–supported video codecs, at the expense of higher processor utilization, than the aforementioned codecs. The Main profile requires more processor power, though, than the Base profile:

(320 x 240 x 29.97)  8250 ? 280 Kbps

Each video encoding solution has its own set of compression profiles that try to match the best video width, height, and frame rate for these video codecs.

Variations within subject matter

The amount of video bit rate you need for a clip depends on its content. I prefer to place video content into one of three categories:

  • Average movement: If at least 25 percent of the pixels on any given frame of video remain the same, your video content isn’t updating frequently. Much of the content visible on prior frame(s) can be reused on subsequent frames. The bit rate formula in the previous section assumes your video exhibits average movement. Most video encoders and their presets assume your content has average movement in the frame. For example, a shot of a person walking across the room to pick up a glass might contain average movement.
  • Slow movement: If fewer than 15 percent of the pixels on any given frame change from frame to frame, your content is relatively stationary. For example, if your shot shows a person talking while sitting in a chair, the video frame is mainly updating around the person’s face. If your content exhibits slow movement, you can adjust the bit rate formula by dividing the result in half.
  • Fast movement: If more than 25 percent of the pixels on any given frame are changing, your content may be rapidly updating and may require more data to store the new information. A close-up shot of rushing water in a mountain stream exhibits fast movement. Fast movement clips can require up to twice as much bit rate. In the bit rate formula, be prepared to double the result.

You should also consider the complexity of the scene composition along with the motion in the scene. For example, you could have a clip featuring a moving subject on a relatively simple background, such as a dog running along a path shot from a fixed, nonmoving camera position. Even though the subject is moving, the background is static. Or, you could have a clip with a stationary subject on very complex background, such as a musician sitting on a chair and playing a guitar against a backdrop of a varied and detailed garden. In both of these instances, the complexity of the scene composition and the amount of motion should be averaged and applied to the bit rate formula.

Let’s compare some samples of content containing different styles of movement. The following series of figures demonstrates a slow, average, and fast movement bit rate formula. Each sample uses the same frame width, frame height, and frame rate with the same quality of source material (HDV).

Figure 3.1 shows a slow movement profile applied to a clip containing little or no motion. In this example, a park trail is shown with slight movement in the trees. The bit rate used for this clip is 280 Kbps with the Main profile of the AVC/H.264 codec.

Figure 3.1 The bit rate is 280 Kbps, with the Main profile of the AVC/H.264 codec.

Figure 3.2 shows an average movement profile applied to a clip containing some movement. This clip of a waterfall spilling into a large pool uses twice the bit rate for the same clip characteristics: 550 Kbps with the Main profile of the AVC/H.264 codec.

Figure 3.2 The bit rate is 550 Kbps, with the Main profile of the AVC/H.264 codec.

Figure 3.3 illustrates a fast movement profile applied to a clip with several changing areas. This clip of rushing water uses a bit rate of 1100 Kbps (or 1.1 Mbps) with the Main profile of the AVC/H.264 codec, twice that of the previous example.

Figure 3.3 The bit rate is 1100 Kbps, with the Main profile of the AVC/H.264 codec.

But what happens if you use a lower bit rate with the rushing-water clip, leaving the frame width, frame height, and frame rate identical? The resulting video image suffers horribly (Figure 3.4).

Figure 3.4 The bit rate is 280 Kbps, with the Main profile of the AVC/H.264 codec.

The formulas described in this section are by no means absolute—every piece of video is different. Use the bit rate formulas to help you establish reasonable start points in your compression tests.

Variations in audio quality

Thankfully, the relationship between audio quality and audio bit rate with a given video file is much simpler to predict and determine. Four primary factors determine audio quality with a given audio bit rate:

  • Sampling rate: This property determines how many audio samples are recorded per second, expressed in kilohertz (kHz). The higher the value, the more faithfully the original sound is reproduced. The common sampling rates for Web video are 11.025 kHz (or 11 kHz), 22.050 kHz (or 22 kHz), and 44.100 kHz (or 44.1 kHz). Audio CD recordings use a 44.1 kHz sampling rate, and some digital video formats record at 48 kHz. The sound quality you hear from FM radio broadcasts is roughly 22 kHZ, whereas 11 kHz is equivalent to telephone sound quality. Flash Player resamples all sound sources to 44.1 kHz during playback. For high-quality audio, I recommend always using 44.1 kHz. Use 22 kHz or 11 kHz sampling rates only if you need to encode low bit rate audio for slow connection speeds.
  • Channels: The audio track can be divided into one or more channels. A channel contains independent and discrete sound information. Most video files have only one (mono) or two (stereo) channels. Channels are usually aligned to a specific speaker for playback, such as a left channel and a right channel in stereo audio. Although some video specifications such as AVC/H.264 and its sister audio codec, AAC, support more than two channels of sound, Flash Player down-mixes additional sound tracks to stereo audio. Unless you want to retain stereo sound effects, I recommend using a single (mono) track of audio for Web video.
  • Bit depth: The range of values that can be recorded with the audio sampling rate depends on the bit depth of the audio track. For Web video, you should always use 16-bit audio, which enables an audio track to use a range of 65,536 values. Some audio recordings can be made at 8-bit, which is only 256 levels of audio and greatly reduces the overall sound quality.
  • Audio codec: The audio codec controls the compression applied to the audio track, just as the video codec does for the video track. Flash Player 8 and older support the MPEG-1 Audio Layer III (MP3) codec for the FLV file format, and Flash Player 9.0.115 and newer support the higher-quality AAC codec for AVC/H.264 video. Just as AVC/H.264 codec supports multiple profiles, the AAC codec has different profiles. Flash Player 9.0.115 supports AAC Main, AAC Low Complexity (LC), and High Efficiency AAC v2 (HE-AAC v2).

The formula to determine the appropriate bit rate for high-quality audio contains the following variables:

To convert the value to kilobits per second, divide the result by 1,000.

The divisors for Flash Player–supported audio codecs employed by video files are listed in Table 3.2. The MP3 codec has a compression ratio of 11:1, which means it reduces the uncompressed sound data by a factor of 11. So if you wanted to compress the audio track with the MP3 audio codec at 44.1 kHz with a mono channel at 16 bit, you should use an audio bit rate of 64 Kbps:

Table 3.2 Audio Codec Divisors

Codec

Divisor

MP3

11

AAC LC

15

AAC Main

16

HE-AAC v2

17

Unlike the video bit rate, the audio bit rate should conform to fixed values according to the specifications of the audio codec. For both MP3 and AAC codecs, refer to Table 3.3 Audio Bit Rates for MP3 and AAC Codecs

Table 3.3 for these fixed bit rates. Always round up the result of the audio formula to the nearest bit rate listed in the specification. Every encoding application I use enforces these bit rate values, and you usually choose an audio bit rate from a drop-down menu.

Table 3.3 Audio Bit Rates for MP3 and AAC Codecs

Bit rate (in Kbps)

8

40

112

16

48

128

18

56

160

20

64

192

24

80

256

32

96

320

When you intend to deliver video over the Web, you should carefully consider how you want visitors to experience the video playback. Connection speeds on the Internet vary greatly; some people have fast cable or fiber-optic modems, whereas others are still using slow 56 Kbps dial-up modems. Two general methods are used to deliver video on the Web, and each method greatly affects how to compress your video:

  • One bit rate: Only one bit rate is offered per piece of video content on the site. This is akin to a “one size fits all” approach, where you pick the quality of the video you want everyone to experience. If you choose a low bit rate, everyone sees a low-quality video, but the video content downloads quickly regardless of connection speed. If you pick a high bit rate, everyone can see a better-quality video, but visitors with slower connection speeds have to wait for the video to download. As a video compressionist, you need to encode and upload only one video file per piece of content.
  • Multiple bit rates: My preferred approach with most video content is to offer tiers of data rates. Visitors with fast Internet connections get high-quality, higher-bit rate video content, and visitors with slower Internet speeds get lesser-quality, low-bit rate video content. The video selection can be automated or user-initiated. For this approach, you must encode a separate video file for each targeted data rate.

If you decide to pick one bit rate for your video content, be aware of bandwidth problems that result. A high-bit rate video served over a slow Internet connection will result in long load times and possibly constant rebuffering during playback. When a video is sent from a server to a Flash movie, the video packets are temporarily stored in a memory buffer. If you play a video file and the buffer is empty or runs out, the video pauses until more video packets have downloaded.

To resolve this problem, make sure the video file’s bit rate is less than the network connection speed. The video can then download to the user as it’s played without as much risk that rebuffering will occur.

3. Learning About Player Versions and Codec Options | Next Section Previous Section