Go
Not registered? Sign up!

Bitrate Switching Tutorial

Google Translate

Version 4.6 of the JW Player introduces a server-independent mechanism for bitrate switching. You can now provide the player with multiple versions of a video, letting it select the version that best match a visitor's screen size and bandwidth. Visitors with a broadband connection can watch the HD version of your video, while visitors with a dialup connection will get a low-quality (but smooth playing) version served. Bitrate switching is a one-size-fits-all solution that requires no action from the visitor.

How it works

The JW Player has a very basic, pragmatic implementation of bitrate switching:

  • It is automatically enabled when an XML playlist is loaded that contains multiple videos per playlistitem (setup below).
  • Each of these video levels need to have a width and a bitrate property set.
  • Based upon the streaming type, the player has a number of switching moments (e.g. on startup).
  • At such a moment, the player matches the display width to the width of the different levels, and the bandwidth of the connection to the bitrate of the different levels.
  • The highest quality level whose width and bitrate fits within the display width and connection bandwidth is selected for playback.

The number of switching moments depends on the streaming type used:

  • With regular video downloads (no streaming), the level is only selected on startup.
  • With HTTP streaming, the level is selected on startup and with every resize (going to/from fullscreen) and seek action.
  • With RTMP streaming, the level is also selected on startup, resize and seek.
  • However, if the RTMP server is Flash Media Server 3.5, the level is continously being evaluated (every 2 seconds), in a mechanism Adobe calls dynamic streaming.
    • The big advantage of dynamic streaming is that no re-buffering of the stream is required. Therefore it is the only streaming type that offers bitrate switching in the middle of playback. With all other streaming types, the player only switches levels at a moment the user is already interfering with playback himself (resizing the player or seeking in the stream).

      Stream switching for RTMP based upon bandwidth only works if the server implements a checkBandwidth call. This is default in FMS 3.0+, and trivial to setup with Wowza. If there's no checkBandwidth handler, streams will be switched solely based upon the available display width.

      Example Player

      Here is a player that offers a bitrate switching example for every streaming type. The little plugin on top of the video (the Quality Monitor plugin) shows the current display width, the current bandwidth and the currently playing level. While testing, you'll see that the progressive download example only switches on startup and that the RTMP/HTTP examples need a little rebuffering after every switch.

      You'll also note it takes the FMS3.5 example about 10 seconds to update the stream every time a switch is performed. This is as expected: the server first needs to wait for the next keyframe in the video to anticipate the switch and then for the second keyframe in the video to actually perform the switch.

      Get the Flash Player to see this player.

      Every example in this player uses four different transcodes of the Elephant's Dream video, ranging from Youtube quality to just below 720p HD:

      • A version that is 320px wide and 400 kbps.
      • A version that is 480px wide and 800 kbps.
      • A version that is 720px wide and 1200 kbps.
      • A version that is 1080px wide and 1600 kbps.

      All four versions are MP4 files with H264/AAC, whereby the baseline encoding profile of H264 is used. An advantage of this profile over the - better - main or high profiles is that it needs less CPU for decoding. CPU stress is still something to keep in mind, since the JW Player does not take it along as part of the bitrate switching mechanism.

      Playlist Setup

      Moving to the actual setup, it is good to know that video exported by any encoding software will work with bitrate switching. There's no alignment of keyframes or other special requirements. Both FLV and MP4 are supported. You are free to select the number of quality levels to use (3 to 5 recommended), and the bitrate of these levels (200kbps to 2000kbps recommended).

      No specific flashvars are needed to setup bitrate switching. All neccessary data is placed in the XML playlist, which can be assigned to the player with the file flashvar. Here is an example XML with just a single video, played as a regular progressive download:

      <rss version="2.0" xmlns:media="http://search.yahoo.com/mrss/" >
        <channel>
          <item>
      
            <title>Progressive download</title>
            <link>http://www.bigbuckbunny.org/</link>
            <description>Big Buck Bunny is a short animated film by the Blender Institute.</description>
            <media:group>
      
              <media:content bitrate="1500" url="http://bitsontherun.com/videos/Qvxp3Jnv-486.mp4"  width="1080" />
              <media:content bitrate="1100" url="http://bitsontherun.com/videos/Qvxp3Jnv-485.mp4" width="720"/>
              <media:content bitrate="700" url="http://bitsontherun.com/videos/Qvxp3Jnv-484.mp4" width="480" />
              <media:content bitrate="400" url="http://bitsontherun.com/videos/Qvxp3Jnv-483.mp4" width="320" />
            </media:group>
          </item>
      
        </channel>
      </rss>
      
      
      

      Once the player sees multiple media:content entries, it'll automatically enable bitrate switching. Note that:

      • Each media:content entry does need a width and bitrate (in kbps! see the MRSS specs) attribute.
      • The first matching level will be selected. Therefore, insert the highest quality level at the top and then move down the list.
      • The media:group element is optional, but the media:content element is required. The enclosure or jwplayer:file entries do not offer the required attributes and therefore cannot be used.

      If you use a streaming server, you can add the familiar jwplayer:streamer and jwplayer:type entries to the playlist. For example, here is:

      • An XML playlist for RTMP streaming
      • The XML playlist of the example above, with all streaming types.

      For more playlist-related info, check the playlists section of the formats wiki page.

JW FLV Player

JW FLV Player Download the world's most popular open source player. It supports FLV, MP3, MP4 & AAC; it's Plugin-extensible; and it's fully integrated with our AdSolution. No wonder it's #1.

Monetize Your Video

Monetize Your Video Earn money with ads from LongTail's AdSolution. Watch our demos and sign up now!

JW Setup Wizard

JW Setup Wizard Use the JW Setup Wizard to quickly customize the JW Player™ without any writing code. Simply pick your player and our Wizard will do the rest.