Esempio n. 1
0
 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
         });
     }
 }
Esempio n. 2
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
                });
            }
        }