Example #1
0
        public Job CreateJob(string authToken, string transformName, string jobName, string jobDescription, Priority jobPriority,
                             string jobData, string inputFileUrl, string inputAssetName, MediaJobOutputMode outputAssetMode,
                             string[] outputAssetDescriptions, string[] outputAssetAlternateIds, string streamingPolicyName)
        {
            JObject  jobPublish = GetJobPublish(authToken, jobData, streamingPolicyName);
            MediaJob mediaJob   = new MediaJob()
            {
                Name                    = jobName,
                Description             = jobDescription,
                Priority                = jobPriority,
                Data                    = jobPublish,
                InputFileUrl            = inputFileUrl,
                InputAssetName          = inputAssetName,
                OutputAssetMode         = outputAssetMode,
                OutputAssetDescriptions = outputAssetDescriptions,
                OutputAssetAlternateIds = outputAssetAlternateIds
            };
            Job             job        = CreateJob(transformName, mediaJob);
            MediaJobAccount jobAccount = new MediaJobAccount()
            {
                JobName       = job.Name,
                TransformName = transformName,
                MediaAccount  = MediaAccount
            };

            using (DatabaseClient databaseClient = new DatabaseClient())
            {
                string collectionId = Constant.Database.Collection.MediaJobAccount;
                databaseClient.UpsertDocument(collectionId, jobAccount);
            }
            return(job);
        }
Example #2
0
        public Job CreateJob(string transformName, string jobName, string jobDescription, Priority jobPriority, string inputFileUrl, Asset inputAsset,
                             string outputAssetStorage, MediaJobOutputPublish outputPublish, MediaJobOutputInsight outputInsight, bool setEventGrid)
        {
            if (setEventGrid)
            {
                EventGridClient.SetMediaSubscription(this.MediaAccount);
            }
            if (string.IsNullOrEmpty(jobName))
            {
                jobName = Guid.NewGuid().ToString();
            }
            MediaJob mediaJob = new MediaJob()
            {
                Name               = jobName,
                Description        = jobDescription,
                Priority           = jobPriority,
                InputFileUrl       = inputFileUrl,
                InputAsset         = inputAsset,
                OutputAssetStorage = outputAssetStorage,
                OutputPublish      = outputPublish,
                OutputInsight      = outputInsight
            };

            return(CreateJob(transformName, mediaJob));
        }
Example #3
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);
        }
Example #4
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);
        }
Example #5
0
        private Job CreateJob(string transformName, MediaJob mediaJob)
        {
            if (string.IsNullOrEmpty(mediaJob.Name))
            {
                mediaJob.Name = Guid.NewGuid().ToString();
            }
            Job job = new Job()
            {
                Description     = mediaJob.Description,
                Priority        = mediaJob.Priority,
                CorrelationData = GetDataItems(mediaJob.Data),
                Input           = GetJobInput(mediaJob),
                Outputs         = GetJobOutputs(transformName, mediaJob)
            };

            return(_media.Jobs.Create(MediaAccount.ResourceGroupName, MediaAccount.Name, transformName, mediaJob.Name, job));
        }
Example #6
0
        private IList <JobOutput> GetJobOutputs(string transformName, MediaJob mediaJob)
        {
            List <JobOutputAsset> outputAssets = new List <JobOutputAsset>();
            Transform             transform    = GetEntity <Transform>(MediaEntity.Transform, transformName);

            for (int i = 0; i < transform.Outputs.Count; i++)
            {
                TransformOutput transformOutput  = transform.Outputs[i];
                string          outputAssetName  = GetOutputAssetName(transformOutput, mediaJob, out string outputAssetStorage);
                string          assetDescription = i > mediaJob.OutputAssetDescriptions.Length - 1 ? null : mediaJob.OutputAssetDescriptions[i];
                string          assetAlternateId = i > mediaJob.OutputAssetAlternateIds.Length - 1 ? null : mediaJob.OutputAssetAlternateIds[i];
                CreateAsset(outputAssetStorage, outputAssetName, assetDescription, assetAlternateId);
                JobOutputAsset outputAsset = new JobOutputAsset(outputAssetName);
                outputAssets.Add(outputAsset);
            }
            return(outputAssets.ToArray());
        }
Example #7
0
        private string GetOutputAssetName(MediaTransformPreset transformPreset, MediaJob mediaJob)
        {
            string outputAssetName = mediaJob.InputAsset == null ? null : mediaJob.InputAsset.Name;

            if (string.IsNullOrEmpty(outputAssetName) && !string.IsNullOrEmpty(mediaJob.InputFileUrl))
            {
                Uri inputFileUri = new Uri(mediaJob.InputFileUrl);
                outputAssetName = Path.GetFileNameWithoutExtension(inputFileUri.LocalPath);
            }
            string outputAssetNameSuffix = GetOutputAssetNameSuffix(transformPreset);

            if (!string.IsNullOrEmpty(outputAssetNameSuffix))
            {
                outputAssetName = string.Concat(outputAssetName, " (", outputAssetNameSuffix, ")");
            }
            return(outputAssetName);
        }
Example #8
0
        private JobInput GetJobInput(MediaJob mediaJob)
        {
            JobInput jobInput;

            if (!string.IsNullOrEmpty(mediaJob.InputFileUrl))
            {
                jobInput = new JobInputHttp()
                {
                    Files = new string[] { mediaJob.InputFileUrl }
                };
            }
            else
            {
                jobInput = new JobInputAsset()
                {
                    AssetName = mediaJob.InputAssetName
                };
            }
            return(jobInput);
        }
Example #9
0
        private string GetOutputAssetName(TransformOutput transformOutput, MediaJob mediaJob, out string outputAssetStorage)
        {
            outputAssetStorage = this.PrimaryStorageAccount;
            string outputAssetName = mediaJob.InputAssetName;

            if (!string.IsNullOrEmpty(mediaJob.InputFileUrl) && string.IsNullOrEmpty(outputAssetName))
            {
                Uri inputFileUri = new Uri(mediaJob.InputFileUrl);
                outputAssetName = Path.GetFileNameWithoutExtension(inputFileUri.LocalPath);
            }
            else if (!string.IsNullOrEmpty(mediaJob.InputAssetName))
            {
                Asset inputAsset = GetEntity <Asset>(MediaEntity.Asset, mediaJob.InputAssetName);
                outputAssetStorage = inputAsset.StorageAccountName;
            }
            switch (mediaJob.OutputAssetMode)
            {
            case MediaJobOutputMode.SingleAsset:
                outputAssetName = string.Concat(outputAssetName, " (", Constant.Media.Job.OutputAssetNameSuffix.Default, ")");
                break;

            case MediaJobOutputMode.DistinctAssets:
                string assetNameSuffix = Constant.Media.Job.OutputAssetNameSuffix.Default;
                if (transformOutput.Preset is BuiltInStandardEncoderPreset)
                {
                    assetNameSuffix = Constant.Media.Job.OutputAssetNameSuffix.AdaptiveStreaming;
                }
                else if (transformOutput.Preset is VideoAnalyzerPreset)
                {
                    assetNameSuffix = Constant.Media.Job.OutputAssetNameSuffix.VideoAnalyzer;
                }
                else if (transformOutput.Preset is AudioAnalyzerPreset)
                {
                    assetNameSuffix = Constant.Media.Job.OutputAssetNameSuffix.AudioAnalyzer;
                }
                outputAssetName = string.Concat(outputAssetName, " (", assetNameSuffix, ")");
                break;
            }
            return(outputAssetName);
        }
Example #10
0
        private Job CreateJob(string transformName, MediaJob mediaJob)
        {
            Job job = null;

            try
            {
                MediaTransformPreset[] transformPresets = GetTransformPresets(transformName);
                JobInput                     jobInput   = GetJobInput(mediaJob);
                JobOutputAsset[]             jobOutputs = GetJobOutputs(transformPresets, mediaJob);
                IDictionary <string, string> jobPublish = GetJobPublish(mediaJob.OutputPublish);
                job = new Job()
                {
                    Description     = mediaJob.Description,
                    Priority        = mediaJob.Priority,
                    Input           = jobInput,
                    Outputs         = jobOutputs,
                    CorrelationData = jobPublish
                };
                job = _media.Jobs.Create(MediaAccount.ResourceGroupName, MediaAccount.Name, transformName, mediaJob.Name, job);
                SetOutputAssetLink(transformPresets, jobOutputs, mediaJob.OutputInsight);
            }
            catch (Exception ex)
            {
                Dictionary <string, string> exProperties = new Dictionary <string, string>
                {
                    { "Media Account", JsonConvert.SerializeObject(MediaAccount) },
                    { "Transform Name", transformName },
                    { "Media Job", JsonConvert.SerializeObject(mediaJob) }
                };
                if (job != null)
                {
                    exProperties.Add("Job", JsonConvert.SerializeObject(job));
                }
                TelemetryClient telemetryClient = new TelemetryClient();
                telemetryClient.TrackException(ex, exProperties);
                throw;
            }
            return(job);
        }
Example #11
0
        public static MediaJob GetJob(string authToken, MediaClient mediaClient, MediaJob mediaJob, MediaJobInput[] jobInputs)
        {
            List <MediaJobTask> jobTasks = new List <MediaJobTask>();

            foreach (MediaJobTask jobTask in mediaJob.Tasks)
            {
                MediaJobTask[] tasks = null;
                switch (jobTask.MediaProcessor)
                {
                case MediaProcessor.EncoderStandard:
                case MediaProcessor.EncoderPremium:
                    tasks = GetEncoderTasks(mediaClient, jobTask, jobInputs);
                    break;

                case MediaProcessor.VideoIndexer:
                    IndexerClient indexerClient = new IndexerClient(authToken);
                    if (indexerClient.IndexerEnabled)
                    {
                        foreach (MediaJobInput jobInput in jobInputs)
                        {
                            IAsset asset      = mediaClient.GetEntityById(MediaEntity.Asset, jobInput.AssetId) as IAsset;
                            string documentId = DocumentClient.GetDocumentId(asset, out bool videoIndexer);
                            if (videoIndexer)
                            {
                                indexerClient.ResetIndex(authToken, documentId);
                            }
                            else
                            {
                                indexerClient.IndexVideo(authToken, mediaClient, asset, jobTask.ContentIndexer);
                            }
                        }
                    }
                    break;

                case MediaProcessor.VideoAnnotation:
                    tasks = GetVideoAnnotationTasks(mediaClient, jobTask, jobInputs);
                    break;

                case MediaProcessor.VideoSummarization:
                    tasks = GetVideoSummarizationTasks(mediaClient, jobTask, jobInputs);
                    break;

                case MediaProcessor.FaceDetection:
                    tasks = GetFaceDetectionTasks(mediaClient, jobTask, jobInputs);
                    break;

                case MediaProcessor.SpeechAnalyzer:
                    tasks = GetSpeechAnalyzerTasks(mediaClient, jobTask, jobInputs);
                    break;

                case MediaProcessor.MotionDetection:
                    tasks = GetMotionDetectionTasks(mediaClient, jobTask, jobInputs);
                    break;

                case MediaProcessor.ContentModeration:
                    tasks = GetContentModerationTasks(mediaClient, jobTask, jobInputs);
                    break;

                case MediaProcessor.CharacterRecognition:
                    tasks = GetCharacterRecognitionTasks(mediaClient, jobTask, jobInputs);
                    break;
                }
                if (tasks != null)
                {
                    jobTasks.AddRange(tasks);
                }
            }
            mediaJob.Tasks = jobTasks.ToArray();
            if (string.IsNullOrEmpty(mediaJob.Name))
            {
                mediaJob.Name = jobInputs[0].AssetName;
            }
            return(mediaJob);
        }
Example #12
0
        private JobOutputAsset[] GetJobOutputs(MediaTransformPreset[] transformPresets, MediaJob mediaJob)
        {
            List <JobOutputAsset> jobOutputs = new List <JobOutputAsset>();

            foreach (MediaTransformPreset transformPreset in transformPresets)
            {
                string outputAssetName = GetOutputAssetName(transformPreset, mediaJob);
                CreateAsset(mediaJob.OutputAssetStorage, outputAssetName);
                JobOutputAsset jobOutput = new JobOutputAsset(outputAssetName);
                jobOutputs.Add(jobOutput);
            }
            return(jobOutputs.ToArray());
        }
Example #13
0
        internal static MediaJob SetJob(MediaClient mediaClient, MediaJob mediaJob, MediaAssetInput[] inputAssets)
        {
            List <MediaJobTask> taskList = new List <MediaJobTask>();

            foreach (MediaJobTask jobTask in mediaJob.Tasks)
            {
                MediaJobTask[] tasks = null;
                switch (jobTask.MediaProcessor)
                {
                case MediaProcessor.EncoderStandard:
                case MediaProcessor.EncoderPremium:
                case MediaProcessor.EncoderUltra:
                    tasks = GetEncoderTasks(mediaClient, jobTask, inputAssets);
                    break;

                case MediaProcessor.Indexer_v1:
                    tasks = GetIndexerV1Tasks(mediaClient, jobTask, inputAssets);
                    break;

                case MediaProcessor.Indexer_v2:
                    tasks = GetIndexerV2Tasks(mediaClient, jobTask, inputAssets);
                    break;

                case MediaProcessor.FaceDetection:
                    tasks = GetFaceDetectionTasks(mediaClient, jobTask, inputAssets);
                    break;

                case MediaProcessor.FaceRedaction:
                    tasks = GetFaceRedactionTasks(mediaClient, jobTask, inputAssets);
                    break;

                case MediaProcessor.MotionDetection:
                    tasks = GetMotionDetectionTasks(mediaClient, jobTask, inputAssets);
                    break;

                case MediaProcessor.MotionHyperlapse:
                    tasks = GetMotionHyperlapseTasks(mediaClient, jobTask, inputAssets);
                    break;

                case MediaProcessor.MotionStabilization:
                    tasks = GetMotionStabilizationTasks(mediaClient, jobTask, inputAssets);
                    break;

                case MediaProcessor.VideoAnnotation:
                    tasks = GetVideoAnnotationTasks(mediaClient, jobTask, inputAssets);
                    break;

                case MediaProcessor.VideoSummarization:
                    tasks = GetVideoSummarizationTasks(mediaClient, jobTask, inputAssets);
                    break;

                case MediaProcessor.CharacterRecognition:
                    tasks = GetCharacterRecognitionTasks(mediaClient, jobTask, inputAssets);
                    break;

                case MediaProcessor.ContentModeration:
                    tasks = GetContentModerationTasks(mediaClient, jobTask, inputAssets);
                    break;
                }
                if (tasks != null)
                {
                    taskList.AddRange(tasks);
                }
            }
            mediaJob.Tasks = taskList.ToArray();
            if (string.IsNullOrEmpty(mediaJob.Name))
            {
                mediaJob.Name = mediaJob.Tasks[0].Name;
            }
            return(mediaJob);
        }
Example #14
0
        public static object SubmitJob(string directoryId, string authToken, MediaClient mediaClient, MediaJob mediaJob, MediaJobInput[] jobInputs)
        {
            IJob         job         = null;
            IJobTemplate jobTemplate = null;

            if (mediaJob.Tasks != null)
            {
                mediaJob = MediaClient.GetJob(authToken, mediaClient, mediaJob, jobInputs);
            }
            if (mediaJob.Tasks != null || !string.IsNullOrEmpty(mediaJob.TemplateId))
            {
                job = mediaClient.CreateJob(mediaJob, jobInputs, out jobTemplate);
            }
            if (job != null && !string.IsNullOrEmpty(job.Id))
            {
                TrackJob(directoryId, authToken, job, mediaJob.Tasks);
            }
            return(GetJobOutput(job, jobTemplate, jobInputs));
        }