我有一个应用程序,它使用 AWS Elastic Transcoder 通过 Lambda 函数将上传到 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 函数将上传到 S3 存储桶(现已替换为 Azure Blob 存储)的视频转换为具有不同视频质量级别(380p、480p、720p、1080p)的流格式 (HLS/.m3u8)。
- 目前,我的任务是将此应用程序中使用的所有资源从 AWS 迁移到 Azure,而且我是 Azure 服务的新手。
- 根据我的研究,我确定 Azure 媒体服务是 AWS Elastic Media Encoder 的替代方案。
为了上传视频文件,我将 S3 存储桶替换为 Azure Blob 存储。
请帮助解决以下任何问题:
- 有哪些示例可以说明我应该使用 Azure 媒体服务的哪种方法/函数在 Node js 中转换为 HLS 格式?
- 视频应该存储在 Blob 存储还是媒体服务 Assets 中?
最佳答案
我在这里有大量用 Typescript 和 Node.js 编写的用于 Azure 媒体服务的编码示例: https://github.com/Azure-Samples/media-services-v3-node-tutorials/tree/main/VideoEncoding
我建议仅使用内容感知编码预设。您可以轻松地将这些示例中的大部分代码移至 Azure Function 中。
这里有一篇文章展示了如何执行此操作:
https://learn.microsoft.com/en-us/azure/media-services/latest/integrate-azure-functions-dotnet-how-to
回答你的第二个问题 - 是的,视频将直接上传到 Blob 容器中。这本质上就是 AMS“ Assets ”,但您首先通过 AMS SDK 创建 Assets ,然后请求容器 URL 以将内容上传到其中。从上面的示例中很容易看出这一点。如果有帮助请告诉我。
要将内容作为 HLS 进行流式传输,您必须在 AMS 帐户上启用流式传输端点。完成后,您可以在 Assets 上创建流定位器并使用 URL 的 HLS 版本。
流媒体样本也证明了这一点。查看基本的上传、编码和流式传输示例,以更好地了解其工作原理。
https://github.com/Azure-Samples/media-services-v3-node-tutorials/blob/main/Streaming/StreamFilesSample/index.ts
关于javascript - 使用 Azure 媒体服务和 Node Js 流式传输/编码视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74882298/