RTMPストリーミング実装例1

  • 動作確認環境
    • Ubuntu 10.04 server
    • apache2:2.2.14-5ubuntu8.4
  • 採用ソフトウェア(インストール方法は省略)
    • crtmpserver
    • ffmpeg
      • “-metadata” の設定が出来ないと、ストリーミング対象になる名前がわからないから自前コンパイル推奨。
    • flowplayer
  • 実践
    • crtmpserverの起動
      • <code>cd ~/crtmpserver/builders/cmake && ./crtmpserver/crtmpserver ./crtmpserver/crtmpserver.lua</code>
        • 動作が安定し始めたら、“–daemon”オプションをつけてバックグラウンド動作にする。
      • 割とこうなる。
      • <code>+—————————————————————————–+
        Services

        +—+—————+—–+————————-+————————-+

        c ip port protocol stack name application name

        +—+—————+—–+————————-+————————-+

        tcp 0.0.0.0 1935 inboundRtmp appselector

        +—+—————+—–+————————-+————————-+

        tcp 0.0.0.0 8081 inboundRtmps appselector

        +—+—————+—–+————————-+————————-+

        tcp 0.0.0.0 8080 inboundRtmpt appselector

        +—+—————+—–+————————-+————————-+

        udp 0.0.0.0 1935 inboundRtmfp flvplayback

        +—+—————+—–+————————-+————————-+

        tcp 0.0.0.0 6666 inboundLiveFlv flvplayback

        +—+—————+—–+————————-+————————-+

        tcp 0.0.0.0 9999 inboundTcpTs flvplayback

        +—+—————+—–+————————-+————————-+

        tcp 0.0.0.0 8989 inboundHTTPDBAccess samplefactory

        +—+—————+—–+————————-+————————-+

        tcp 0.0.0.0 1111 inboundHttpXmlVariant vptests

        +—+—————+—–+————————-+————————-+

        tcp 0.0.0.0 1112 inboundJsonCli admin

        +—+—————+—–+————————-+————————-+

        tcp 0.0.0.0 6665 inboundLiveFlv proxypublish

        +—+—————+—–+————————-+————————-+

        tcp 0.0.0.0 6544 inboundTcpTs vmapp

        +—+—————+—–+————————-+————————-+

/home/flv/crtmpserver/sources/crtmpserver/src/crtmpserver.cpp:231 GO! GO! GO! (27274)</code>

* ffmpegから、crtmpserverに向けてTCPで動画ストリームを出力
  * <code>/usr/local/bin/ffmpeg -i mov000448.mp4 -re -r 15 -acodec copy -g 10 -vcodec libx264 -s 854x480 -metadata duration=24.00 -metadata streamName=mov000448 -f flv tcp://127.0.0.1:6666?pkt_size=1400</code>
  * crtmpserverの出力例
  * <code>/root/crtmpserver/sources/thelib/src/netio/epoll/tcpacceptor.cpp:133 Client connected: 127.0.0.1:47993 -> 0.0.0.0:6666

/root/crtmpserver/sources/thelib/src/protocols/liveflv/inboundliveflvprotocol.cpp:46 parameters: <MAP name=“” isArray=“false”

>

  <STR name="ip">0.0.0.0</STR>
  <INT16 name="port">6666</INT16>
  <STR name="protocol">inboundLiveFlv</STR>
  <NULL name="sslCert"></NULL>
  <NULL name="sslKey"></NULL>
  <BOOL name="waitForMetadata">true</BOOL>

</MAP>

/

root/crtmpserver/sources/thelib/src/protocols/liveflv/inboundliveflvprotocol.cpp:51 waitForMetadata: 1 /root/crtmpserver/sources/thelib/src/netio/epoll/iohandlermanager.cpp:98 Handlers count changed: 11→12 IOHTTCPCARRIER /root/crtmpserver/sources/thelib/src/protocols/liveflv/baseliveflvappprotocolhandler.cpp:45 protocol CTCP(16) ↔ TCP(3) ↔ [ILFL(4)] registered to app flvplayback /root/crtmpserver/sources/thelib/src/protocols/liveflv/inboundliveflvprotocol.cpp:230 Stream name: mov000448 /root/crtmpserver/sources/thelib/src/application/baseclientapplication.cpp:156 Stream 1 of type INLFLV with name mov000448 registered to application flvplayback /root/crtmpserver/sources/thelib/src/streaming/streamsmanager.cpp:91 short name: mov000448; long name: mov000448 /root/crtmpserver/sources/thelib/src/streaming/streamsmanager.cpp:100 short count: 0; long count: 0 /root/crtmpserver/sources/thelib/src/protocols/liveflv/inboundliveflvprotocol.cpp:239 subscribedOutStreams count: 0 /root/crtmpserver/sources/thelib/src/protocols/liveflv/inboundliveflvprotocol.cpp:184 Stream metadata: <MAP name=“” isArray=“true”> <MAP name=“indexvalue0” isArray=“true”> <DOUBLE name=“audiocodecid”>10.000</DOUBLE> <DOUBLE name=“audiodatarate”>149.771</DOUBLE> <DOUBLE name=“audiosamplerate”>48000.000</DOUBLE> <DOUBLE name=“audiosamplesize”>16.000</DOUBLE> <STR name=“compatiblebrands”

>isommp423gp5</STR>

      <STR name="creation_time">2011-07-05 06:49:44</STR>
      <STR name="duration">24.00</STR>
      <STR name="encoder">Lavf53.0.3</STR>
      <DOUBLE name="filesize">0.000</DOUBLE>
      <DOUBLE name="framerate">15.000</DOUBLE>
      <DOUBLE name="height">480.000</DOUBLE>
      <STR name="major_brand">mp42</STR>
      <STR name="minor_version">1</STR>
      <BOOL name="stereo">true</BOOL>
      <STR name="streamName">mov000448</STR>
      <DOUBLE name="videocodecid">7.000</DOUBLE>
      <DOUBLE name="videodatarate">195.312</DOUBLE>
      <DOUBLE name="width">854.000</DOUBLE>
  </MAP>

</MAP></code>

  • 最後に、RTMPを見るように設定したHTMLファイルを作ってアクセスする。
    • HTMLコード
    • <code><html><head></head> <div style=“width:854px;height:480px;” id=“fms” class=“player”

      >

      <

      a class=“player” id=“fms”

      > </a>

<

/div> <script type=“text/javascript” src=“plugins/Movie/flowplayer-3.2.6.min.js”

> </script>

<

script> $f(“fms”,“plugins/Movie/flowplayer-3.2.7.swf”, {

clip: { url: 'mov000448', live: true, provider: 'rtmp' },

plugins: { rtmp: { url: 'plugins/Movie/flowplayer.rtmp-3.2.3.swf', durationFunc: 'getStreamLength', netConnectionUrl: 'rtmp:www.ainoniwa.net:1935/flvplayback' } } }); </script> </html></code> * 上手く繋がればOK * <code>/root/crtmpserver/sources/thelib/src/netio/epoll/tcpacceptor.cpp:133 Client connected: 10.0.0.1:58663 → 0.0.0.0:1935 /root/crtmpserver/sources/thelib/src/netio/epoll/iohandlermanager.cpp:98 Handlers count changed: 12→13 IOHTTCPCARRIER /root/crtmpserver/sources/thelib/src/protocols/rtmp/basertmpappprotocolhandler.cpp:100 Register protocol CTCP(17) ↔ TCP(35) ↔ [IR(36)] to application appselector /root/crtmpserver/sources/thelib/src/netio/epoll/tcpacceptor.cpp:133 Client connected: 10.0.0.1:57698 → 0.0.0.0:1935 /root/crtmpserver/sources/thelib/src/netio/epoll/iohandlermanager.cpp:98 Handlers count changed: 13→14 IOHTTCPCARRIER /root/crtmpserver/sources/thelib/src/protocols/rtmp/basertmpappprotocolhandler.cpp:100 Register protocol CTCP(18) ↔ TCP(37) ↔ [IR(38)] to application appselector /root/crtmpserver/sources/applications/appselector/src/rtmpappprotocolhandler.cpp:81 Selected application: flvplayback /root/crtmpserver/sources/thelib/src/application/baseclientapplication.cpp:148 Protocol CTCP(18) ↔ TCP(37) ↔ [IR(38)] unregistered from application: appselector /root/crtmpserver/sources/thelib/src/protocols/rtmp/basertmpappprotocolhandler.cpp:100 Register protocol CTCP(18) ↔ TCP(37) ↔ [IR(38)] to application flvplayback /root/crtmpserver/sources/thelib/src/netio/epoll/iohandlermanager.cpp:257 *Event handler HUP: 0x9953c0 /root/crtmpserver/sources/thelib/src/netio/epoll/tcpcarrier.cpp:78 Unable to read data. 10.0.0.1:58663 → 192.168.1.80:1935 /root/crtmpserver/sources/thelib/src/protocols/protocolmanager.cpp:43 Enqueue for delete for protool [TCP(35)] ↔ IR(36) /root/crtmpserver/sources/thelib/src/netio/epoll/iohandlermanager.cpp:107 Handlers count changed: 14→13 IOHTTCPCARRIER /root/crtmpserver/sources/thelib/src/protocols/protocolmanager.cpp:43 Enqueue for delete for protool [IR(36)] /root/crtmpserver/sources/thelib/src/application/baseclientapplication.cpp:148 Protocol [IR(36)] unregistered from application: appselector /root/crtmpserver/sources/thelib/src/application/baseclientapplication.cpp:156 Stream 8 of type NR with name registered to application `flvplayback` /root/crtmpserver/sources/thelib/src/protocols/rtmp/basertmpappprotocolhandler.cpp:414 User control message type: RM_USRCTRL_TYPE_STREAM_SET_BUFFER_LENGTH /root/crtmpserver/sources/thelib/src/netio/epoll/tcpacceptor.cpp:133 Client connected: 10.0.0.1:51971 -> 0.0.0.0:1935 /root/crtmpserver/sources/thelib/src/netio/epoll/iohandlermanager.cpp:98 Handlers count changed: 13->14 IOHT_TCP_CARRIER /root/crtmpserver/sources/thelib/src/protocols/rtmp/basertmpappprotocolhandler.cpp:100 Register protocol CTCP(17) <-> TCP(39) <-> [IR(40)] to application appselector /root/crtmpserver/sources/thelib/src/protocols/rtmp/basertmpappprotocolhandler.cpp:775 Play request for stream name `mov000448`. Start: -2; length: -1 /root/crtmpserver/sources/thelib/src/application/baseclientapplication.cpp:164 Stream 8 of type NR with name unregistered from application flvplayback /root/crtmpserver/sources/thelib/src/application/baseclientapplication.cpp:156 Stream 9 of type ONR4R with name mov000448 registered to application flvplayback /root/crtmpserver/sources/thelib/src/protocols/rtmp/basertmpappprotocolhandler.cpp:414 User control message type: RMUSRCTRLTYPESTREAMSETBUFFERLENGTH /root/crtmpserver/sources/thelib/src/netio/epoll/iohandlermanager.cpp:257 *Event handler HUP: 0xa15e20 /root/crtmpserver/sources/thelib/src/netio/epoll/tcpcarrier.cpp:78 Unable to read data. 10.0.0.1:51971 → 192.168.1.80:1935 /root/crtmpserver/sources/thelib/src/protocols/protocolmanager.cpp:43 Enqueue for delete for protool [TCP(39)] ↔ IR(40) /root/crtmpserver/sources/thelib/src/netio/epoll/iohandlermanager.cpp:107 Handlers count changed: 14→13 IOHTTCPCARRIER /root/crtmpserver/sources/thelib/src/protocols/protocolmanager.cpp:43 Enqueue for delete for protool [IR(40)] /root/crtmpserver/sources/thelib/src/application/baseclientapplication.cpp:148 Protocol [IR(40)] unregistered from application: appselector</code>

CC Attribution-Noncommercial-Share Alike 4.0 International
Driven by DokuWiki Recent changes RSS feed Valid CSS Valid XHTML 1.0