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

发布于 2024-11-05 03:03:43 字数 2501 浏览 1 评论 0原文

我正在用 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 中。我应该遵循什么步骤来纠正它? 先感谢您

I am developing a website with django . I wanted to embed a video which is iterated through a for loop.

{% 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 %}

I am getting the video on the page, but not able to stream it. !! Can anyone please help me?

working on localhost:8000, it does show me a video box but cannot run .

Update:
This is the error i got in the terminal when the django server is run, the website is still on the Chorme (in 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

Further:
The other thing i noticed, is that this error occurs only in google-chrome and not in firefox4 .. Any step i should follow to get it corrected ?
Thank you in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

晨敛清荷 2024-11-12 03:03:43

这种类型的错误不是来自 Django。但 Google Chrome 可能会出现一些连接错误!

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

This type of error is not from Django. But the Google Chrome might have some error connecting!

Here are many such errors where they tell its browser fault:

南…巷孤猫 2024-11-12 03:03:43

Django 与此无关,真的。

AVI 视频不能仅作为 运行。您应该使用 HTML5 标记(并非在每个浏览器),或将视频转换为 .flv 并使用 Flash 播放器,例如 OSPlayer,例如。

Django has nothing to do with this, really.

AVI video cannot just run as an <embed>. You should use either HTML5 <video> tag (won't work in every browser), or convert your video to .flv and use a flash player, like OSPlayer, for example.

救星 2024-11-12 03:03:43

您可能会遇到 Django 缺乏对 HTTP Range 请求的支持的问题 - 常用于视频流。因此,您最好将 Django 与网络服务器(例如 Nginx、Apache)结合使用,这样 Django 就可以处理由网络服务器直接提供的媒体内容的动态内容。请参阅此问题了解更多详细信息:
Django 中的字节范围

You may be encountering a problem with Django's lack of support for HTTP Range requests - which are commonly used with video streaming. So you're probably better off using Django in conjunction with a webserver (e.g. Nginx, Apache) so Django handles the dynamic content with the media content is provided directly by the webserver. See this Question for more details:
Byte Ranges in Django

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文