Beispiel #1
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);
        }
Beispiel #2
0
 public PageService(
     IProjectService projectService,
     IPageQueries pageQueries,
     IPageCommands pageCommands,
     PageEvents eventHandlers,
     IMediaProcessor mediaProcessor,
     IContentProcessor contentProcessor,
     IPageUrlResolver pageUrlResolver,
     IMemoryCache cache,
     IStringLocalizer <cloudscribe.SimpleContent.Web.SimpleContent> localizer,
     IPageNavigationCacheKeys cacheKeys,
     IContentHistoryCommands historyCommands,
     ILogger <PageService> logger
     )
 {
     _projectService   = projectService;
     _pageQueries      = pageQueries;
     _pageCommands     = pageCommands;
     _mediaProcessor   = mediaProcessor;
     _pageUrlResolver  = pageUrlResolver;
     _contentProcessor = contentProcessor;
     _cache            = cache;
     _cacheKeys        = cacheKeys;
     _eventHandlers    = eventHandlers;
     _sr = localizer;
     _historyCommands = historyCommands;
     _log             = logger;
 }
Beispiel #3
0
        private static async Task <IJob> CreateMediaEncodeJob(CloudMediaContext context, IAsset assetToEncode)
        {
            //string encodingPreset = "H264 Broadband 720p";
            string encodingPreset = "H264 Smooth Streaming 720p";

            IJob job = context.Jobs.Create("Encoding " + assetToEncode.Name + " to " + encodingPreset);

            string[] y =
                context.MediaProcessors.Where(mp => mp.Name.Equals("Azure Media Encoder"))
                .ToArray()
                .Select(mp => mp.Version)
                .ToArray();

            IMediaProcessor latestWameMediaProcessor =
                context.MediaProcessors.Where(mp => mp.Name.Equals("Azure Media Encoder"))
                .ToArray()
                .OrderByDescending(
                    mp =>
                    new Version(int.Parse(mp.Version.Split('.', ',')[0]),
                                int.Parse(mp.Version.Split('.', ',')[1])))
                .First();

            ITask encodeTask = job.Tasks.AddNew("Encoding", latestWameMediaProcessor, encodingPreset, TaskOptions.None);

            encodeTask.InputAssets.Add(assetToEncode);
            encodeTask.OutputAssets.AddNew(assetToEncode.Name + " as " + encodingPreset, AssetCreationOptions.None);

            job.StateChanged += new EventHandler <JobStateChangedEventArgs>((sender, jsc) => Console.WriteLine(
                                                                                $"{((IJob) sender).Name}\n  State: {jsc.CurrentState}\n  Time: {DateTime.UtcNow.ToString(@"yyyy_M_d_hhmmss")}\n\n"));
            return(await job.SubmitAsync());
        }
        public void ShouldSubmitAndFinishJobWithMultipleAssetAndVerifyOrderOfInputAssets()
        {
            // Create multiple assets, set them as parents for a job, and validate that the parent links are set.
            IAsset asset1 = AssetTests.CreateAsset(_mediaContext, WindowsAzureMediaServicesTestConfiguration.SmallWmv2, AssetCreationOptions.StorageEncrypted);
            IAsset asset2 = AssetTests.CreateAsset(_mediaContext, _smallWmv, AssetCreationOptions.StorageEncrypted);
            IAsset asset3 = AssetTests.CreateAsset(_mediaContext, WindowsAzureMediaServicesTestConfiguration.SmallMp41, AssetCreationOptions.StorageEncrypted);

            asset1.Name = "SmallWmv2";
            asset2.Name = "SmallWmv";
            asset3.Name = "SmallMP41";
            asset1.Update();
            asset2.Update();
            asset3.Update();

            string configuration = File.ReadAllText(WindowsAzureMediaServicesTestConfiguration.MultiConfig);

            IJob            job            = _mediaContext.Jobs.Create("Test");
            IMediaProcessor mediaProcessor = GetMediaProcessor(_mediaContext, WindowsAzureMediaServicesTestConfiguration.MpEncoderName);
            ITask           task           = job.Tasks.AddNew("Task1", mediaProcessor, configuration, TaskOptions.None);

            task.InputAssets.Add(asset1);
            task.InputAssets.Add(asset2);
            task.InputAssets.Add(asset3);
            task.OutputAssets.AddNew("JobOutput", options: AssetCreationOptions.None);
            job.Submit();

            WaitForJob(job.Id, JobState.Finished, VerifyAllTasksFinished);

            Assert.IsTrue(job.InputMediaAssets.Count == 3);
            Assert.IsTrue(job.InputMediaAssets[0].Name == "SmallWmv2");
            Assert.IsTrue(job.InputMediaAssets[1].Name == "SmallWmv");
            Assert.IsTrue(job.InputMediaAssets[2].Name == "SmallMP41");
        }
Beispiel #5
0
        internal IJob CreateJob(MediaJob mediaJob)
        {
            IJob job = _media.Jobs.Create(mediaJob.Name, mediaJob.Priority);

            foreach (MediaJobTask jobTask in mediaJob.Tasks)
            {
                string          processorId = Processors.GetMediaProcessorId(jobTask.MediaProcessor);
                IMediaProcessor processor   = GetEntityById(MediaEntity.Processor, processorId) as IMediaProcessor;
                ITask           currentTask = job.Tasks.AddNew(jobTask.Name, processor, jobTask.ProcessorConfig, jobTask.Options);
                if (jobTask.ParentIndex.HasValue)
                {
                    ITask parentTask = job.Tasks[jobTask.ParentIndex.Value];
                    currentTask.InputAssets.AddRange(parentTask.OutputAssets);
                }
                else
                {
                    IAsset[] assets = GetAssets(jobTask.InputAssetIds);
                    currentTask.InputAssets.AddRange(assets);
                }
                currentTask.OutputAssets.AddNew(jobTask.OutputAssetName, jobTask.OutputAssetEncryption, jobTask.OutputAssetFormat);
            }
            INotificationEndPoint notificationEndpoint = GetNotificationEndpoint(mediaJob.Notification);

            if (notificationEndpoint != null)
            {
                job.JobNotificationSubscriptions.AddNew(NotificationJobState.FinalStatesOnly, notificationEndpoint);
            }
            SetProcessorUnits(job, mediaJob.Scale);
            job.Submit();
            return(job);
        }
        public void ShouldCreateJobWithMultipleAssetsAndValidateParentLinks()
        {
            // Create multiple assets, set them as parents for a job, and validate that the parent links are set.
            IAsset asset1 = AssetTests.CreateAsset(_mediaContext, _smallWmv, AssetCreationOptions.StorageEncrypted);
            IAsset asset2 = AssetTests.CreateAsset(_mediaContext, WindowsAzureMediaServicesTestConfiguration.SmallWmv2, AssetCreationOptions.StorageEncrypted);
            IAsset asset3 = AssetTests.CreateAsset(_mediaContext, WindowsAzureMediaServicesTestConfiguration.SmallMp41, AssetCreationOptions.StorageEncrypted);

            string configuration = File.ReadAllText(WindowsAzureMediaServicesTestConfiguration.MultiConfig);

            IJob            job            = _mediaContext.Jobs.Create("Test");
            IMediaProcessor mediaProcessor = GetMediaProcessor(_mediaContext, WindowsAzureMediaServicesTestConfiguration.MpEncoderName);
            ITask           task           = job.Tasks.AddNew("Task1", mediaProcessor, configuration, TaskOptions.None);

            task.InputAssets.Add(asset1);
            task.InputAssets.Add(asset2);
            task.InputAssets.Add(asset3);
            task.OutputAssets.AddNew("JobOutput", options: AssetCreationOptions.None);
            job.Submit();

            WaitForJob(job.Id, JobState.Finished, VerifyAllTasksFinished, delegate(double d) { Console.WriteLine(d); });

            Assert.IsTrue(job.OutputMediaAssets[0].ParentAssets.Count == 3);
            IEnumerable <string> parentIds = job.OutputMediaAssets[0].ParentAssets.Select(a => a.Id);

            Assert.IsTrue(parentIds.Contains(asset1.Id));
            Assert.IsTrue(parentIds.Contains(asset2.Id));
            Assert.IsTrue(parentIds.Contains(asset3.Id));
        }
        public static int AddTask(Microsoft.Azure.WebJobs.ExecutionContext execContext, CloudMediaContext context, IJob job, IAsset sourceAsset, string value, string processor, string presetfilename, string stringtoreplace, ref int taskindex, int priority = 10, string specifiedStorageAccountName = null)
        {
            if (value != null)
            {
                // Get a media processor reference, and pass to it the name of the
                // processor to use for the specific task.
                IMediaProcessor mediaProcessor = MediaServicesHelper.GetLatestMediaProcessorByName(context, processor);

                string presetPath = Path.Combine(System.IO.Directory.GetParent(execContext.FunctionDirectory).FullName, "presets", presetfilename);

                string Configuration = File.ReadAllText(presetPath).Replace(stringtoreplace, value);

                // Create a task with the encoding details, using a string preset.
                var task = job.Tasks.AddNew(processor + " task",
                                            mediaProcessor,
                                            Configuration,
                                            TaskOptions.None);

                task.Priority = priority;

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

                // Add an output asset to contain the results of the job.
                // Use a non default storage account in case this was provided in 'AddTask'

                task.OutputAssets.AddNew(sourceAsset.Name + " " + processor + " Output", specifiedStorageAccountName, AssetCreationOptions.None);

                return(taskindex++);
            }
            else
            {
                return(-1);
            }
        }
Beispiel #8
0
 public BlogService(
     IProjectService projectService,
     IProjectSecurityResolver security,
     IPostQueries postQueries,
     IPostCommands postCommands,
     IMediaProcessor mediaProcessor,
     IContentProcessor contentProcessor,
     //IHtmlProcessor htmlProcessor,
     IBlogRoutes blogRoutes,
     PostEvents eventHandlers,
     IUrlHelperFactory urlHelperFactory,
     IActionContextAccessor actionContextAccesor,
     IHttpContextAccessor contextAccessor = null)
 {
     _security             = security;
     _postQueries          = postQueries;
     _postCommands         = postCommands;
     context               = contextAccessor?.HttpContext;
     _mediaProcessor       = mediaProcessor;
     _urlHelperFactory     = urlHelperFactory;
     _actionContextAccesor = actionContextAccesor;
     _projectService       = projectService;
     _contentProcessor     = contentProcessor;
     _blogRoutes           = blogRoutes;
     _eventHandlers        = eventHandlers;
 }
Beispiel #9
0
        static public IAsset EncodeToAdaptiveBitrateMP4Set(IAsset asset)
        {
            // Declare a new job.
            IJob job = _context.Jobs.Create("Media Encoder Standard Job");
            // Get a media processor reference, and pass to it the name of the
            // processor to use for the specific task.
            IMediaProcessor processor = GetLatestMediaProcessorByName("Media Encoder Standard");

            // Create a task with the encoding details, using a string preset.
            // In this case "H264 Multiple Bitrate 720p" preset is used.
            ITask task = job.Tasks.AddNew("My encoding task",
                                          processor,
                                          "H264 Multiple Bitrate 720p",
                                          TaskOptions.None);

            // Specify the input asset to be encoded.
            task.InputAssets.Add(asset);
            // Add an output asset to contain the results of the job.
            // This output is specified as AssetCreationOptions.None, which
            // means the output asset is not encrypted.
            task.OutputAssets.AddNew("Output asset",
                                     AssetCreationOptions.None);

            job.StateChanged += new EventHandler <JobStateChangedEventArgs>(JobStateChanged);
            job.Submit();
            job.GetExecutionProgressTask(CancellationToken.None).Wait();

            return(job.OutputMediaAssets[0]);
        }
 public MetaWeblogService(
     IProjectService projectService,
     IProjectSecurityResolver security,
     IContentHistoryCommands contentHistoryCommands,
     IPageUrlResolver pageUrlResolver,
     IBlogUrlResolver blogUrlResolver,
     IMediaProcessor mediaProcessor,
     ITimeZoneHelper timeZoneHelper,
     ITreeCache treeCache,
     ILogger <MetaWeblogService> logger,
     IBlogService blogService = null,
     IPageService pageService = null
     )
 {
     _projectService         = projectService;
     _security               = security;
     _contentHistoryCommands = contentHistoryCommands;
     _pageUrlResolver        = pageUrlResolver;
     _blogUrlResolver        = blogUrlResolver;
     _timeZoneHelper         = timeZoneHelper;
     _blogService            = blogService ?? new NotImplementedBlogService();
     _pageService            = pageService ?? new NotImplementedPageService();
     _mediaProcessor         = mediaProcessor;
     _mapper          = new MetaWeblogModelMapper();
     _navigationCache = treeCache;
     _log             = logger;
 }
Beispiel #11
0
        public void Encode(IAsset asset, params string[] encodings)
        {
            IJob job          = mediaContext.Jobs.Create("Encoding task");
            var  theProcessor = from p in mediaContext.MediaProcessors
                                where p.Name == "Windows Azure Media Encoder"
                                select p;

            //string configuration = File.ReadAllText(configFilePath);

            IMediaProcessor processor = theProcessor.First();
            var             i         = 0;

            foreach (var encoding in encodings)
            {
                ITask task = job.Tasks.AddNew(i.ToString() + " task", processor, encoding, TaskCreationOptions.ProtectedConfiguration);
                task.InputMediaAssets.Add(asset);
                task.OutputMediaAssets.AddNew(i.ToString() + " output asset", true, AssetCreationOptions.CommonEncryptionProtected);
                i++;
            }
            job.Submit();

            CheckJobProgress(job.Id);
            job = GetJob(job.Id);
            IAsset outputAsset = job.OutputMediaAssets[0];

            GetSasUrl(outputAsset, TimeSpan.FromMinutes(5));
        }
        public void ShouldReportJobProgress()
        {
            IAsset          asset           = AssetTests.CreateAsset(_mediaContext, _smallWmv, AssetCreationOptions.StorageEncrypted);
            IMediaProcessor mediaProcessor  = GetMediaProcessor(_mediaContext, WindowsAzureMediaServicesTestConfiguration.MpEncoderName);
            string          name            = GenerateName("Job 1");
            IJob            job             = CreateAndSubmitOneTaskJob(_mediaContext, name, mediaProcessor, GetWamePreset(mediaProcessor), asset, TaskOptions.None);
            bool            progressChanged = false;
            var             task            = Task.Factory.StartNew(delegate
            {
                while (!IsFinalJobState(job.State))
                {
                    Thread.Sleep(100);
                    double progress = job.Tasks[0].Progress;
                    if (progress > 0 && progress < 100)
                    {
                        progressChanged = true;
                    }
                    job.Refresh();
                }
            });

            task.Wait();
            task.ThrowIfFaulted();
            Assert.AreEqual(JobState.Finished, job.State);
            Assert.IsTrue(progressChanged, "Task progress has not been changed while job is expected to be finished");
        }
        public void ShouldSubmitJobWhereOutPutInNoneDefaultStorage()
        {
            var nondefault = _mediaContext.StorageAccounts.Where(c => c.IsDefault == false).FirstOrDefault();

            //This test need to be executed when media account multiple storage account associated with it.
            if (nondefault == null)
            {
                return;
            }
            IAsset          asset          = AssetTests.CreateAsset(_mediaContext, _smallWmv, AssetCreationOptions.StorageEncrypted);
            IMediaProcessor mediaProcessor = GetMediaProcessor(_mediaContext, WindowsAzureMediaServicesTestConfiguration.MpEncoderName);
            string          name           = GenerateName("Job 1");
            IJob            job            = _mediaContext.Jobs.Create(name);
            ITask           task           = job.Tasks.AddNew("Task1", mediaProcessor, GetWamePreset(mediaProcessor), TaskOptions.None);

            task.InputAssets.Add(asset);
            var outputAsset = task.OutputAssets.AddNew("Output asset", nondefault.Name, AssetCreationOptions.None);

            job.Submit();
            Assert.AreEqual(nondefault.Name, outputAsset.StorageAccountName, "Storage account are not matching");
            WaitForJob(job.Id, JobState.Finished, VerifyAllTasksFinished);

            var refreshed = _mediaContext.Jobs.Where(c => c.Id == job.Id).FirstOrDefault();

            Assert.IsNotNull(refreshed);
            Assert.AreEqual(1, refreshed.Tasks.Count, "Number of Tasks in job is not matching");
            Assert.AreEqual(1, refreshed.Tasks[0].OutputAssets.Count, "Number of output assets in job is not matching");
            Assert.AreEqual(nondefault.Name, refreshed.Tasks[0].OutputAssets[0].StorageAccountName, "Storage account name in output assset is not matching");
        }
Beispiel #14
0
 public PageService(
     IProjectService projectService,
     IProjectSecurityResolver security,
     IPageQueries pageQueries,
     IPageCommands pageCommands,
     PageEvents eventHandlers,
     IMediaProcessor mediaProcessor,
     IUrlHelperFactory urlHelperFactory,
     IMemoryCache cache,
     IPageNavigationCacheKeys cacheKeys,
     IActionContextAccessor actionContextAccesor,
     IHttpContextAccessor contextAccessor = null)
 {
     this.projectService       = projectService;
     this.security             = security;
     this.pageQueries          = pageQueries;
     this.pageCommands         = pageCommands;
     context                   = contextAccessor?.HttpContext;
     this.mediaProcessor       = mediaProcessor;
     this.urlHelperFactory     = urlHelperFactory;
     this.actionContextAccesor = actionContextAccesor;
     htmlProcessor             = new HtmlProcessor();
     this.cache                = cache;
     this.cacheKeys            = cacheKeys;
     this.eventHandlers        = eventHandlers;
 }
        public void EncodeAsset(IAsset asset, List <String> options)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context null - can't communicate");
            }
            if (asset == null)
            {
                throw new ArgumentNullException("asset null - can't upload");
            }

            IJob job = context.Jobs.Create("");

            mediaProcessor = GetMediaProcessor("Windows Azure Media Encoder");

            foreach (String configOption in options)
            {
                ITask task = job.Tasks.AddNew("task " + configOption,
                                              mediaProcessor,
                                              configOption,
                                              TaskCreationOptions.None);
                task.InputMediaAssets.Add(asset);
                task.OutputMediaAssets.AddNew(asset.Name + " " + configOption, true, AssetCreationOptions.None);
            }
            job.Submit();
        }
Beispiel #16
0
        private IAsset CreateMbrMp4Asset(AssetCreationOptions options)
        {
            IMediaProcessor encoder = JobTests.GetEncoderMediaProcessor(_mediaContext);
            IJob            job     = _mediaContext.Jobs.Create("Job for ValidateEffectiveEncryptionStatusOfMultiBitRateMP4");

            ITask adpativeBitrateTask = job.Tasks.AddNew("MP4 to Adaptive Bitrate Task",
                                                         encoder,
                                                         "H264 Adaptive Bitrate MP4 Set 720p",
                                                         TaskOptions.None);

            // Specify the input Asset
            IAsset asset = AssetTests.CreateAsset(_mediaContext, WindowsAzureMediaServicesTestConfiguration.SmallMp41, AssetCreationOptions.None);

            adpativeBitrateTask.InputAssets.Add(asset);

            // Add an output asset to contain the results of the job.
            // This output is specified as AssetCreationOptions.None, which
            // means the output asset is in the clear (unencrypted).
            IAsset abrAsset = adpativeBitrateTask.OutputAssets.AddNew("Multibitrate MP4s", options);

            job.Submit();

            job.GetExecutionProgressTask(CancellationToken.None).Wait();

            job.Refresh();

            return(job.OutputMediaAssets[0]);
        }
Beispiel #17
0
        private IAsset CreateHlsFromSmoothAsset(IAsset sourceAsset, AssetCreationOptions options)
        {
            IJob            job            = _mediaContext.Jobs.Create("Smooth to Hls Job");
            IMediaProcessor mediaProcessor = JobTests.GetMediaProcessor(_mediaContext, WindowsAzureMediaServicesTestConfiguration.MpEncryptorName);

            string smoothToHlsConfiguration = null;

            if (options == AssetCreationOptions.EnvelopeEncryptionProtected)
            {
                smoothToHlsConfiguration = File.ReadAllText(WindowsAzureMediaServicesTestConfiguration.SmoothToEncryptHlsConfig);
            }
            else
            {
                smoothToHlsConfiguration = File.ReadAllText(WindowsAzureMediaServicesTestConfiguration.SmoothToHlsConfig);
            }

            ITask task = job.Tasks.AddNew("Smooth to Hls conversion task", mediaProcessor, smoothToHlsConfiguration, TaskOptions.None);

            task.InputAssets.Add(sourceAsset);
            task.OutputAssets.AddNew("JobOutput", options);
            job.Submit();

            job.GetExecutionProgressTask(CancellationToken.None).Wait();

            job.Refresh();

            return(job.OutputMediaAssets[0]);
        }
        private IAsset ValidateMultibitrateMP4s(IAsset multibitrateMP4sAsset)
        {
            // Set .ism as a primary file
            // in a multibitrate MP4 set.
            SetISMFileAsPrimary(multibitrateMP4sAsset);

            // Create a new job.
            IJob job = _MediaServiceContext.Jobs.Create("MP4 validation and converstion to Smooth Stream job.");

            // Read the task configuration data into a string.
            string configMp4Validation = LoadEncodeProfile(myConfig.XmlValidationProfile);

            // Get the SDK extension method to  get a reference to the Azure Media Packager.
            IMediaProcessor processor = GetLatestMediaProcessorByName(myConfig.MediaProcessorName);

            // Create a task with the conversion details, using the configuration data.
            ITask task = job.Tasks.AddNew("Mp4 Validation Task", processor, configMp4Validation, TaskOptions.None);

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

            // Add an output asset to contain the results of the job.
            // This output is specified as AssetCreationOptions.None, which
            // means the output asset is in the clear (unencrypted).
            task.OutputAssets.AddNew(string.Format(myConfig.OutputAssetName, multibitrateMP4sAsset.Name), AssetCreationOptions.None);

            // Submit the job and wait until it is completed.
            job.Submit();

            Task progressJobTask = job.GetExecutionProgressTask(CancellationToken.None);

            this.WaitJobFinish(job.Id);
            return(job.OutputMediaAssets[0]);
        }
Beispiel #19
0
        /// <summary>
        /// Creates a task to encrypt Smooth Streaming with PlayReady.
        /// Note: To deliver DASH, make sure to set the useSencBox and adjustSubSamples
        /// configuration properties to true.
        /// In this example, MediaEncryptor_PlayReadyProtection.xml contains configuration.
        /// </summary>
        /// <param name="job">The job to which to add the new task.</param>
        /// <param name="asset">The input asset.</param>
        /// <returns>The output asset.</returns>
        private static IAsset EncryptSmoothStreamWithPlayReadyTask(IJob job, IAsset asset)
        {
            // Get the SDK extension method to  get a reference to the Azure Media Encryptor.
            IMediaProcessor playreadyProcessor = _context.MediaProcessors.GetLatestMediaProcessorByName(
                MediaProcessorNames.WindowsAzureMediaEncryptor);

            // Read the configuration XML.
            //
            // Note that the configuration defined in MediaEncryptor_PlayReadyProtection.xml
            // is using keySeedValue. It is recommended that you do this only for testing
            // and not in production. For more information, see
            // http://msdn.microsoft.com/en-us/library/windowsazure/dn189154.aspx.
            //
            string configPlayReady = File.ReadAllText(Path.Combine(_configurationXMLFiles,
                                                                   @"MediaEncryptor_PlayReadyProtection.xml"));

            ITask playreadyTask = job.Tasks.AddNew("My PlayReady Task",
                                                   playreadyProcessor,
                                                   configPlayReady,
                                                   TaskOptions.ProtectedConfiguration);

            playreadyTask.InputAssets.Add(asset);

            // Add an output asset to contain the results of the job.
            // This output is specified as AssetCreationOptions.CommonEncryptionProtected.
            IAsset playreadyAsset = playreadyTask.OutputAssets.AddNew(
                "PlayReady Smooth Streaming",
                AssetCreationOptions.CommonEncryptionProtected);

            return(playreadyAsset);
        }
Beispiel #20
0
        /// <summary>
        /// Creates a task to convert the MP4 file(s) to a Smooth Streaming asset.
        /// Adds the new task to a job.
        /// </summary>
        /// <param name="job">The job to which to add the new task.</param>
        /// <param name="asset">The input asset.</param>
        /// <returns>The output asset.</returns>
        private static IAsset PackageMP4ToSmoothStreamingTask(IJob job, IAsset asset)
        {
            // Get the SDK extension method to  get a reference to the Azure Media Packager.
            IMediaProcessor packager = _context.MediaProcessors.GetLatestMediaProcessorByName(
                MediaProcessorNames.WindowsAzureMediaPackager);

            // Azure Media Packager does not accept string presets, so load xml configuration
            string smoothConfig = File.ReadAllText(Path.Combine(
                                                       _configurationXMLFiles,
                                                       "MediaPackager_MP4toSmooth.xml"));

            // Create a new Task to convert adaptive bitrate to Smooth Streaming.
            ITask smoothStreamingTask = job.Tasks.AddNew("MP4 to Smooth Task",
                                                         packager,
                                                         smoothConfig,
                                                         TaskOptions.None);

            // Specify the input Asset, which is the output Asset from the first task
            smoothStreamingTask.InputAssets.Add(asset);

            // Add an output asset to contain the results of the job.
            // This output is specified as AssetCreationOptions.None, which
            // means the output asset is in the clear (unencrypted).
            IAsset smoothOutputAsset =
                smoothStreamingTask.OutputAssets.AddNew("Clear Smooth Stream",
                                                        AssetCreationOptions.None);

            return(smoothOutputAsset);
        }
        public void ShouldSaveJobAsTemplateAndCreateNewJobwithItWhereOutPutInNoneDefaultStorage()
        {
            var nondefault = _mediaContext.StorageAccounts.Where(c => c.IsDefault == false).FirstOrDefault();

            //This test need to be executed when media account multiple storage account associated with it.
            if (nondefault == null)
            {
                return;
            }

            IAsset          asset          = AssetTests.CreateAsset(_mediaContext, _smallWmv, AssetCreationOptions.StorageEncrypted);
            IMediaProcessor mediaProcessor = GetMediaProcessor(_mediaContext, WindowsAzureMediaServicesTestConfiguration.MpEncoderName);
            string          name           = GenerateName("Job 1");
            IJob            job            = _mediaContext.Jobs.Create(name);
            ITask           task           = job.Tasks.AddNew("Task1", mediaProcessor, GetWamePreset(mediaProcessor), TaskOptions.None);

            task.InputAssets.Add(asset);
            var outputAsset = task.OutputAssets.AddNew("Output asset", nondefault.Name, AssetCreationOptions.None);

            job.Submit();
            var    template   = job.SaveAsTemplate("JobTests.StorageAccounts.cs_" + Guid.NewGuid().ToString());
            string newJobName = GenerateName("Job from template with non default storage account");
            var    newJob     = _mediaContext.Jobs.Create(newJobName, template, new[] { asset });

            newJob.Submit();
            WaitForJob(newJob.Id, JobState.Finished, VerifyAllTasksFinished);
            newJob = _mediaContext.Jobs.Where(c => c.Id == newJob.Id).FirstOrDefault();
            Assert.AreEqual(nondefault.Name, newJob.Tasks[0].OutputAssets[0].StorageAccountName, "Storage account name in output assset is not matching");
        }
Beispiel #22
0
        static private IJob CreateEncodingJob(IAsset asset)
        {
            // Declare a new job
            IJob job = mediaContext.Jobs.Create("Encode to SD MP4");

            // Encoding profile
            string profile = "H264 Multiple Bitrate 16x9 SD";

            Console.WriteLine($"Encoding Profile: {profile}");

            // Get a media processor reference, and pass to it the name of the
            // processor to use for the specific task.
            IMediaProcessor processor = mediaContext.MediaProcessors.
                                        Where(p => p.Name == "Media Encoder Standard").ToList().
                                        OrderBy(p => new Version(p.Version)).LastOrDefault();

            // Add task to job
            ITask task = job.Tasks.AddNew("Encode to SD MP4 task",
                                          processor,
                                          profile,
                                          TaskOptions.None);

            task.InputAssets.Add(asset);
            task.OutputAssets.AddNew("Bitten by the Frost SD", AssetCreationOptions.None);

            // Hook an event handler for job state changes
            // job.StateChanged += new EventHandler<JobStateChangedEventArgs>(JobStateChangedHandler);
            job.Submit();
            //job.GetExecutionProgressTask(new CancellationToken()).Wait();
            Console.WriteLine("Encoding job submitted.");

            return(job);
        }
 public BlogService(
     IProjectService projectService,
     IProjectSecurityResolver security,
     IPostQueries postQueries,
     IPostCommands postCommands,
     IMediaProcessor mediaProcessor,
     IHtmlProcessor htmlProcessor,
     IBlogRoutes blogRoutes,
     PostEvents eventHandlers,
     IUrlHelperFactory urlHelperFactory,
     IActionContextAccessor actionContextAccesor,
     IHttpContextAccessor contextAccessor = null)
 {
     this.security             = security;
     this.postQueries          = postQueries;
     this.postCommands         = postCommands;
     context                   = contextAccessor?.HttpContext;
     this.mediaProcessor       = mediaProcessor;
     this.urlHelperFactory     = urlHelperFactory;
     this.actionContextAccesor = actionContextAccesor;
     this.projectService       = projectService;
     this.htmlProcessor        = htmlProcessor;
     this.blogRoutes           = blogRoutes;
     this.eventHandlers        = eventHandlers;
 }
Beispiel #24
0
        private IAsset CreateEncodingJob(IAsset workflow, IAsset video)
        {
            IEncoderSupport myEncodigSupport = new EncoderSupport(_MediaServicesContext);

            // Declare a new job.
            currentJob = _MediaServicesContext.Jobs.Create(myConfig.EncodingJobName);
            // Get a media processor reference, and pass to it the name of the
            // processor to use for the specific task.
            IMediaProcessor processor = myEncodigSupport.GetLatestMediaProcessorByName("Media Encoder Premium Workflow");
            // Create a task with the encoding details, using a string preset.
            ITask task = currentJob.Tasks.AddNew(myConfig.EncodigTaskName, processor, "", TaskOptions.None);

            // Specify the input asset to be encoded.
            task.InputAssets.Add(workflow);
            task.InputAssets.Add(video); // we add one asset
            // Add an output asset to contain the results of the job.
            // This output is specified as AssetCreationOptions.None, which
            // means the output asset is not encrypted.
            task.OutputAssets.AddNew(video.Name + "_mb", AssetCreationOptions.None);
            // Use the following event handler to check job progress.
            // The StateChange method is the same as the one in the previous sample
            currentJob.StateChanged += new EventHandler <JobStateChangedEventArgs>(myEncodigSupport.StateChanged);
            // Launch the job.
            currentJob.Submit();
            //9. Revisa el estado de ejecución del JOB
            Task progressJobTask = currentJob.GetExecutionProgressTask(CancellationToken.None);

            //10. en vez de utilizar  progressJobTask.Wait(); que solo muestra cuando el JOB termina
            //se utiliza el siguiente codigo para mostrar avance en porcentaje, como en el portal
            myEncodigSupport.WaitJobFinish(currentJob.Id);
            return(currentJob.OutputMediaAssets.FirstOrDefault());
        }
Beispiel #25
0
        public void CreateThumbnails(Models.Asset asset)
        {
            // Declare a new job.
            IJob job = this.MediaService.MediaContext.Jobs.Create(asset.MediaAsset.Name + " Thumbnails");
            // Get a media processor reference, and pass to it the name of the
            // processor to use for the specific task. Use a method like the
            // GetMediaProcessor method shown in this document.
            IMediaProcessor processor = this.MediaService
                                        .GetMediaProcessorByName(MediaEncoders.WINDOWS_AZURE_MEDIA_ENCODER);

            ITask task3 = job.Tasks.AddNew("Thumnail creator",
                                           processor,
                                           @"<?xml version=""1.0"" encoding=""utf-16""?>
<Thumbnail Size=""150,150"" Type=""Jpeg"" 
Filename=""{OriginalFilename}_{ThumbnailTime}.{DefaultExtension}"">
  <Time Value=""0:0:4"" Step=""0:0:1"" Stop=""0:0:5""/>
</Thumbnail>",
                                           TaskOptions.None);

            task3.InputAssets.Add(asset.MediaAsset);
            IAsset thumbprintAssets = task3.OutputAssets
                                      .AddNew(asset.MediaAsset.Name + " Thumbpnails", AssetCreationOptions.None);

            job.Submit();
        }
Beispiel #26
0
        public void CreateNewJob(Models.Asset asset, string mediaEncoder, string taskPreset)
        {
            // Declare a new job.
            IJob job = this.MediaService.MediaContext.Jobs.Create(asset.MediaAsset.Name + " Job");

            // Get a media processor reference, and pass to it the name of the
            // processor to use for the specific task. Use a method like the
            // GetMediaProcessor method shown in this document.
            IMediaProcessor processor = this.MediaService
                                        .GetMediaProcessorByName(mediaEncoder);
            //  Create a task with the encoding details, using a string preset.
            ITask task = job.Tasks.AddNew("Ad-hoc Task",
                                          processor,
                                          taskPreset,
                                          TaskOptions.None);

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

            //Add an output asset to contain the results of the job.
            //This output is specified as AssetCreationOptions.None, which
            //means the output asset is in the clear (unencrypted).
            IAsset outputAsset = task.OutputAssets.AddNew(asset.MediaAsset.Name + " result ",
                                                          AssetCreationOptions.None);

            job.Submit();
        }
Beispiel #27
0
        public void DecryptAsset(Models.Asset theAsset)
        {
            // Declare a new job.
            IJob job = this.MediaService.MediaContext.Jobs.Create(theAsset.MediaAsset.Name + " Decrypting Job");

            // Get a media processor reference, and pass to it the name of the
            // processor to use for the specific task. Use a method like the
            // GetMediaProcessor method shown in this document.
            IMediaProcessor processor = this.MediaService
                                        .GetMediaProcessorByName(MediaEncoders.STORAGE_DECRYPTION_ENCODER);
            //  Create a task with the encoding details, using a string preset.
            ITask task = job.Tasks.AddNew("New Decrypting",
                                          processor,
                                          string.Empty,
                                          TaskOptions.None);

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

            //Add an output asset to contain the results of the job.
            //This output is specified as AssetCreationOptions.None, which
            //means the output asset is in the clear (unencrypted).
            IAsset decruptedAsset = task.OutputAssets
                                    .AddNew(theAsset.MediaAsset.Name + " decrypted",
                                            AssetCreationOptions.None);

            // Launch the job.
            job.Submit();
        }
Beispiel #28
0
 public PageService(
     IProjectService projectService,
     IProjectSecurityResolver security,
     IPageQueries pageQueries,
     IPageCommands pageCommands,
     PageEvents eventHandlers,
     IMediaProcessor mediaProcessor,
     IContentProcessor contentProcessor,
     //IHtmlProcessor htmlProcessor,
     IUrlHelperFactory urlHelperFactory,
     IPageRoutes pageRoutes,
     IMemoryCache cache,
     IStringLocalizer <cloudscribe.SimpleContent.Web.SimpleContent> localizer,
     IPageNavigationCacheKeys cacheKeys,
     IActionContextAccessor actionContextAccesor,
     IHttpContextAccessor contextAccessor = null)
 {
     this.projectService       = projectService;
     this.security             = security;
     this.pageQueries          = pageQueries;
     this.pageCommands         = pageCommands;
     context                   = contextAccessor?.HttpContext;
     this.mediaProcessor       = mediaProcessor;
     this.urlHelperFactory     = urlHelperFactory;
     this.actionContextAccesor = actionContextAccesor;
     this.pageRoutes           = pageRoutes;
     _contentProcessor         = contentProcessor;
     //this.htmlProcessor = htmlProcessor;
     this.cache         = cache;
     this.cacheKeys     = cacheKeys;
     this.eventHandlers = eventHandlers;
     sr = localizer;
 }
 public RedditMessageHandlerTests()
 {
     _fakeRedditClientWrapper = A.Fake <IRedditClientWrapper>();
     SetupCommentRootPostStubs();
     _fakeMediaProcessor   = A.Fake <IMediaProcessor>();
     _fakeReplyBuilder     = A.Fake <IReplyBuilder>();
     _redditMessageHandler = new RedditMessageHandler(_fakeRedditClientWrapper, _fakeMediaProcessor, _fakeReplyBuilder);
 }
Beispiel #30
0
        public IJob CreateJob(MediaJob mediaJob, MediaJobInput[] jobInputs, out IJobTemplate jobTemplate)
        {
            IJob job = null;

            jobTemplate = null;
            if (!string.IsNullOrEmpty(mediaJob.TemplateId))
            {
                List <IAsset> inputAssets = new List <IAsset>();
                foreach (MediaJobInput jobInput in jobInputs)
                {
                    IAsset asset = GetEntityById(MediaEntity.Asset, jobInput.AssetId) as IAsset;
                    if (asset != null)
                    {
                        inputAssets.Add(asset);
                    }
                }
                jobTemplate = GetEntityById(MediaEntity.JobTemplate, mediaJob.TemplateId) as IJobTemplate;
                job         = _media.Jobs.Create(mediaJob.Name, jobTemplate, inputAssets, mediaJob.Priority);
            }
            else if (mediaJob.Tasks.Length > 0)
            {
                job = _media.Jobs.Create(mediaJob.Name, mediaJob.Priority);
                foreach (MediaJobTask jobTask in mediaJob.Tasks)
                {
                    string          processorId = Processor.GetProcessorId(jobTask.MediaProcessor, jobTask.ProcessorConfig);
                    IMediaProcessor processor   = GetEntityById(MediaEntity.Processor, processorId) as IMediaProcessor;
                    ITask           currentTask = job.Tasks.AddNew(jobTask.Name, processor, jobTask.ProcessorConfig, jobTask.Options);
                    if (jobTask.ParentIndex.HasValue)
                    {
                        ITask parentTask = job.Tasks[jobTask.ParentIndex.Value];
                        currentTask.InputAssets.AddRange(parentTask.OutputAssets);
                    }
                    else
                    {
                        IAsset[] assets = GetAssets(jobTask.InputAssetIds);
                        currentTask.InputAssets.AddRange(assets);
                    }
                    currentTask.OutputAssets.AddNew(jobTask.OutputAssetName, jobTask.OutputAssetEncryption, jobTask.OutputAssetFormat);
                }
                INotificationEndPoint notificationEndpoint = GetNotificationEndpoint();
                job.JobNotificationSubscriptions.AddNew(NotificationJobState.FinalStatesOnly, notificationEndpoint);
            }
            if (job != null)
            {
                if (mediaJob.SaveWorkflow)
                {
                    string templateName = mediaJob.Name;
                    jobTemplate = job.SaveAsTemplate(templateName);
                }
                else
                {
                    SetProcessorUnits(job, jobTemplate, mediaJob.NodeType, true);
                    job.Submit();
                }
            }
            return(job);
        }
 public MediaAnalyticsGeneric(CloudMediaContext context, IMediaProcessor processor, Image processorImage, bool preview)
 {
     InitializeComponent();
     this.Icon = Bitmaps.Azure_Explorer_ico;
     _context = context;
     _processor = processor;
     _preview = preview;
     _processorImage = processorImage;
     buttonJobOptions.Initialize(_context);
 }
 // media processor versions
 public static string GetWamePreset(IMediaProcessor mediaProcessor)
 {
     var mpVersion = new Version(mediaProcessor.Version);
     if (mpVersion.Major == 1)
     {
         return WameV1Preset;
     }
     else
     {
         return WameV2Preset;
     }
 }
        public IAsset GenerateThumbnail(IJob job, IAsset asset, IMediaProcessor processor, int width, int height)
        {
            var task = job.Tasks.AddNew("Thumnail creator",
                            processor,
                            string.Format(@"<?xml version=""1.0"" encoding=""utf-16""?>
                            <Thumbnail Size=""{0},{1}"" Type=""Jpeg"" 
                            Filename=""{{OriginalFilename}}_{{ThumbnailTime}}.{{DefaultExtension}}"">
                              <Time Value=""0:0:5""/>
                              <Time Value=""0:0:4"" Step=""0:0:1"" Stop=""0:0:5""/>
                            </Thumbnail>", width, height), TaskOptions.None);
            task.InputAssets.Add(asset);
            var thumbprintAsset = task.OutputAssets.AddNew(string.Format("{0} thumbnail", asset.Name), AssetCreationOptions.None);

            return thumbprintAsset;
        }
 public static IJob CreateAndSubmitOneTaskJob(CloudMediaContext context, string name, IMediaProcessor mediaProcessor, string preset, IAsset asset, TaskOptions options)
 {
     IJob job = context.Jobs.Create(name);
     job.Priority = InitialJobPriority;
     ITask task = job.Tasks.AddNew("Task1", mediaProcessor, preset, options);
     task.InputAssets.Add(asset);
     task.OutputAssets.AddNew("Output asset", AssetCreationOptions.None);
     DateTime timebeforeSubmit = DateTime.UtcNow;
     job.Submit();
     Assert.AreEqual(1, job.Tasks.Count, "Job contains unexpected amount of tasks");
     Assert.AreEqual(1, job.InputMediaAssets.Count, "Job contains unexpected total amount of input assets");
     Assert.AreEqual(1, job.OutputMediaAssets.Count, "Job contains unexpected total amount of output assets");
     Assert.AreEqual(1, job.Tasks[0].InputAssets.Count, "job.Task[0] contains unexpected amount of input assets");
     Assert.AreEqual(1, job.Tasks[0].OutputAssets.Count, "job.Task[0] contains unexpected amount of output assets");
     Assert.IsFalse(String.IsNullOrEmpty(job.Tasks[0].InputAssets[0].Id), "Asset Id is Null or empty");
     Assert.IsFalse(String.IsNullOrEmpty(job.Tasks[0].OutputAssets[0].Id), "Asset Id is Null or empty");
     return job;
 }
        public void LaunchJobs(IMediaProcessor processor, List<IAsset> selectedassets, string jobname, int jobpriority, string taskname, string outputassetname, List<string> configuration, AssetCreationOptions myAssetCreationOptions, TaskOptions myTaskOptions, string storageaccountname = "")
        {
            foreach (IAsset asset in selectedassets)
            {
                string jobnameloc = jobname.Replace(Constants.NameconvInputasset, asset.Name);
                IJob myJob = _context.Jobs.Create(jobnameloc, jobpriority);
                foreach (string config in configuration)
                {
                    string tasknameloc = taskname.Replace(Constants.NameconvInputasset, asset.Name).Replace(Constants.NameconvAMEpreset, config);
                    ITask myTask = myJob.Tasks.AddNew(
                           tasknameloc,
                          processor,
                          config,
                          myTaskOptions);

                    myTask.InputAssets.Add(asset);

                    // Add an output asset to contain the results of the task
                    string outputassetnameloc = outputassetname.Replace(Constants.NameconvInputasset, asset.Name).Replace(Constants.NameconvAMEpreset, config);
                    if (storageaccountname == "")
                    {
                        myTask.OutputAssets.AddNew(outputassetnameloc, asset.StorageAccountName, myAssetCreationOptions); // let's use the same storage account than the input asset
                    }
                    else
                    {
                        myTask.OutputAssets.AddNew(outputassetnameloc, storageaccountname, myAssetCreationOptions);
                    }
                }


                // Submit the job and wait until it is completed. 
                try
                {
                    myJob.Submit();
                }
                catch (Exception e)
                {
                    // Add useful information to the exception
                    if (selectedassets.Count < 5)  // only if 4 or less jobs submitted
                    {
                        MessageBox.Show(string.Format("There has been a problem when submitting the job '{0}'", jobnameloc) + Constants.endline + Constants.endline + Program.GetErrorMessage(e), "Job Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }

                    // Add useful information to the exception
                    TextBoxLogWriteLine("There has been a problem when submitting the job {0}.", jobnameloc, true);
                    TextBoxLogWriteLine(e);
                    return;
                }
                TextBoxLogWriteLine("Job '{0}' submitted.", jobnameloc);
                Task.Factory.StartNew(() => dataGridViewJobsV.DoJobProgress(myJob));
            }
            DotabControlMainSwitch(Constants.TabJobs);
            DoRefreshGridJobV(false);
        }
        public void LaunchJobs_OneJobPerInputAssetWithSpecificConfig(IMediaProcessor processor, List<IAsset> selectedassets, string jobname, int jobpriority, string taskname, string outputassetname, List<string> configuration, AssetCreationOptions myAssetCreationOptions, TaskOptions myTaskOptions, string storageaccountname = "")
        {
            // a job per asset, one task per job, but each task has a specific config
            Task.Factory.StartNew(() =>
            {
                int index = -1;

                foreach (IAsset asset in selectedassets)
                {
                    index++;
                    string jobnameloc = jobname.Replace(Constants.NameconvInputasset, asset.Name);
                    IJob myJob = _context.Jobs.Create(jobnameloc, jobpriority);
                    string config = configuration[index];

                    string tasknameloc = taskname.Replace(Constants.NameconvInputasset, asset.Name).Replace(Constants.NameconvAMEpreset, config);
                    ITask myTask = myJob.Tasks.AddNew(
                           tasknameloc,
                          processor,
                          config,
                          myTaskOptions);

                    myTask.InputAssets.Add(asset);

                    // Add an output asset to contain the results of the task
                    string outputassetnameloc = outputassetname.Replace(Constants.NameconvInputasset, asset.Name).Replace(Constants.NameconvAMEpreset, config);
                    if (storageaccountname == "")
                    {
                        myTask.OutputAssets.AddNew(outputassetnameloc, asset.StorageAccountName, myAssetCreationOptions); // let's use the same storage account than the input asset
                    }
                    else
                    {
                        myTask.OutputAssets.AddNew(outputassetnameloc, storageaccountname, myAssetCreationOptions);
                    }


                    // Submit the job and wait until it is completed. 
                    bool Error = false;
                    try
                    {
                        TextBoxLogWriteLine("Job '{0}' : submitting...", jobnameloc);
                        myJob.Submit();
                    }

                    catch (Exception ex)
                    {
                        // Add useful information to the exception
                        TextBoxLogWriteLine("Job '{0}' : problem", jobnameloc, true);
                        TextBoxLogWriteLine(ex);
                        Error = true;
                    }
                    if (!Error)
                    {
                        TextBoxLogWriteLine("Job '{0}' : submitted.", jobnameloc);
                        Task.Factory.StartNew(() => dataGridViewJobsV.DoJobProgress(myJob));
                    }
                    TextBoxLogWriteLine();
                }

                DotabControlMainSwitch(Constants.TabJobs);
                DoRefreshGridJobV(false);

            }

                );
        }