Node.js异步视频转换速度慢
我写了一个小网站/服务,它可以从网站(当前是 Youtube)下载视频,并将其即时转换为 mp3 文件,并将该文件作为响应发送回来。
例如,当您请求 http://localhost 时: 8000/v=http://www.youtube.com/watch?v=HhoewflkQu0,那么它将下载该视频并响应以 MP3 编码的音频层。
这一切都运行得很好,我的问题是这非常慢,我不明白为什么。
简化后的脚本行为如下:
下载视频并将其写入 ffmpeg 的标准输入,标准输出转到响应。 视频(MP4、FLV)-> FFMPEG-> MP3
我使用curl 来计算脚本的速度:
$ curl http://localhost:8000/v=http://www.youtube.com/watch?v=HhoewflkQu0
我只得到大约5-10k。
那么为什么这么慢呢?
- 我下载视频的服务器速度很慢。
- 转换速度很慢(因为 CPU 速度很慢)。
- Node.js之间的数据传输-> FFMPEG 速度很慢。
我尝试在普通的下载管理器中下载视频,得到了大约320k,这是我的正常下载速度,所以第一点不是瓶颈。
对于第 2 点和第 3 点,我尝试将本地文件写入标准输入,并且我得到了大约 600k,所以这也不是。
那么为什么我的脚本这么慢,我能做些什么来让它更快呢?
https://gist.github.com/1304637
提前致谢。
I wrote a little website/service, which can download a video from a website (currently Youtube) and converts it on the fly to an mp3 file and sends this file back as the response.
For example, you when you request http://localhost:8000/v=http://www.youtube.com/watch?v=HhoewflkQu0, then it will download this video and response the audio layer encoded in MP3.
This all works very well, my problem is that this is very slow and I can't figure out why.
Simplified the script behaves like this:
Download the video and write it to the stdin of ffmpeg, and the stdout goes to the response.
Video (MP4, FLV) -> FFMPEG -> MP3
I used curl to figure out how fast the script is:
$ curl http://localhost:8000/v=http://www.youtube.com/watch?v=HhoewflkQu0
I get only about 5-10k.
So why is this so slow?
- The server, from which I am downloading the video is slow.
- The conversion is slow (because of a slow CPU).
- The data transfer between node.js -> FFMPEG is slow.
I tried to download the video in a normal download manager, and i got about 320k, which is my normal download speed, so the first point isn't the bottleneck.
To point 2 and 3, I tried to write a local file to the stdin, and I got about 600k so that isn't it either.
So why is my script so slow, and what can I do to make it faster?
https://gist.github.com/1304637
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我遇到了这个问题。我更新到最新版本的 ffmpeg 并修复了它(截至 2016 年 12 月 v.3.2.1)
I had this problem. I updated to the latest version of ffmpeg and that fixed it (v.3.2.1 as of Dec 2016)