Live streaming

From Red5Wiki

Jump to: navigation, search

Contents

Introduction

The following short tutorial is written for Linux systems. Users of different operating systems might have a look to get an idea how live streaming works and perhaps find out how to do the same on their system.

By default red5 listens for rtmp streams on port 1935. This is configured in <red5_home>/conf/red5.properties.

westermann@westermann-desktop:~$ netstat -aln | grep 1935
tcp        0      0 0.0.0.0:1935            0.0.0.0:*               LISTEN     

An example will be given in which a rtmp stream is sent to this port (via the xuggler version of ffmpeg) and a JWPlayer client subscribes to this stream.

Install Xuggler

Red5 accepts "stream providers" in form of rtmp streams (or rtmps streams) to allow subscribers (rtmp clients) to view them. Xuggler adds rtmp support to ffmpeg.

Check ffmpeg version

In case you have installed ffmpeg before please check if it supports xuggler:

ffmpeg -i /invalid/file

Your output should look something like:

FFmpeg version SVN-r21606-xuggle-4.0.844, Copyright (c) 2000-2010 Fabrice Bellard, et al.
 built on Feb  2 2010 10:57:41 with gcc 4.4.1
 configuration: --prefix=/home/aclarke/Stage --extra-version=xuggle-4.0.844 --extra-cflags=-I/home/aclarke/Work/internal/xuggle/java/xuggle-xuggler/build/native/i686-pc-linux-gnu/captive/home/aclarke/Stage/include --extra-ldflags=-L/home/aclarke/Work/internal/xuggle/java/xuggle-xuggler/build/native/i686-pc-linux-gnu/captive/home/aclarke/Stage/lib --enable-shared --enable-gpl --enable-nonfree --enable-version3 --disable-stripping --disable-optimizations --disable-mmx --disable-mmx2 --enable-libx264 --enable-libmp3lame --enable-libvorbis --enable-libtheora --enable-libspeex --enable-libfaac --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-pthreads
 libavutil     50. 8. 0 / 50. 8. 0
 libavcodec    52.51. 0 / 52.51. 0
 libavformat   52.50. 0 / 52.50. 0
 libavdevice   52. 2. 0 / 52. 2. 0
 libswscale     0. 9. 0 /  0. 9. 0
/invalid/file: no such file or directory

Make sure the --extra-version string above includes "xuggle" in it. If not, you have to continue with installation.

Install it really

Inspired by: http://www.youtube.com/watch?v=PuC_RKLotLE&feature=player_detailpage#t=150s

cd ~
mkdir xuggler-build
cd xuggler-build
http://com.xuggle.s3.amazonaws.com/xuggler/xuggler-3.4.FINAL/xuggle-xuggler.3.4.1012-src.tar.gz
tar -xzvf xuggle-xuggler.3.4.1012-src.tar.gz
export XUGGLE_HOME=/usr/local
export PATH=$XUGGLE_HOME/bin:$PATH
export LD_LIBRARY_PATH=$XUGGLE_HOME/lib/:$LD_LIBRARY_PATH
ant run-tests
# 600 bottles of beer later (see video)
ant run-tests
java -cp /usr/local/share/java/jars/xuggle-xuggler.jar com.xuggle.xuggler.demos.GetContainerInfo /home/westermann/video.flv

Now ffmpeg should support "rtmp":

westermann@westermann-desktop:~$ ffmpeg -protocols
FFmpeg version SVN-r21566-xuggle-3.4.843, Copyright (c) 2000-2010 Fabrice Bellard, et al.
  built on Apr 20 2011 13:43:47 with gcc 4.4.3
  configuration: --prefix=/usr/local --extra-version=xuggle-3.4.843 --extra-cflags=-I/home/westermann/Downloads/xuggler/build/native/x86_64-unknown-linux-gnu/captive/usr/local/include --extra-ldflags=-L/home/westermann/Downloads/xuggler/build/native/x86_64-unknown-linux-gnu/captive/usr/local/lib --enable-shared --enable-gpl --enable-nonfree --enable-version3 --enable-libx264 --enable-libmp3lame --enable-libvorbis --enable-libtheora --enable-libspeex --enable-libfaac --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-pthreads
 libavutil     50. 8. 0 / 50. 8. 0
 libavcodec    52.49. 0 / 52.49. 0
 libavformat   52.48. 0 / 52.48. 0
 libavdevice   52. 2. 0 / 52. 2. 0
 libswscale     0. 9. 0 /  0. 9. 0
Supported file protocols:
file
gopher
http
pipe
rtmp
rtp
tcp
udp
...

Create the live stream to red5

This demo uses a static video file to test if we can stream to red5. In a real world example one would push a live stream to red5 by having a different source URL (-i).

ffmpeg -i /home/westermann/video.flv -f flv rtmp://127.0.0.1:1935/live/livestream

This will send the video.flv via rtmp to the local red5 to the application /live/ with the streamname "livestream". You should read more about ffmpeg to find out the right parameters for your streaming video.

Red5 will tell something like:

[DEBUG] [NioProcessor-1] org.red5.server.Scope - Add child: org.red5.server.stream.BroadcastScope@adb24
[DEBUG] [NioProcessor-1] org.red5.server.Scope - Add child scope: org.red5.server.stream.BroadcastScope@adb24 to [WebScope@79a422d9 Depth = 1, Path = '/default', Name = 'live']
[INFO] [NioProcessor-1] org.red5.server.stream.ClientBroadcastStream - Provider connect
[INFO] [NioProcessor-1] org.red5.server.stream.ClientBroadcastStream - Stream start
[INFO] [NioProcessor-1] org.red5.server.stream.ClientBroadcastStream - Provider connect

Subscribe to stream via flash (JWPlayer)

It should be possible to view this live stream now with a JWPlayer with the following integration. This is a only for testing, JWPlayer integration could be done better (e.g. with option for HTML5).

player.html:

 ...
 <script type="text/javascript" src="/somepath/swfobject.js"> 
 </script> 
 <div class="flash420"> 
 <div id="player"> 
 Unfortunately you don't have Adobe Flash-Player....
 <a href="http://get.adobe.com/flashplayer/">Klicken Sie hier für den kostenlosen Adobe Flash-Player.</a> 
 </div><script type="text/javascript"> 
  var flashvars = {
          file:'livestream',
          streamer:'rtmp://10.70.136.1/live/',
          image:'/somepath/millennium_1.jpg',
          bufferlength:'2',
          backcolor:'#000000',
          frontcolor:'#166EBA',
          screencolor:'#999999',
          lightcolor:'#990000',
          autostart:'false',
          repeat:'none',
          stretching:'',
          playlist:'bottom',
          playlistsize:'160',
 
        };
  var params = { allowfullscreen:'false', allowscriptaccess:'always', wmode:'transparent' };
  var attributes = { id:'player1', name:'player1' };
  swfobject.embedSWF('/somepath/player-licensed-5.2.swf','player','384','468','9.0.0','false',flashvars, params, attributes);
 </script> 
 </div> 
 ...
Personal tools