Accessibility

Encoding Best Practices for Prerecorded Flash Video

Kevin Towes

Adobe

There are three challenging aspects to mastering posting video on the Internet: encoding it, delivering it, and customizing the experience. This article focuses on the encoding process to prepare your video with the highest possible quality. As you will see, there is no single solution for encoding. I will provide insight into the encoding process and show you how to prepare your video for smooth playback with an eye towards bandwidth costs and your audience.

I will also explore and compare the Flash Video settings for encoding prerecorded video. My second article, Producing Live Video, details the same process for live video. I do not discuss the details of each setting, however, because they are fully described in the "Capturing and Encoding Video" section of the Flash Video Learner's Guide.

Requirements

This article makes references to the following software and files:

Macromedia Flash MX 2004 Professional

Level of Expertise Required

This article pertains to all skill levels: basic to advanced.

Related Information

Before reading this article, get comfortable with the aspects of the Sorenson Spark video codec and Flash Video in general by reviewing the following comprehensive documents. They are a great introduction to Flash Video and bandwidth strategies:


Also check out my other article on Flash Video, Encoding Best Practices for Live Video.

Video Encoder Matrixes (for Prerecorded Video)

Prioritizing video properties is key to producing high-quality Internet video. My team and I conducted a study to develop the following recommendations for encoding Flash Video. For this study, I used the Flash Video (FLV) Exporter and Sorenson Squeeze. I adjusted the compression settings of the FLV exporter to balance the data rate with the frame rate and size. The following sections provide settings recommendations for various combinations of video quality and user bandwidth.

Note: Many of the terms used in this section are described in the "Capturing and Encoding Video" section of the Flash Video Learner's Guide. For more information on the methods and source clips used in this study, see the Optimal Encoder Settings Study section of this article.

Encoder Matrix for Video Sources of Higher Quality

Table 1 lists my recommended encoder settings for video from higher quality sources with good lighting. Further down are some points to consider when setting up your encoding scheme. I've included an example of video for each setting.

Note to Flash Video Kit users: This table takes the place of the Interactive Settings Calculator mentioned in the "Flash Video Primer."

Table 1. High-Quality Source Footage
Target Connection Speed Video Bitrate Height Width FPS Keyframe
Interval
Audio Bitrate
High Motion High motion; lots of zooms, fades and people moving around
1.5 Mbps 750 Kbps 320 240 29.97 60 96 Kbps
768 kbps 575 Kbps 320 240 29.97 60 64 Kbps
384 Kbps 329 Kbps 320 240 14.98 30 32 Kbps
56k Dial Up 40 Kbps 192 144 9.99 20 8 Kbps
Low Motion Low motion; general talking heads
1.5 Mbps 650 Kbps 320 240 29.97 60 96 Kbps
768 kbps 230 Kbps 320 240 14.98 30 64 Kbps
384 Kbps 153 Kbps 320 240 9.99 20 32 Kbps
56k Dial Up 40 Kbps 192 144 9.99 20 8 Kbps

Note: Keyframes are set to 1 KF every 2 seconds.

Considerations When Encoding

Below are some general rules of thumb to follow when compressing video to Flash Video for delivery over the Internet. These general rules will help you manipulate the previous matrices to produce higher quality Flash Video:

Frame Rate, Size, Keyframes, and Data Rate

As you read the following discussion, consider the relationships among frame rate, size, keyframes, and data rate and how they all are affected by the quality and motion level of the six video clips (see Figure 1).

Flash Video Exporter version 1.2 pointing out the key settings that affect the encoder

Figure 1. Flash Video Exporter version 1.2 pointing out the key settings that affect the encoder

Data rate (quality) is related directly to frame rate and frame size:

((320 x 240 x 30fps)/1000) DIV 2.5 = 922 Kbps

The above formula is derived from the standard formula for calculating data rate:

frame height x frame width x frame rate (fps) = total bits/sec.

I divided by 1000 to convert bps to Kbps, and I've divided that result by 2.5 because the Sorenson Spark codec has a 2.5:1 compression ratio as you apply it.

Reducing the frame rate by half requires half the data rate:

((320 x 240 x 15fps)/1000) DIV 2.5 = 460 Kbps

Reducing the frame size by half produces a much more dramatic effect on the bandwidth requirements. In the following scenario, notice that by reducing the frame size by half and keeping the frame rate at 30 reduces the data rate demand to one quarter of the original:

((160 x 120 x 30fps)/1000) DIV 2.5 = 230 Kbps

Keyframes are directly related to the frame rate. The higher the frame rate, the more uncompressed keyframes are required. Keyframes are calculated on a per-second basis. The Flash Video encoder requires a value describing the number of frames between each keyframe. You can enter any value you like into the encoder; however, calculating keyframes on a per-second formula produces optimal results. The Flash Video Exporter suggests a keyframe every four frames. You can see this in the Flash Video Exporter by changing the frame rate and then selecting Auto for the keyframes. To calculate more or fewer keyframes, use the following formula:

keyframe interval (sec.) x frame rate (fps) = keyframe value

1s x 12fps = 1 keyframe every 12 frames
2s x 15fps = 1 keyframe every 30 frames
4s x 15fps = 1 keyframe every 60 frames
5s x 30fps = 1 keyframe every 150 frames

Adjusting the keyframe interval does not affect the data rate value directly but does affect the physical size (on your hard drive) of the compressed video file. Alternatively, the data rate value does affect the image quality of the keyframes: The more keyframes you have, the more bits per second are consumed. The recommended rate is one keyframe every four seconds; if you increase this rate to one keyframe every two seconds, the quality of the keyframes will be reduced and, ultimately, the quality of your video will be affected. Increase your data rate to compensate for keyframes above one every four seconds.

Factors That Affect Video Encoding

Outside the physical properties of your video there are factors that affect the efficiency of the encoder and ultimately the user experience of the video playback. Two factors play a significant role in the encoding process: source quality and frame motion.

Source Quality

You determine the source quality of your video as soon as you press the recording button on your camera. Here are some basic rules for getting great source video quality and maximizing quality in your final compressed video.

Frame Motion

Frame motion is another factor to consider in your encoding formula: It is the percentage of pixel change from one frame to another. This change can result from character (or actor) events, camera effects, or post-production effects:

The higher percentage of frame motion within your video clip, the more information the encoder has to compress. If your clip is relatively still (such as a talking head video), there isn't much pixel change from frame to frame. The video compressor uses a method of dropping frames and then encoding a series of fully uncompressed frames. These uncompressed frames, called keyframes, are used to calculate and "rebuild" the missing frames during playback.

Figure 2 demonstrates this effect. The capture on the left shows a dissolve (high-motion) effect with a low data rate. The capture on the right shows the same effect with a much higher data rate.

Comparison of a low (100 Kbps) data-rate capture on the left, and a high (384 Kbps) data-rate capture on the right.
Comparison of a low (100 Kbps) data-rate capture on the left, and a high (384 Kbps) data-rate capture on the right.

Figure 2. Comparison of a low (100 Kbps) data-rate capture on the left and a high (384 Kbps) data-rate capture on the right

Notice the artifacts of the dissolve with a lower data rate in the image of the 100 Kbps capture. High motion will have the same result of a blocky and blurry image. Notice the higher-quality dissolve when using an increased data rate in the 384 Kbps capture on the right. The image is also much sharper and has a higher quality.

When little motion is involved, too much data rate is a waste of space. Figure 3 demonstrates this fact clearly. The capture on the left is the same 100 Kbps video. Notice the image quality is only slightly less then the image quality of the 384 Kbps capture. Compare that with the differences in Figure 2.

Low-motion, low data-rate capture (left), and low-motion, high data-rate capture (right)
Low-motion, low data-rate capture (left), and low-motion, high data-rate capture (right)

Figure 3. Low-motion, low data-rate capture (left) and low-motion, high data-rate capture (right)

In the images shown in Figure 3, notice that when there is little motion in the video frame, you can get away with a lower data rate, as demonstrated in the 100 Kbps image on the left. The image is much sharper in the higher data rate (383 Kbps) image on the right, but is it worth 284 Kbps extra?

Key Frames and the Key Frame Interval

Flash Video is encoded using a temporal method of digitizing. During the digitizing process, keyframes are used as full-frame, uncompressed images inserted into the video clip. These images are frames that the decoder uses to recreate the frames (delta frames) in between them. It's a similar concept to traditional Flash animation. Consider as an example, a Flash file with an object positioned on the stage. In the timeline, the object is repositioned at another frame. When played, the system calculates the in-between frames, called tweens or delta frames.

Typically, the Flash Video Exporter recommends a keyframe every four seconds to produce the optimal setting. The keyframe interval is the number of frames that pass before a new keyframe is created. It is calculated by multiplying the frame rate by the time interval (in seconds).

Formula:
frame rate (fps) x interval (sec.) = keyframe interval

Example:
15 fps x 4 sec. = 60

This places a keyframe every 60 frames starting at frame 1.

The greater the interval between keyframes, the harder it is for the codec to rebuild the missing frames. For example, a high-motion video clip with a large keyframe interval results in the perception of poorer quality. If your keyframe interval is too great, you run the risk of not having enough data rate to compress and transmit the data bits.

With Flash Video, keyframes are vital if your solution has a seek or scrub feature, which allows a user to advance the stream during playback. The streaming server Flash Communication Server is required to enable this feature.

Sorenson Squeeze Extra Encoding Features

Sorenson Squeeze (www.sorenson.com) has a unique feature called Automatic Key Frames that automatically generates a keyframe every time there is a major change in the video image (such as a straight cut). You can further control this feature by selecting the threshold of change for the keyframe generator (see Figure 4).

The Sorenson Squeeze automatic keyframe generator and quality settings help produce a cleaner, smoother FLV file.

Figure 4. The Sorenson Squeeze automatic keyframe generator and quality settings help produce a cleaner, smoother FLV file

One important feature of the product is the Drop Frames option. During the encoding process, if the data rate limit is in risk of being reached, this option maintains the integrity of the video stream. It will not compromise the quality by simply dropping frames. Because this may result in sporadic "jumps" in video playback, be careful when selecting the keyframe frequency.

The Minimum Quality option throttles the data rate dynamically to ensure that the quality of the video is within a threshold you set. Be careful with this option and make sure the Drop Frames option is also set. The data rate will increase beyond your preset limit and may result in a poor reception (rebuffering) by low-bandwidth users.

Encoding Methods

Two encoding methods are available for most streaming packages, including those that compress the FLV format. Constant bit rate encoding and variable bit rate encoding are two options for compressing a file within the limit of the data rate ceiling:

Many compression packages support a two-pass VBR. The first pass allows the compression package to analyze the video and store information about it before it starts the encoding process in the second pass. This option increases the time it takes to compress the video but yields much better results. Both the Flash Video Exporter and Sorenson Squeeze support two-pass VBR encoding.

Optimal Encoder Settings Study

In this article, I'm presenting the results of a study to produce optimal encoder settings for high-quaility video. To discover the optimal compressor settings for creating Flash Video, I developed a study to measure changes in the encoder settings with some constants. I then used the two factors—motion and target bandwidth—as a foundation for setting up the encoder tests. This resulted in two variations of video at different bandwidth targets. You can study the recommended encoder settings for high-quality source in the High-Quality Source Footage matrix earlier in the article.

How We Determined the Settings

In our test, each video clip was 30 seconds in length with no audio track. Three clips were produced from higher quality sources (film, digital Beta, etc.) with professional lighting, stability (tripod/Steadicam), and production quality.

We developed three motion levels: high, medium. and low. High motion included large amounts of camera zooming, cross fading, and general movement of objects within the video frame. Medium motion clips reduced the amount of zooming, panning, and movement within the frame. Low motion levels reflect a "talking head" or a wide shot where little changes in the frame.

To offer a fair comparison, we matched the following video properties across all three videos:

Conclusion

In summary, encoding your video is a critical part of the process of publishing video to the web. Use the settings and formulas in this article only as a foundation. Everyone has different demands for video and different video problems that need to be solved. The Flash Video platform is an excellent platform for delivering the best possible experience to the greatest number of people. It is an excellent solution to customize the video surroundings and give you absolute control over every part of its delivery. Mastering the art of encoding takes trial and error, but after reading this article, you should have a much better understanding of the process and be able to produce excellent results.

About the author

Kevin Towes is the product manager for Flash Media Server at Adobe Systems and is responsible for defining, delivering, and supporting Adobe streaming video products and services. Before joining Adobe, Kevin spent 13 years working to enable customers with Flash based interactive video streaming solutions using Flash Media Server. His Flash Media Server Live Video work with the Canadian Broadcasting Corporation (CBC) led to an Emmy nomination in 2004.