CloudFrontでストリーミングをする時に、デフォルトで試聴ログが取れるので、
試してみました。
○ストリーミングの設定
はじめに、ストリーミング用とログ用のにバケットを2つ用意します。
- stream.memorycraft.jp:CDNストリーミングとプレイヤーのWEBホスト用のバケット
- log.stream.memorycraft.jp:ストリームログ用のバケット
CDN用のバケットではストリーミングする動画プレイヤーのページをWEBホスティングするので、
「Website」の設定をしておきます。
次にストリーミング用のバケットにプレイヤーとムービー等をアップロードします。
今回はWEBプレイヤーのJWPlayerを使用しました。
このフリープレイヤーには、ムービーのサンプルとプレイヤーを埋め込むためのHTMLのテンプレートが
用意されているので、以下のように変更してCDN用のバケットにアップロードします。
また、今回はユーザーを特定するために、rtmpアクセスにuser_idのクエリを付与しました。
変更部分は赤字で示しています。
The following code is from longtailvideo.com’s ‘Setup Wizard’, found at http://www.longtailvideo.com/support/jw-player-setup-wizard
–>
Streaming Video with JW Player
–>This is my header
–>
This text will be replaced
–>
– You cannot have any spaces in any of your URL’s (including your ‘rtmp://…’ URL) (i.e., http:// thereisaspaceatthebeginninghere.xxx)
– Be sure you are calling the correctly numbered version of the flowplayer objects/players (i.e. flowplayer-3.2.2.swf
– You cannot have duplicates of ‘s3.amazonaws.com’ or ‘cloudfront.net’ in the same address (i.e. (http://s3.amazonaws.com/s3.amazonaws.com/YOUR_BUCKET/player.swf)
– There is a different naming protocol for mp4 vs flv files. For .mp4 files, YOU MUST write it as ‘mp4:YOUR_VIDEO_FILE_WITHOUT_THE _MP4_SUFFIX’. For .flv files, you simply write the name of the file, ‘YOUR_VIDEO_FILE_WITHOUT_THE_FLV_SUFFIX’.
–>
バケットにアップロードされるファイルは下記のようになります。
次に、CDNの設定を行います。
CloudFrontタブで「Create Distribution」を選択し、最初のDISTRIBUTION TYPEのフェーズで
「Delivery Method」にStreamingを選択します。
また、Bucketには先程ムービー一式をアップしたCDN用のバケットを指定します。
次のDISTRIBUTION DETAILSフェーズでは「Logging」の項目をOnに設定して、「Select Log Bucket」から
先程のログ用のバケットを指定します。
また、ここでは「Log Prefix」にstreamと入力して作成を終了します。
それでは、S3ホスティングされたプレイヤーのページを表示してみます。
上記のように、無事表示されました。
○ログの確認
しばらく(数時間)すると、ログ用のバケットにストリーミングのログが出力され始めます。
これらの一つをダウンロードして開いてみると以下のようなFMSのログになっています。
#Version: 1.0
#Fields: date time x-edge-location c-ip x-event sc-bytes x-cf-status x-cf-client-id cs-uri-stem cs-uri-query c-referrer x-page-url c-user-agent x-sname x-sname-query x-file-ext x-sid
2012-02-02 18:12:00 SFO4 219.117.233.241 connect 3073 OK 66f18822-d17a-4e1d-9319-e279ffe82caa rtmp://s23sut0ft0hkv9.cloudfront.net/cfx/st/ user_id=5678 http://s3-ap-northeast-1.amazonaws.com/stream.memorycraft.jp/player.swf http://s3-ap-northeast-1.amazonaws.com/stream.memorycraft.jp/player.html MAC%2011,2,202,183 – – – –
2012-02-02 18:12:00 SFO4 219.117.233.241 play 3476 OK 66f18822-d17a-4e1d-9319-e279ffe82caa rtmp://s23sut0ft0hkv9.cloudfront.net/cfx/st/ user_id=5678 http://s3-ap-northeast-1.amazonaws.com/stream.memorycraft.jp/player.swf http://s3-ap-northeast-1.amazonaws.com/stream.memorycraft.jp/player.html MAC%2011,2,202,183 mymovie – mp4 1
2012-02-02 18:12:01 SFO4 219.117.233.241 stop 205127 OK 66f18822-d17a-4e1d-9319-e279ffe82caa rtmp://s23sut0ft0hkv9.cloudfront.net/cfx/st/ user_id=5678 http://s3-ap-northeast-1.amazonaws.com/stream.memorycraft.jp/player.swf http://s3-ap-northeast-1.amazonaws.com/stream.memorycraft.jp/player.html MAC%2011,2,202,183 mymovie – mp4 1
2012-02-02 18:12:04 SFO4 219.117.233.241 pause 205295 OK 66f18822-d17a-4e1d-9319-e279ffe82caa rtmp://s23sut0ft0hkv9.cloudfront.net/cfx/st/ user_id=5678 http://s3-ap-northeast-1.amazonaws.com/stream.memorycraft.jp/player.swf http://s3-ap-northeast-1.amazonaws.com/stream.memorycraft.jp/player.html MAC%2011,2,202,183 mymovie – mp4 –
2012-02-02 18:12:18 SFO4 219.117.233.241 unpause 205295 OK 66f18822-d17a-4e1d-9319-e279ffe82caa rtmp://s23sut0ft0hkv9.cloudfront.net/cfx/st/ user_id=5678 http://s3-ap-northeast-1.amazonaws.com/stream.memorycraft.jp/player.swf http://s3-ap-northeast-1.amazonaws.com/stream.memorycraft.jp/player.html MAC%2011,2,202,183 mymovie – mp4 –
2012-02-02 18:12:21 SFO4 219.117.233.241 disconnect 205295 OK 66f18822-d17a-4e1d-9319-e279ffe82caa rtmp://s23sut0ft0hkv9.cloudfront.net/cfx/st/ user_id=5678 http://s3-ap-northeast-1.amazonaws.com/stream.memorycraft.jp/player.swf http://s3-ap-northeast-1.amazonaws.com/stream.memorycraft.jp/player.html MAC%2011,2,202,183 – – – –
これらの項目は以下のようになっています。
date | 日付 |
time | 時刻 |
x-edge-location | CDNのエッジロケーションを空港名のような3文字コード+数字で示しています。 |
c-ip | クライアントのIP |
x-event | ストリームのイベントです。 Connect, Disconnect, Play, Stop, Pause, Unpause, Seekがあります。 |
sc-bytes | サーバーから送られたバイト数 |
x-cf-status | イベントのステータス |
x-cf-client-id | コネクションに対して一意のクライアントID |
cs-uri-stem | ストリームURIのベース部分 |
cs-uri-query | ストリームURIのクエリ部分 |
c-referrer | ストリーミングアクセスのリファラ |
x-page-url | ストリーミングアクセス元のWEBページのURL |
c-user-agent | ユーザーエージェント |
x-sname | ストリーミングされるファイル名 |
x-sname-query | ストリーミングアクセスのクエリ |
x-file-ext | ストリーミングされるファイルの拡張子 |
x-sid | コネクション内で一意なストリームID |
ここで、x-eventでストリームの状態(Play, Stop, Pause, Unpause等)と、x-sname-queryでユーザーの特定や
その他のデータを送信できることで、工夫すれば試聴解析ができそうです。
こちらの記事はなかの人(memorycraft)監修のもと掲載しています。
元記事は、こちら