繁体   English   中英

使用 Azure 媒体服务和 Node Js 流式传输/编码视频

[英]Stream/Encode videos using Azure Media Services and Node Js

我有一个应用程序使用 Lambda 函数使用 AWS Elastic Transcoder 将上传到 S3 存储桶的视频编码为 HLS 流格式:

 var AWS = require('aws-sdk'); var eltr = new AWS.ElasticTranscoder({ apiVersion: '2012–09–25', region: 'ap-south-1' }); exports.handler = function (event, context) { var key = event.Records[0].s3.object.key; let srcKey = decodeURIComponent(key.replace(/\+/g, " ")); //the object may have spaces let newKey = key.split('.')[0].replace('protected-video-input/', '') eltr.createJob({ PipelineId: pipelineId, OutputKeyPrefix: 'protected-video-output/' + newKey + '/', Input: { Key: srcKey, FrameRate: 'auto', Resolution: 'auto', AspectRatio: 'auto', Interlaced: 'auto', Container: 'auto' }, Outputs: [ { Key: newKey + '_64k_audio', PresetId: '1351620000001-200071', SegmentDuration: "10" }, { Key: newKey + '_360', PresetId: '1593703351160-e26c00', SegmentDuration: "10" }, { Key: newKey + '_480', PresetId: '1593703253941-idqn5g', SegmentDuration: "10" }, { Key: newKey + '_720', PresetId: '1593702727032-5klbqi', SegmentDuration: "10" }, { Key: newKey + '_1080', PresetId: '1593702631383-73kckt', SegmentDuration: "10" }, { Key: newKey + '.mp4', PresetId: '1351620000001-000020' }, ], Playlists: [ { Format: 'HLSv3', Name: newKey, OutputKeys: [ newKey + '_64k_audio', newKey + '_360', newKey + '_480', newKey + '_720', newKey + '_1080' ] } ] }); };

  • 这个 lambda function 将上传到 S3 存储桶(现在替换为 Azure Blob 存储)的视频转换为具有不同视频质量级别(380p、480p、720p、1080p)的流格式(HLS /.m3u8)。
  • 目前,我的任务是将此应用程序中使用的所有资源从 AWS 迁移到 Azure,我是 Azure 服务的新手。
  • 根据我的研究,我已经确定 Azure 媒体服务可以替代 AWS Elastic Media Encoder。

为了上传我的视频文件,我用 Azure Blob 存储替换了 S3 存储桶。

请帮助解决以下任何问题:

  1. 我应该使用 Azure 媒体服务的哪种方法/功能来转换为 node.js 中的 HLS 格式?
  2. 视频应该存储在 Blob 存储还是媒体服务资产中?

我在 Typescript 和 Node.js 中为 Azure 媒体服务编写了大量编码样本: https://github.com/Azure-Samples/media-services-v3-node-tutorials/tree/main/VideoEncoding

我建议只使用 Content Aware Encoding 预设。 您可以轻松地将这些示例中的大部分代码移动到 Azure Function 中。
这里有一篇文章展示了如何执行此操作: https://learn.microsoft.com/en-us/azure/media-services/latest/integrate-azure-functions-do.net-how-to

回答你的第二个问题 - 是的,视频将直接上传到 blob 容器中。 这本质上就是 AMS“资产”,但您首先通过 AMS SDK 创建资产,然后请求容器 URL 将内容上传到。 这在上面的示例中很容易弄清楚。 让我知道是否有帮助。

要将 stream 内容作为 HLS,您必须在您的 AMS 帐户上启用流媒体端点。 完成后,您就可以在资产上创建一个 Streaming Locator 并使用 URL 的 HLS 版本。
流式示例中也证明了这一点。 查看基本的上传、编码和 stream 示例,了解其工作原理。 https://github.com/Azure-Samples/media-services-v3-node-tutorials/blob/main/Streaming/StreamFilesSample/index.ts

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM