dev camp2012jpn day2session2

59
Developer Camp 2012 Japan Fall 10.4 Thu – 5 Fri 渋谷ヒカリエ

Upload: daiyu-hatakeyama

Post on 28-May-2015

384 views

Category:

Documents


5 download

TRANSCRIPT

Page 1: Dev camp2012jpn day2session2

Developer Camp2012 Japan Fall

10.4 Thu – 5 Fri

渋谷ヒカリエ

Page 2: Dev camp2012jpn day2session2

マルチデバイスへの動画配信サービス~ Windows Azure Media Services とは~日本マイクロソフト株式会社通信メディア統括本部ソリューションスペシャリスト畠山 大有

Page 3: Dev camp2012jpn day2session2

Developer Camp | 2012 Japan Fall

本セッションの目的• Windows Azure Media Services で動画配信アプリケーションを開発する方法を理解します。

• 動画配信そのものについては取り扱いません。

• 本セッションは、2012年6月リリースの public beta の仕様に基づきます。今後、予告なく変更される可能性がありますのでご注意ください。

Page 4: Dev camp2012jpn day2session2

Developer Camp | 2012 Japan Fall

本日の内容• Windows Azure Media Services を知る

• Windows Azure Media Services 開発の ”イロハ”

Page 5: Dev camp2012jpn day2session2

Windows Azure Media Services

を知る

Page 6: Dev camp2012jpn day2session2

Developer Camp | 2012 Japan Fall

Windows Azure Media Services• 拡張可能なマルチテナントのメディア配信プラットフォーム

• クラウド上へのMicrosoft Media Platform 実装

• パートナーエコシステム• エンコーディング/パッケージング

• セキュリティ

• マルチデバイス

• オンデマンド / ライブ

• REST API

Page 7: Dev camp2012jpn day2session2

Developer Camp | 2012 Japan Fall

Windows Azure Media Services

動画配信のワークフロー

Page 8: Dev camp2012jpn day2session2

Developer Camp | 2012 Japan Fall

パートナーエコシステム

IngestEncoding/

TranscodingContent

ProtectionOrigin &

CDN

ISV

Page 9: Dev camp2012jpn day2session2

Developer Camp | 2012 Japan Fall

アーキテクチャ (VOD)C

om

pute

Stora

ge

Windows Azure Media Services

Page 10: Dev camp2012jpn day2session2

Windows Azure Media Services

開発の”イロハ”

Page 11: Dev camp2012jpn day2session2

Developer Camp | 2012 Japan Fall

コードを書く前に必要な事

Page 13: Dev camp2012jpn day2session2

Developer Camp | 2012 Japan Fall

開発環境の準備• Windows 7, Windows 8, Windows 2008 R2

• .NET Framework 3.5 SP1, .NET Framework 4

• Visual Studio 2010 SP1

• Windows Azure SDK 1.6 (November 2011)

• Windows Azure Media Services SDK (June 2012 Preview)

• WCF Data Services 5.0 for OData V3

• http://msdn.microsoft.com/en-us/library/hh973620.aspx

Page 14: Dev camp2012jpn day2session2

Developer Camp | 2012 Japan Fall

Visual Studio の設定

• アセンブリ参照• Microsoft.WindowsAzure.MediaServices.Management.Sdk.dll

• %ProgramFiles(x86)%¥Microsoft SDKs¥Windows Azure Media Services¥Services¥v1.0

Page 15: Dev camp2012jpn day2session2

Developer Camp | 2012 Japan Fall

Sample Player の準備• Smooth Streaming

• Microsoft Media Platform: Player Framework• Windows 8: http://playerframework.codeplex.com/releases/view/94684

• Silverlight: http://smf.codeplex.com/releases/view/88970

• HTML5 <video> (iOS用)<video width="640"

height="480"

src="http://<your url>/hogehoge.mp4"

autoplay controls >ご利用のWeb ブラウザーでは再生できません

</video>

Page 16: Dev camp2012jpn day2session2

Developer Camp | 2012 Japan Fall

Media Services SDK for .NETMicrosoft.WindowsAzure.MediaServices.Client.

CloudMediaContext サービスとのセッション

Assets コンテンツの集合体(ファイル)

Jobs / Tasks エンコードなどのメディア処理

MediaProcessors メディア処理アプリ定義

Locators 配布/配信ポイント

AccessPolicies 配布/配信公開ポリシー

Page 17: Dev camp2012jpn day2session2

Developer Camp | 2012 Japan Fall

コーディングの流れ

Page 18: Dev camp2012jpn day2session2

Demo

Ingest – Processing – Delivery : sample code

Page 19: Dev camp2012jpn day2session2

Developer Camp | 2012 Japan Fall

Windows Azure Media Services接続

• Windows Azure Media Servicesとの全てのやりとりは、CloudMediaContextクラスを通じて

• 注意点• CloudMediaContextはスレッドセーフではない

CloudMediaContext context = new CloudMediaContext(

ConfigurationManager.AppSettings["accountName"],

ConfigurationManager.AppSettings["accountKey"]

);

Page 20: Dev camp2012jpn day2session2

Developer Camp | 2012 Japan Fall

Ingest

Ingest

• Asset作成 = Windows Azure Media Services 管理下に、ファイルを置く

• ファイルのアップロード

• 別の Blob からのコピーも可能• Asset に書き込み可能な SAS URLを作成し、それを元に

Containerを作成する• http://social.msdn.microsoft.com/Forums/en-US/MediaServices/thread/be486bac-ac37-4984-87d0-

20931fcb1328

• 2つの暗号化オプション: AES 256bit / Common Encryption

Page 21: Dev camp2012jpn day2session2

Developer Camp | 2012 Japan Fall

Ingest – sample code

context.Assets.OnUploadProgress += newEventHandler<UploadProgressEventArgs>(Assets_OnUploadProgress);

IAsset ingestAsset = context.Assets.Create(@"D:¥MediaServices¥Contents¥file.wmv“,

AssetCreationOptions.StorageEncrypted);

void Assets_OnUploadProgress(object sender, UploadProgressEventArgs e){Console.WriteLine(" 経過{0:0.0}%", e.Progress);

}

Ingest

Page 22: Dev camp2012jpn day2session2

Video

爆速 Aspera

Page 23: Dev camp2012jpn day2session2

Developer Camp | 2012 Japan Fall

Manage

• Asset / Job / AccessPolicyの管理• 実際には Windows Azure SQL database 上で管理

• LINQ サポート

• 注意点• オブジェクトのリファレンスは自動リフレッシュしないため、都度、再クエリが必要

Ingest

Page 24: Dev camp2012jpn day2session2

Developer Camp | 2012 Japan Fall

Manage: Asset

• Windows Azure Blob コンテナ• アプリケーション的なメタは持っていない• Asset. AlternateIdにてCMS連携

• 削除する際の注意点• 関連する Locator は個別削除が必要• AssetCreationOptions.CommonEncryptionProtected指定をした

Asset を削除する場合は、ContentsKeyの個別削除が必須

Ingest

Id AlternateId Name

<guid> 0001 contoso

ID Name Title Artist

0001 Contoso Great Video Art #1

Page 25: Dev camp2012jpn day2session2

Developer Camp | 2012 Japan Fall

Process

• エンコードなどのメディア処理の実行単位

• Job に、n個の Task を作成• Job がコマンド発行の単位

• 開始/キャンセル/終了/エラーなど

• 入力/出力ファイル

• 処理は非同期で

• ファイル同士の依存関係がないとTask は並列実行。あると直列実行

Ingest

Job

Task

Input Asset

Output

Asset

Task

Input Asset

Output

Asset

Page 26: Dev camp2012jpn day2session2

Developer Camp | 2012 Japan Fall

Process: Windows Azure Media Encoder

• Expression Encoder 4 Pro SP2 がベース

• Azure に最適化• Adaptive Bitrate Streamingでは、複数VMを使う

• タスクプリセット指定• http://msdn.microsoft.com/en-us/library/jj129582.aspx

• 「現在」は、Expression Encoder 4 Pro SP2 のカスタムタスクプリセット (XML文字列)も動作する!

• サムネイル作成, 時間指定の切り出しなど

Ingest

Page 27: Dev camp2012jpn day2session2

Developer Camp | 2012 Japan Fall

Process: Windows Azure Media Encoder

• サポートしているファイルフォーマット• 3GPP, 3GPP2

• Advanced Systems Format (ASF)

• Advanced Video Coding High Definition (AVCHD) [MPEG-2 Transport

Stream]

• Audio-Video Interleaved (AVI)

• AviSynth

• Digital camcorder MPEG-2 (MOD)

• Digital video (DV) camera file

• DVD transport stream (TS) file

• DVD video object (VOB) file

• Expression Encoder Screen Capture Codec file

• MP4

• MPEG-1 System Stream

• MPEG-2 video file

• Smooth Streaming File Format (PIFF 1.3)

• Windows Media Video (WMV)

ビデオ

• AC-3 (Dolby Digital) audio

• Audio Interchange File Format (AIFF)

• Broadcast Wave Format

• MP3 (MPEG-1 Audio Layer 3)

• MP4 audio

• MPEG-4 audio book

• WAVE file

• Windows Media Audio

オーディオ

Ingest

Page 28: Dev camp2012jpn day2session2

Developer Camp | 2012 Japan Fall

Process: Windows Azure Media Encoder

• サポートしているコーデック

• H.264

• MPEG-1

• MPEG-2

• VC-1

• Windows Media Video

ビデオ

• AC-3 (Dolby Digital audio)

• Advanced Audio Coding (AAC)

• MP3 (MPEG-1 Audio Layer 3)

• Windows Media Audio

オーディオ

Ingest

Page 29: Dev camp2012jpn day2session2

Developer Camp | 2012 Japan Fall

Process: Windows Azure Media Packager / Encryptor

• IIS Transform Manager 1.0 がベース• http://msdn.microsoft.com/en-us/library/hh973619.aspx

• Media Processor 定義 + 設定XML文字列• PlayReady Protection Task

• MP4 to Smooth Streams Task

• Smooth Streams to HLS Conversion Task

• Storage Decyption• http://msdn.microsoft.com/en-us/library/jj129580.aspx#get_media_processor

Ingest

Page 30: Dev camp2012jpn day2session2

Developer Camp | 2012 Japan Fall

Process – sample code (1)

IJob job = context.Jobs.Create("WMV to SS and HLS");IMediaProcessor windowsAzureMediaEncoder = (from a in context.MediaProcessors

where a.Name == “Windows Azure Media Encoder”select a).First();

ITask WMS2SSTask = job.Tasks.AddNew("WMV to Smooth Streaming",windowsAzureMediaEncoder,"H.264 IIS Smooth Streaming iPhone WiFi",TaskCreationOptions.None);

// 入出力ファイル

WMS2SSTask.InputMediaAssets.Add(ingestAsset);IAsset SSedAssed = WMS2SSTask.OutputMediaAssets.AddNew(”SmoothStreaming",

true,AssetCreationOptions.None);

job.Submit();

Ingest

Page 31: Dev camp2012jpn day2session2

Developer Camp | 2012 Japan Fall

Process – sample code (2)

bool jobFinalize = false;while (!jobFinalize) {

job = (from j in context.Jobswhere j.Id == job.Idselect j).FirstOrDefault();

Console.WriteLine(" ***: {0}", job.State.ToString());

switch (job.State) {case JobState.Finished:

jobFinalize = true;Console.WriteLine(" 正常終了: {0}", job.RunningDuration);

break;case JobState.Error:

jobFinalize = true;Console.WriteLine(" エラー発生: {0}", job.Tasks[0].ErrorDetails);

break;default:

Console.WriteLine(" 15秒間 待機します: {0}", DateTime.Now.ToLongTimeString());

System.Threading.Thread.Sleep(15000);break;

}}

Ingest

Page 32: Dev camp2012jpn day2session2

Developer Camp | 2012 Japan Fall

Delivery

• ストリーミング / ダウンロードのオリジンサーバー

• Locator に Asset 単位で割り当てる• 1 つの Asset につき 5つの Locator が上限

• AccessPolicyによって、時間単位での公開を設定• アクセス権設定ではない

Ingest

Page 33: Dev camp2012jpn day2session2

Developer Camp | 2012 Japan Fall

Delivery – sample code

IAccessPolicy accessPolicy = context.AccessPolicies.Create("Streaming",TimeSpan.FromHours(3),AccessPermissions.Read | AccessPermissions.List);

/// *** 配信サーバー設定

ILocator SS_StreamingPointLocator = context.Locators.CreateOriginLocator(job.OutputMediaAssets[0],

accessPolicy);

string SS_StreaingPointPath = SS_StreamingPointLocator.Path +(from ism in job.OutputMediaAssets[0].Fileswhere ism.Name.EndsWith(".ism")select ism).FirstOrDefault().Name

+ "/manifest";

Ingest

Page 34: Dev camp2012jpn day2session2

Demo

Windows 8, Mac OS, iOSへ配信

Page 35: Dev camp2012jpn day2session2

Developer Camp | 2012 Japan Fall

Live Origin / Delivery (TAP)

• IIS Media Services 4.1 ベース

• 状態管理• Allocation – Start / Stop / Shutdown

• ヘルスチェック

• アーカイブ• Blob Storage へ

• IP Filtering

Page 36: Dev camp2012jpn day2session2

Demo

Live Origin - Delivery

Page 37: Dev camp2012jpn day2session2

Developer Camp | 2012 Japan Fall

まとめ

Quick and EasyシンプルなAPIPaaS

Open and Flexible様々な Partner Application様々なAPI: REST, .NET, Java, PHP

Powerful and Cost Effective進化し続けるCloudインフラのメリットを直接共有Capex / Opexの最小化

Page 38: Dev camp2012jpn day2session2

Developer Camp | 2012 Japan Fall

ご参考リソース

• MSDN Online: Windows Azure Media Services:

• http://msdn.microsoft.com/en-us/library/hh973629.aspx

• ScottGu’s Blog: Windows Azure Media Services and London 2012 Olympics

• http://weblogs.asp.net/scottgu/archive/2012/08/21/windows-azure-media-services-and-the-london-2012-olympics.aspx

Page 39: Dev camp2012jpn day2session2

© 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries.

The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of

Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

Page 40: Dev camp2012jpn day2session2

Media Services SDK

Page 41: Dev camp2012jpn day2session2

Developer Camp | 2012 Japan Fall

Media Services APIs and SDKs • REST API for all platforms, using OData 3.0

Simple to write your own client libraries using REST API and

standard HTTP verbs (GET, POST, PUT, DELETE)•

.NET library available in Preview•

Future - JAVA library available in Fall• Open Libraries available with source code (Apache 2 license) on GitHub

Page 42: Dev camp2012jpn day2session2

Developer Camp | 2012 Japan Fall

On-Demand Workflow

• Ingest

• Encode

• Package

• Encrypt

• Deliver

Page 43: Dev camp2012jpn day2session2

Developer Camp | 2012 Japan Fall

Ingest

Ingest Assets into the Media Services

Pre-encrypt files prior to uploading(AES 256)

Secure HTTPS upload

Network level peering for fast HTTP into Azure

Fast upload using UDP with Aspera

Bulk ingest support

Page 44: Dev camp2012jpn day2session2

Developer Camp | 2012 Japan Fall

Encode

Windows Azure Media Encoder

Supports encoding to H.264 or VC-1 video

Encodes audio to AAC-LC, HE-AAC, Dolby DD+, WMA

Packages to MP4, HLS, Smooth Streaming, HDS, WMV

Encrypts with PlayReady, Common Encryption, AES

Encoding with third-parties

Partner SDK for enabling ‘build-in’ encoders

Page 45: Dev camp2012jpn day2session2

Developer Camp | 2012 Japan Fall

Package

Page 46: Dev camp2012jpn day2session2

Developer Camp | 2012 Japan Fall

Encrypt

Page 47: Dev camp2012jpn day2session2

Developer Camp | 2012 Japan Fall

Deliver

Page 48: Dev camp2012jpn day2session2

Developer Camp | 2012 Japan Fall

Target

MP4

Page 49: Dev camp2012jpn day2session2

Developer Camp | 2012 Japan Fall

API Entities

Page 50: Dev camp2012jpn day2session2

Developer Camp | 2012 Japan Fall

Assets

The logical unit that represents a single audiovisual presentation in Media Services

An asset contains a collection of one to many media files

Page 51: Dev camp2012jpn day2session2

Developer Camp | 2012 Japan Fall

An Asset Is….• An asset should be considered a single version

or derivative of an audiovisual presentation

• Examples:• a full movie, TV show, specific edit

• a clip from a movie, TV show, animation, camera ISO file, event, etc..

• a movie trailer or promotional video

• an advertisement

• an audio file, radio show, podcast, sound file, etc…

Page 52: Dev camp2012jpn day2session2

Developer Camp | 2012 Japan Fall

An Asset Is NOT….

• A folder to organize and store multiple versions of the same presentation in

• For example, you would never use an Asset to store the Movie, its trailer, an advertisement, and an international edit version of the same movie in a single Asset

A folder for submitting batch processing of multiple audiovisual presentations to Azure Media Encoder

Page 53: Dev camp2012jpn day2session2

Developer Camp | 2012 Japan Fall

Access PoliciesAccess Policies define the permissions and duration of access to an Asset

Controls Read/Write semantics

Controls duration in minutes that a URL has access

Future expansion for more policy settings; IP white-listing, Geo-restriction, Identity/Group access, etc…

Page 54: Dev camp2012jpn day2session2

Developer Camp | 2012 Japan Fall

Content KeysEncryption information (AES Content Key, X.509 certificate) for protected assets

Assets can be either:

“storage encrypted” (256-bit key) to protect them at rest

“common encrypted” (128-bit key) for DRM delivery.

Assets are storage encrypted by default

Page 55: Dev camp2012jpn day2session2

Developer Camp | 2012 Japan Fall

Files

Actual video, audio, image, or metadata blobs stored in your Azure storage account

Source files are often referred to as “Mezzanine” files

Page 56: Dev camp2012jpn day2session2

Developer Camp | 2012 Japan Fall

LocatorsA Locator is a URI that provides time-based access to a specific asset

It is used with an AccessPolicy to define the permissions and duration that a client has access to a given Asset

Locators can be used to generate SAS URLs, Origin Server URLs , CDN URLs, 3rd party origin URLs, etc…

Page 57: Dev camp2012jpn day2session2

Developer Camp | 2012 Japan Fall

JobsA job is an “workflow” in Media Services that can be scheduled, monitored and canceled

The Job entity holds metadata about Tasks, which do processing on the files in an Asset

A job always has one or more associated inputs, tasks, and outputs

Page 58: Dev camp2012jpn day2session2

Developer Camp | 2012 Japan Fall

Job Templates

A JobTemplate provides reusable settings for Jobs that need to be run repeatedly

JobTemplates can be saved from existing Jobs for re-use

Page 59: Dev camp2012jpn day2session2

Developer Camp | 2012 Japan Fall

TasksA Task is an individual operation of work on an Asset and is defined in a Job

Tasks point to “Media Processors” that can be either first or third party

Each Task has its own configuration and can be scheduled to run sequentially or in parallel