gpt4 book ai didi

python - 基于Tornado的视频网站服务

转载 作者:太空宇宙 更新时间:2023-11-03 17:08:12 24 4
gpt4 key购买 nike

我是 Tornado 的新手,我想建立一个简单的网站来观看电影。当然,hello world网站是成功的,我想在空网站中添加电影。因此我在html 5中使用视频标签编写了一个html。

<html>
<body>
<video autoplay=true>
<source src="aa.mp4" type="video/mp4"></source>
</video>
</body>
</html>

tornado 中的代码也很简单。

class IndexHandler(tornado.web.RequestHandler):
def get(self):
self.render('index.html')

图片还可以,但是当我使用500MB的视频时。出现内存错误。

Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/tornado/web.py", line 1141, in _when_complete
callback()
File "/usr/lib/python2.7/dist-packages/tornado/web.py", line 1167, in _execute_finish
self.finish()
File "/usr/lib/python2.7/dist-packages/tornado/web.py", line 760, in finish
self.flush(include_footers=True)
File "/usr/lib/python2.7/dist-packages/tornado/web.py", line 703, in flush
chunk = b"".join(self._write_buffer)
MemoryError

我觉得问题是浏览器下载了整个视频,所以该函数无法返回并抛出异常。这样对吗?以及如何解决,非常感谢。

感谢您的帮助,我编写了一行代码来提供视频文件。但我发现还是有些不对劲。当文件是图片时没问题,当我提供更大的视频文件时就会出错。

(r"/(.*)",tornado.web.StaticFileHandler,{"path":"/home/alex/one/static"})

最佳答案

StaticFileHandler 应该能够处理大文件。

来自StaticFileHandler docs :

This handler is intended primarily for use in development and light-duty file serving; for heavy traffic it will be more efficient to use a dedicated static file server (such as nginx or Apache). We support the HTTP Accept-Ranges mechanism to return partial content (because some browsers require this functionality to be present to seek in HTML5 audio or video).

如果您使用旧版本的 Tornado,您应该更新到最新版本。
或者如文档所述,使用专用的静态文件服务器(例如 nginx 或 Apache)。

关于python - 基于Tornado的视频网站服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34380003/

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