chakemiです。 本日は、ExpressionEncoder SDKを使用して、WindowsMediaServiceでPush配信をしてみたいと思います。
開発環境
- WindowsXP SP3
- VisualC#2010Express
- ExpressionEncoder4 SDK ※ExpressionEncoderは無償版
デバイスの取得、プロファイルの部分は前々回を参考にしてください。 Push配信を行なうには、Micosoft.Expression.Encoder.Live名前空間のPushBroadcastPublishFormatクラスを使用します。
PublishingPointプロパティへPush先のパブリッシュポイントを指定します。
1
|
PublishingPoint = new Uri("http://192.168.1.2/code-life");
|
PushBroadcastPublishFormatクラスには、UserNameプロパティとPasswordプロパティがありますが、Passwordプロパティはセキュリティ上の問題で、ジョブファイルで保持出来ないようです。
ここでは、Push配信時の接続に、AcquireCredentialsEventArgsクラスを使用します。 AcquireCredentialsEventArgsは、ユーザーがリモートサイトにアクセスする権限があるかを確認するために、ユーザーの資格情報を取得します。
1
2
3
4
5
6
7
8
9
10
11
12
|
liveJob.AcquireCredentials += new EventHandler<AcquireCredentialsEventArgs>(liveJob_AcquireCredentials);
//
//
//省略
//
//
static void liveJob_AcquireCredentials(object sender, AcquireCredentialsEventArgs e)
{
e.UserName = _userName;
e.Password = _pw;
e.Modes = AcquireCredentialModes.None;
}
|
サーバ認証に使用される一連のフラグを取得するため、ここで、AcquireCredentialModesを「None」に設定する必要があります。
接続の際に、コンソールからユーザ名、パスワードを入力出来るようにします。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
Console.Write("ユーザー名:");
_userName = Console.ReadLine();
Console.Write("パスワード:");
_pw = new SecureString();
ConsoleKeyInfo key;
do
{
key = Console.ReadKey(true);
if (key.Key != ConsoleKey.Enter)
{
_pw.AppendChar(key.KeyChar);
}
}
while (key.Key != ConsoleKey.Enter);
|
また、エンコーダからパブリッシュポイントへの接続状況を確認出来るようステータスを表示するためにEncodeStatusEventArgsを追加します。
1
2
3
4
5
6
7
8
9
10
|
liveJob.Status += new EventHandler<EncodeStatusEventArgs>(liveJob_Status);
//
//
//省略
//
//
static void liveJob_Status(object sender, EncodeStatusEventArgs e)
{
Console.Out.WriteLine("\nStatus:" + e.Status.ToString());
}
|
以下、全体のソース
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Expression.Encoder;
using System.Drawing;
using Microsoft.Expression.Encoder.Profiles;
using Microsoft.Expression.Encoder.Live;
using Microsoft.Expression.Encoder.Devices;
using System.Collections.ObjectModel;
using System.Security;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
LiveDeviceSource source;
LiveJob liveJob = new LiveJob();
//使用できるデバイスを取得
Collection<EncoderDevice> videoDevice = EncoderDevices.FindDevices(EncoderDeviceType.Video);
Collection<EncoderDevice> audioDevice = EncoderDevices.FindDevices(EncoderDeviceType.Audio);
source = liveJob.AddDeviceSource(videoDevice[0], audioDevice[0]);
liveJob.ActivateSource(source);
//プロファイルの設定
WindowsMediaOutputFormat outputFormat = new WindowsMediaOutputFormat();
outputFormat.VideoProfile = new MainVC1VideoProfile();
outputFormat.VideoProfile.Bitrate = new ConstantBitrate(512);
outputFormat.VideoProfile.Size = new Size(320, 240);
outputFormat.VideoProfile.FrameRate = 30;
outputFormat.AudioProfile = new WmaAudioProfile();
outputFormat.AudioProfile.Codec = AudioCodec.Wma;
outputFormat.AudioProfile.Bitrate = new ConstantBitrate(64);
outputFormat.AudioProfile.BitsPerSample = 16;
liveJob.OutputFormat = outputFormat;
//イベントハンドラ追加
liveJob.AcquireCredentials += new EventHandler<AcquireCredentialsEventArgs>(liveJob_AcquireCredentials);
liveJob.Status += new EventHandler<EncodeStatusEventArgs>(liveJob_Status);
//Push配信 設定
PushBroadcastPublishFormat push = new PushBroadcastPublishFormat();
push.PublishingPoint = new Uri("http://192.168.1.212/code-life");
Console.Write("ユーザー名:");
_userName = Console.ReadLine();
Console.Write("パスワード:");
_pw = new SecureString();
ConsoleKeyInfo key;
do
{
key = Console.ReadKey(true);
if (key.Key != ConsoleKey.Enter)
{
_pw.AppendChar(key.KeyChar);
}
}
while (key.Key != ConsoleKey.Enter);
liveJob.PublishFormats.Add(push);
liveJob.StartEncoding();
Console.WriteLine("Start Encoding");
Console.Read();
liveJob.StopEncoding();
}
//イベント処理
static void liveJob_Status(object sender, EncodeStatusEventArgs e)
{
Console.Out.WriteLine("\nStatus:" + e.Status.ToString());
}
static void liveJob_AcquireCredentials(object sender, AcquireCredentialsEventArgs e)
{
e.UserName = _userName;
e.Password = _pw;
e.Modes = AcquireCredentialModes.None;
}
public static string _userName { get; set; }
public static SecureString _pw { get; set; }
}
}
|
実際に、WindowsServer2003のWindowsMediaServiceと接続してみます。

プレーヤーで再生まで確認出来たら完成♪
これで一旦、「ExpressionEncoder SDKを触ってみる」は終了します。
Proライセンス手に入れば、Smoothストリーミングとか試してみたいのになぁ~。