Digital Web Magazine

The web professional's online magazine of choice.

Efficient Video Delivery Over The Internet

Got something to say?

Share your comments on this topic with other web professionals

In: Articles

By Lei Zhu

Published on May 13, 2008

They say a picture is worth a thousand words. In this day and age of digital media, video on your web site can be priceless. Whether you have a corporate, social networking, or video streaming site, video instantly captures your visitor’s attention and describes your product and services quickly and effectively. Due to its large install base, Flash video is now the de-facto standard in internet video delivery. With recent updates to Flash 9, Flash Player adds the capability of playing H264 encoded video in full screen mode, making the delivery of Flash videos on the internet not only practical, but efficient as well. In this article, I will examine a few different techniques for delivering Flash videos over the internet and compare the advantages and disadvantages of each.

HTTP Progressive Download

The simplest and most straightforward approach to delivering Flash video over the internet is using HTTP progressive download.

To distribute a Flash video using HTTP progressive download, simply place Flash-compatible video files on your web server and point the Flash player to the URL of the video file. Delivering video using HTTP progressive download does not require any additional software or hardware beyond what is necessary for hosting a standard web site. A Flash video player is required for playing the video. There are quite a few good open source players that can be readily used. If your video is viewed by a large number of users, you probably want to deliver the video over a CDN (Content Distribution Network). HTTP progressive download can work with any CDN service.

The disadvantage to HTTP progressive download is that the video content is loaded sequentially, meaning that the user cannot access a later part of the video until the video is completed. For example, a ten minute video may take a couple of minutes to download depending on the user’s bandwidth. If your user only wants to see the last minute of the video, they must wait for the first nine minutes to download before proceeding to the end. Thus, the first nine minutes of the downloaded video are effectively wasted. Another issue to be aware of when using HTTP progressive download is the lack of access privileges. Anyone can point their browser to the video file URL, download, and replay it on their local computer with a Flash compatible video player.

In general, HTTP progressive download is a good solution if:

RTMP Streaming

A more bandwidth-efficient and user-friendly video delivery method is RTMP streaming.

RTMP is a proprietary protocol developed by Adobe. In addition to streaming video, RTMP can be used to broadcast live video streams and ingest live Flash audio and video. Streaming Flash video using RTMP requires the Adobe Media Streaming Server or Red5, an open source software package that implements RTMP. In general, RTMP streaming does require more up-front investment in terms of configuring media servers. However, with RTMP streaming, it is possible for a user to jump to different points in the video without having to wait for the entire video to be downloaded. In addition, only video data viewed by the user is delivered. RTMP streaming servers can also restrict access to contents served. So, for example, it is possible to create a pay-per-view service using RTMP streaming. Established CDN providers such as Akamai and Limewire Networks have specific services for optimized streaming of Flash-compatible video files.

Use RTMP streaming if:

HTTP Streaming

A hybrid of the two previous approaches to delivering video, that has some advantages of both, is HTTP streaming.

HTTP streaming is based on the idea of HTTP progressive delivery, but it lets users jump to a specific point in the video. Popular web sites such as YouTube and Google Video use HTTP streaming to serve video over the internet. An HTTP streaming-capable server can start streaming from a specific keyframe if the video file is encoded with proper metadata. A commonly used tool for injecting metadata into flv files is flvtools.

HTTP streaming does require server configuration in addition to the standard web server. Many open-source tools exist for HTTP streaming. If you are using lighttpd, simply install mod_flv_stream or mod_h264_stream to stream flv or H264-encoded Flash videos. Any web server that supports PHP can use HTTP streaming using PHP streaming.

While HTTP streaming does let users jump to a different video quickly, it suffers some of the same drawbacks as HTTP progressive download. Video content may be downloaded without actually being viewed, resulting in inefficient bandwidth usage. In addition, HTTP streaming is not supported by storage services only capable of serving static content such as Amazon’s S3. So, use HTTP streaming if:

Partitioning Multiple Segments

Finally, there is an approach to delivering Flash video that has the advantages of both HTTP progressive download and HTTP streaming. The advantages of this approach are:

This approach requires video to be partitioned into multiple segments. Each segment is a file that contains a part of the video in a specific time period. Think of each segment as a chapter in a DVD. Instead of having each chapter carrying a specific scene, segments are fixed in length with the exception of the last segment. A good length for each segment is 5 to 10 seconds depending on the type and length of the video. Assuming each segment is 10 seconds long, the Flash video player starts by loading and playing the first segment. As the first segment passes the 5 second mark, the player begins to buffer the second segment, when the first segment completes, the players starts playing the second segment and so on. If you want to jump to the 36th second in the video, the player starts playing the 3rd segment of the video. The video will start playing at the 30th second which is not the exact location, but pretty close. If the video being served is long, this wouldn’t be a significant issue. It is possible to shorten the segment to 5 seconds to allow more fine tuned location seeking. Each segment of the video is only loaded when viewed or when the previous segment approaches the end. Therefore, at most one extra segment of video file is loaded beyond what is viewed. In addition, since each segment has a fixed URL and are generally small, the loaded segments can be cached by the web browser.

Use this approach if:

Playing video in segments does require a specific Flash player. Implementing a Flash video player capable of playing segmented video files is fairly straight-forward.

First, the Flash video player has to load and play video for each segment. In order to buffer the next segment of the video while the current video is being played, two NetStream objects are necessary. The currentStream object holds the stream currently being played while the nextStream object buffers the next segment. In the Video object’s ENTER_FRAME event handler, the buffering of the nextStream object should start when the currentFrame passes a certain threshold, i.e. the middle of the segment. When the currentStream reaches the length of the segment, the nextStream becomes the currentStream and the video player starts playing the next segment of the video.

View an example of this technique here.

In the example, the video is split into 5-second segments. The names of the video files are time-coded, making it easy to seek to a specific segment. Beneath the video player, the file currently being played and buffered are shown as well as the current timestamp of the video. Thumbnails of video segments make it easy to jump to different parts of the video easily. As you can see, only the segments viewed and buffered are actually downloaded.

Supported Video Formats for Flash

There are three different codecs supported by different versions of Flash players.

The Sorenson codec is supported by Flash 6 and above. It is the most widely supported format, but not as efficient. Flash 8 added support for the On2 VP6 codec. The recently release of Flash 9 update 3 supports the H264 codec. H264 is the codec used to encode Blu-Ray videos and is highly efficient. With H264 support, Flash can play HD-quality video over the internet.

If your video file is not encoded in one of Flash’s supported codecs, you will need to transcode your video. The Adobe CS3 Flash Professional development packages offer tools for transcoding video files into Flash-supported formats. Alternatively, you can use an open source tool such as ffmpeg.

Finally, an issue with streaming H264-encoded video that you should be aware of is that most encoders put a ‘moov atom’ at the end of the file, forcing Flash players to read the whole file before video playing can start. Tools such as qt-faststart and QT Index Swapper move the moov atom to the front, so streaming can start instantly.

Conclusion

This is an exciting time for video streaming. With H264 support, online video is no longer limited to short fuzzy videos. Instead, video streamed over the internet can rival the quality of broadcast video. With all the advantages of video available on demand over the internet, it will be exciting to see what new services and features will become available as the latest Flash player penetrates the market.

I hope the techniques discussed here will be a helpful guide to getting video streaming on your web site.

Further reading and resources

Got something to say?

Share your comments  with other professionals (6 comments)

Related Topics: Technology, Browsers

 

Lei Zhu is a software developer living in New York City. One of his technical interests is to build highly reliable web applications using inexpensive infrastructure. He can be reached at lei~at~leizhu.com.

Media Temple

via Ad Packs