简体   繁体   English

AWS 上的媒体转换

[英]Media conversion on AWS

I have an API written in nodeJS (/api/uploadS3) which is a PUT request and accepts a video file and a URL (AWS s3 URL in this case).我有一个用 nodeJS (/api/uploadS3) 编写的 API,它是一个 PUT 请求并接受一个视频文件和一个 URL(在这种情况下是 AWS s3 URL)。 Once called its task is to upload the file on the s3 URL.一旦被调用,它的任务就是在 s3 URL 上上传文件。

Now, users are uploading files to this node API in different formats (thanks to the different browsers recording videos in different formats) and I want to convert all these videos to mp4 and then store them in s3.现在,用户正在以不同的格式将文件上传到这个节点 API(由于不同的浏览器以不同的格式录制视频),我想将所有这些视频转换为 mp4,然后将它们存储在 s3 中。

I wanted to know what is the best approach to do this?我想知道这样做的最佳方法是什么?

I have 2 solutions till now到目前为止,我有 2 个解决方案

1. Convert on node server using ffmpeg - 1. 使用 ffmpeg 在节点服务器上转换 -

The issue with this is that ffmpeg can only execute a single operation at a time.问题在于 ffmpeg 一次只能执行一个操作。 And since I have only one server I will have to implement a queue for multiple requests which can lead to longer waiting times for users who are at the end of the queue.而且由于我只有一台服务器,我将不得不为多个请求实现一个队列,这可能会导致队列末尾的用户等待更长的时间。 Apart from that, I am worried that during any ongoing video conversion if my node's traffic handling capability will be affected.除此之外,我担心在任何正在进行的视频转换过程中,如果我的节点的流量处理能力会受到影响。

Can someone help me understand what will be the effect of other requests coming to my server while video conversion is going on?有人可以帮助我了解在进行视频转换时其他请求到达我的服务器的影响吗? How will it impact the RAM, CPU usage and speed of processing other requests?它将如何影响 RAM、CPU 使用率和处理其他请求的速度?

2. Using AWS lambda function - 2. 使用 AWS lambda 函数 -

To avoid load on my node server I was thinking of using an AWS lambda server where my node API will upload the file to S3 in the format provided by the user.为了避免我的节点服务器上的负载,我正在考虑使用 AWS lambda 服务器,我的节点 API 将以用户提供的格式将文件上传到 S3。 Once, done s3 will trigger a lambda function which can then take that s3 file and convert it into .mp4 using ffmpeg or AWS MediaConvert and once done it uploads the mp4 file to a new s3 path.一次,done s3 将触发一个 lambda 函数,然后该函数可以获取该 s3 文件并使用 ffmpeg 或 AWS MediaConvert 将其转换为 .mp4,一旦完成,它将 mp4 文件上传到新的 s3 路径。 Now I don't want the output path to be any s3 path but the path that was received by the node API in the first place.现在我不希望输出路径是任何 s3 路径,而是节点 API 首先接收到的路径。

Moreover, I want the user to wait while all this happens as I have to enable other UI features based on the success or error of this upload.此外,我希望用户等待所有这些发生,因为我必须根据此上传的成功或错误启用其他 UI 功能。

The query here is that, is it possible to do this using just a single API like /api/uploadS3 which --> uploads to s3 --> triggers lambda --> converts file --> uploads the mp4 version --> returns success or error.这里的查询是,是否可以仅使用像 /api/uploadS3 这样的单个 API 来执行此操作,它 --> 上传到 s3 --> 触发 lambda --> 转换文件 --> 上传 mp4 版本 --> 返回成功或错误。

Currently, if I upload to s3 the request ends then and there.目前,如果我上传到 s3,请求就会结束。 So is there a way to defer the API response until and unless all the operations have been completed?那么有没有办法将 API 响应推迟到并且除非所有操作都已完成?

Also, how will the lambda function access the path of the output s3 bucket which was passed to the node API?此外,lambda 函数将如何访问传递给节点 API 的输出 s3 存储桶的路径?

Any other better approach will be welcomed.欢迎任何其他更好的方法。

PS - the s3 path received by the node API is different for each user. PS - 节点 API 接收到的 s3 路径对于每个用户都是不同的。

Thanks for your post.谢谢你的帖子。 The output S3 bucket generates File Events when a new file arrives (ie, is delivered from AWS MediaConvert).当新文件到达(即从 AWS MediaConvert 交付)时,输出 S3 存储桶会生成文件事件。

This file event can trigger a second Lambda Function which can move the file elsewhere using any of the supported transfer protocols, re-try if necessary;此文件事件可以触发第二个 Lambda 函数,该函数可以使用任何支持的传输协议将文件移动到其他位置,必要时重试; log a status to AWS CloudWatch and/or AWS SNS;将状态记录到 AWS CloudWatch 和/或 AWS SNS; and then send a final API response based on success/completion of them move.然后根据他们移动的成功/完成发送最终的 API 响应。

AWS has a Step Functions feature which can maintain state across successive lambda functions, for automating simple workflows. AWS 有一个 Step Functions 功能,可以跨连续的 lambda 函数维护状态,用于自动化简单的工作流程。 This should work for what you want to accomplish.这应该适用于您想要完成的工作。 see https://docs.aws.amazon.com/step-functions/latest/dg/tutorial-creating-lambda-state-machine.html请参阅https://docs.aws.amazon.com/step-functions/latest/dg/tutorial-creating-lambda-state-machine.html

Note, any one lambda function has a 15 minute maximum runtime, so any one transcoding or file copy operation must complete within 15min.请注意,任何一个 lambda 函数的最大运行时间为 15 分钟,因此任何一项转码或文件复制操作都必须在 15 分钟内完成。 The alternative is to run on EC2.另一种方法是在 EC2 上运行。

I hope this helps you out!我希望这可以帮助你!

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

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