Azure 视频索引器不从视频文件中检索情绪

Azure Video indexer not retrieve the emotion from video file

我正在尝试检索视频文件中人们的情绪。我正在使用 Azure 视频索引器工具来实现这一点。我在 MSDN 网站上阅读了 documentation 关于视频索引器输出文件的内容。但是我的情况是在输出 json.

中没有捕捉到任何情绪值

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

Video Indexer 根据语音和音频提示识别情绪。识别出的情绪可能是:快乐、悲伤、愤怒或恐惧。

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

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.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();
        }
    }
}

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

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

这里是 JSON 输出:

希望对您有所帮助。

我问过微软这个问题,他们说如果只识别出两种情绪是积极的和消极的,emotions.json 文件将是空的,相反,情绪可以在 "sentiments" 此端点的 index.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 的完整回复。