使用FFmpeg对上传的音频进行编码,使用Django,VPS(Linux)和Amazon S3

时间:2021-07-21 23:04:20

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.

我的项目将要求用户上传未压缩的WAV音频文件,一旦他们这样做,服务器将需要用MP3对其进行编码以在网站上提供服务。我正在将Django用于此项目,它将托管在Linux VPS(来自Linode)上。由于空间和带宽,我想使用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)?

我很可能会使用django-storages应用程序与Amazon S3交谈。但是我不确定在什么时候我会为FFmpeg运行服务器命令来进行转换。如果用户正在上传音频文件,django-storage将把它放在Amazon S3上。但是,在哪里以及如何,我是否让FFmpeg在该文件上运行它的命令行,刚刚上传到编码到MP3然后我的网站服务并使用那个MP3(此时应该也在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?

我对如何去做有点困惑。就像我说的,我不是专家!谁能指导我这个?

2 个解决方案

#1


1  

You 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/

您可以考虑编写自定义存储后端。这应该可以插入django-storages,但我从来没有使用过该应用程序,也无法肯定地说。您可以在此处找到有关编写自定义存储后端的一些指导: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

在你的后端,你可以使用Python的subprocess命令来运行ffmgpeg来处理mp3转换:http://docs.python.org/library/subprocess.html#subprocess.call

#2


0  

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.

可能不会对这些文件使用django-storage,您可以将音频转换为服务器上的临时mp3文件(Linux VPS)并使用boto或命令行S3工具或其他方式将mp3上传到S3。

#1


1  

You 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/

您可以考虑编写自定义存储后端。这应该可以插入django-storages,但我从来没有使用过该应用程序,也无法肯定地说。您可以在此处找到有关编写自定义存储后端的一些指导: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

在你的后端,你可以使用Python的subprocess命令来运行ffmgpeg来处理mp3转换:http://docs.python.org/library/subprocess.html#subprocess.call

#2


0  

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.

可能不会对这些文件使用django-storage,您可以将音频转换为服务器上的临时mp3文件(Linux VPS)并使用boto或命令行S3工具或其他方式将mp3上传到S3。