Section 7.1. Audio and Video Compression


7.1. Audio and Video Compression

Most digital audio and video content is compressed for efficient storage and transmission. Uncompressed content requires large file sizes; for example, 1 second of uncompressed broadcast television-quality video consumes at least 26 MB of storage. Such bandwidth requirements are unrealistic for real-time viewing over even the fastest networks. As a result, media formatssuch as Windows AVI (Video for Windows) and Apple QuickTimeuse various codecs to compress and decompress audio and video information. One of the more popular consumer video formats, DVD-Video, uses the MPEG-2 codec. Some codecs are specific to the file format or platform. However, the Sorenson Spark codec used for the Flash Video (FLV) files is built into the Flash Player and therefore supported on all platforms. Sorenson Spark is the primary video codec used by Flash Player 6 (or higher), as well as FlashCom Server.

When not using FlashCom, Flash Player 6 requires the video to be embedded in a FLA file (it is included within the published SWF file), but Flash Player 7 supports progressive download video. This allows external FLV files to be played from a standard web server over HTTP and delivered to a browser equipped with Flash Player 7. FlashCom uses the same file format (FLV) but offers streaming capabilities and other features not supported by a web server alone, as described in the Preface.

With the release of the Flash Video Exporter version 1.1 (and now version 1.2) included with Flash Pro, Macromedia added a metadata field named totalTime to FLV files. FLV files that contain this extra piece of information are dubbed FLV 1.1 files, while earlier FLV files are considered version 1.0. If you install the latest Updater 2 to your FlashCom Server installation, the server will also record this extra metadata to your FLV files. You can use either FLV 1.0 or 1.1 files with any version of FlashCom Server. Both versions can also be loaded progressively with Flash Player 7. See the related notes under "Exporting Video from QuickTime Player Pro with the FLV Exporter" and "MediaPlayback Component" later in this chapter.

7.1.1. The Sorenson Spark Codec

The Sorenson Spark codec allows the Flash Player to play video content. The Spark codec is built right into Flash Player 6 and later, so no extra system files or installation is required. (Other video players, such as Apple QuickTime, support external codecs that are installed by default or downloaded separately.) Sorenson Spark can be used to play back streams from a FlashCom application. It can also be used to encode real-time, live video from a web cam or other video source and send it to a FlashCom application.

The fact that the Spark codec is built into Flash Player 6 and later saves Flash developers a lot of griefother multimedia authoring engines, such as Macromedia Shockwave, rely on external video players such as QuickTime, which may require additional downloads to install more components or the necessary codec.

The Sorenson Spark codec can encode (compress) video material in one of two ways: constant bit rate (CBR) compression or variable bit rate (VBR) compression. The following sections discuss the difference between these two encoding options.

7.1.1.1 Constant bit rate (CBR) compression

Constant bit rate (CBR) compression is most common for live streaming video. When you publish or subscribe to a live stream delivered from a FlashCom Server, the video is using CBR compression. The term basic or standard Spark codec refers to the CBR encoding mechanism.

In CBR compression, each video frame is encoded with uniform data size constraints, regardless of content changes. A stream using CBR will "dice up" the available bandwidth over the number of frames delivered over a given amount of time. For this reason, the amount of change occurring within the video frame should be kept to a minimum. Talking heads or any other slow-moving content work reasonably well with CBR compression applied. However, fast-moving content, such as hockey players skating over ice following a puck, will not fare well with CBR compressionthe content within the video frame changes at a rapid rate; as a result, more compression must be applied to each frame to keep it within the bit rate constraints. More compression means lower quality, appearing as "blocky" or chunky video.

Refer to Chapter 6 for more information about controlling the quality and bandwidth limits for live video streams using the Camera class.

7.1.1.2 Variable bit rate (VBR) compression

While CBR compression is the only option for live streaming video, you can use variable bit rate (VBR) compression for video content that you have already recorded or created with another software application, such as a 3D modeling program or a recording device like a professional video camcorder.

VBR compression is one of the features available in the Sorenson Spark Pro edition codec. Sorenson Squeeze, discussed later in this chapter, utilizes the Pro edition of the codec and offers several encoding options unavailable in other Flash Video utilities.


A variable bit rate allows the encoding mechanism of Sorenson Spark to change the amount of data stored in each frame, enabling it to utilize any leftover bandwidth for more intensive frames (i.e., a frame that has substantially more content changes). During the VBR encoding process, the entire video clip is analyzed , frame by frame. The encoder makes a log of the analysis and decides which frames it can group together because there is little or no difference among them. With these similar frames, the encoded video file stores only the changes from one frame to the next . In truth, CBR-encoded video can also do similar interframe detection, but not nearly as efficiently . The additional analysis performed during VBR encoding, however, makes it impossible to use for real-time (live) encoding. Within a group of similar frames, a VBR encoder can minimize the bandwidth required and " borrow " the bandwidth it saved for use on more intensive frames (actually exceeding the bandwidth cap).

The qualitative differences between CBR and VBR compression cannot be overemphasized. VBR compression will always yield better looking video content and usually results in substantially smaller file sizes as well. Figure 7-1 shows a black-and-white (grayscale) video frame encoded with CBR and VBR compression.

Figure 7-1. Comparison of CBR encoding (left) and VBR encoding (right)

If you can't see the difference in print, you can find a demo comparing encoding types at:

http://www.flash-communications.net/examples/ch07/encoding.html

In order to compress video with Sorenson Spark's VBR codec, you need to use a dedicated software utility. Macromedia Flash MX Professional 2004 (Flash Pro) includes the Flash Video Exporter Tool, an add-on to Apple QuickTime, enabling you to create VBR-encoded FLV files. (The Flash Video Exporter is also known as simply the FLV Exporter.) Third-party applications such as Sorenson Squeeze and Wildform Flix can also be used to create high-quality FLV files with VBR compression. We cover all of these utilities later in this chapter.

7.1.2. The Speech Codec

Flash Player 6 and later also includes a built-in Speech codec, specifically added for streaming live audio. The Speech codec is the only audio codec available for live streaming audio from the Flash Player. The Speech codec uses a constant bit rate to encode audio information. You can control the quality (and bandwidth intensity) of the audio stream using the Microphone.setRate( ) method. The Speech codec can use the following sampling rates: 5, 8, 11, 22, or 44 kHz. The higher rates yield higher-quality (better sounding) audio at the expense of higher bandwidth.

When you publish an audio source to FlashCom, the audio encoded by the Speech codec can support only monaural sound. Stereo sound cannot be published to a FlashCom application. Refer to Chapter 6 for more information regarding the control of audio quality with the Microphone class.

7.1.3. Prerecorded Versus FlashCom-Recorded Media

Chapter 6 taught you how to record content to a FlashCom application with the Camera and Microphone classes. When you record live content to FlashCom from a video source captured by the Flash Player, you have the following limitations:

  • The video source is encoded with the Sorenson Spark codec using CBR compression, limiting the quality of the video image.

  • The audio source is encoded with the Speech codec using CBR compression.

  • The audio source is converted to mono sound.

However, if you record or capture your content with an external application, your media options expand greatly. You can control the following options with one or more of the applications discussed later in this chapter:


Video codec type

With the FLV Exporter tool included with Flash Pro, you can choose between the Sorenson Spark codec or the Screen Recording codec. See the later section "The Screen Recording Codec" for more information.


Audio compression

With any of the Flash Video encoding utilities, you can encode the audio channel of your source file with MP3 compression, which supports stereo sound and higher bit rates than the Speech codec.

Regardless of how you create the FLV files used by your FlashCom application, you can view any FLV files over HTTP with the progressive download option for NetStream instances in Flash Player 7. Refer to the Preface for details on how this option differs from streaming support provided by FlashCom.

7.1.4. The Screen Recording Codec

One of the benefits of the Flash Video Exporter over other third-party FLV encoders is the capability to encode FLV files with the Screen Recording codec. As its name implies, this lossless codec is designed to work with desktop screen captures. If you have recorded an AVI or MOV file of a task performed with a desktop application (e.g., a tutorial video demonstrating how to use a program such as Flash MX 2004), you can create a compressed FLV file with the Screen Recording codec for optimal clarity of screen details. Make sure you use a low frame rate (6 to 10 fps) and a high keyframe interval (60 or higher) to keep your FLV bit rate from being too demanding for your target audience's bandwidth availability.



Programming Flash Communication Server
Programming Flash Communication Server
ISBN: 0596005040
EAN: 2147483647
Year: 2003
Pages: 203

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net