如何在http响应中使用Content_type、video/mp2t?

发布于 2024-10-06 15:57:12 字数 658 浏览 1 评论 0原文

我正在准备响应发送视频的 http 请求并收到错误:破碎的管道

 if self.path.endswith(".ts"):  
     f = open("filename.ts", 'r')
     self.send_response(200)
     self.send_header('Content-Type', "video/mp2t")
     self.end_headers()
     self.wfile.write(f.read())
     return

下面的相同响应工作正常。

 if self.path.endswith(".mov"):  
            f = open("filename.mov", 'r')
            self.send_response(200)
            self.send_header('Content-Type', "video/mpeg")
            self.end_headers()
            self.wfile.write(f.read())
            return

我怀疑这与 mimetype 问题有关。谁能建议我如何将 video/mp2t 与 baseHttpServer 一起使用?

I am preparing response to a http request to send video and receiving error: Broken Pipe

 if self.path.endswith(".ts"):  
     f = open("filename.ts", 'r')
     self.send_response(200)
     self.send_header('Content-Type', "video/mp2t")
     self.end_headers()
     self.wfile.write(f.read())
     return

Same response below works fine.

 if self.path.endswith(".mov"):  
            f = open("filename.mov", 'r')
            self.send_response(200)
            self.send_header('Content-Type', "video/mpeg")
            self.end_headers()
            self.wfile.write(f.read())
            return

I suspect it is related to mimetype issue. Can any one suggest me how can i use video/mp2t with baseHttpServer ??

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

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

发布评论

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

评论(2

救赎№ 2024-10-13 15:57:13

好吧,我会尝试一下。服务器端的“断管”通常意味着客户端关闭连接,而服务器仍在发送数据。根据您之前的问题,我假设您的客户端是浏览器(使用 标记)。这很可能意味着浏览器不支持 MPEG 传输流的播放。事实上我还没有听说过任何浏览器支持它。

也许您应该尝试流式传输 Ogg Theora 视频(MIME 类型“video/theora”)进行测试 - Firefox 3.1+ 开箱即用地支持此功能。如果有效,则您的服务器实现是正确的。

Alright, I'll give it a try. "Broken pipe" on the server side usually means that the client closes the connection while the server is still sending data. From your previous question, I assume your client is a browser (using the <video> tag). That most probably means that the browser does not support playback of MPEG transport streams. Actually I haven't heard of any browser that supports it.

Maybe you should try to stream an Ogg Theora video (MIME type "video/theora") for testing - Firefox 3.1+ supports this out of the box. If that works, your server implementation is correct.

童话 2024-10-13 15:57:13

在 mpeg2ts 的上下文中,客户端(浏览器中的 Quicktime)在多个 GET 请求中请求特定的字节范围。根据请求的字节范围准备响应解决了该问题。

In the context of mpeg2ts, client(Quicktime in Browser) requesting specific byte ranges in multiple GET requests. preparing the response as per the requested byte ranges fixed the issue.

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