Ejemplo n.º 1
0
 public VideoControl(string filename)
 {
     if (filename == null)
     {
         _originalFileString = null;
     }
     _videoServiceClient         = new VideoServiceClient(_videoAPISubscriptionKey);
     _videoServiceClient.Timeout = TimeSpan.FromMinutes(10);
 }
Ejemplo n.º 2
0
 /// <summary>Snippet for GetVideo</summary>
 /// <remarks>
 /// This snippet has been automatically generated for illustrative purposes only.
 /// It may require modifications to work in your environment.
 /// </remarks>
 public void GetVideoResourceNames()
 {
     // Create client
     VideoServiceClient videoServiceClient = VideoServiceClient.Create();
     // Initialize request argument(s)
     VideoName resourceName = VideoName.FromCustomerVideo("[CUSTOMER_ID]", "[VIDEO_ID]");
     // Make the request
     Video response = videoServiceClient.GetVideo(resourceName);
 }
 /// <summary>Snippet for GetVideo</summary>
 /// <remarks>
 /// This snippet has been automatically generated for illustrative purposes only.
 /// It may require modifications to work in your environment.
 /// </remarks>
 public void GetVideo()
 {
     // Create client
     VideoServiceClient videoServiceClient = VideoServiceClient.Create();
     // Initialize request argument(s)
     string resourceName = "customers/[CUSTOMER_ID]/videos/[VIDEO_ID]";
     // Make the request
     Video response = videoServiceClient.GetVideo(resourceName);
 }
Ejemplo n.º 4
0
        /// <summary>Snippet for GetVideoAsync</summary>
        /// <remarks>
        /// This snippet has been automatically generated for illustrative purposes only.
        /// It may require modifications to work in your environment.
        /// </remarks>
        public async Task GetVideoResourceNamesAsync()
        {
            // Create client
            VideoServiceClient videoServiceClient = await VideoServiceClient.CreateAsync();

            // Initialize request argument(s)
            VideoName resourceName = VideoName.FromCustomerVideo("[CUSTOMER]", "[VIDEO]");
            // Make the request
            Video response = await videoServiceClient.GetVideoAsync(resourceName);
        }
        /// <summary>Snippet for GetVideoAsync</summary>
        /// <remarks>
        /// This snippet has been automatically generated for illustrative purposes only.
        /// It may require modifications to work in your environment.
        /// </remarks>
        public async Task GetVideoAsync()
        {
            // Create client
            VideoServiceClient videoServiceClient = await VideoServiceClient.CreateAsync();

            // Initialize request argument(s)
            string resourceName = "customers/[CUSTOMER]/videos/[VIDEO]";
            // Make the request
            Video response = await videoServiceClient.GetVideoAsync(resourceName);
        }
Ejemplo n.º 6
0
        // -----------------------------------------------------------------------
        // KEY SAMPLE CODE STARTS HERE
        // -----------------------------------------------------------------------
        private async Task DetectMotion(string subscriptionKey, string originalFilePath)
        {
            _dataContext.IsWorking  = true;
            _dataContext.SourceUri  = null;
            _dataContext.ResultText = null;

            Helpers.Log(LogIdentifier, "Start motion detection");
            VideoServiceClient client = new VideoServiceClient(subscriptionKey);

            client.Timeout = TimeSpan.FromMinutes(10);

            using (FileStream originalStream = new FileStream(originalFilePath, FileMode.Open, FileAccess.Read))
            {
                // Creates a video operation of motion detection
                Helpers.Log(LogIdentifier, "Start uploading video");
                MotionDetectionOperationSettings settings = new MotionDetectionOperationSettings
                {
                    SensitivityLevel   = MotionDetectionOperationSettings.SensitivityLevels.Medium,
                    DetectLightChange  = true,
                    FrameSamplingValue = 1,
                    MergeTimeThreshold = 0.0
                };
                Operation operation = await client.CreateOperationAsync(originalStream, settings);

                Helpers.Log(LogIdentifier, "Uploading video done");

                // Starts querying service status
                OperationResult result = await client.GetOperationResultAsync(operation);

                while (result.Status != OperationStatus.Succeeded && result.Status != OperationStatus.Failed)
                {
                    Helpers.Log(LogIdentifier, "Server status: {0}, wait {1} seconds...", result.Status, QueryWaitTime.TotalSeconds);
                    await Task.Delay(QueryWaitTime);

                    result = await client.GetOperationResultAsync(operation);
                }
                Helpers.Log(LogIdentifier, "Finish processing with server status: " + result.Status);

                // Processing finished, checks result
                if (result.Status == OperationStatus.Succeeded)
                {
                    // Gets output JSON
                    _dataContext.SourceUri       = new Uri(originalFilePath);
                    _dataContext.ResultText      = Helpers.FormatJson <MotionDetectionResult>(result.ProcessingResult);
                    _dataContext.FrameHighlights = GetHighlights(result.ProcessingResult).ToList();
                }
                else
                {
                    // Failed
                    Helpers.Log(LogIdentifier, "Fail reason: " + result.Message);
                }
                _dataContext.IsWorking = false;
            }
        }
 /// <summary>Snippet for GetVideo</summary>
 public void GetVideoResourceNames()
 {
     // Snippet: GetVideo(VideoName, CallSettings)
     // Create client
     VideoServiceClient videoServiceClient = VideoServiceClient.Create();
     // Initialize request argument(s)
     VideoName resourceName = VideoName.FromCustomerVideo("[CUSTOMER]", "[VIDEO]");
     // Make the request
     Video response = videoServiceClient.GetVideo(resourceName);
     // End snippet
 }
 /// <summary>Snippet for GetVideo</summary>
 public void GetVideo()
 {
     // Snippet: GetVideo(string, CallSettings)
     // Create client
     VideoServiceClient videoServiceClient = VideoServiceClient.Create();
     // Initialize request argument(s)
     string resourceName = "customers/[CUSTOMER]/videos/[VIDEO]";
     // Make the request
     Video response = videoServiceClient.GetVideo(resourceName);
     // End snippet
 }
Ejemplo n.º 9
0
 /// <summary>Snippet for GetVideo</summary>
 /// <remarks>
 /// This snippet has been automatically generated for illustrative purposes only.
 /// It may require modifications to work in your environment.
 /// </remarks>
 public void GetVideoRequestObject()
 {
     // Create client
     VideoServiceClient videoServiceClient = VideoServiceClient.Create();
     // Initialize request argument(s)
     GetVideoRequest request = new GetVideoRequest
     {
         ResourceNameAsVideoName = VideoName.FromCustomerVideo("[CUSTOMER]", "[VIDEO]"),
     };
     // Make the request
     Video response = videoServiceClient.GetVideo(request);
 }
        /// <summary>Snippet for GetVideoAsync</summary>
        /// <remarks>
        /// This snippet has been automatically generated for illustrative purposes only.
        /// It may require modifications to work in your environment.
        /// </remarks>
        public async Task GetVideoRequestObjectAsync()
        {
            // Create client
            VideoServiceClient videoServiceClient = await VideoServiceClient.CreateAsync();

            // Initialize request argument(s)
            GetVideoRequest request = new GetVideoRequest
            {
                ResourceNameAsVideoName = VideoName.FromCustomerVideo("[CUSTOMER_ID]", "[VIDEO_ID]"),
            };
            // Make the request
            Video response = await videoServiceClient.GetVideoAsync(request);
        }
        /// <summary>Snippet for GetVideoAsync</summary>
        public async Task GetVideoAsync()
        {
            // Snippet: GetVideoAsync(string, CallSettings)
            // Additional: GetVideoAsync(string, CancellationToken)
            // Create client
            VideoServiceClient videoServiceClient = await VideoServiceClient.CreateAsync();

            // Initialize request argument(s)
            string resourceName = "customers/[CUSTOMER_ID]/videos/[VIDEO_ID]";
            // Make the request
            Video response = await videoServiceClient.GetVideoAsync(resourceName);

            // End snippet
        }
        /// <summary>Snippet for GetVideoAsync</summary>
        public async Task GetVideoResourceNamesAsync()
        {
            // Snippet: GetVideoAsync(VideoName, CallSettings)
            // Additional: GetVideoAsync(VideoName, CancellationToken)
            // Create client
            VideoServiceClient videoServiceClient = await VideoServiceClient.CreateAsync();

            // Initialize request argument(s)
            VideoName resourceName = VideoName.FromCustomerVideo("[CUSTOMER_ID]", "[VIDEO_ID]");
            // Make the request
            Video response = await videoServiceClient.GetVideoAsync(resourceName);

            // End snippet
        }
        // -----------------------------------------------------------------------
        // KEY SAMPLE CODE STARTS HERE
        // -----------------------------------------------------------------------
        private async Task DetectFaces(string subscriptionKey, string filePath)
        {
            _dataContext.IsWorking  = true;
            _dataContext.SourceUri  = null;
            _dataContext.ResultText = null;

            Helpers.Log(LogIdentifier, "Start face tracking");
            VideoServiceClient client = new VideoServiceClient(subscriptionKey);

            using (FileStream originalStream = new FileStream(filePath, FileMode.Open, FileAccess.Read))
            {
                byte[] bytes = new byte[originalStream.Length];
                await originalStream.ReadAsync(bytes, 0, (int)originalStream.Length);

                // Creates a video operation of face tracking
                Helpers.Log(LogIdentifier, "Start uploading video");
                Operation operation = await client.CreateOperationAsync(bytes, new FaceDetectionOperationSettings());

                Helpers.Log(LogIdentifier, "Uploading video done");

                // Starts querying service status
                OperationResult result = await client.GetOperationResultAsync(operation);

                while (result.Status != OperationStatus.Succeeded && result.Status != OperationStatus.Failed)
                {
                    Helpers.Log(LogIdentifier, "Server status: {0}, wait {1} seconds...", result.Status, QueryWaitTime.TotalSeconds);
                    await Task.Delay(QueryWaitTime);

                    result = await client.GetOperationResultAsync(operation);
                }
                Helpers.Log(LogIdentifier, "Finish processing with server status: " + result.Status);

                // Processing finished, checks result
                if (result.Status == OperationStatus.Succeeded)
                {
                    // Gets output JSON
                    Helpers.Log(LogIdentifier, "Downloading result done");
                    _dataContext.SourceUri       = new Uri(filePath);
                    _dataContext.ResultText      = Helpers.FormatJson <FaceTracking>(result.ProcessingResult);
                    _dataContext.FrameHighlights = GetHighlights(result.ProcessingResult).ToList();
                }
                else
                {
                    // Failed
                    Helpers.Log(LogIdentifier, "Fail reason: " + result.Message);
                }
                _dataContext.IsWorking = false;
            }
        }
        /// <summary>Snippet for GetVideoAsync</summary>
        public async Task GetVideoRequestObjectAsync()
        {
            // Snippet: GetVideoAsync(GetVideoRequest, CallSettings)
            // Additional: GetVideoAsync(GetVideoRequest, CancellationToken)
            // Create client
            VideoServiceClient videoServiceClient = await VideoServiceClient.CreateAsync();

            // Initialize request argument(s)
            GetVideoRequest request = new GetVideoRequest
            {
                ResourceNameAsVideoName = VideoName.FromCustomerVideo("[CUSTOMER]", "[VIDEO]"),
            };
            // Make the request
            Video response = await videoServiceClient.GetVideoAsync(request);

            // End snippet
        }
Ejemplo n.º 15
0
        private IEnumerable <FrameHighlight> DetectFaces(string subscriptionKey, string filePath)
        {
            Logable.WriteLog("Start face tracking");
            VideoServiceClient client = new VideoServiceClient(subscriptionKey);

            client.Timeout = TimeSpan.FromMinutes(10);

            using (FileStream originalStream = new FileStream(filePath, FileMode.Open, FileAccess.Read))
            {
                // Creates a video operation of face tracking
                Logable.WriteLog("Start uploading video");
                Operation operation = client.CreateOperationAsync(originalStream, new FaceDetectionOperationSettings()).Result;
                Logable.WriteLog("Uploading video done");

                // Starts querying service status
                OperationResult result = client.GetOperationResultAsync(operation).Result;
                while (result.Status != OperationStatus.Succeeded && result.Status != OperationStatus.Failed)
                {
                    Logable.WriteLog(string.Format("Server status: {0}, wait {1} seconds...", result.Status, QueryWaitTime.TotalSeconds));
                    Task.Delay(QueryWaitTime).Wait();
                    result = client.GetOperationResultAsync(operation).Result;
                }
                Logable.WriteLog("Finish processing with server status: " + result.Status);

                // Processing finished, checks result
                if (result.Status == OperationStatus.Succeeded)
                {
                    // Gets output JSON
                    Logable.WriteLog("Downloading result done");
                    Debug.WriteLine(JsonHelper.FormatJson <FaceTracking>(result.ProcessingResult));
                    var frameHighlights = GetHighlights(result.ProcessingResult).ToList();
                    return(frameHighlights);
                }
                else
                {
                    // Failed
                    Logable.WriteLog("Fail reason: " + result.Message);
                }
            }
            return(null);
        }
 /// <summary>
 /// VideoOperations constructor. Creates new objects for Emotion and Video APIs
 /// </summary>
 public VideoOperations()
 {
     _emotionServiceClient = new EmotionServiceClient("API_KEY_HERE");
     _videoServiceClient   = new VideoServiceClient("API_KEY_HERE");
 }
Ejemplo n.º 17
0
 public VideoInfoDataService()
 {
     Client = new VideoServiceClient(ConfigurationManager.AppSettings["VideoServiceClientEndpoint"]);
 }
Ejemplo n.º 18
0
 private VideoManager()
 {
     _videoServiceClient         = new VideoServiceClient(KeyManager.Instance.MsVideoKey);
     _videoServiceClient.Timeout = TimeSpan.FromMinutes(15);
 }