示例#1
0
        public static string GeneratesInsights([ActivityTrigger] InitialSetupResult initialSetup, TraceWriter log)
        {
            // Building up Json sentence
            dynamic flexibleObj = new ExpandoObject();

            flexibleObj.assetId       = initialSetup.Asset.Id;
            flexibleObj.videoFileName = initialSetup.Video.VideoFileName;
            var jsonStr = JsonConvert.SerializeObject(flexibleObj);

            try
            {
                using (var client = new HttpClient())
                {
                    var content = new StringContent(jsonStr);
                    content.Headers.ContentType.CharSet   = string.Empty;
                    content.Headers.ContentType.MediaType = "application/json";

                    var response = client.PostAsync(_logicappuri, content);
                    log.Info(response.Result.ToString());

                    return(response.Result.ToString());
                }
            }
            catch (Exception)
            {
                return(string.Empty);
            }
        }
示例#2
0
        public static string GeneratesEncoder([ActivityTrigger] InitialSetupResult initialSetupResult, TraceWriter log)
        {
            IJob job;

            // Step 1: Setting up queue, context and endpoint
            string endPointAddress = Guid.NewGuid().ToString();

            AzureAdTokenCredentials tokenCredentials = new AzureAdTokenCredentials(_tenantDomain, new AzureAdClientSymmetricKey(_clientId, _clientSecret), AzureEnvironments.AzureCloudEnvironment);
            var tokenProvider = new AzureAdTokenProvider(tokenCredentials);

            _context = new CloudMediaContext(new Uri(_restApiUrl), tokenProvider);

            // Create the queue that will be receiving the notification messages.
            _queue = MediaServices.CreateQueue(_storageConnection, endPointAddress);

            // Create the notification point that is mapped to the queue.
            _notificationEndPoint = _context.NotificationEndPoints.Create(Guid.NewGuid().ToString(), NotificationEndPointType.AzureQueue, endPointAddress);

            // Step 2: Creating the encoding job
            try
            {
                log.Info("Starting encoding job...");
                IMediaProcessor mediaProcessor = MediaServices.GetLatestMediaProcessorByName("Media Encoder Standard", _context);
                job = MediaServices.SubmitEncodingJobWithNotificationEndPoint(_context, mediaProcessor.Name, initialSetupResult, _notificationEndPoint);
                log.Info("Done. Encoding job successfuly scheduled.");

                log.Info("Waiting the encoding process get completed...");
                MediaServices.WaitForJobToReachedFinishedState(job.Id, _queue, log);
            }
            catch (Exception ex)
            {
                return(string.Empty);
            }

            log.Info("Done. Encoding completed.");

            // Step 3: Cleaning up temporary resources
            _queue.Delete();
            _notificationEndPoint.Delete();

            // Step 4: Returns the final result
            return(job.Id);
        }
示例#3
0
        ////////////////////////////////////////////////////////////// NEW VERSION ////////////////////////////////////////////////////////////////////////////////////

        public static IJob SubmitEncodingJobWithNotificationEndPoint(CloudMediaContext _context, string mediaProcessorName, InitialSetupResult initialSetup, INotificationEndPoint _notificationEndPoint)
        {
            // Declare a new job.
            IJob job = _context.Jobs.Create($"Job_Encoding_{initialSetup.Video.VideoFileName}");

            //Create an encrypted asset and upload the mp4
            IAsset asset = LoadExistingAsset(initialSetup.Asset.Id, _context);

            // Get a media processor reference, and pass to it the name of the
            // processor to use for the specific task.
            IMediaProcessor processor = GetLatestMediaProcessorByName(mediaProcessorName, _context);

            // Create a task with the conversion details, using a configuration file.
            ITask task = job.Tasks.AddNew($"Job_Encoding_Task_{initialSetup.Video.VideoFileName}", processor, "Adaptive Streaming", Microsoft.WindowsAzure.MediaServices.Client.TaskOptions.None);

            // Specify the input asset to be encoded.
            task.InputAssets.Add(asset);

            // Add an output asset to contain the results of the job.
            task.OutputAssets.AddNew($"Output_Encoding_{initialSetup.Video.VideoFileName}", AssetCreationOptions.None);

            // Add a notification point to the job. You can add multiple notification points.
            job.JobNotificationSubscriptions.AddNew(NotificationJobState.FinalStatesOnly, _notificationEndPoint);

            job.Submit();

            return(job);
        }