Ejemplo n.º 1
0
        private static MediaInsight GetMediaInsight(MediaClient mediaClient, Asset asset)
        {
            MediaInsight mediaInsight = new MediaInsight();

            if (mediaClient.IndexerEnabled())
            {
                using (DatabaseClient databaseClient = new DatabaseClient(false))
                {
                    string         collectionId = Constant.Database.Collection.MediaAssets;
                    MediaAssetLink assetLink    = databaseClient.GetDocument <MediaAssetLink>(collectionId, asset.Name);
                    if (assetLink != null)
                    {
                        string insightId = null;
                        if (assetLink.JobOutputs.ContainsKey(MediaTransformPreset.VideoIndexer))
                        {
                            insightId = assetLink.JobOutputs[MediaTransformPreset.VideoIndexer];
                        }
                        else if (assetLink.JobOutputs.ContainsKey(MediaTransformPreset.AudioIndexer))
                        {
                            insightId = assetLink.JobOutputs[MediaTransformPreset.AudioIndexer];
                        }
                        if (!string.IsNullOrEmpty(insightId) && mediaClient.IndexerInsightExists(insightId, out JObject insight))
                        {
                            mediaInsight.WidgetUrl = mediaClient.IndexerGetInsightUrl(insightId);
                            mediaInsight.ViewToken = insight["videos"][0]["viewToken"].ToString();
                        }
                    }
                }
            }
            return(mediaInsight);
        }
Ejemplo n.º 2
0
        private static JObject GetProcessorConfig(string documentId)
        {
            JObject processorConfig;

            using (DatabaseClient databaseClient = new DatabaseClient(false))
            {
                processorConfig = databaseClient.GetDocument(documentId);
            }
            return(processorConfig);
        }
Ejemplo n.º 3
0
        public static MediaJobPublish PublishJobOutput(string jobName, string insightId)
        {
            MediaJobAccount jobAccount;
            MediaJobPublish jobPublish = null;

            using (DatabaseClient databaseClient = new DatabaseClient())
            {
                string collectionId = Constant.Database.Collection.MediaJobAccount;
                string documentId   = string.IsNullOrEmpty(jobName) ? insightId : jobName;
                jobAccount = databaseClient.GetDocument <MediaJobAccount>(collectionId, documentId);
            }
            if (jobAccount != null)
            {
                using (MediaClient mediaClient = new MediaClient(null, jobAccount.MediaAccount))
                {
                    if (!string.IsNullOrEmpty(insightId))
                    {
                        JObject insight = mediaClient.IndexerGetInsight(insightId);
                        if (insight != null)
                        {
                            using (DatabaseClient databaseClient = new DatabaseClient())
                            {
                                string collectionId = Constant.Database.Collection.MediaContentInsight;
                                databaseClient.UpsertDocument(collectionId, insight);
                            }
                        }
                    }
                    else
                    {
                        Job job = mediaClient.GetEntity <Job>(MediaEntity.TransformJob, jobName, jobAccount.TransformName);
                        if (job != null)
                        {
                            jobPublish = GetJobPublish(job);
                            jobPublish.UserNotification.JobOutputMessage = GetNotificationMessage(job, jobAccount, jobPublish);
                            string streamingPolicyName = PredefinedStreamingPolicy.ClearStreamingOnly;
                            if (!string.IsNullOrEmpty(jobPublish.StreamingPolicyName))
                            {
                                streamingPolicyName = jobPublish.StreamingPolicyName;
                            }
                            foreach (JobOutputAsset jobOutput in job.Outputs)
                            {
                                mediaClient.CreateLocator(jobOutput.AssetName, jobOutput.AssetName, streamingPolicyName, jobPublish.ContentProtection);
                            }
                        }
                    }
                }
            }
            return(jobPublish);
        }
Ejemplo n.º 4
0
        public static MediaTrack[] GetMediaTracks(MediaClient mediaClient, Asset asset)
        {
            List <MediaTrack> mediaTracks = new List <MediaTrack>();

            using (DatabaseClient databaseClient = new DatabaseClient(false))
            {
                string         collectionId = Constant.Database.Collection.MediaAssets;
                MediaAssetLink assetLink    = databaseClient.GetDocument <MediaAssetLink>(collectionId, asset.Name);
                if (assetLink != null)
                {
                    string trackType      = null;
                    string trackLabel     = null;
                    string trackSourceUrl = null;
                    if (assetLink.JobOutputs.ContainsKey(MediaTransformPreset.AudioIndexer))
                    {
                        trackType  = Constant.Media.Track.AudioTranscript.CaptionsType;
                        trackLabel = Constant.Media.Track.AudioTranscript.CaptionsLabel;
                        string insightId = assetLink.JobOutputs[MediaTransformPreset.AudioIndexer];
                        trackSourceUrl = mediaClient.IndexerGetCaptionsUrl(insightId);
                    }
                    else if (assetLink.JobOutputs.ContainsKey(MediaTransformPreset.AudioAnalyzer))
                    {
                        trackType  = Constant.Media.Track.AudioTranscript.SubtitlesType;
                        trackLabel = Constant.Media.Track.AudioTranscript.SubtitlesLabel;
                        string assetName = assetLink.JobOutputs[MediaTransformPreset.AudioAnalyzer];
                        string fileName  = Constant.Media.Track.AudioTranscript.FileName;
                        trackSourceUrl = mediaClient.GetDownloadUrl(assetName, fileName);
                    }
                    if (!string.IsNullOrEmpty(trackSourceUrl))
                    {
                        MediaTrack mediaTrack = new MediaTrack()
                        {
                            Type      = trackType,
                            Label     = trackLabel,
                            SourceUrl = trackSourceUrl
                        };
                        mediaTracks.Add(mediaTrack);
                    }
                }
            }
            return(mediaTracks.ToArray());
        }
Ejemplo n.º 5
0
        private static MediaJobTask[] GetEncoderTasks(MediaClient mediaClient, MediaJobTask jobTask, MediaAssetInput[] inputAssets)
        {
            List <MediaJobTask> jobTasks = new List <MediaJobTask>();

            if (jobTask.MediaProcessor != MediaProcessor.EncoderStandard)
            {
                List <MediaAssetInput> assets = new List <MediaAssetInput>(inputAssets);
                assets.Sort(OrderByWorkflow);
                inputAssets = assets.ToArray();
            }
            else
            {
                if (string.Equals(jobTask.ProcessorConfig, Constants.Media.ProcessorConfig.EncoderStandardThumbnailsPreset, StringComparison.InvariantCultureIgnoreCase))
                {
                    string settingKey = Constants.AppSettingKey.MediaProcessorThumbnailGenerationDocumentId;
                    string documentId = AppSetting.GetValue(settingKey);
                    using (DatabaseClient databaseClient = new DatabaseClient(false))
                    {
                        JObject processorConfig = databaseClient.GetDocument(documentId);
                        jobTask.ProcessorConfig = processorConfig.ToString();
                    }
                }
                bool inputSubclipped = false;
                foreach (MediaAssetInput inputAsset in inputAssets)
                {
                    if (!string.IsNullOrEmpty(inputAsset.MarkIn))
                    {
                        inputSubclipped = true;
                    }
                }
                if (inputSubclipped && !jobTask.ProcessorConfig.StartsWith("{"))
                {
                    using (DatabaseClient databaseClient = new DatabaseClient(true))
                    {
                        string  collectionId  = Constants.Database.DocumentCollection.Encoding;
                        string  procedureId   = "getEncoderConfig";
                        JObject encoderConfig = databaseClient.ExecuteProcedure(collectionId, procedureId, "name", jobTask.ProcessorConfig);
                        jobTask.ProcessorConfig = encoderConfig.ToString();
                    }
                }
            }
            JArray inputSources = new JArray();

            foreach (MediaAssetInput inputAsset in inputAssets)
            {
                if (!string.IsNullOrEmpty(inputAsset.MarkIn))
                {
                    JObject inputSource = new JObject();
                    inputSource.Add("StartTime", inputAsset.MarkIn);
                    inputSource.Add("Duration", inputAsset.ClipDuration);
                    inputSources.Add(inputSource);
                }
            }
            if (inputSources.Count > 0)
            {
                JObject oldConfig = JObject.Parse(jobTask.ProcessorConfig);
                oldConfig.Remove("Sources");
                JObject newConfig = new JObject();
                newConfig.Add(oldConfig.First);
                newConfig.Add("Sources", inputSources);
                oldConfig.First.Remove();
                JEnumerable <JToken> children = oldConfig.Children();
                foreach (JToken child in children)
                {
                    newConfig.Add(child);
                }
                jobTask.ProcessorConfig = newConfig.ToString();
            }
            bool multipleInputTask = jobTask.MediaProcessor != MediaProcessor.EncoderStandard;

            MediaJobTask[] mappedJobTasks = MapJobTasks(mediaClient, jobTask, inputAssets, multipleInputTask);
            jobTasks.AddRange(mappedJobTasks);
            return(jobTasks.ToArray());
        }