Computerglitch

An ongoing adventure

Converting Axis RTSP to RTMP Streams

These are some notes I took while integrating a solution providing live streaming of an Axis camera to a media server that converted the stream from rtsp to rtmp and was displayed on a website using flowplayer. The following technologies were used to accomplish this configuration:

First find the link that displays your cameras rtsp feed. In the case of the axis camera, the feed is located at: rtsp://[ip.add.re.ss]/axis-media/media.amp

Once you have your cameras rtsp link you should test to make sure it’s displaying the feed correctly with something like VLC and the following command:

1
vlc rtsp://[ip.add.re.ss]/axis-media/media.amp

Once the feed is verified it’s time to start working on getting the media server to consume and convert the stream. crtmpserver provides many binaries for various platforms. In this example I’ll be using the CentOS 6.2 binary build found at: http://www.rtmpd.com/downloads/

Extract the binary in /opt and create a symlink

1
2
3
cd /opt
tar xvzf crtmpserver-version-1.1-tar.gz
ln -s crtmpserver-version-1.1 crtmpserver

Create a configuration file for the rtsp to rtmp conversion process. Under externalStreams replace the values for uri and localStreamName with the url for your rtsp feed and what you would like to call this feed.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
vi /opt/crtmpserver/configs/axisfeed.lua

configuration=
{
  daemon=false,
  pathSeparator="/",

  logAppenders=
  {
      {
          name="console appender",
          type="coloredConsole",
          level=6
      },
      {
          name="file appender",
          type="file",
          level=6,
          fileName="./logs/crtmpserver",
          fileHistorySize=10,
          fileLength=1024*1024,
          singleLine=true    
      }
  },
  
  applications=
  {
      rootDirectory="applications",
      {
          description="FLV Playback",
          name="flvplayback",
          protocol="dynamiclinklibrary",
          default=true,
          aliases=
          {
              "simpleLive",
              "vod",
              "live",
              "WeeklyQuest",
              "SOSample",
              "oflaDemo",
          },
          acceptors =
          {
              {
                  ip="0.0.0.0",
                  port=1935,
                  protocol="inboundRtmp"
              },
              {
                  ip="0.0.0.0",
                  port=6666,
                  protocol="inboundLiveFlv",
                  waitForMetadata=true,
              },
              {
                  ip="0.0.0.0",
                  port=9999,
                  protocol="inboundTcpTs"
              },
          },
          externalStreams =
          {
              {
                          uri="rtsp://ip.add.re.ss/axis-media/media.amp",
                          localStreamName="feednamecanbewhateveryouwant",
                          forceTcp=true
                  }
          },
          validateHandshake=false,
          keyframeSeek=true,
          seekGranularity=1.5, --in seconds, between 0.1 and 600
          clientSideBuffer=12, --in seconds, between 5 and 30
          --generateMetaFiles=true, --this will generate seek/meta files on application startup
          --renameBadFiles=false,
          mediaFolder="./media",
      },
  }
}

Test your configuration by running the following command. This will give you console output about the feeds being served from crtmpserver. You may also want to open another terminal and double check the server is indeed listening on port 1935 for inbound rtmp. netstat -antp | grep 1935

1
/opt/crtmpserver/crtmpserver /opt/crtmpserver/configs/axisfeed.lua

Next create a simple bash script you can use to start crtmpserver using this configuration as a daemon

1
2
3
4
vi /opt/crtmpserver/RunFeed.sh

#!/bin/bash
./crtmpserver --daemon ./configs/axisfeed.lua

Once you have crtmp server correctly serving your feed it’s time to display the feed on your webpage with Flowplayer. First download the latest versions of Flowplayer and Flowplayer RTMP from the links at the beginning of this write-up to your webserver. You will then need the following code on your page, replacing name-of-your-feed with the feed name you created for the value of localStreamName you created previously.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<script src="flowplayer/flowplayer-3.2.13.min.js"></script>

<div>
   <a id="rtmp_player" name="rtmp_player" style=
    "display: block;height:400px;width:600px;background-color: #ffffff;border: solid 1px #ccc;"></a><br>

  <br>
   <script>
    $f("rtmp_player", "flowplayer/flowplayer-3.2.18.swf", {
        clip: {
               url : 'name-of-your-feed',
               live : true,
               provider: 'rtmp'
              },

        plugins: {
               rtmp: {
               url: 'flowplayer/flowplayer.rtmp-3.2.13.swf',
               netConnectionUrl: 'rtmp://crtmp.server.ip.address/live' ,
               subscribe:true
                }
              }
            });
                    </script>
</div>

Your feed should now be viewable as a live stream in flowplayer.

Comments