python - 在 Django 项目中包含 ffmpeg

标签 python django ffmpeg

我正在制作一个非常简单的 Django 应用程序(这是对非 Django 类(class)的测试),我需要在那里分析一个 mp3 文件,所以我尝试将其转换为 wav:

 sound = AudioSegment.from_mp3('upload/' + filename)
 sound.export('upload/wavfile', format="wav")
 rate, data = wav.read('upload/wavfile')

我已经通过 pip install ffmpeg 安装了 ffmpeg在 venv 终端中,因为我希望我的代码不仅在我的机器上运行。 ffmpeg ffprobe 文件夹已出现在/venv/lib/python3.7/site-packages/但是当我运行我的服务器时,我收到警告:

RuntimeWarning: Couldn't find ffmpeg or avconv - defaulting to ffmpeg, but may not work warn("Couldn't find ffmpeg or avconv - defaulting to ffmpeg, but may not work", RuntimeWarning)



当我在网页中加载文件时,它会抛出

[Errno 2] No such file or directory: 'ffprobe': 'ffprobe'



在上面代码的第一行。

对于如何在我的应用程序中使用 ffmpeg 或以其他方式处理我的 mp3 文件的任何帮助,我将不胜感激。

最佳答案

您必须为 ffmpeg 可执行文件添加路径

import sys
sys.path.append('/path/to/ffmpeg')

or 

import ffmpy

ff = ffmpy.FFmpeg(executable='C:\\ffmpeg\\bin\\ffmpeg.exe', inputs={path+'/Stage1Rap.wav': None}, outputs={path+'/FinalRap.mp3': ["-filter:a", "atempo=0.5"]})
ff.run()

关于python - 在 Django 项目中包含 ffmpeg,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60826809/

相关文章:

python - 使用 selenium python 下载图像

python - 如何替换 "key": value pairs in string with key: value (remove quotes from key)?

python - Django REST API - 是否可以为每个应用程序创建一个 routers.py?

python - Django 多个数据库 - 关系不存在;第 1 行 : SELECT COUNT(*) AS "__count" FROM

flutter ( Dart ): Merge two videos and view the new output in the device's gallery (photos)

html - 在连续流上解码音频数据失败并出现空错误

python - 有没有办法将数学函数作为 Python 3 中函数的参数?

python - 奇怪的 PyPI 身份验证行为

django - 类型 'Response'的对象在DRF中没有len()

PHP exec 等待返回键