1
- using Microsoft . WindowsAzure . MediaServices . Client ;
1
+ //****************************************************************************************
2
+ // Microsoft Azure Media Services allows you to build scalable, cost effective, end-to-end
3
+ // media distribution solutions that can stream media to Adobe Flash, Android, iOS, Windows,
4
+ // and other devices and platforms. If you dont have a Microsoft Azure subscription you can
5
+ // get a FREE trial account here: http://go.microsoft.com/fwlink/?LinkId=330212
6
+ //
7
+ //
8
+ //TODO: 1. Provision a Media Service using the Microsoft Azure Management Portal
9
+ // http://go.microsoft.com/fwlink/?LinkId=324582
10
+ // 2. Open App.Config and update the value of appSettings:
11
+ // MediaServices-AccountName
12
+ // MediaServices-AccountKey
13
+ // Your-Demo-mp4 (this should point at your *.mp4 input file)
14
+ //****************************************************************************************
15
+
2
16
using System ;
3
17
using System . Collections . Generic ;
4
18
using System . Configuration ;
5
19
using System . Linq ;
6
- using System . Text ;
7
20
using System . Threading ;
8
- using System . Threading . Tasks ;
21
+ using Microsoft . WindowsAzure . MediaServices . Client ;
9
22
10
23
namespace VODWorkflow
11
24
{
12
- class Program
13
- {
14
- //****************************************************************************************
15
- // Microsoft Azure Media Services allows you to build scalable, cost effective, end-to-end
16
- // media distribution solutions that can stream media to Adobe Flash, Android, iOS, Windows,
17
- // and other devices and platforms. If you dont have a Microsoft Azure subscription you can
18
- // get a FREE trial account here: http://go.microsoft.com/fwlink/?LinkId=330212
19
- //
20
- //
21
- //TODO: 1. Provision a Media Service using the Microsoft Azure Management Portal
22
- // http://go.microsoft.com/fwlink/?LinkId=324582
23
- // 2. Open App.Config and update the value of appSetting MediaServicesAccountName
24
- // and MediaServicesAccountKey
25
- // 3. Update _singleInputMp4Path variable below to point at your *.mp4 input file
26
- //****************************************************************************************
27
-
28
- private static readonly string _singleInputMp4Path = @"C:\users\you\your.mp4" ;
29
- private static readonly string _mediaServicesAccountKey = ConfigurationManager . AppSettings [ "MediaServicesAccountKey" ] ;
30
- private static readonly string _mediaServicesAccountName = ConfigurationManager . AppSettings [ "MediaServicesAccountName" ] ;
31
-
32
-
33
- // Field for service context.
34
- private static CloudMediaContext _context = null ;
35
-
36
- static void Main ( string [ ] args )
37
- {
38
- try
39
- {
40
- MediaServicesCredentials credentials = new MediaServicesCredentials ( _mediaServicesAccountName , _mediaServicesAccountKey ) ;
41
- CloudMediaContext context = new CloudMediaContext ( credentials ) ;
42
-
43
- Console . WriteLine ( "Creating new asset from local file..." ) ;
44
-
45
- // 1. Create a new asset by uploading a mezzanine file from a local path.
46
- IAsset inputAsset = context . Assets . CreateFromFile ( _singleInputMp4Path , AssetCreationOptions . None ,
47
- ( af , p ) =>
48
- {
49
- Console . WriteLine ( "Uploading '{0}' - Progress: {1:0.##}%" , af . Name , p . Progress ) ;
50
- } ) ;
51
-
52
- Console . WriteLine ( "Asset created." ) ;
53
-
54
- // 2. Prepare a job with a single task to transcode the previous mezzanine asset
55
- // into a multi-bitrate asset.
56
- IJob job = context . Jobs . CreateWithSingleTask ( MediaProcessorNames . WindowsAzureMediaEncoder ,
57
- MediaEncoderTaskPresetStrings . H264AdaptiveBitrateMP4Set720p ,
58
- inputAsset ,
59
- "Sample Adaptive Bitrate MP4" ,
60
- AssetCreationOptions . None ) ;
61
-
62
- Console . WriteLine ( "Submitting transcoding job..." ) ;
63
-
64
- // 3. Submit the job and wait until it is completed.
65
- job . Submit ( ) ;
66
- job = job . StartExecutionProgressTask ( j => {
67
- Console . WriteLine ( "Job state: {0}" , j . State ) ;
68
- Console . WriteLine ( "Job progress: {0:0.##}%" , j . GetOverallProgress ( ) ) ;
69
- } , CancellationToken . None ) . Result ;
70
-
71
- Console . WriteLine ( "Transcoding job finished." ) ;
72
-
73
- IAsset outputAsset = job . OutputMediaAssets [ 0 ] ;
74
-
75
- Console . WriteLine ( "Publishing output asset..." ) ;
76
-
77
- // 4. Publish the output asset by creating an Origin locator for adaptive streaming,
78
- // and a SAS locator for progressive download.
79
- context . Locators . Create ( LocatorType . OnDemandOrigin , outputAsset , AccessPermissions . Read , TimeSpan . FromDays ( 30 ) ) ;
80
- context . Locators . Create ( LocatorType . Sas , outputAsset , AccessPermissions . Read , TimeSpan . FromDays ( 30 ) ) ;
81
-
82
- IEnumerable < IAssetFile > mp4AssetFiles = outputAsset . AssetFiles . ToList ( )
83
- . Where ( af => af . Name . EndsWith ( ".mp4" , StringComparison . OrdinalIgnoreCase ) ) ;
84
-
85
- // 5. Generate the Smooth Streaming, HLS and MPEG-DASH URLs for adaptive streaming,
86
- // and the Progressive Download URL.
87
- Uri smoothStreamingUri = outputAsset . GetSmoothStreamingUri ( ) ;
88
- Uri hlsUri = outputAsset . GetHlsUri ( ) ;
89
- Uri mpegDashUri = outputAsset . GetMpegDashUri ( ) ;
90
- List < Uri > mp4ProgressiveDownloadUris = mp4AssetFiles . Select ( af => af . GetSasUri ( ) ) . ToList ( ) ;
91
-
92
- // 6. Get the asset URLs.
93
- Console . WriteLine ( smoothStreamingUri ) ;
94
- Console . WriteLine ( hlsUri ) ;
95
- Console . WriteLine ( mpegDashUri ) ;
96
- mp4ProgressiveDownloadUris . ForEach ( uri => Console . WriteLine ( uri ) ) ;
97
-
98
- Console . WriteLine ( "Output asset available for adaptive streaming and progressive download." ) ;
99
-
100
- Console . WriteLine ( "VOD workflow finished." ) ;
101
- }
102
- catch ( Exception exception )
103
- {
104
- // Parse the XML error message in the Media Services response and create a new
105
- // exception with its content.
106
- exception = MediaServicesExceptionParser . Parse ( exception ) ;
107
-
108
- Console . Error . WriteLine ( exception . Message ) ;
109
- }
110
- finally
111
- {
112
- Console . ReadLine ( ) ;
113
- }
114
- }
115
- }
116
- }
25
+ class Program
26
+ {
27
+ private static readonly string SingleInputMp4Path = ConfigurationManager . AppSettings [ "Your-Demo-mp4" ] ;
28
+ private static readonly string MediaServicesAccountKey = ConfigurationManager . AppSettings [ "MediaServices-AccountKey" ] ;
29
+ private static readonly string MediaServicesAccountName = ConfigurationManager . AppSettings [ "MediaServices-AccountName" ] ;
30
+
31
+ static void Main ( )
32
+ {
33
+ try
34
+ {
35
+ MediaServicesCredentials credentials = new MediaServicesCredentials ( MediaServicesAccountName , MediaServicesAccountKey ) ;
36
+ CloudMediaContext context = new CloudMediaContext ( credentials ) ;
37
+
38
+ Console . WriteLine ( "Creating new asset from local file..." ) ;
39
+
40
+ // 1. Create a new asset by uploading a mezzanine file from a local path.
41
+ IAsset inputAsset = context . Assets . CreateFromFile ( SingleInputMp4Path , AssetCreationOptions . None ,
42
+ ( af , p ) =>
43
+ {
44
+ Console . WriteLine ( "Uploading '{0}' - Progress: {1:0.##}%" , af . Name , p . Progress ) ;
45
+ } ) ;
46
+
47
+ Console . WriteLine ( "Asset created." ) ;
48
+
49
+ // 2. Prepare a job with a single task to transcode the previous mezzanine asset
50
+ // into a multi-bitrate asset.
51
+ IJob job = context . Jobs . CreateWithSingleTask ( MediaProcessorNames . WindowsAzureMediaEncoder ,
52
+ MediaEncoderTaskPresetStrings . H264AdaptiveBitrateMP4Set720p ,
53
+ inputAsset ,
54
+ "Sample Adaptive Bitrate MP4" ,
55
+ AssetCreationOptions . None ) ;
56
+
57
+ Console . WriteLine ( "Submitting transcoding job..." ) ;
58
+
59
+ // 3. Submit the job and wait until it is completed.
60
+ job . Submit ( ) ;
61
+ job = job . StartExecutionProgressTask ( j =>
62
+ {
63
+ Console . WriteLine ( "Job state: {0}" , j . State ) ;
64
+ Console . WriteLine ( "Job progress: {0:0.##}%" , j . GetOverallProgress ( ) ) ;
65
+ } , CancellationToken . None ) . Result ;
66
+
67
+ Console . WriteLine ( "Transcoding job finished." ) ;
68
+
69
+ IAsset outputAsset = job . OutputMediaAssets [ 0 ] ;
70
+
71
+ Console . WriteLine ( "Publishing output asset..." ) ;
72
+
73
+ // 4. Publish the output asset by creating an Origin locator for adaptive streaming,
74
+ // and a SAS locator for progressive download.
75
+ context . Locators . Create ( LocatorType . OnDemandOrigin , outputAsset , AccessPermissions . Read , TimeSpan . FromDays ( 30 ) ) ;
76
+ context . Locators . Create ( LocatorType . Sas , outputAsset , AccessPermissions . Read , TimeSpan . FromDays ( 30 ) ) ;
77
+
78
+ IEnumerable < IAssetFile > mp4AssetFiles = outputAsset . AssetFiles . ToList ( )
79
+ . Where ( af => af . Name . EndsWith ( ".mp4" , StringComparison . OrdinalIgnoreCase ) ) ;
80
+
81
+ // 5. Generate the Smooth Streaming, HLS and MPEG-DASH URLs for adaptive streaming,
82
+ // and the Progressive Download URL.
83
+ Uri smoothStreamingUri = outputAsset . GetSmoothStreamingUri ( ) ;
84
+ Uri hlsUri = outputAsset . GetHlsUri ( ) ;
85
+ Uri mpegDashUri = outputAsset . GetMpegDashUri ( ) ;
86
+ List < Uri > mp4ProgressiveDownloadUris = mp4AssetFiles . Select ( af => af . GetSasUri ( ) ) . ToList ( ) ;
87
+
88
+ // 6. Get the asset URLs.
89
+ Console . WriteLine ( smoothStreamingUri ) ;
90
+ Console . WriteLine ( hlsUri ) ;
91
+ Console . WriteLine ( mpegDashUri ) ;
92
+ mp4ProgressiveDownloadUris . ForEach ( Console . WriteLine ) ;
93
+
94
+ Console . WriteLine ( "Output asset available for adaptive streaming and progressive download." ) ;
95
+
96
+ Console . WriteLine ( "VOD workflow finished." ) ;
97
+ }
98
+ catch ( Exception exception )
99
+ {
100
+ // Parse the XML error message in the Media Services response and create a new
101
+ // exception with its content.
102
+ exception = MediaServicesExceptionParser . Parse ( exception ) ;
103
+
104
+ Console . Error . WriteLine ( exception . Message ) ;
105
+ }
106
+ finally
107
+ {
108
+ Console . ReadLine ( ) ;
109
+ }
110
+ }
111
+ }
112
+ }
0 commit comments