【问题标题】:Azure Video indexer not retrieve the emotion from video fileAzure 视频索引器无法从视频文件中检索情感
【发布时间】:2019-11-22 03:01:18
【问题描述】:

我正在尝试检索视频文件中人们的情感。我正在使用 Azure 视频索引器工具来实现这一点。我在 MSDN 网站上阅读了关于视频索引器输出文件的 documentation。但我的情况是输出 json 中没有捕获任何情感值。

是否需要任何特殊的输入参数来检索它。

【问题讨论】:

    标签: c# azure ml.net face-api video-indexer


    【解决方案1】:

    视频索引器根据语音和音频提示识别情绪。识别出的情绪可能是:喜悦、悲伤、愤怒或恐惧。

    这是我为它编写的一段代码:

    using Newtonsoft.Json;
    using System;
    using System.Collections.Generic;
    using System.Diagnostics;
    using System.IO;
    using System.Linq;
    using System.Net.Http;
    using System.Text;
    using System.Threading;
    using System.Threading.Tasks;
    
    namespace VideoIndexer
    {
        class Program
        {
            static void Main(string[] args)
            {
                Console.WriteLine("Starting process");
                var apiUrl = "https://api.videoindexer.ai";
                var accountId = "xxxxxxxxxxxxxxxxxxxxxxxxxx";
                var location = "trial";
                var apiKey = "xxxxxxxxxx";
    
                System.Net.ServicePointManager.SecurityProtocol = System.Net.ServicePointManager.SecurityProtocol | System.Net.SecurityProtocolType.Tls12;
    
                // create the http client
                var handler = new HttpClientHandler();
                handler.AllowAutoRedirect = false;
                var client = new HttpClient(handler);
                client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", apiKey);
    
                // obtain account access token
                var accountAccessTokenRequestResult = client.GetAsync($"{apiUrl}/auth/{location}/Accounts/{accountId}/AccessToken?allowEdit=true").Result;
                var accountAccessToken = accountAccessTokenRequestResult.Content.ReadAsStringAsync().Result.Replace("\"", "");
    
                client.DefaultRequestHeaders.Remove("Ocp-Apim-Subscription-Key");
    
                // upload a video
                var content = new MultipartFormDataContent();
                Debug.WriteLine("Uploading...");
                // get the video from URL
                //var videoUrl = "https://www.videvo.net/video/young-boy-playing-with-balloons-16/380264/"; // replace with the video URL
    
                // as an alternative to specifying video URL, you can upload a file.
                // remove the videoUrl parameter from the query string below and add the following lines:
                FileStream video = File.OpenRead(@"C:\MV\LAB\VideoIndexer\1.mp4");
                byte[] buffer = new byte[video.Length];
                video.Read(buffer, 0, buffer.Length);
                content.Add(new ByteArrayContent(buffer));
    
                var uploadRequestResult = client.PostAsync($"{apiUrl}/{location}/Accounts/{accountId}/Videos?accessToken={accountAccessToken}&name=some_name&description=some_description&privacy=private&partition=some_partition", content).Result;
                var uploadResult = uploadRequestResult.Content.ReadAsStringAsync().Result;
    
                // get the video id from the upload result
                var videoId = JsonConvert.DeserializeObject<dynamic>(uploadResult)["id"];
                Console.WriteLine("Uploaded");
                Console.WriteLine("Video ID: " + videoId);
    
                // obtain video access token            
                client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", apiKey);
                var videoTokenRequestResult = client.GetAsync($"{apiUrl}/auth/{location}/Accounts/{accountId}/Videos/{videoId}/AccessToken?allowEdit=true").Result;
                var videoAccessToken = videoTokenRequestResult.Content.ReadAsStringAsync().Result.Replace("\"", "");
    
                client.DefaultRequestHeaders.Remove("Ocp-Apim-Subscription-Key");
    
                // wait for the video index to finish
                while (true)
                {
                    Thread.Sleep(10000);
    
                    var videoGetIndexRequestResult = client.GetAsync($"{apiUrl}/{location}/Accounts/{accountId}/Videos/{videoId}/Index?accessToken={videoAccessToken}&language=English").Result;
                    var videoGetIndexResult = videoGetIndexRequestResult.Content.ReadAsStringAsync().Result;
    
                    var processingState = JsonConvert.DeserializeObject<dynamic>(videoGetIndexResult)["state"];
    
                    Debug.WriteLine("");
                    Debug.WriteLine("State:");
                    //Debug.WriteLine(processingState);
    
                    // job is finished
                    if (processingState != "Uploaded" && processingState != "Processing")
                    {
                        Console.WriteLine("");
                        Console.WriteLine("Full JSON:");
                        Console.WriteLine(videoGetIndexResult);
                        break;
                    }
                }
    
                // search for the video
                var searchRequestResult = client.GetAsync($"{apiUrl}/{location}/Accounts/{accountId}/Videos/Search?accessToken={accountAccessToken}&id={videoId}").Result;
                var searchResult = searchRequestResult.Content.ReadAsStringAsync().Result;
                Debug.WriteLine("");
                Debug.WriteLine("Search:");
                Console.WriteLine(searchResult);
    
                // get insights widget url
                var insightsWidgetRequestResult = client.GetAsync($"{apiUrl}/{location}/Accounts/{accountId}/Videos/{videoId}/InsightsWidget?accessToken={videoAccessToken}&widgetType=Keywords&allowEdit=true").Result;
                var insightsWidgetLink = insightsWidgetRequestResult.Headers.Location;
                Debug.WriteLine("Insights Widget url:");
                Console.WriteLine(insightsWidgetLink);
    
                // get player widget url
                var playerWidgetRequestResult = client.GetAsync($"{apiUrl}/{location}/Accounts/{accountId}/Videos/{videoId}/PlayerWidget?accessToken={videoAccessToken}").Result;
                var playerWidgetLink = playerWidgetRequestResult.Headers.Location;
                Debug.WriteLine("");
                Debug.WriteLine("Player Widget url:");
                Console.WriteLine(playerWidgetLink);
    
                Console.ReadLine();
            }
        }
    }
    

    这是我下载的视频的链接并将其输入视频索引器

    https://www.youtube.com/watch?v=LjyBs6vb0Jk

    这是 JSON 输出:

    希望对你有帮助。

    【讨论】:

      【解决方案2】:

      我向微软询问了这个问题,他们说如果识别出的只有两种情绪是正面和负面的,那么emotions.json 文件将为空,相反,情绪可以在索引的“情绪”对象中找到此端点的 .json 文件:

      https://api.videoindexer.ai/{location}/Accounts/{accountId}/Projects/{projectId}/Index[?language][&reTranslate][&accessToken]

      查看 json 对象中的 summarizedInsights.sentiments 条目: https://api-portal.videoindexer.ai/docs/services/Operations/operations/Get-Video-Index

      请参阅https://api-portal.videoindexer.ai/issues/5ee5037bbe45742290624d0c 了解 MS 的完整回复。

      【讨论】:

        猜你喜欢
        • 2022-07-22
        • 2018-10-17
        • 2021-10-22
        • 2016-08-30
        • 1970-01-01
        • 2020-01-09
        • 2013-07-02
        • 1970-01-01
        • 2018-04-21
        相关资源
        最近更新 更多