gpt4 book ai didi

python - 在heroku上使用ffmpeg的内存限制错误

转载 作者:行者123 更新时间:2023-12-04 22:54:55 30 4
gpt4 key购买 nike

我有一个在 Heroku 上运行的 Flask 应用程序,我想做的是使用 FFmpeg 将视频重新编码为 x265。为此,我有以下路线

@app.route('/x265', methods=['POST'])
def rotax265():
up_file = request.files['file'].stream

in_file = tempfile.TemporaryFile()
in_file.write(up_file.read())
in_file.seek(0)
out_file = tempfile.TemporaryFile()

conv = VideoConverter(in_file, out_file)

conv.x265()
out_file.seek(0)

return out_file.read()
它使用 VideoConverter我创建的类:
class VideoConverter(object):
def __init__(self, in_file, out_file):
self.input = in_file
self.output = out_file

def x265(self, read_chunk_size=-1):
args = (
ffmpeg
.input('pipe:', format='matroska')
.output('pipe:', vcodec='libx265', format='matroska')
.get_args()
)

p = subprocess.Popen(
['ffmpeg'] + args, stdin=self.input, stdout=self.output)
p.wait()
此类使用 ffmpeg-python subprocess模块。
我在输入和输出中都使用管道,这样我就不会使用存储空间并避免收到 R-14 错误(超出内存配额)。
这在本地运行时按预期工作,但是当我尝试在 Heroku 服务器上运行脚本时,它仍然返回 R-14 错误。
有什么办法可以避免出现这些错误?

最佳答案

I am using pipe both in input and output so that I don't use storage space and avoid receiving R-14 errors (memory quota exceeded).


存储(磁盘)和内存(RAM)是不同的东西。此错误与内存有关。
您的管道可能会阻止您写入磁盘,但它们不会做任何事情来减少内存使用量。事实上,它们可能会增加内存使用量——数据必须存在于某个地方,如果无法写入磁盘,则需要保留在内存中。
如果您在 Heroku 上遇到内存问题,您只有两个选择:
  • 使用更少的内存
  • 将您的测功机升级到内存更大的测功机

  • 视频转换通常会占用大量内存,除了处理非常短的视频剪辑之外,我不知道有什么好的方法可以减少内存。这给您留下了一个真正的选择:投资更大的测功机。

    关于python - 在heroku上使用ffmpeg的内存限制错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62879898/

    30 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com