【问题标题】:How Can I automatically download a Transcript (VTT file) of a video using a Logic APP?如何使用 Logic APP 自动下载视频的转录本(VTT 文件)?
【发布时间】:2020-03-23 19:46:13
【问题描述】:

我使用逻辑应用程序将几个视频索引到 videoindexer.ai。但我想知道,有没有办法使用 Logic 应用程序下载 VTT 格式的脚本文件并将它们放在 Onedrive 文件夹中?没有看到有关如何通过逻辑应用程序完成此操作的文档。

Azure 函数:

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");
        }
    }
}

【问题讨论】:

  • LogicApps 的视频索引器有一个连接器,它有一个“获取字幕”操作:docs.microsoft.com/en-us/connectors/videoindexer-v2/…
  • @NicolasR 我想我成功了,但我有一个问题。当它下载 VTT 文件到“输出”文件夹时,为什么文件名的数字是:27352-Caprion.vtt?我们如何使文件名与索引视频时相同?例如,如果我们为名为“test.mp4”的视频编制索引,则 VTT 应为“test-Caption.vtt”

标签: azure azure-functions azure-logic-apps azure-cognitive-services


【解决方案1】:

我通过执行以下操作做了一个快速演示(并且它正在工作):

  • Lo​​gicApp #1 用于视频上传:触发一个 OneDrive“输入”文件夹,并将视频上传到 Video Indexer 进行索引
  • 用于结果收集的 LogicApp #2:将通过索引调用的 http 触发器,然后获取标题并在 OneDrive“输出”文件夹中创建一个文件。

诀窍在于,如视频索引器的Upload Video 操作中所述(请参阅here),您可以添加回调:

如您所见,此回调将在查询字符串中添加视频的 id。

因此,在您的 LogicApp #2 中,在视频索引器的 Get Video Captions 操作上使用此 id

获取id的表达式为triggerOutputs()['queries']['id']

然后你只需要复制到你的输出:

我使用了基于视频 ID 的命名:concat(triggerOutputs()['queries']['id'],'-Captions.vtt')

而且它有效:

为了获得更好的实现,您应该添加一个检查以过滤由于上述面部检测而导致的回调。这可以通过过滤“状态”查询字符串值来完成。

这是我的 LogicApp #2 的代码(带有一些隐藏字段):

{
    "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": { ... }
            }
        }
    }
}

顺便说一句,您的用例几乎在 Microsoft 的一篇博文中有所描述(这里他们获取的是索引,而不是标题):https://azure.microsoft.com/en-us/blog/logic-apps-flow-connectors-will-make-automating-video-indexer-simpler-than-ever/

【讨论】:

  • 能否展开“收到 HTTP 请求时”选项卡?我想看看你在 HTTP POST URL 中添加了什么。谢谢。
  • 我想我成功了,但我有一个问题。当它下载 VTT 文件到“输出”文件夹时,为什么文件名的数字是:27352-Caprion.vtt?我们如何使文件名与索引视频时相同?例如,如果我们为名为“test.mp4”的视频编制索引,则 VTT 应为“test-Caption.vtt”
  • 我在 HTTP 触发器中没有添加任何内容,因为来自视频索引器的回调会自动添加所需的字段(我无法为此回调设置有效负载)。对于输出文件名,你可以放你想要的,它在“创建文件”操作中,字段“文件名”。如果你想使用你的视频名称,你必须在之前添加一个步骤“获取视频索引”来获取这个字段docs.microsoft.com/en-us/connectors/videoindexer-v2/…
  • 能否告诉我,一旦 VTT 文件位于“输出”文件夹中,我该如何获取它们,并将这些文件作为 Outlook 电子邮件附件发送给特定的人?因此,每当“输出”文件夹中有一个新的 VTT 文件时,这些文件就会作为附件发送给那个人。
  • 手动还是自动?
【解决方案2】:

直接使用逻辑应用连接器我认为不可能,但您可以直接使用 REST API 获取它。执行一个请求,并根据响应,添加一个新任务,它将是 onedrive 连接器:

https://docs.microsoft.com/en-us/azure/connectors/connectors-native-http

https://docs.microsoft.com/en-us/connectors/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 Functions 会很棒):

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

您需要将响应传递给工作流程中的 Onedrive 任​​务。

https://api-portal.videoindexer.ai/docs/services/operations/operations/Get-video-captions

【讨论】:

  • 您好,我部分理解您在说什么,但我不理解 ECHO 示例,因为我不熟悉 echo。这一切都可以在 .NET C# 中完成吗? .另外,“添加新任务”到底是什么意思是逻辑应用程序的这一部分?
  • 我有一个问题。我已获取您提供的示例代码并将其插入到由 HTTP 触发的 Azure 函数中。请您看一下该功能,让我知道它是否准确或需要更改什么?谢谢。
  • 您需要插入订阅密钥/帐户ID等...功能正确,因为它来自微软的官方文档。你最好从 curl 开始(让它工作)然后切换到 c# 代码
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-11-28
  • 1970-01-01
  • 2017-09-05
  • 1970-01-01
相关资源
最近更新 更多