需要使用 EC2 设计视频转码处理方面的帮助吗?
我目前正在 linode 服务器中对用户上传的视频进行转码,并使用 s3 来存储它们,但是,作为乐观主义者,我希望将转码转移到 Amazon EC2 以在必要时进行扩展,同时也可以从使用它中获得经验。这是我到目前为止的工作流程:
- 将视频直接上传到 s3,绕过 nginx/Rails 堆栈
- 使用视频 url 在 Amazon 简单队列服务中创建一个条目
- 查看是否有任何 EC2 实例正在运行,如果没有,则使用一个简单的 ruby 脚本启动一个实例脚本(我相信亚马逊允许启动脚本小于 6kb)
- Ruby 脚本连接到简单队列并运行 ffmpeg 命令来转码视频
- 脚本查看是否有任何其他队列并运行它们
- 当没有更多队列时关闭实例(可能会使其运行整小时,因为 Amazon 对 EC 实例运行的任何部分都按整小时收费)
显然,上述内容是基本的,并没有充分利用 EC2 的目的。我考虑过使用线程连接到队列并在同一 EC2 实例上运行新作业或创建其他 EC2 实例,其中启动脚本将运行 ruby 脚本。对于前者,我们需要根据 CPU 使用情况限制同一 EC2 中的作业数量。
后者似乎很浪费,但考虑到视频转码是CPU密集型的,也许同时使用两个ffmpeg是不可行的。我还考虑过 Amazon 自动扩展来创建新实例,但对我来说使用 Ruby 似乎更简单、更容易。
- 我的问题是有效地做到这一点的最佳方法是什么?
- 运行两个 ffmpeg 被认为是不好的做法吗? (假设视频大小平均约为 200mbs。)
- 考虑到 Ruby 线程的坏名声,使用 Ruby 线程是否是最佳选择?
- 我应该研究 EventMachine 来代替线程吗?
除非必要,否则我不想运行任何 EC2 实例,从实例中获得最大收益,但不要让我的用户等待太长时间才能完成视频转码。
基于这篇文章http://stream0.org/2009/10/h264-video-encoding-on-amazons.htmlhttp://stream0.org/2009/10/h264-video-encoding -on-amazons.html 高CPU、超大实例似乎是最好的选择。当然,我计划自己做一些测试,但我想在深入研究之前获得一些专家的意见。谢谢!
原来这是一篇文章,抱歉太长了。
I'm currently transcoding user uploaded videos in a linode server and using s3 to store them, but, being the optimist I am, I want to move the transcoding to Amazon EC2 to scale up if necessary, also to gain experience from using it. This is my work flow so far:
- Upload videos directly to s3, bypassing nginx/Rails stack
- Create an entry in Amazon simple queue service with video url
- See if any instances of EC2 are running, if not start one with a simple ruby script as startup script (I believe Amazon allows startup scripts under 6kb)
- Ruby script connects to simple queue and runs the ffmpeg command to transcode the video
- Script sees if there are any additional queues and runs them
- Shutdowns the instance when there are no more queues (might make it run the full hour since Amazon charges for full hour for any part of the hour EC instance is running)
Obviously the above is basic and doesn't use EC2 to its full purpose. I've thought about using threads to connect to queue and run new jobs on same EC2 instance or create additional EC2 instances, where the startup script will run the ruby script. With the former we'll need to limit number of jobs in same EC2 based on cpu usage.
The latter seems a waste, but given video transcoding is cpu intensive, maybe two ffmpegs at same time is not feasible. I've also thought about Amazon's auto scaling to create new instances, but using Ruby seems simpler and easier to me.
- My question is what is the best way to do this efficiently?
- Is running two ffmpegs considered bad practice? (Let's assume the video size will be around 200mbs average.)
- Is using Ruby threads optimal given the bad name they seem to have?
- Should I look into EventMachine in place of threads?
I don't want to run any EC2 instances unless necessary, get the maximum juice out of the instances, but not let my users wait too long for their videos to be transcoded.
Based on this article http://stream0.org/2009/10/h264-video-encoding-on-amazons.htmlhttp://stream0.org/2009/10/h264-video-encoding-on-amazons.html High-CPU, Extra Large Instance seems to be the best option. Of course I plan to do some of my own testing, but I wanted to get some expert opinion before I dive in. Thanks!
This turned out to be an essay, sorry for the length.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我今天在本地计算机上运行了一些测试,以测试多个 ffmpeg 进程的 CPU 使用情况。我在互联网上找到了以下命令,到目前为止它工作正常,它编码为 flv,减小了文件大小,而质量没有明显差异。我对 ffmpeg 几乎一无所知,所以也许这个命令完全是垃圾(如果是,请告诉我)。一个问题是它不支持 ffmpeg 中的线程,但我认为这可能是编解码器的问题。
我以半秒为间隔使用
top -b -d 0.5
来测量 CPU 使用情况,并执行grep Cpu
来获取相关信息。这些文件大小约为 150mbs,并使用相同的 ffmpeg 命令进行编码。在开始新的进程之前,我让该进程运行一会儿,这是我的结果:根据数据,一个接一个地转换视频在资源使用情况下非常糟糕,而且 ffmpeg 进程非常稳定,减去了几个峰值。 4 个 ffmpeg 实例,至少对于我的机器来说,似乎是最有效的。
我似乎在使用系统命令使用
Thread
或fork
并行运行两个 ffmpeg 进程时遇到问题。有人对此有什么想法吗?特别是如何使用 Ruby 脚本运行两个 ffmpeg 进程?
I ran some tests today on my local machine to test CPU usage with multiple ffmpeg processes. I found the following command on the Internet and so far it works decently, it encodes into flv, reduces file sizes without noticeable difference in quality. I know next to nothing about ffmpeg so maybe the command is total crap (please let me know if it is). One problem is it doesn't support threads in ffmpeg, but I think that might be a codec thing.
I used
top -b -d 0.5
in half second intervals to measure CPU usage and didgrep Cpu
to get relevant info. The files were about 150mbs in size and were encoded with the same ffmpeg command. I let the process run a little before starting a new one and here are my results:Based on the data, converting videos one by one is gross under usage of resources, also ffmpeg processes are pretty stable, minus couple spikes. 4 instances of ffmpeg, at least for my machine, seems to be most efficient.
I seem to be having trouble running two ffmpeg process parallel using
Thread
orfork
using system command.Does anyone have any thoughts on this? Especially how to run two ffmpeg process using a Ruby script?