Wiedza Converting RTSP to RTMP Streams

Discussion in 'Research Tuts/Notes' started by Silas Mariusz, May 2, 2015.

Loading...
  1. Silas Mariusz
    Online

    Silas Mariusz SysOp Administrator

    Joined:
    Apr 5, 2008
    Messages:
    8,752
    Local Time:
    5:30 PM
    Ratings:
    +1,826 / 39 / -9
    Followers:
    37
    QNAP:
    TS-x77
    Ethernet:
    1 GbE
    TS-x77 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.

    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:
    Code (Winbatch):
    1. 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
    Code (Bash):
    1. cd /opt
    2. tar xvzf crtmpserver-version-1.1-tar.gz
    3. 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.
    Code (Bash):
    1. vi /opt/crtmpserver/configs/axisfeed.lua
    Code (Javascript):
    1. configuration=
    2. {
    3.   daemon=false,
    4.   pathSeparator="/",
    5.  
    6.   logAppenders=
    7.   {
    8.       {
    9.           name="console appender",
    10.           type="coloredConsole",
    11.           level=6
    12.       },
    13.       {
    14.           name="file appender",
    15.           type="file",
    16.           level=6,
    17.           fileName="./logs/crtmpserver",
    18.           fileHistorySize=10,
    19.           fileLength=1024*1024,
    20.           singleLine=true    
    21.       }
    22.   },
    23.   applications=
    24.   {
    25.       rootDirectory="applications",
    26.       {
    27.           description="FLV Playback",
    28.           name="flvplayback",
    29.           protocol="dynamiclinklibrary",
    30.           default=true,
    31.           aliases=
    32.           {
    33.               "simpleLive",
    34.               "vod",
    35.               "live",
    36.               "WeeklyQuest",
    37.               "SOSample",
    38.               "oflaDemo",
    39.           },
    40.           acceptors =
    41.           {
    42.               {
    43.                   ip="0.0.0.0",
    44.                   port=1935,
    45.                   protocol="inboundRtmp"
    46.               },
    47.               {
    48.                   ip="0.0.0.0",
    49.                   port=6666,
    50.                   protocol="inboundLiveFlv",
    51.                   waitForMetadata=true,
    52.               },
    53.               {
    54.                   ip="0.0.0.0",
    55.                   port=9999,
    56.                   protocol="inboundTcpTs"
    57.               },
    58.           },
    59.           externalStreams =
    60.           {
    61.               {
    62.                           uri="rtsp://ip.add.re.ss/axis-media/media.amp",
    63.                           localStreamName="feednamecanbewhateveryouwant",
    64.                           forceTcp=true
    65.                   }
    66.           },
    67.           validateHandshake=false,
    68.           keyframeSeek=true,
    69.           seekGranularity=1.5, --in seconds, between 0.1 and 600
    70.           clientSideBuffer=12, --in seconds, between 5 and 30
    71.           --generateMetaFiles=true, --this will generate seek/meta files on application startup
    72.           --renameBadFiles=false,
    73.           mediaFolder="./media",
    74.       },
    75.   }
    76. }
    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.
    Code (Bash):
    1. netstat -antp | grep 1935
    Code (Bash):
    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

    Code (Bash):
    1. vi /opt/crtmpserver/RunFeed.sh
    Code (Bash):
    1. #!/bin/bash
    2. ./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:
    1. <script src="flowplayer/flowplayer-3.2.13.min.js"></script>
    2.  
    3. <div>
    4.    <a id="rtmp_player" name="rtmp_player" style=
    5.    "display: block;height:400px;width:600px;background-color: #ffffff;border: solid 1px #ccc;"></a><br>
    6.  
    7.    <br>
    8.    <script>
    9.     $f("rtmp_player", "flowplayer/flowplayer-3.2.18.swf", {
    10.         clip: {
    11.                url : 'name-of-your-feed',
    12.                live : true,
    13.                provider: 'rtmp'
    14.               },
    15.  
    16.         plugins: {
    17.                rtmp: {
    18.                url: 'flowplayer/flowplayer.rtmp-3.2.13.swf',
    19.                netConnectionUrl: 'rtmp://crtmp.server.ip.address/live' ,
    20.                subscribe:true
    21.                 }
    22.               }
    23.             });
    24.    </script>
    25. </div>
    Your feed should now be viewable as a live stream in flowplayer.
     
    • Lizak Lizak x 1