javascript 使用Azure Media Services和Node J对视频进行流式传输/编码

ryoqjall  于 2022-12-28  发布在  Java
关注(0)|答案(1)|浏览(130)

我有一个应用程序,使用AWS弹性转码器将上传到S3桶的视频编码为HLS流格式,使用Lambda函数:

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存储所取代)的视频转换为具有不同视频质量级别(380 p、480 p、720 p、1080 p)的流格式(HLS / .m3u8)。
  • 目前,我的任务是将此应用程序中使用的所有资源从AWS迁移到Azure,我是Azure服务的新手。
  • 根据我的研究,我已经确定Azure媒体服务是AWS弹性媒体编码器的替代方案。

为了上传我的视频文件,我把S3桶换成了Azure Blob存储。
请帮助解决以下任何问题:
1.我应该使用Azure媒体服务的哪种方法/函数在node js中转换为HLS格式?
1.视频应该存储在Blob存储还是Media Services资产中?

nsc4cvqm

nsc4cvqm1#

我在这里有大量用Typescript和Node.js编写的用于Azure媒体服务的编码示例:https://github.com/Azure-Samples/media-services-v3-node-tutorials/tree/main/VideoEncoding
我建议只使用内容感知编码预设。你可以很容易地将这些示例中的大部分代码移到Azure函数中。
这里有一篇文章展示了如何做到这一点:https://learn.microsoft.com/en-us/azure/media-services/latest/integrate-azure-functions-dotnet-how-to
回答你的第二个问题--是的,视频将直接上传到blob容器中。这就是AMS“资产”的本质,但你首先通过AMS SDK创建资产,然后询问容器URL以上传内容。这在上面的示例中很容易理解。如果有帮助,请告诉我。
要将内容作为HLS进行流式传输,您必须在AMS帐户上启用流式端点。完成此操作后,您可以在资产上创建流式定位器并使用HLS版本的URL。
流媒体示例中也演示了这一点。请看一下基本的上传、编码和流媒体示例,以便更好地了解其工作原理。https://github.com/Azure-Samples/media-services-v3-node-tutorials/blob/main/Streaming/StreamFilesSample/index.ts

相关问题