// -----------------------------------------------------------------------
        // KEY SAMPLE CODE STARTS HERE
        // -----------------------------------------------------------------------
        private async Task StabilizeVideo(string subscriptionKey, string originalFilePath)
        {
            _dataContext.IsWorking = true;
            _dataContext.SourceUri = null;
            _dataContext.ResultUri = null;

            Helpers.Log(LogIdentifier, "Start stabilizing");
            Microsoft.ProjectOxford.Video.VideoServiceClient client =
                new Microsoft.ProjectOxford.Video.VideoServiceClient(subscriptionKey);

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

                // Creates a video operation of video stabilization
                Helpers.Log(LogIdentifier, "Start uploading video");
                Operation operation = await client.CreateOperationAsync(bytes, OperationType.Stabilize);
                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)
                {
                    // Downloads generated video
                    string tmpFilePath = Path.GetTempFileName() + Path.GetExtension(originalFilePath);
                    Helpers.Log(LogIdentifier, "Start downloading result video");
                    using (Stream resultStream = await client.GetResultVideoAsync(result.ResourceLocation))
                    using (FileStream stream = new FileStream(tmpFilePath, FileMode.Create))
                    {
                        byte[] b = new byte[2048];
                        int length = 0;
                        while ((length = await resultStream.ReadAsync(b, 0, b.Length)) > 0)
                        {
                            await stream.WriteAsync(b, 0, length);
                        }
                    }
                    Helpers.Log(LogIdentifier, "Downloading result video done");

                    _dataContext.SourceUri = new Uri(originalFilePath);
                    _dataContext.ResultUri = new Uri(tmpFilePath);
                }
                else
                {
                    // Failed
                    Helpers.Log(LogIdentifier, "Fail reason: " + result.Message);
                }

                _dataContext.IsWorking = false;
            }
        }
        // -----------------------------------------------------------------------
        // 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");
            Microsoft.ProjectOxford.Video.VideoServiceClient client =
                new Microsoft.ProjectOxford.Video.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, OperationType.TrackFace);

                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;
            }
        }
        // -----------------------------------------------------------------------
        // 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");
            Microsoft.ProjectOxford.Video.VideoServiceClient client =
                new Microsoft.ProjectOxford.Video.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, OperationType.TrackFace);
                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;
            }
        }
        // -----------------------------------------------------------------------
        // KEY SAMPLE CODE STARTS HERE
        // -----------------------------------------------------------------------
        private async Task StabilizeVideo(string subscriptionKey, string originalFilePath)
        {
            _dataContext.IsWorking = true;
            _dataContext.SourceUri = null;
            _dataContext.ResultUri = null;

            Helpers.Log(LogIdentifier, "Start stabilizing");
            Microsoft.ProjectOxford.Video.VideoServiceClient client =
                new Microsoft.ProjectOxford.Video.VideoServiceClient(subscriptionKey);

            client.Timeout = TimeSpan.FromMinutes(10);

            using (FileStream originalStream = new FileStream(originalFilePath, FileMode.Open, FileAccess.Read))
            {
                // Creates a video operation of video stabilization
                Helpers.Log(LogIdentifier, "Start uploading video");
                Operation operation = await client.CreateOperationAsync(originalStream, new VideoStabilizationOperationSettings());

                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)
                {
                    // Downloads generated video
                    string tmpFilePath = Path.GetTempFileName() + Path.GetExtension(originalFilePath);
                    Helpers.Log(LogIdentifier, "Start downloading result video");
                    using (Stream resultStream = await client.GetResultVideoAsync(result.ResourceLocation))
                        using (FileStream stream = new FileStream(tmpFilePath, FileMode.Create))
                        {
                            byte[] b      = new byte[2048];
                            int    length = 0;
                            while ((length = await resultStream.ReadAsync(b, 0, b.Length)) > 0)
                            {
                                await stream.WriteAsync(b, 0, length);
                            }
                        }
                    Helpers.Log(LogIdentifier, "Downloading result video done");

                    _dataContext.SourceUri = new Uri(originalFilePath);
                    _dataContext.ResultUri = new Uri(tmpFilePath);
                }
                else
                {
                    // Failed
                    Helpers.Log(LogIdentifier, "Fail reason: " + result.Message);
                }

                _dataContext.IsWorking = false;
            }
        }
Beispiel #5
0
        // -----------------------------------------------------------------------
        // KEY SAMPLE CODE STARTS HERE
        // -----------------------------------------------------------------------
        private async Task GenerateVideoThumbnail(string subscriptionKey, string originalFilePath)
        {
            _dataContext.IsWorking = true;
            _dataContext.SourceUri = null;
            _dataContext.ResultUri = null;

            Helpers.Log(LogIdentifier, "Start generating thumbnail");
            Microsoft.ProjectOxford.Video.VideoServiceClient client =
                new Microsoft.ProjectOxford.Video.VideoServiceClient(subscriptionKey);

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

                VideoThumbnailOperationSettings vtOperationSettings = new VideoThumbnailOperationSettings
                {
                    OutputType = VideoThumbnailOperationSettings.OutputTypes.Video,
                    MaxMotionThumbnailDurationInSecs = 10,
                    FadeInFadeOut = true,
                    OutputAudio   = true
                };
                // Creates a video operation of video thumbnail
                Helpers.Log(LogIdentifier, "Start uploading video");
                Operation operation = await client.CreateOperationAsync(bytes, vtOperationSettings);

                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)
                {
                    // Downloads generated video
                    string tmpFilePath = Path.GetTempFileName() + Path.GetExtension(originalFilePath);
                    Helpers.Log(LogIdentifier, "Start downloading result video");
                    using (Stream resultStream = await client.GetResultVideoAsync(result.ResourceLocation))
                        using (FileStream stream = new FileStream(tmpFilePath, FileMode.Create))
                        {
                            byte[] b      = new byte[2048];
                            int    length = 0;
                            while ((length = await resultStream.ReadAsync(b, 0, b.Length)) > 0)
                            {
                                await stream.WriteAsync(b, 0, length);
                            }
                        }
                    Helpers.Log(LogIdentifier, "Downloading result video done");

                    _dataContext.SourceUri = new Uri(originalFilePath);
                    _dataContext.ResultUri = new Uri(tmpFilePath);
                }
                else
                {
                    // Failed
                    Helpers.Log(LogIdentifier, "Fail reason: " + result.Message);
                }

                _dataContext.IsWorking = false;
            }
        }
        // -----------------------------------------------------------------------
        // KEY SAMPLE CODE STARTS HERE
        // -----------------------------------------------------------------------
        private async Task GenerateVideoThumbnail(string subscriptionKey, string originalFilePath)
        {
            _dataContext.IsWorking = true;
            _dataContext.SourceUri = null;
            _dataContext.ResultUri = null;

            Helpers.Log(LogIdentifier, "Start generating thumbnail");
            Microsoft.ProjectOxford.Video.VideoServiceClient client =
                new Microsoft.ProjectOxford.Video.VideoServiceClient(subscriptionKey);

            client.Timeout = TimeSpan.FromMinutes(10);

            using (FileStream originalStream = new FileStream(originalFilePath, FileMode.Open, FileAccess.Read))
            {
                VideoThumbnailOperationSettings vtOperationSettings = new VideoThumbnailOperationSettings
                {
                    OutputType = VideoThumbnailOperationSettings.OutputTypes.Video,
                    MaxMotionThumbnailDurationInSecs = 10,
                    FadeInFadeOut = true,
                    OutputAudio = true
                };
                // Creates a video operation of video thumbnail
                Helpers.Log(LogIdentifier, "Start uploading video");
                Operation operation = await client.CreateOperationAsync(originalStream, vtOperationSettings);
                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)
                {
                    // Downloads generated video
                    string tmpFilePath = Path.GetTempFileName() + Path.GetExtension(originalFilePath);
                    Helpers.Log(LogIdentifier, "Start downloading result video");
                    using (Stream resultStream = await client.GetResultVideoAsync(result.ResourceLocation))
                    using (FileStream stream = new FileStream(tmpFilePath, FileMode.Create))
                    {
                        byte[] b = new byte[2048];
                        int length = 0;
                        while ((length = await resultStream.ReadAsync(b, 0, b.Length)) > 0)
                        {
                            await stream.WriteAsync(b, 0, length);
                        }
                    }
                    Helpers.Log(LogIdentifier, "Downloading result video done");

                    _dataContext.SourceUri = new Uri(originalFilePath);
                    _dataContext.ResultUri = new Uri(tmpFilePath);
                }
                else
                {
                    // Failed
                    Helpers.Log(LogIdentifier, "Fail reason: " + result.Message);
                }

                _dataContext.IsWorking = false;
            }
        }