FLVio MediaKit - Encoding H.264 Video
Overview
This document describes how to produce H.264/HE-AAC encoded video using the FLVio MediaKit API. It also shows an example of how to configure a Flash video player to playback H.264/He-AAC video but automatically fallback to FLV video if the user's version of Flash is too old.
Introduction
Flash Player started supporting video playback in version 6, requiring a proprietary video format called Flash Video (using the file extension FLV). Flash Video files contain video streams which are a variant of the H.263 video standard, called Sorenson Spark. FLV video quality is adequate for web-based playback, but tends to produce relatively large file sizes (hence requiring large bandwidth) for high quality video.
As of Flash Player version 9 update 3 (December 2007) support for H.264 video (and HE-AAC audio) was added. H.264 is an advanced, open codec that produces very high quality video with smaller file sizes (lower bandwidth). It is used by some high definition video formats (Blu-Ray, HD-DVD) for example.
FLVio supports encoding videos to H.264/HE-AAC in a format that is fully compatible with Flash Player (version 9 update 3 and greater) providing FLVio users with higher quality video while using less bandwidth than Flash Video.
The main disadvantage to using H.264 video is that many users may still not have updated their Flash Player to version 9 update 3 or greater. To cater for this, FLVio makes it easy to encode both H.264 and FLV formats of the same video file so that Flash video players can be configured to play the best format possible for the version of Flash running on a user's computer.
Encoding H.264/HE-AAC
By default, FLVio encodes uploaded videos to Flash Video (FLV) format (and produces a JPEG thumbnail image). However, the encoded video formats, or "targets", can be customised using the header:
X-Flvio-Targets
The value of "X-Flvio-Targets" is a comma-separated list of target names. The currently supported target names are:
Target Name Description flv Flash Video (FLV) format [default]; h264 H.264/HE-AAC video (in an mp4 container).
To produce only a H.264 video you would specify the header:
X-Flvio-Targets: h264
To produce both FLV and H.264 video use:
X-Flvio-Targets: flv,h264
Note that a JPEG thumbnail is always produced.
Customising H.264 Bitrate
By default, H.264 video is encoded at a bitrate of 384kbps. This can be customised by specifying the header:
X-Flvio-Target-h264-bitrate
For example, to produce a 512kbps H.264 video use the header:
X-Flvio-Target-h264-bitrate: 512k
This header only makes sense when "h264" is specified as a target.
Flash Player Automatic Format Selection
FLVio works with any Flash video player but for the sake of this demonstration we will use the JW FLV Media Player. This video player can be configured to select between H.264 and FLV video based on the version of Flash that the user is running.
The example below shows the snippet of the HTML page that embeds the Flash video player. It is configured to play the H.264 video file "123.mp4". It is also configured with a "fallback" option to play the FLV video file "123.flv" if the version of Flash Player that the browser is using does not support H.264.
<p id="player"><a href="http://www.macromedia.com/go/getflashplayer">Get Flash</a> to see this player.</p>
<script type="text/javascript">
var so = new SWFObject('/flvplayer.swf','player','320','240','7');
so.addVariable("file","http://media.serve.flvio.com/media/mediakit/h264/demo/123.mp4");
so.addVariable("image","http://media.serve.flvio.com/media/mediakit/thumb/demo/123.jpg");
so.addVariable("fallback","http://media.serve.flvio.com/media/mediakit/flv/demo/123.flv");
so.write('player');
</script>
Other Flash video players should also support this handy feature, although may be configured differently.
| Updated: | 2008-08-26 |
|---|---|
| Version: | 1.0.0 |
| Copyright: | Locayta LTD 2008. All rights reserved. |