pdoc 0.1 documentation

RTMPストリーミング

«  プログレッシブダウンロード   ::   Contents   ::   MoinMoin  »

RTMPストリーミング

RTMPストリーミングに必要なもの
RTMP Server
Red5, crtmpserver, rtmplite...etc
RTMP Client
flowplayer...etc
動画コンテンツ
動画コンテンツはRTMPサーバがRTMPパケットに分割できる動画形式であればいい。 動画形式は各RTMP Serverの実装に依存するので、一概には言えない。 間にffmpeg等のエンコーダを挟むことで、制限を緩和することはできる。
RTMP Server一覧
Red5

http://www.red5.org/downloads/ Java製のRTMPサーバ。h264もいける。 buffer_sizeの調整とか。

wowza media server 2
http://www.wowzamedia.com/ Java製のRTMPサーバ。 ライセンスが面倒で試してない。
rtmplite
http://code.google.com/p/rtmplite/ Python製のRTMPサーバ。h264が動いたり動かなかったりする。
crtmpserver

http://www.rtmpd.com/ C++製のRTMPサーバ。 ストリームの名前付方法が独特。 何故か/crtmpserver/builder/cmake配下で./crtmpserver/crtmpserver ./crtmpserver/crtmpserver.luaとしないと怒られる。 ffmpegのオプションで、-metadata streamName=XXXX のようにすることで、RTMPストリーム名を可変にできる。

逆に、-metadataを付けない場合は、アクセス元の送信元ポート番号が使用されるため、接続先が分からなくなる。
perlrtmp
http://code.google.com/p/perlrtmp/ Perl製のRTMPサーバ。 試したこと無い。
RbuyIZUMI
http://code.google.com/p/rubyizumi/ Ruby製のRTMPサーバ。メンテされてない? 試したこと無い。
ErlyVideo
http://erlyvideo.org/ 今度試す。

RTMPストリーミング実装例

環境

Ubuntu 10.04 server

apache2:2.2.14-5ubuntu8.4

採用ソフトウェア(インストール方法は省略)

crtmpserver

ffmpeg
“-metadata” の設定が出来ないと、ストリーミング対象になる名前がわからないから自前コンパイル推奨。

flowplayer

crtmpserverの動作確認

cd ~/crtmpserver/builders/cmake && ./crtmpserver/crtmpserver ./crtmpserver/crtmpserver.lua

動作が安定し始めたら、”–daemon”オプションをつけてバックグラウンド動作にする。

起動後

+-----------------------------------------------------------------------------+
|                                                                     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)

ffmpegから、crtmpserverに向けてTCPで動画ストリームを出力

/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

crtmpserverの出力例

/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 IOHT_TCP_CARRIER
/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="__index__value__0" 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="compatible_brands">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>

RTMPを見るように設定したHTMLファイルを作ってアクセスする。

crtmp_test.html

<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>

フォアグラウンドで動かしているcrtmpserverのログ

/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 IOHT_TCP_CARRIER
/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 IOHT_TCP_CARRIER
/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 IOHT_TCP_CARRIER
/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: RM_USRCTRL_TYPE_STREAM_SET_BUFFER_LENGTH
/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 IOHT_TCP_CARRIER
/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

«  プログレッシブダウンロード   ::   Contents   ::   MoinMoin  »