Wednesday, March 20, 2013

Switching bitrates in RTMP

Today I have fixed an issue with RTMP bitrate switch for VOD streams. With JWPlayer version 6 it's possible to choose RTMP bitrate while playing stream in a way similar to youtube. I'll provide a small tutorial here how to set up this on your system.

smil

In latest master I have updated JWPlayer to version 6. This version supports the following config format.



<script type="text/javascript" src="/jwplayer/jwplayer.js"></script></pre>
<div id="container">Loading the player ...</div>
<script type="text/javascript">
jwplayer("container").setup({
sources:[
{
file:"/sintel.smil"
}
],
ga: {},
autostart: true,
width: 640,
height: 480,
primary: 'flash'
});
</script>


This configuration refers smil file setting different bitrates/qualities for the same video. Here's an example of sintel.smil

<smil>
<head>
<meta base="rtmp://localhost/vod/" />
</head>
<body>
<switch>
<video src="mp4:sintel-120p.mp4" height="120" />
<video src="mp4:sintel-240p.mp4" height="240" />
<video src="mp4:sintel-480p.mp4" height="480" />
</switch>
</body>
</smil>


Mp4 files for different bitrates can be created from the source sintel.mp4 with the following ffmpeg calls

ffmpeg -i sintel.mp4 -c:v libx264 -c:a copy -s 640x480 sintel-480p.mp4
ffmpeg -i sintel.mp4 -c:v libx264 -c:a copy -s 320x240 sintel-240p.mp4
ffmpeg -i sintel.mp4 -c:v libx264 -c:a copy -s 160x120 sintel-120p.mp4


The error fixed in 0.9.12 is nginx crash when switching stream quality in case VOD file is accessed remotely with http.

Thanks to fjyaniez for the report and config examples.

5 comments:

  1. Thank you for your effort, nginx-rtmp-module is awesome :)

    ReplyDelete
  2. Does this fix also apply to live rtmp streams and auto bandwidth detection (vide: netstream2 function)?

    ReplyDelete
  3. Hi, flowplayer sollutions? not working, i think there is server problem. thx

    http://flowplayer.blacktrash.org/test/koukni.html

    ReplyDelete
  4. I didn't test that with flowplayer. I will do that when I have time. Thanks.

    ReplyDelete