Azure 如何使用Logic应用程序自动下载视频的成绩单(VTT文件)?
我使用逻辑应用程序将一些视频编入videoindexer.ai。但我想知道,有没有一种方法可以使用Logic app下载VTT格式的成绩单文件,并将其放在Onedrive文件夹中?没有看到关于如何通过逻辑应用程序实现这一点的文档 Azure功能:Azure 如何使用Logic应用程序自动下载视频的成绩单(VTT文件)?,azure,azure-functions,azure-logic-apps,azure-cognitive-services,Azure,Azure Functions,Azure Logic Apps,Azure Cognitive Services,我使用逻辑应用程序将一些视频编入videoindexer.ai。但我想知道,有没有一种方法可以使用Logic app下载VTT格式的成绩单文件,并将其放在Onedrive文件夹中?没有看到关于如何通过逻辑应用程序实现这一点的文档 Azure功能: using System; using System.IO; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; using Microsoft.Azure.WebJobs; us
using System;
using System.IO;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using System.Net.Http.Headers;
using System.Text;
using System.Net.Http;
using System.Web;
namespace TranscriptVtt
{
public static class Function1
{
[FunctionName("Function1")]
public static async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
ILogger log)
{
var client = new HttpClient();
var queryString = HttpUtility.ParseQueryString(string.Empty);
// Request headers
client.DefaultRequestHeaders.Add("x-ms-client-request-id", "");
client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", "{subscription key}");
// Request parameters
queryString["indexId"] = "{string}";
queryString["format"] = "Vtt";
queryString["language"] = "{string}";
queryString["accessToken"] = "{string}";
var uri = "https://api.videoindexer.ai/{location}/Accounts/{accountId}/Videos/{videoId}/Captions?" + queryString;
var response = await client.GetAsync(uri);
return new OkObjectResult("VTT Processed");
}
}
}
使用系统;
使用System.IO;
使用System.Threading.Tasks;
使用Microsoft.AspNetCore.Mvc;
使用Microsoft.Azure.WebJobs;
使用Microsoft.Azure.WebJobs.Extensions.Http;
使用Microsoft.AspNetCore.Http;
使用Microsoft.Extensions.Logging;
使用Newtonsoft.Json;
使用System.Net.Http.Header;
使用系统文本;
使用System.Net.Http;
使用System.Web;
名称空间转录本
{
公共静态类函数1
{
[功能名称(“功能1”)]
公共静态异步任务运行(
[HttpTrigger(AuthorizationLevel.Function,“get”,“post”,Route=null)]HttpRequest请求,
ILogger日志)
{
var client=新的HttpClient();
var queryString=HttpUtility.ParseQueryString(string.Empty);
//请求头
client.DefaultRequestHeaders.Add(“x-ms-client-request-id”,”);
Add(“Ocp Apim订阅密钥”,“{Subscription Key}”);
//请求参数
queryString[“indexId”]=“{string}”;
查询字符串[“格式”]=“Vtt”;
查询字符串[“语言”]=“{string}”;
queryString[“accessToken”]=“{string}”;
var uri=”https://api.videoindexer.ai/{location}/Accounts/{accountId}/Videos/{videoId}/字幕?+queryString;
var response=await client.GetAsync(uri);
返回新的OkObjectResult(“VTT处理”);
}
}
}
直接使用Logic App connector我认为这是不可能的,但您可以直接使用REST API获得它。执行请求,并根据响应添加新任务,该任务将是onedrive连接器:
REST API:
curl -v -X GET "https://api.videoindexer.ai/{location}/Accounts/{accountId}/Videos/{videoId}/Captions?indexId={string}&format=Vtt&language={string}&accessToken={string}"
-H "x-ms-client-request-id: "
-H "Ocp-Apim-Subscription-Key: {subscription key}"
--data-ascii "{body}"
编辑:
等价的int c#。您需要在web服务器上使用它(Azure功能将非常好):
您需要在工作流中将响应传递给Onedrive任务
我做了一个快速演示,方法如下(它正在工作):
- 用于视频上传的LogicApp#1:触发一个OneDrive“输入”文件夹,并将视频上传到视频索引器进行索引
- LogicApp#2用于结果收集:http触发器将通过索引调用,然后获取标题并在OneDrive“输出”文件夹中创建文件
上载视频
操作(请参阅)中所述,您可以添加回调:
如您所见,此回调将在查询字符串中添加视频的id
因此,在LogicApp#2中,在视频索引器的获取视频字幕
操作上使用此id
:
获取id的表达式是triggerOutputs()['queries']['id']
然后您只需复制到输出:
我使用了基于视频id的命名:concat(triggerOutputs()['queries']['id'],'-Captions.vtt')
它的工作原理是:
为了获得更好的实现,您应该添加一个检查来过滤由于上面提到的面部检测而产生的回调。这可以通过过滤“状态”查询字符串值来完成
以下是我的LogicApp#2的代码(带有一些隐藏字段):
顺便说一下,您的用例几乎在Microsoft的一篇博文中得到了描述(这里他们得到的是索引,而不是标题):您好,我部分理解您的意思,但我不理解ECHO示例,因为我不熟悉ECHO。这些都可以在.NETC#中完成吗。另外,你所说的“添加新任务”到底是什么意思?这是Logic应用程序的一部分吗?我有一个问题。我已经获取了您提供的示例代码,并将其插入到由HTTP触发的Azure函数中。请你看一下这个函数,告诉我它是否准确,或者有什么需要更改的吗?谢谢。您需要插入订阅密钥/帐户id等。。。该函数是正确的,因为它来自微软的官方文档。你最好从卷曲开始(让它工作),然后切换到c代码LogicApps的视频索引器有一个连接器,它有一个“获取字幕”操作:@NicolasR我想我可以工作了,但我有一个问题。当它将VTT文件下载到“output”文件夹中时,为什么文件名的数字是:27352-Caprion.VTT?我们如何使文件名与索引视频时的文件名相同?例如,如果我们索引了一个名为“test.mp4”的视频,那么VTT应该是“test Caption.VTT”,请展开“收到HTTP请求时”选项卡?我想看看您在HTTP POST URL中添加了什么。谢谢你。我想我成功了,但我有一个问题。当它将VTT文件下载到“output”文件夹中时,为什么文件名的数字是:27352-Caprion.VTT?我们如何使文件名与索引视频时的文件名相同?例如,如果我们索引了一个名为“test.mp4”的视频,那么VTT应该是“test Caption.VTT”,我没有在HTTP触发器中添加任何内容,因为来自视频索引器的回调会自动添加所需的字段(并且我无法设置此回调的有效负载)。对于输出文件名,您可以将所需内容放入“创建文件”操作的“文件名”字段中。如果您想使用您的视频名称,您必须在获取此字段之前添加一个步骤“获取视频索引”。请告诉我,一旦VTT文件位于“输出”文件夹中,我如何获取这些文件,并将这些文件作为outlook电子邮件附件发送给特定的人?因此,无论何时,“输出”文件夹中有新的VTT文件,这些文件都会作为附件发送给此人。是手动发送,还是自动发送?
using System;
using System.Net.Http.Headers;
using System.Text;
using System.Net.Http;
using System.Web;
namespace CSHttpClientSample
{
static class Program
{
static void Main()
{
MakeRequest();
Console.WriteLine("Hit ENTER to exit...");
Console.ReadLine();
}
static async void MakeRequest()
{
var client = new HttpClient();
var queryString = HttpUtility.ParseQueryString(string.Empty);
// Request headers
client.DefaultRequestHeaders.Add("x-ms-client-request-id", "");
client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", "{subscription key}");
// Request parameters
queryString["indexId"] = "{string}";
queryString["format"] = "Vtt";
queryString["language"] = "{string}";
queryString["accessToken"] = "{string}";
var uri = "https://api.videoindexer.ai/{location}/Accounts/{accountId}/Videos/{videoId}/Captions?" + queryString;
var response = await client.GetAsync(uri);
}
}
}
{
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"actions": {
"Create_file": {
"inputs": {
"body": "@body('Get_Video_Captions')",
"host": {
"connection": {
"name": "@parameters('$connections')['onedrive']['connectionId']"
}
},
"method": "post",
"path": "/datasets/default/files",
"queries": {
"folderPath": "/LogicAppsDemo/VideoIndexing/Output",
"name": "@{concat(triggerOutputs()['queries']['id'],'-Captions.vtt')}"
}
},
"runAfter": {
"Get_Video_Captions": [
"Succeeded"
]
},
"runtimeConfiguration": {
"contentTransfer": {
"transferMode": "Chunked"
}
},
"type": "ApiConnection"
},
"Get_Account_Access_Token": {
"inputs": {
"host": {
"connection": {
"name": "@parameters('$connections')['videoindexer-v2']['connectionId']"
}
},
"method": "get",
"path": "/auth/@{encodeURIComponent('##VI-REGION##')}/Accounts/@{encodeURIComponent('##VI-ACCOUNT##')}/AccessToken",
"queries": {
"allowEdit": false
}
},
"runAfter": {},
"type": "ApiConnection"
},
"Get_Video_Captions": {
"inputs": {
"host": {
"connection": {
"name": "@parameters('$connections')['videoindexer-v2']['connectionId']"
}
},
"method": "get",
"path": "/@{encodeURIComponent('##VI-REGION##')}/Accounts/@{encodeURIComponent('##VI-ACCOUNT##')}/Videos/@{encodeURIComponent(triggerOutputs()['queries']['id'])}/Captions",
"queries": {
"accessToken": "@body('Get_Account_Access_Token')",
"format": "vtt",
"language": "English"
}
},
"runAfter": {
"Get_Account_Access_Token": [
"Succeeded"
]
},
"type": "ApiConnection"
}
},
"contentVersion": "1.0.0.0",
"outputs": {},
"parameters": {
"$connections": {
"defaultValue": {},
"type": "Object"
}
},
"triggers": {
"manual": {
"inputs": {
"method": "POST",
"schema": {}
},
"kind": "Http",
"type": "Request"
}
}
},
"parameters": {
"$connections": {
"value": {
"onedrive": { ... },
"videoindexer-v2": { ... }
}
}
}
}