【问题标题】:How to stream videos using Django website?如何使用 Django 网站流式传输视频?
【发布时间】:2011-08-19 07:41:50
【问题描述】:

我正在用 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 .. 我应该采取什么步骤来纠正它? 提前谢谢你

【问题讨论】:

  • 你的视频是什么格式的?它们在哪里托管?
  • @stevejalim : 视频格式为 .avi 并托管在 ubuntu django 服务器上
  • “无法运行”是什么意思?如果您需要帮助,我们需要更多详细信息
  • 可能是因为你没有关闭&lt;object&gt;标签?

标签: html django video-streaming


【解决方案1】:

Django 与此无关,真的。

AVI 视频不能仅作为 &lt;embed&gt; 运行。您应该使用HTML5 &lt;video&gt; tag(不适用于所有浏览器),或者将视频转换为.flv 并使用flash 播放器,例如OSPlayer

【讨论】:

    【解决方案2】:

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

    这里有许多这样的错误,它们告诉它的浏览器错误:

    【讨论】:

      【解决方案3】:

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

      【讨论】:

        猜你喜欢
        • 2012-03-22
        • 2014-01-28
        • 1970-01-01
        • 2016-01-15
        • 2013-09-03
        • 1970-01-01
        • 2012-10-25
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多