使用 FFmpeg 对上传的音频进行编码,使用 Django、VPS (Linux) 和 Amazon S3
我的项目将要求用户上传未压缩的 WAV 音频文件,一旦上传,服务器将需要将其编码为 MP3 以便在网站上提供服务。我在这个项目中使用 Django,它将托管在 Linux VPS(来自 Linode)上。由于空间和带宽的原因,我想使用 Amazon S3。
我不是这方面的专家,这个项目将为我涵盖许多新事物。但任何关于这方面的指导对我来说都是一件好事。
我很可能会使用 django-storages 应用程序与 Amazon S3 进行交互。但我不确定在什么时候运行 FFmpeg 的服务器命令来进行转换。如果用户上传音频文件,django-storages 会将其放置在 Amazon S3 上。但是,我在哪里以及如何让 FFmpeg 在刚刚上传的文件上运行它的命令行以对 MP3 进行编码,然后我的网站来提供和使用该 MP3(此时也应该在 Amazon S3 上)?
我对如何去做有点困惑。就像我说的,我不是专家!有人可以指导我吗?
My project will require users to upload uncompressed WAV audio files and once they do, the server will need to encode it in MP3 to serve it on the site. I'm using Django for this project and it'll be hosted on a Linux VPS (from Linode). Due to space and bandwidth, I want to use Amazon S3.
I'm not an expert at this stuff, this project will be covering many new things for me. But any guidance on this would be a great thing for me.
I will most probably be using the django-storages app to talk with Amazon S3. But I'm not sure at what point I would run the server command for FFmpeg to do it's conversions. If a user is uploading an audio file, django-storages will place it on Amazon S3. But then, where and how, do I get FFmpeg to run it's commandline on that file just uploaded to do the encoding to MP3 and then my website to serve and use that MP3 (which should at that point also be on Amazon S3)?
I'm a little confused on how to go about it. Like I say, I'm not an expert! Could anyone guide me on this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可能会考虑编写自定义存储后端。这应该可以插入 django-storages 中,但我从未使用过该应用程序,也不能确定。您可以在此处找到有关编写自定义存储后端的一些指南: http:// /docs.djangoproject.com/en/dev/howto/custom-file-storage/
在后端,您可以使用 Python 的
subprocess
命令来运行 ffmgpeg 来处理 mp3 转换: < a href="http://docs.python.org/library/subprocess.html#subprocess.call" rel="nofollow noreferrer">http://docs.python.org/library/subprocess.html#subprocess.callYou might consider writing a custom storage backend. This should be pluggable into django-storages, but I've never used the app and can't say for sure. You can find some guidance on writing custom storage backends here: http://docs.djangoproject.com/en/dev/howto/custom-file-storage/
In your backend, you can use Python's
subprocess
command to run ffmgpeg to handle the mp3 conversion: http://docs.python.org/library/subprocess.html#subprocess.call可能不要对此类文件使用 django-storage,您可以将音频转换为服务器(Linux VPS)上的临时 mp3 文件并使用 boto 或 命令行 S3 工具l 或其他方式上传mp3 到 S3。
May be don't use django-storage for such files, You can convert the audio to a temp mp3 file on server (Linux VPS) and using boto or command line S3 tool or some other way upload mp3 to S3.