Wiedza Converting RTSP to RTMP Streams

Silas Mariusz

rm -rf /
Help us, GOD!
5 Kwiecień 2008
10 167
31
2 243
153
39
Nowy Sącz
forum.qnap.net.pl
QNAP
TS-x77
Ethernet
1 GbE
Source: Converting Axis RTSP to RTMP Streams - Computerglitch

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:
acdn.computerglitch.net_images_crtmpserver2.jpg


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]/live.src

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:
Kod:
vlc rtsp://[ip.add.re.ss]/live.src
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
Bash:
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.
Bash:
vi /opt/crtmpserver/configs/axisfeed.lua
JavaScript:
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.
Bash:
netstat -antp | grep 1935

Bash:
/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

Bash:
vi /opt/crtmpserver/RunFeed.sh
Bash:
#!/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.
HTML:
<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.
 
  • Lubię to
Reakcje: kaktus