/// <summary> /// PublishAsset - Publishes the asset with global descriptor to enable the asset for streaming. /// </summary> /// <param name="asset">asset</param> /// <returns>Returns list of streaming uri's for all available streaming formats</returns> public PublishedUrlDetails PublishAsset(IAsset asset) { PublishedUrlDetails publishedUrls = new PublishedUrlDetails(); var assetFile = asset.AssetFiles.Where(f => f.Name.ToLower().EndsWith(".ism")).FirstOrDefault(); IAccessPolicy policy = _mediaContext.AccessPolicies.Create("Streaming policy", TimeSpan.FromDays(365), AccessPermissions.Read); ILocator originLocator = _mediaContext.Locators.CreateLocator(LocatorType.OnDemandOrigin, asset, policy, DateTime.UtcNow.AddMinutes(-5)); Uri smoothStreamingUri = asset.GetSmoothStreamingUri(); Uri hlsUri = asset.GetHlsUri(); Uri mpegDashUri = asset.GetMpegDashUri(); Uri hlsv3Uri = asset.GetHlsv3Uri(); publishedUrls.SmoothUrl = smoothStreamingUri != null?smoothStreamingUri.ToString().Replace("http://", "https://") : " "; publishedUrls.Hlsv4Uri = hlsUri != null?hlsUri.ToString().Replace("http://", "https://") : " "; publishedUrls.Hlsv3Uri = hlsv3Uri != null?hlsv3Uri.ToString().Replace("http://", "https://") : " "; publishedUrls.MpegDashUri = mpegDashUri != null?mpegDashUri.ToString().Replace("http://", "https://") : " "; if (assetFile != null) { publishedUrls.UrlWithOriginLocator = originLocator.Path.Replace("http://", "https://") + assetFile.Name + "/manifest"; } return(publishedUrls); }
static void Main() { // Create and cache the Media Services credentials in a static class variable. cachedCredentials = new MediaServicesCredentials(MediaServicesAccountName, MediaServicesAccountKey); // Use the cached credentials to create CloudMediaContext. context = new CloudMediaContext(cachedCredentials); // Encoding and encrypting assets ////////////////////// // Load a single MP4 file. IAsset asset = IngestSingleMp4File(SingleMp4File, AssetCreationOptions.None); // Encode an MP4 file to a set of multibitrate MP4s. // Then, package a set of MP4s to clear Smooth Streaming. IAsset clearSmoothStreamAsset = ConvertMp4ToMultibitrateMp4SToSmoothStreaming(asset); // Encrypt your clear Smooth Streaming to Smooth Streaming with PlayReady. IAsset outputAsset = CreateSmoothStreamEncryptedWithPlayReady(clearSmoothStreamAsset); // You can use the http://smf.cloudapp.net/healthmonitor player // to test the smoothStreamURL URL. Console.WriteLine("Smooth Streaming URL: {0}", outputAsset.GetSmoothStreamingUri()); // You can use the http://dashif.org/reference/players/javascript/ player // to test the dashURL URL. Console.WriteLine("MPEG DASH URL: {0}", outputAsset.GetMpegDashUri()); }
static public void PublishAssetGetURLs(IAsset asset, bool onDemaindURL = true, string fileExt = "") { // Publish the output asset by creating an Origin locator for adaptive streaming, // and a SAS locator for progressive download. System.IO.StreamWriter file = File.AppendText(text_path); if (onDemaindURL) { _context.Locators.Create( LocatorType.OnDemandOrigin, asset, AccessPermissions.Read, TimeSpan.FromDays(30)); // Get the Smooth Streaming, HLS and MPEG-DASH URLs for adaptive streaming, // and the Progressive Download URL. Uri smoothStreamingUri = asset.GetSmoothStreamingUri(); Uri hlsUri = asset.GetHlsUri(); Uri mpegDashUri = asset.GetMpegDashUri(); // Display the streaming URLs. Console.WriteLine("Use the following URLs for adaptive streaming: "); Console.WriteLine(smoothStreamingUri); file.WriteLine(smoothStreamingUri); //Console.WriteLine(hlsUri); //Console.WriteLine(mpegDashUri); Console.WriteLine(); } else { _context.Locators.Create( LocatorType.Sas, asset, AccessPermissions.Read, TimeSpan.FromDays(30)); IEnumerable <IAssetFile> assetFiles = asset .AssetFiles .ToList() .Where(af => af.Name.EndsWith(fileExt, StringComparison.OrdinalIgnoreCase)); // Get the URls for progressive download for each specified file that was generated as a result // of encoding. List <Uri> sasUris = assetFiles.Select(af => af.GetSasUri()).ToList(); // Display the URLs for progressive download. Console.WriteLine("Use the following URLs for progressive download."); sasUris.ForEach(uri => file.WriteLine(uri)); Console.WriteLine(); } file.Close(); }
static public void PublishAssetGetURLs(IAsset asset) { // Publish the output asset by creating an Origin locator for adaptive streaming, // and a SAS locator for progressive download. _context.Locators.Create( LocatorType.OnDemandOrigin, asset, AccessPermissions.Read, TimeSpan.FromDays(30)); _context.Locators.Create( LocatorType.Sas, asset, AccessPermissions.Read, TimeSpan.FromDays(30)); IEnumerable <IAssetFile> mp4AssetFiles = asset .AssetFiles .ToList() .Where(af => af.Name.EndsWith(".mp4", StringComparison.OrdinalIgnoreCase)); // Get the Smooth Streaming, HLS and MPEG-DASH URLs for adaptive streaming, // and the Progressive Download URL. Uri smoothStreamingUri = asset.GetSmoothStreamingUri(); Uri hlsUri = asset.GetHlsUri(); Uri mpegDashUri = asset.GetMpegDashUri(); // Get the URls for progressive download for each MP4 file that was generated as a result // of encoding. List <Uri> mp4ProgressiveDownloadUris = mp4AssetFiles.Select(af => af.GetSasUri()).ToList(); // Display the streaming URLs. Console.WriteLine("Use the following URLs for adaptive streaming: "); Console.WriteLine(smoothStreamingUri); Console.WriteLine(hlsUri); Console.WriteLine(mpegDashUri); Console.WriteLine(); // Display the URLs for progressive download. Console.WriteLine("Use the following URLs for progressive download."); mp4ProgressiveDownloadUris.ForEach(uri => Console.WriteLine(uri + "\n")); Console.WriteLine(); // Download the output asset to a local folder. string outputFolder = "job-output"; if (!Directory.Exists(outputFolder)) { Directory.CreateDirectory(outputFolder); } Console.WriteLine(); Console.WriteLine("Downloading output asset files to a local folder..."); asset.DownloadToFolder( outputFolder, (af, p) => { Console.WriteLine("Downloading '{0}' - Progress: {1:0.##}%", af.Name, p.Progress); }); Console.WriteLine("Output asset files available at '{0}'.", Path.GetFullPath(outputFolder)); }
public static async Task <VideoQueueMessage> Run( [HttpTrigger(authLevel: AuthorizationLevel.Function, methods: "post")] HttpRequestMessage req, TraceWriter log) { try { log.Info($"Webhook was triggered!"); string jsonContent = await req.Content.ReadAsStringAsync(); log.Info($"Publish Message: {jsonContent}"); var publishMsg = JsonConvert.DeserializeObject <VideoPublishMessage>(jsonContent); AzureAdTokenCredentials tokenCredentials = new AzureAdTokenCredentials(AADTenantDomain, new AzureAdClientSymmetricKey(mediaServicesClientId, mediaServicesClientSecret), AzureEnvironments.AzureCloudEnvironment); AzureAdTokenProvider tokenProvider = new AzureAdTokenProvider(tokenCredentials); context = new CloudMediaContext(new Uri(RESTAPIEndpoint), tokenProvider); IAsset asset = null; foreach (var item in context.Assets) { if (item.Name == publishMsg.AssetName) { asset = item; } break; } if (asset == null) { return(null); } log.Info($"Found asset: {asset.Name}"); var videoQueueMsg = new VideoQueueMessage(); // Create the on demand await context.Locators.CreateAsync(LocatorType.OnDemandOrigin, asset, AccessPermissions.Read, TimeSpan.FromDays(365)); videoQueueMsg.ReviewId = publishMsg.ReviewId; videoQueueMsg.SmoothStreamingUri = asset.GetSmoothStreamingUri().AbsoluteUri; videoQueueMsg.HLSUri = asset.GetHlsUri().AbsoluteUri; videoQueueMsg.MpegDashUri = asset.GetMpegDashUri().AbsoluteUri; // Create the progressive download await context.Locators.CreateAsync(LocatorType.Sas, asset, AccessPermissions.Read, TimeSpan.FromDays(365)); var imageUri = asset.AssetFiles.ToList().Where(af => af.Name.EndsWith("png", StringComparison.OrdinalIgnoreCase)).FirstOrDefault()?.GetSasUri(); videoQueueMsg.ThumbnailUri = imageUri?.AbsoluteUri ?? ""; // Write the message to the queue return(videoQueueMsg); } catch (Exception ex) { log.Error($"Error during publishing! {ex.Message}"); } return(null); }
static void Main(string[] args) { try { MediaServicesCredentials credentials = new MediaServicesCredentials(_mediaServicesAccountName, _mediaServicesAccountKey); CloudMediaContext context = new CloudMediaContext(credentials); Console.WriteLine("Creating new asset from local file..."); // 1. Create a new asset by uploading a mezzanine file from a local path. IAsset inputAsset = context.Assets.CreateFromFile(_singleInputMp4Path, AssetCreationOptions.None, (af, p) => { Console.WriteLine("Uploading '{0}' - Progress: {1:0.##}%", af.Name, p.Progress); }); Console.WriteLine("Asset created."); // 2. Prepare a job with a single task to transcode the previous mezzanine asset // into a multi-bitrate asset. IJob job = context.Jobs.CreateWithSingleTask(MediaProcessorNames.WindowsAzureMediaEncoder, MediaEncoderTaskPresetStrings.H264AdaptiveBitrateMP4Set720p, inputAsset, "Sample Adaptive Bitrate MP4", AssetCreationOptions.None); Console.WriteLine("Submitting transcoding job..."); // 3. Submit the job and wait until it is completed. job.Submit(); job = job.StartExecutionProgressTask(j => { Console.WriteLine("Job state: {0}", j.State); Console.WriteLine("Job progress: {0:0.##}%", j.GetOverallProgress()); }, CancellationToken.None).Result; Console.WriteLine("Transcoding job finished."); IAsset outputAsset = job.OutputMediaAssets[0]; Console.WriteLine("Publishing output asset..."); // 4. Publish the output asset by creating an Origin locator for adaptive streaming, // and a SAS locator for progressive download. context.Locators.Create(LocatorType.OnDemandOrigin, outputAsset, AccessPermissions.Read, TimeSpan.FromDays(30)); context.Locators.Create(LocatorType.Sas, outputAsset, AccessPermissions.Read, TimeSpan.FromDays(30)); IEnumerable <IAssetFile> mp4AssetFiles = outputAsset.AssetFiles.ToList() .Where(af => af.Name.EndsWith(".mp4", StringComparison.OrdinalIgnoreCase)); // 5. Generate the Smooth Streaming, HLS and MPEG-DASH URLs for adaptive streaming, // and the Progressive Download URL. Uri smoothStreamingUri = outputAsset.GetSmoothStreamingUri(); Uri hlsUri = outputAsset.GetHlsUri(); Uri mpegDashUri = outputAsset.GetMpegDashUri(); List <Uri> mp4ProgressiveDownloadUris = mp4AssetFiles.Select(af => af.GetSasUri()).ToList(); // 6. Get the asset URLs. Console.WriteLine(smoothStreamingUri); Console.WriteLine(hlsUri); Console.WriteLine(mpegDashUri); mp4ProgressiveDownloadUris.ForEach(uri => Console.WriteLine(uri)); Console.WriteLine("Output asset available for adaptive streaming and progressive download."); Console.WriteLine("VOD workflow finished."); } catch (Exception exception) { // Parse the XML error message in the Media Services response and create a new // exception with its content. exception = MediaServicesExceptionParser.Parse(exception); Console.Error.WriteLine(exception.Message); } finally { Console.ReadLine(); } }
/// <summary> /// Refer to: http://msdn.microsoft.com/en-us/library/jj889436.aspx /// </summary> /// <param name="asset"></param> /// <returns></returns> public static List<Uri> GetAdaptiveStreamingURLs(IAsset asset) { // Generate the Smooth Streaming, HLS and MPEG-DASH URLs for adaptive streaming. Uri smoothStreamingUri = asset.GetSmoothStreamingUri(); //for MS XBOX etc. Uri hlsUri = asset.GetHlsUri(); //For Apple devices Uri mpegDashUri = asset.GetMpegDashUri(); //The ISO standard var result = new List<Uri>(); result.Add(smoothStreamingUri); result.Add(hlsUri); result.Add(mpegDashUri); return result; }
static void Main(string[] args) { // Create and cache the Media Services credentials in a static class variable. _cachedCredentials = new MediaServicesCredentials( _mediaServicesAccountName, _mediaServicesAccountKey); // Use the cached credentials to create CloudMediaContext. _context = new CloudMediaContext(_cachedCredentials); // Encoding and encrypting assets ////////////////////// // Load a single MP4 file. IAsset asset = IngestSingleMP4File(_singleMP4File, AssetCreationOptions.None); // Encode an MP4 file to a set of multibitrate MP4s. // Then, package a set of MP4s to clear Smooth Streaming. IAsset clearSmoothStreamAsset = ConvertMP4ToMultibitrateMP4sToSmoothStreaming(asset); // Create a common encryption content key that is used // a) to set the key values in the MediaEncryptor_PlayReadyProtection.xml file // that is used for encryption. // b) to configure the license delivery service and // Guid keyId; byte[] contentKey; IContentKey key = CreateCommonEncryptionKey(out keyId, out contentKey); // Add the common encryption key to asset's keys. // asset.ContentKeys.Add(key); // The content key authorization policy must be configured by you // and met by the client in order for the PlayReady license // to be delivered to the client. ConfigureLicenseDeliveryService(key); Uri acquisitionUrl = key.GetKeyDeliveryUrl(ContentKeyDeliveryType.PlayReadyLicense); // Update the MediaEncryptor_PlayReadyProtection.xml file with the key and URL info. UpdatePlayReadyConfigurationXMLFile(keyId, contentKey, acquisitionUrl); // Encrypt your clear Smooth Streaming to Smooth Streaming with PlayReady. IAsset outputAsset = CreateSmoothStreamEncryptedWithPlayReady(clearSmoothStreamAsset); // You can use the http://smf.cloudapp.net/healthmonitor player // to test the smoothStreamURL URL. string smoothStreamURL = outputAsset.GetSmoothStreamingUri().ToString(); Console.WriteLine("Smooth Streaming URL:"); Console.WriteLine(smoothStreamURL); // You can use the http://dashif.org/reference/players/javascript/ player // to test the dashURL URL. string dashURL = outputAsset.GetMpegDashUri().ToString(); Console.WriteLine("MPEG DASH URL:"); Console.WriteLine(dashURL); }
public static void PublishAssetGetURLs(IAsset asset) { // Publish the output asset by creating an Origin locator for adaptive streaming, // and a SAS locator for progressive download. _context.Locators.Create( LocatorType.OnDemandOrigin, asset, AccessPermissions.Read, TimeSpan.FromDays(30)); _context.Locators.Create( LocatorType.Sas, asset, AccessPermissions.Read, TimeSpan.FromDays(30)); IEnumerable<IAssetFile> mp4AssetFiles = asset .AssetFiles .ToList() .Where(af => af.Name.EndsWith(".mp4", StringComparison.OrdinalIgnoreCase)); // Get the Smooth Streaming, HLS and MPEG-DASH URLs for adaptive streaming, // and the Progressive Download URL. Uri smoothStreamingUri = asset.GetSmoothStreamingUri(); Uri hlsUri = asset.GetHlsUri(); Uri mpegDashUri = asset.GetMpegDashUri(); // Get the URls for progressive download for each MP4 file that was generated as a result // of encoding. List<Uri> mp4ProgressiveDownloadUris = mp4AssetFiles.Select(af => af.GetSasUri()).ToList(); // Display the streaming URLs. Console.WriteLine("Use the following URLs for adaptive streaming: "); Console.WriteLine(smoothStreamingUri); Console.WriteLine(hlsUri); Console.WriteLine(mpegDashUri); Console.WriteLine(); // Display the URLs for progressive download. Console.WriteLine("Use the following URLs for progressive download."); mp4ProgressiveDownloadUris.ForEach(uri => Console.WriteLine(uri + "\n")); Console.WriteLine(); // Download the output asset to a local folder. string outputFolder = "job-output"; if (!Directory.Exists(outputFolder)) { Directory.CreateDirectory(outputFolder); } Console.WriteLine(); Console.WriteLine("Downloading output asset files to a local folder..."); asset.DownloadToFolder( outputFolder, (af, p) => { Console.WriteLine("Downloading '{0}' - Progress: {1:0.##}%", af.Name, p.Progress); }); Console.WriteLine("Output asset files available at '{0}'.", Path.GetFullPath(outputFolder)); }
static public void PublishAssetGetURLs(IAsset asset, bool onDemaindURL = true, string fileExt = "") { // Publish the output asset by creating an Origin locator for adaptive streaming, // and a SAS locator for progressive download. if (onDemaindURL) { _context.Locators.Create( LocatorType.OnDemandOrigin, asset, AccessPermissions.Read, TimeSpan.FromDays(30)); // Get the Smooth Streaming, HLS and MPEG-DASH URLs for adaptive streaming, // and the Progressive Download URL. Uri smoothStreamingUri = asset.GetSmoothStreamingUri(); Uri hlsUri = asset.GetHlsUri(); Uri mpegDashUri = asset.GetMpegDashUri(); // Display the streaming URLs. Console.WriteLine("Use the following URLs for adaptive streaming: "); Console.WriteLine(smoothStreamingUri); Console.WriteLine(hlsUri); Console.WriteLine(mpegDashUri); Console.WriteLine(); } else { _context.Locators.Create( LocatorType.Sas, asset, AccessPermissions.Read, TimeSpan.FromDays(30)); IEnumerable<IAssetFile> assetFiles = asset .AssetFiles .ToList() .Where(af => af.Name.EndsWith(fileExt, StringComparison.OrdinalIgnoreCase)); // Get the URls for progressive download for each specified file that was generated as a result // of encoding. List<Uri> sasUris = assetFiles.Select(af => af.GetSasUri()).ToList(); // Display the URLs for progressive download. Console.WriteLine("Use the following URLs for progressive download."); sasUris.ForEach(uri => Console.WriteLine(uri + "\n")); Console.WriteLine(); } }
private static void VodWorkflowUsingExtensions(CloudMediaContext context) { Console.WriteLine("Creando nuevo asset desde un archivo local..."); // 1. Create a new asset by uploading a mezzanine file from a local path. IAsset inputAsset = context.CreateAssetFromFile( "big_buck_bunny_720p_stereo.mp4", AssetCreationOptions.None, (af, p) => { Console.WriteLine("Subiendo '{0}' - Progreso {1:0.##}%", af.Name, p.Progress); }); Console.WriteLine("Asset creado."); // 2. Prepare a job with a single task to transcode the previous mezzanine asset // into a multi-bitrate asset. IJob job = context.PrepareJobWithSingleTask("Windows Azure Media Encoder", "H264 Adaptive Bitrate MP4 Set 720p", inputAsset, "Big Buck Bunny Dynamic Packaging", AssetCreationOptions.None); Console.WriteLine("Enviando transcoding job..."); // 3. Submit the job and wait until it is completed. job.Submit(); job = context.StartExecutionProgressTask( job, j => { Console.WriteLine("Estado del job: {0}", j.State); Console.WriteLine("Progreso del job: {0:0.##}%", j.GetOverallProgress()); }, CancellationToken.None).Result; Console.WriteLine("Transcoding job terminado."); IAsset outputAsset = job.OutputMediaAssets[0]; Console.WriteLine("Publicando output asset..."); // 4. Publish the output asset by creating an Origin locator for adaptive streaming, and a SAS locator for progressive download. context.CreateLocator(outputAsset, LocatorType.OnDemandOrigin, AccessPermissions.Read, TimeSpan.FromDays(30)); context.CreateLocator(outputAsset, LocatorType.Sas, AccessPermissions.Read, TimeSpan.FromDays(30)); IEnumerable <IAssetFile> mp4AssetFiles = outputAsset .AssetFiles .ToList() .Where(af => af.Name.EndsWith(".mp4", StringComparison.OrdinalIgnoreCase)); // 5. Generate the Smooth Streaming, HLS and MPEG-DASH URLs for adaptive streaming, and the Progressive Download URL. Uri smoothStreamingUri = outputAsset.GetSmoothStreamingUri(); Uri hlsUri = outputAsset.GetHlsUri(); Uri mpegDashUri = outputAsset.GetMpegDashUri(); List <Uri> mp4ProgressiveDownloadUris = mp4AssetFiles.Select(af => af.GetSasUri()).ToList(); Console.WriteLine(smoothStreamingUri); Console.WriteLine(hlsUri); Console.WriteLine(mpegDashUri); mp4ProgressiveDownloadUris.ForEach(uri => Console.WriteLine(uri)); string filePath = @"asset-urls.txt"; // 6. Save the URLs to a local file. smoothStreamingUri.Save(filePath); hlsUri.Save(filePath); mpegDashUri.Save(filePath); mp4ProgressiveDownloadUris.ForEach(uri => uri.Save(filePath)); Console.WriteLine("Output asset disponible para adaptive streaming."); Console.WriteLine("VOD workflow terminado."); }