コード例 #1
0
        public static Job CreateJob([ActivityTrigger] DurableActivityContext context)
        {
            ValueTuple <MediaWorkflowManifest, string, Asset> jobInput = context.GetInput <(MediaWorkflowManifest, string, Asset)>();
            MediaWorkflowManifest workflowManifest = jobInput.Item1;
            string inputFileUrl = jobInput.Item2;
            Asset  inputAsset   = jobInput.Item3;

            Job         job         = null;
            string      insightId   = null;
            MediaClient mediaClient = new MediaClient(workflowManifest);

            bool videoIndexer = workflowManifest.TransformPresets.Contains <MediaTransformPreset>(MediaTransformPreset.VideoIndexer);
            bool audioIndexer = workflowManifest.TransformPresets.Contains <MediaTransformPreset>(MediaTransformPreset.AudioIndexer);

            if (mediaClient.IndexerEnabled() && (videoIndexer || audioIndexer))
            {
                insightId = mediaClient.IndexerUploadVideo(inputFileUrl, inputAsset, workflowManifest.JobPriority, videoIndexer, audioIndexer);
            }

            Transform transform = mediaClient.GetTransform(workflowManifest.TransformPresets);

            if (transform != null)
            {
                MediaJobOutputInsight outputInsight = new MediaJobOutputInsight()
                {
                    Id           = insightId,
                    VideoIndexer = videoIndexer,
                    AudioIndexer = audioIndexer
                };
                job = mediaClient.CreateJob(transform.Name, workflowManifest.JobName, null, workflowManifest.JobPriority, inputFileUrl, inputAsset, workflowManifest.OutputAssetStorage, workflowManifest.JobOutputPublish, outputInsight, false);
            }
            return(job);
        }
コード例 #2
0
ファイル: jobController.cs プロジェクト: laniatech/SkyMedia
 public JsonResult Create(string transformName, string jobName, string jobDescription, Priority jobPriority, string jobData,
                          string inputFileUrl, string inputAssetName, MediaJobOutputMode outputAssetMode, string streamingPolicyName)
 {
     try
     {
         Job    job       = null;
         string authToken = HomeController.GetAuthToken(Request, Response);
         using (MediaClient mediaClient = new MediaClient(authToken))
         {
             bool      videoAnalyzerPreset = false;
             bool      audioAnalyzerPreset = false;
             Transform transform           = mediaClient.GetEntity <Transform>(MediaEntity.Transform, transformName);
             foreach (TransformOutput transformOutput in transform.Outputs)
             {
                 if (transformOutput.Preset is VideoAnalyzerPreset)
                 {
                     videoAnalyzerPreset = true;
                 }
                 else if (transformOutput.Preset is AudioAnalyzerPreset)
                 {
                     audioAnalyzerPreset = true;
                 }
             }
             string insightId        = null;
             Asset  inputAsset       = null;
             string assetDescription = null;
             if (!string.IsNullOrEmpty(inputAssetName))
             {
                 inputAsset       = mediaClient.GetEntity <Asset>(MediaEntity.Asset, inputAssetName);
                 assetDescription = inputAsset.Description;
             }
             if (mediaClient.IndexerEnabled() && (videoAnalyzerPreset || audioAnalyzerPreset))
             {
                 bool audioOnly = !videoAnalyzerPreset && audioAnalyzerPreset;
                 insightId = mediaClient.IndexerUploadVideo(mediaClient.MediaAccount, inputAsset, null, jobPriority, true, audioOnly);
             }
             if (!string.IsNullOrEmpty(transformName))
             {
                 if (string.IsNullOrEmpty(inputFileUrl) && inputAsset != null)
                 {
                     StorageBlobClient blobClient = new StorageBlobClient(mediaClient.MediaAccount, inputAsset.StorageAccountName);
                     MediaAsset        mediaAsset = new MediaAsset(mediaClient, inputAsset);
                     string            fileName   = mediaAsset.Files[0].Name;
                     inputFileUrl = blobClient.GetDownloadUrl(inputAsset.Container, fileName, false);
                 }
                 string[] assetDescriptions = new string[] { assetDescription };
                 string[] assetAlternateIds = new string[] { insightId };
                 job = mediaClient.CreateJob(authToken, transformName, jobName, jobDescription, jobPriority, jobData, inputFileUrl, inputAssetName, outputAssetMode, assetDescriptions, assetAlternateIds, streamingPolicyName);
             }
         }
         return(Json(job));
     }
     catch (ApiErrorException ex)
     {
         return(new JsonResult(ex.Response.Content)
         {
             StatusCode = (int)ex.Response.StatusCode
         });
     }
 }
コード例 #3
0
 public JsonResult Workflow(string storageAccount, string assetName, string assetDescription, string assetAlternateId, string[] fileNames,
                            bool adaptiveStreaming, bool thumbnailImages, bool videoAnalyzer, bool audioAnalyzer, bool videoIndexer, bool audioIndexer)
 {
     try
     {
         Asset[]    inputAssets;
         List <Job> jobs      = new List <Job>();
         string     authToken = HomeController.GetAuthToken(Request, Response);
         using (MediaClient mediaClient = new MediaClient(authToken))
         {
             Transform transform = mediaClient.CreateTransform(adaptiveStreaming, thumbnailImages, videoAnalyzer, audioAnalyzer, videoIndexer, audioIndexer);
             inputAssets = CreateInputAssets(mediaClient, storageAccount, assetName, assetDescription, assetAlternateId, fileNames);
             foreach (Asset inputAsset in inputAssets)
             {
                 Job    job       = null;
                 string insightId = null;
                 if (mediaClient.IndexerEnabled() && (videoIndexer || audioIndexer))
                 {
                     bool audioOnly = !videoIndexer && audioIndexer;
                     insightId = mediaClient.IndexerUploadVideo(mediaClient.MediaAccount, inputAsset, null, Priority.Normal, true, audioOnly);
                 }
                 if (transform != null)
                 {
                     StorageBlobClient         blobClient              = new StorageBlobClient(mediaClient.MediaAccount, inputAsset.StorageAccountName);
                     MediaAsset                mediaAsset              = new MediaAsset(mediaClient, inputAsset);
                     string                    fileName                = mediaAsset.Files[0].Name;
                     string                    inputFileUrl            = blobClient.GetDownloadUrl(inputAsset.Container, fileName, false);
                     MediaJobOutputMode        outputAssetMode         = MediaJobOutputMode.SingleAsset;
                     string[]                  outputAssetDescriptions = new string[] { assetDescription };
                     string[]                  outputAssetAlternateIds = new string[] { insightId };
                     PredefinedStreamingPolicy streamingPolicy         = PredefinedStreamingPolicy.ClearStreamingOnly;
                     job = mediaClient.CreateJob(authToken, transform.Name, null, null, Priority.Normal, null, inputFileUrl, inputAsset.Name, outputAssetMode, outputAssetDescriptions, outputAssetAlternateIds, streamingPolicy);
                 }
                 if (job != null)
                 {
                     if (!string.IsNullOrEmpty(insightId))
                     {
                         job.CorrelationData.Add("insightId", insightId);
                     }
                     jobs.Add(job);
                 }
                 else
                 {
                     inputAsset.AlternateId = insightId;
                 }
             }
         }
         return(jobs.Count > 0 ? Json(jobs.ToArray()) : Json(inputAssets));
     }
     catch (ApiErrorException ex)
     {
         return(new JsonResult(ex.Response.Content)
         {
             StatusCode = (int)ex.Response.StatusCode
         });
     }
 }
コード例 #4
0
        private static void CreateJob(MediaClient mediaClient, MediaIngestManifest ingestManifest, Asset inputAsset, ILogger logger)
        {
            string logData = string.Concat("Input File Url: ", ingestManifest.JobInputFileUrl);

            WriteLog(ingestManifest.Name, logData, logger, false);
            if (mediaClient.IndexerEnabled() && (ingestManifest.TransformPreset.Value.HasFlag(MediaTransformPreset.VideoIndexer) || ingestManifest.TransformPreset.Value.HasFlag(MediaTransformPreset.AudioIndexer)))
            {
                bool   audioOnly = !ingestManifest.TransformPreset.Value.HasFlag(MediaTransformPreset.VideoIndexer) && ingestManifest.TransformPreset.Value.HasFlag(MediaTransformPreset.AudioIndexer);
                string insightId = mediaClient.IndexerUploadVideo(mediaClient.MediaAccount, inputAsset, ingestManifest.JobInputFileUrl, ingestManifest.JobPriority, true, audioOnly);
                logData = string.Concat("Insight Id: ", insightId);
                WriteLog(ingestManifest.Name, logData, logger, false);
            }
            Transform transform = mediaClient.CreateTransform(ingestManifest.TransformPreset.Value);

            if (transform != null)
            {
                Job job = mediaClient.CreateJob(null, transform.Name, ingestManifest.JobName, ingestManifest.JobDescription, ingestManifest.JobPriority, ingestManifest.JobData, ingestManifest.JobInputFileUrl, ingestManifest.AssetName, ingestManifest.JobOutputMode, ingestManifest.JobOutputAssetDescriptions, ingestManifest.JobOutputAssetAlternateIds, ingestManifest.StreamingPolicyName);
                logData = string.Concat("Transform Name: ", transform.Name);
                WriteLog(ingestManifest.Name, logData, logger, false);
                logData = string.Concat("Job Name: ", job.Name);
                WriteLog(ingestManifest.Name, logData, logger, false);
            }
        }
コード例 #5
0
ファイル: jobController.cs プロジェクト: NU11B0T/SkyMedia
 public JsonResult Create(string transformName, string jobName, string jobDescription, string jobPriority, string inputFileUrl,
                          string inputAssetName, StandardBlobTier inputAssetStorageTier, string streamingPolicyName, ContentProtection contentProtection)
 {
     try
     {
         Job    job       = null;
         string authToken = HomeController.GetAuthToken(Request, Response);
         using (MediaClient mediaClient = new MediaClient(authToken))
         {
             bool      videoAnalyzerPreset = false;
             bool      audioAnalyzerPreset = false;
             Transform transform           = mediaClient.GetEntity <Transform>(MediaEntity.Transform, transformName);
             foreach (TransformOutput transformOutput in transform.Outputs)
             {
                 if (transformOutput.Preset is VideoAnalyzerPreset)
                 {
                     videoAnalyzerPreset = true;
                 }
                 else if (transformOutput.Preset is AudioAnalyzerPreset)
                 {
                     audioAnalyzerPreset = true;
                 }
             }
             MediaJobOutputPublish outputAssetPublish = new MediaJobOutputPublish()
             {
                 InputAssetStorageTier = inputAssetStorageTier,
                 StreamingPolicyName   = streamingPolicyName,
                 ContentProtection     = contentProtection,
             };
             string insightId  = null;
             Asset  inputAsset = string.IsNullOrEmpty(inputAssetName) ? null : mediaClient.GetEntity <Asset>(MediaEntity.Asset, inputAssetName);
             if (mediaClient.IndexerEnabled() && (videoAnalyzerPreset || audioAnalyzerPreset))
             {
                 insightId = mediaClient.IndexerUploadVideo(inputFileUrl, inputAsset, jobPriority, videoAnalyzerPreset, audioAnalyzerPreset);
             }
             if (!string.IsNullOrEmpty(transformName))
             {
                 MediaJobOutputInsight outputInsight = new MediaJobOutputInsight()
                 {
                     Id           = insightId,
                     VideoIndexer = videoAnalyzerPreset,
                     AudioIndexer = audioAnalyzerPreset
                 };
                 job = mediaClient.CreateJob(transformName, jobName, jobDescription, jobPriority, inputFileUrl, inputAsset, null, outputAssetPublish, outputInsight, true);
             }
         }
         return(Json(job));
     }
     catch (ValidationException ex)
     {
         Error error = new Error()
         {
             Type    = HttpStatusCode.BadRequest,
             Message = ex.Message
         };
         return(new JsonResult(error)
         {
             StatusCode = (int)error.Type
         });
     }
     catch (ApiErrorException ex)
     {
         return(new JsonResult(ex.Response.Content)
         {
             StatusCode = (int)ex.Response.StatusCode
         });
     }
 }
コード例 #6
0
        public async Task <JsonResult> Workflow(string storageAccount, string assetName, string assetDescription, string assetAlternateId, string[] fileNames,
                                                bool adaptiveStreaming, bool contentAwareEncoding, bool contentProtection, bool thumbnailImages, bool thumbnailSprite,
                                                bool videoAnalyzer, bool audioAnalyzer, bool faceDetector, bool videoIndexer, bool audioIndexer)
        {
            try
            {
                List <MediaWorkflowEntity> newEntities = new List <MediaWorkflowEntity>();
                string authToken = HomeController.GetAuthToken(Request, Response);
                using (MediaClient mediaClient = new MediaClient(authToken))
                {
                    Transform transform   = mediaClient.GetTransform(adaptiveStreaming, contentAwareEncoding, thumbnailImages, thumbnailSprite, videoAnalyzer, audioAnalyzer, faceDetector, videoIndexer, audioIndexer);
                    Asset[]   inputAssets = await mediaClient.CreateAssets(storageAccount, assetName, assetDescription, assetAlternateId, fileNames);

                    foreach (Asset inputAsset in inputAssets)
                    {
                        Job      job         = null;
                        string   insightId   = null;
                        Priority jobPriority = Priority.Normal;
                        MediaJobOutputPublish outputPublish = new MediaJobOutputPublish()
                        {
                            StreamingPolicyName = contentProtection ? PredefinedStreamingPolicy.ClearKey : PredefinedStreamingPolicy.DownloadAndClearStreaming
                        };
                        if (mediaClient.IndexerEnabled() && (videoIndexer || audioIndexer))
                        {
                            insightId = mediaClient.IndexerUploadVideo(null, inputAsset, jobPriority, videoIndexer, audioIndexer);
                        }
                        if (transform != null)
                        {
                            MediaJobOutputInsight outputInsight = new MediaJobOutputInsight()
                            {
                                Id           = insightId,
                                VideoIndexer = videoIndexer,
                                AudioIndexer = audioIndexer
                            };
                            job = mediaClient.CreateJob(transform.Name, null, null, jobPriority, null, inputAsset, null, outputPublish, outputInsight, true);
                        }
                        MediaWorkflowEntity newEntity = new MediaWorkflowEntity();
                        if (job != null)
                        {
                            newEntity.Type = MediaEntity.TransformJob;
                            newEntity.Id   = job.Id;
                            newEntity.Name = job.Name;
                        }
                        else
                        {
                            newEntity.Type = MediaEntity.Asset;
                            newEntity.Id   = inputAsset.Id;
                            newEntity.Name = inputAsset.Name;
                        }
                        newEntity.InsightId = insightId;
                        newEntities.Add(newEntity);
                    }
                }
                return(Json(newEntities.ToArray()));
            }
            catch (ApiErrorException ex)
            {
                return(new JsonResult(ex.Response.Content)
                {
                    StatusCode = (int)ex.Response.StatusCode
                });
            }
        }