将视频流式传输到 Web 浏览器

发布于 2024-12-29 02:55:37 字数 718 浏览 1 评论 0原文

我想在网络浏览器中显示实时视频流。 (如果可能的话,与 IE、Firefox 和 Chrome 的兼容性会很棒。)其他人将负责流式传输视频,但我必须能够接收和显示它。我将通过 UDP 接收视频,但目前我只是使用 VLC 将其流式传输给自己以进行测试。是否有一个开源库可以帮助我使用 HTML 和/或 JavaScript 完成此任务?或者有一个好的网站可以帮助我弄清楚如何自己做到这一点?

我读过一些有关 RTSP 的内容,这似乎是此类问题的传统选择。如果我无法使用 UDP 完成此操作,这可能是我必须依靠的,但如果是这种情况,我仍然不确定如何使用 RTSP/RTMP/RTP 来完成此操作,或者所有这些之间有什么区别缩写词是,如果有的话。

我认为 HTTP 自适应流媒体可能是一段时间内的最佳选择,但似乎所有使用它的解决方案都是专有的(Microsoft IIS Smooth Streaming、Apple HTTP Live Streaming 或 Adob​​e HTTP Dynamic Streaming),而且我没有太多的选择幸运的是我自己知道如何完成它。 MPEG-DASH 听起来也是一个很棒的解决方案,但它似乎还没有被使用,因为它仍然很新。但现在我被告知无论如何我都应该通过 UDP 接收视频,所以这些解决方案对我来说可能不再重要了。

我已经在谷歌上搜索这些东西好几天了,但没有找到任何可以帮助我实现它的东西。我能找到的只是解释相关技术(例如 RTSP、HTTP 自适应流式传输等)或可以购买用于在网络上流式传输自己的视频的工具的文章。非常感谢您的指导!

I would like to display a live video stream in a web browser. (Compatibility with IE, Firefox, and Chrome would be awesome, if possible.) Someone else will be taking care of streaming the video, but I have to be able to receive and display it. I will be receiving the video over UDP, but for now I am just using VLC to stream it to myself for testing purposes. Is there an open source library that might help me accomplish this using HTML and/or JavaScript? Or a good website that would help me figure out how to do this on my own?

I've read a bit about RTSP, which seems like the traditional option for something like this. That might be what I have to fall back on if I can't accomplish this using UDP, but if that is the case I still am unsure of how to go about this using RTSP/RTMP/RTP, or what the differences between all those acronyms are, if any.

I thought HTTP adaptive streaming might be the best option for a while, but it seemed like all the solutions using that were proprietary (Microsoft IIS Smooth Streaming, Apple HTTP Live Streaming, or Adobe HTTP Dynamic Streaming), and I wasn't having much luck figuring out how to accomplish it on my own. MPEG-DASH sounded like an awesome solution as well, but it doesn't seem to be in use yet since it is still so new. But now I am told that I should expect to receive the video over UDP anyways, so those solutions probably don't matter for me anymore.

I've been Googling this stuff for several days without much luck on finding anything to help me implement it. All I can find are articles explaining what the technologies are (e.g. RTSP, HTTP Adaptive Streaming, etc.) or tools that you can buy to stream your own videos over the web. Your guidance would be greatly appreciated!

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

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

发布评论

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

评论(3

终止放荡 2025-01-05 02:55:37

大多数视频网站使用 FLV 的说法是不正确的,MP4 是最广泛支持的格式,并且也可以通过 Flash 播放器播放。
实现您想要的最简单的方法是打开 S3Amzon/cloudFront 帐户并使用 JW 播放器。然后您就可以使用 RTMP 软件来传输视频和音频。这项服务非常便宜。如果您想了解更多信息,请查看这些教程:
http://www.miracletutorials.com/category/s3-amazon-cloudfront/ 从底部开始,逐步进入更高层的教程。

我希望这能帮助您走上自己的道路。

It is incorrect that most video sites use FLV, MP4 is the most widely supported format and it is played via Flash players as well.
The easiest way to accomplish what you want is to open a S3Amzon/cloudFront account and work with JW player. Then you have access to RTMP software to stream video and audio. This service is very cheap. if you want to know more about this, check out these tutorials:
http://www.miracletutorials.com/category/s3-amazon-cloudfront/ Start at the bottom and work your way up to the tutorials higher up.

I hope this will help you get yourself on your way.

长发绾君心 2025-01-05 02:55:37

如果你不需要声音,你可以发送带有如下标头的JPEG:

Content-Type: multipart/x-mixed-replace

这是一个使用nodejs的简单演示,它使用库opencv4nodejs来生成图像。您可以使用任何其他允许在保持连接打开的情况下将数据附加到套接字的 HTTP 服务器。在 Ubuntu Linux 上的 Chrome 和 FF 上进行了测试。

要运行示例,您需要使用 npm install opencv4nodejs 安装此库,这可能需要一段时间,然后像这样启动服务器:node app.js,这里是应用程序.js 本身

var http = require('http')
const cv = require('opencv4nodejs');

var m=new cv.Mat(300, 300, cv.CV_8UC3);
var cnt = 0;
const blue = new cv.Vec3(255, 220, 120);
const yellow = new cv.Vec3(255, 220, 0);
var lastTs = Date.now();
http.createServer((req, res) => {
    if (req.url=='/'){
        res.end("<!DOCTYPE html><style>iframe {transform: scale(.67)}</style><html>This is a streaming video:<br>" +
            "<img  src='/frame'></img></html>")
    } else if (req.url=='/frame') {
        res.writeHead(200, { 'Content-Type': 'multipart/x-mixed-replace;boundary=myboundary' });
        var x =0;
        var fps=0,fcnt=0;
        var next = function () {
            var ts = Date.now();
            var m1=m.copy();
            fcnt++;
            if (ts-lastTs > 1000){
                lastTs = ts;
                fps = fcnt;
                fcnt=0;
            }
            m1.putText(`frame ${cnt}  FPS=${fps}`, new cv.Point2(20,30),1,1,blue);
            m1.drawCircle(new cv.Point2(x,50),10,yellow,-1);
            x+=1;
            if (x>m.cols) x=0;
            cnt++;
            var buf = cv.imencode(".jpg",m1);
            res.write("--myboundary\r\nContent-type:image/jpeg\r\nDaemonId:0x00258009\r\n\r\n");
            res.write(buf,function () {
                next();
            });
        };
        next();
    }
}).listen(80);

稍后我在 python 中找到了这个示例,其中包含更多详细信息: https://blog.miguelgrinberg.com/post/video-streaming-with-flask

更新:如果您将其流式传输到 html img 标记中,它也可以工作。

If you don't need sound, you can send JPEGs with header like this:

Content-Type: multipart/x-mixed-replace

This is a simple demo with nodejs, it uses library opencv4nodejs to generate images. You can use any other HTTP server which allows to append data to the socket while keeping connection opened. Tested on Chrome and FF on Ubuntu Linux.

To run the sample you will need to install this library with npm install opencv4nodejs, it might take while, then start the server like this: node app.js, here is app.js itself

var http = require('http')
const cv = require('opencv4nodejs');

var m=new cv.Mat(300, 300, cv.CV_8UC3);
var cnt = 0;
const blue = new cv.Vec3(255, 220, 120);
const yellow = new cv.Vec3(255, 220, 0);
var lastTs = Date.now();
http.createServer((req, res) => {
    if (req.url=='/'){
        res.end("<!DOCTYPE html><style>iframe {transform: scale(.67)}</style><html>This is a streaming video:<br>" +
            "<img  src='/frame'></img></html>")
    } else if (req.url=='/frame') {
        res.writeHead(200, { 'Content-Type': 'multipart/x-mixed-replace;boundary=myboundary' });
        var x =0;
        var fps=0,fcnt=0;
        var next = function () {
            var ts = Date.now();
            var m1=m.copy();
            fcnt++;
            if (ts-lastTs > 1000){
                lastTs = ts;
                fps = fcnt;
                fcnt=0;
            }
            m1.putText(`frame ${cnt}  FPS=${fps}`, new cv.Point2(20,30),1,1,blue);
            m1.drawCircle(new cv.Point2(x,50),10,yellow,-1);
            x+=1;
            if (x>m.cols) x=0;
            cnt++;
            var buf = cv.imencode(".jpg",m1);
            res.write("--myboundary\r\nContent-type:image/jpeg\r\nDaemonId:0x00258009\r\n\r\n");
            res.write(buf,function () {
                next();
            });
        };
        next();
    }
}).listen(80);

A bit later I've found this example with some more details in python: https://blog.miguelgrinberg.com/post/video-streaming-with-flask

UPDATE: it also works, if you stream this into html img tag.

半枫 2025-01-05 02:55:37

真正的跨浏览器流只能通过 Flash 等“富媒体”客户端实现,这就是为什么几乎所有视频网站都默认使用 Adob​​e 专有的 .flv 格式提供视频的原因。

对于非直播视频,HTML5 中视频嵌入的出现显示出了希望,并且使用 Canvas 和 JavaSCript 流式传输在技术上应该是可行的,但处理流和预加载二进制视频对象必须在 JavaScript 中完成,而且不是很简单。

True cross-browser streaming is only possible through "rich media" clients like Flash, which is why almost all video websites default to serving video using Adobe's proprietary .flv format.

For non-live video the advent of video embeds in HTML5 shows promise, and using Canvas and JavaSCript streaming should be technically possible, but handling streams and preloading binary video objects would have to be done in JavaScript and would not be very straightforward.

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