如何使用Django网站流式传输视频?

时间:2011-05-05 11:44:57

标签: html django video-streaming

我正在用django开发一个网站。我想嵌入一个通过for循环迭代的视频。

{% for i in ImageData %}
<td>
<object width="425px" height="360px" >
<param name="allowFullScreen" value="true"/>
<param name="wmode" value="transparent"/>
<param name="movie" value="{{ MEDIA_URL }}{{ i.video }}"/>
<embed src="{{ MEDIA_URL }}{{ i.video }}" width="425" height="360" allowFullScreen="true" type="video/avi" wmode="transparent"/>
<\td>
{% endfor %}

我在网页上收到视频,但无法播放。 !有人可以帮帮我吗?

在localhost:8000上工作,它确实显示了一个视频框,但无法运行。

更新 这是django服务器运行时终端中出现的错误,网站仍在Chorme(在Ubuntu中)

Traceback (most recent call last):
  File "/usr/local/lib/python2.6/dist-packages/django/core/servers/basehttp.py", line 284, in run
    self.finish_response()
  File "/usr/local/lib/python2.6/dist-packages/django/core/servers/basehttp.py", line 324, in finish_response
    self.write(data)
  File "/usr/local/lib/python2.6/dist-packages/django/core/servers/basehttp.py", line 416, in write
    self._write(data[offset:offset+chunk_size])
  File "/usr/lib/python2.6/socket.py", line 318, in write
    self.flush()
  File "/usr/lib/python2.6/socket.py", line 297, in flush
    self._sock.sendall(buffer(data, write_offset, buffer_size))
error: [Errno 32] Broken pipe
----------------------------------------
Exception happened during processing of request from ('127.0.0.1', 48640)
Traceback (most recent call last):
  File "/usr/lib/python2.6/SocketServer.py", line 283, in _handle_request_noblock
    self.process_request(request, client_address)
  File "/usr/lib/python2.6/SocketServer.py", line 309, in process_request
    self.finish_request(request, client_address)
  File "/usr/lib/python2.6/SocketServer.py", line 322, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "/usr/local/lib/python2.6/dist-packages/django/core/servers/basehttp.py", line 570, in __init__
    BaseHTTPRequestHandler.__init__(self, *args, **kwargs)
  File "/usr/lib/python2.6/SocketServer.py", line 618, in __init__
    self.finish()
  File "/usr/lib/python2.6/SocketServer.py", line 661, in finish
    self.wfile.flush()
  File "/usr/lib/python2.6/socket.py", line 297, in flush
    self._sock.sendall(buffer(data, write_offset, buffer_size))
error: [Errno 32] Broken pipe

另外: 我注意到的另一件事是,这个错误只发生在 google-chrome 而不是 firefox4 ..我应该遵循的任何步骤来纠正它? 提前谢谢

3 个答案:

答案 0 :(得分:0)

Django与此毫无关系,真的。

AVI视频不能仅以<embed>运行。您应该使用HTML5 <video> tag(不能在每个浏览器中使用),或将视频转换为.flv并使用Flash播放器,例如OSPlayer

答案 1 :(得分:0)

这种类型的错误不是来自Django。但谷歌浏览器可能会出现连接错误!

以下是许多此类错误,它们告诉浏览器出现错误:

答案 2 :(得分:0)

您可能遇到Django缺乏对HTTP Range requests的支持的问题 - 这些问题通常用于视频流。因此,您最好将Django与网络服务器(例如Nginx,Apache)结合使用,以便Django处理动态内容,媒体内容由网络服务器直接提供。有关详细信息,请参阅此问题: Byte Ranges in Django