简体   繁体   中英

Stream/Encode videos using Azure Media Services and Node Js

I have an application that uses AWS Elastic Transcoder to encode videos uploaded to S3 buckets into HLS streaming formats using Lambda functions:

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

  • This lambda function converts the videos uploaded to the S3 bucket (now replaced with Azure Blob Storage) into streaming formats (HLS /.m3u8) with different video quality levels (380p, 480p, 720p, 1080p).
  • Currently, I am tasked with migrating all resources used in this application from AWS to Azure, and I am a novice with Azure Services.
  • From my research, I have identified Azure Media Services as an alternative to AWS Elastic Media Encoder.

I replaced the S3 bucket with Azure Blob Storage in order to upload my video files.

Please help with ANY of the following:

  1. Any examples of which method/function of Azure Media Services should I use for converting to HLS format in node.js?
  2. Should the videos be stored in Blob Storage or Media Services Assets?

I have loads of encoding samples written in Typescript and Node.js for Azure Media services up here: https://github.com/Azure-Samples/media-services-v3-node-tutorials/tree/main/VideoEncoding

I would recommend just using the Content Aware Encoding preset. You can move most of the code from these samples into an Azure Function easily.
There is an article showing how to do this here: https://learn.microsoft.com/en-us/azure/media-services/latest/integrate-azure-functions-do.net-how-to

To answer your second question - yes, the videos will be uploaded directly into blob containers. That is essentially what an AMS "Asset" is, but you first create the Asset through the AMS SDK, and then ask for the container URL to upload content to. That is easy to figure out in the sample above. Let me know if that helps.

To stream the content as HLS, you have to enable a Streaming Endpoint on your AMS account. Once that is done, you can then create a Streaming Locator on the Asset and use the HLS version of the URL.
That is also demonstrated in the streaming samples. Take a look at the basic upload, encode and stream sample to get a good feel for how that works. https://github.com/Azure-Samples/media-services-v3-node-tutorials/blob/main/Streaming/StreamFilesSample/index.ts

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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