首页 > 解决方案 > 使用烧瓶发送存储在 mongodb 中的视频文件不允许擦洗并且在移动设备上不起作用

问题描述

我有一个烧瓶应用程序,它从使用 fsgrid 存储的 mongodb 数据库中检索视频文件。然后我将此文件发送给用户。但是问题在于,在 chrome(桌面)上,视频不会让我擦洗或快进。在移动设备上,视频无法播放,它们返回灰屏。我见过有类似问题的人:像nodejs 的这个(修复)和建议发送二进制文件的地方(我这样做)。我已经查看并找不到遇到此问题的使用烧瓶的人。这让我相信我做错了什么。这是我的代码:

@app.route('/view/<postid>')
def Rview(postid):
    ...
    post_id_obj = ObjectId(postid)
    cur_post = col_posts.find_one({"_id": post_id_obj}) # gets entry that matches the id
    location = cur_post['file'] # gets the fsgrid location of the file
    file_mimetype = cur_post['mimetype']
    file_ext =  '.' + file_mimetype.split("/")[1]
    return send_file(BytesIO(fs.get(location).read()), mimetype=file_mimetype, as_attachment=False, attachment_filename=(str(random.randint(10000000,99999999)) + file_ext)) # sends file along with a random file name

不确定这是否需要,但 html

<video class="video" controls>
    <source src="/view/{{ location }}" type="video/mp4">
</video>

任何帮助将不胜感激,谢谢!

如果有帮助,我也在生产服务器上使用 nginx

编辑:

这也可能很重要,我像这样编码/压缩视频 ffmpeg -i -c:v libx264 -crf 18 -preset veryslow -c:a copy。在此之后,我也稍微降低了质量。

标签: pythonmongodbflask

解决方案


推荐阅读