如何将视频数据流传输到视频元素? [英] How to stream video data to a video element?

查看:79
本文介绍了如何将视频数据流传输到视频元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Node.js进程,该进程将视频流输出到我的Node.js应用程序中.

I have a Node.js process which outputs a video stream into my Node.js app.

在客户端上,有一个< video> 标记.我想将来自Node.js的视频流式传输到视频标记的 src 属性.我以前的经验告诉我,为此必须使用 blob 对象.但是,我不能百分百确定如何以及为什么要使用它.

On the client end, there is a <video> tag. I would like to stream the video from Node.js into the src attribute of the video tag. My previous experience tells me that we must use the blob object for this. However, I'm not a hundred percent certain how and why I would use it.

我正在考虑的另一种可能的解决方案是在服务器上创建某种临时文件,然后将流写入该文件,然后将该文件用作视频源.但是,这似乎并不直观.我在想,那么,对于这样的问题是否有更成熟的解决方案.

Another possible solution I'm thinking of is to create some sort of a temporary file on my server, then write the stream to that file, then serve that file as the source for the video. However, that doesn't seem intuitive. I was wondering, then, if there is a more established solution for an issue like this.

推荐答案

可能您可能希望查看以下选项:

Probably you might want to look at the following options:

  1. BinaryJS .它是基于websockets的双向实时二进制数据传输工具.

  1. BinaryJS. It's bidrectional realtime binary data transfer tool based on websockets.

JSMpeg 流服务器(如果被捕获).您需要做的只是启动 ffmpeg 并将其指向运行nodejs脚本的域和端口.有关更多信息,您可以在此处.

JSMpeg stream-server (in case of capturing) from Phoboslab guys. All you need to do is start ffmpeg and point it to the domain and port where the nodejs script is running. More info you can find here.

直接将流放入管道.好的答案被发布在此处.简而言之,您只需要指定 Accept-Ranges Content-Range Content-Length Content-Type 标头,然后创建相关的读取流(使用 start end 选项)并将其通过管道传递到 response 对象.

Pipe a stream directly. Good answer is posted here. In few words you just need to specify Accept-Ranges, Content-Range, Content-Length and Content-Type headers, then create relevant Read stream (with start and end options) and pipe it to the response object.

这篇关于如何将视频数据流传输到视频元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆