简体   繁体   English

使用来自IP Camera RTSP的Twilio流式传输视频

[英]Stream Video using Twilio from IP Camera RTSP

All of Twilio's examples for their Programmable Video service that I've been able to find either demonstrate screen sharing or webcam media streams. 我所能找到的所有Twilio的可编程视频服务示例都演示了屏幕共享或网络摄像头媒体流。 Can someone point me to an example that streams video from an RTSP stream provided by an IP Camera? 有人能指出我从IP Camera提供的RTSP流中传输视频的示例吗?

I've been able to find examples of and experiment with this behavior using Kurento, so I figured Twilio-Video might expose the same. 我已经能够使用Kurento找到并尝试这种行为的示例,所以我认为Twilio-Video可能会暴露相同的行为。 See https://github.com/lulop-k/kurento-rtsp2webrtc 请参阅https://github.com/lulop-k/kurento-rtsp2webrtc

Did you take a look at this? 你看看这个吗?

It's an interesting, well-written article on the matter. 这是一篇有趣的,写得很好的文章。

From the link in question: 从相关链接:

WebRTC Media Gateways for media interoperability For integrating an IP camera with a WebRTC application you first need to achieve media interoperability. 用于媒体互操作性的WebRTC媒体网关要将IP摄像机与WebRTC应用程序集成,首先需要实现媒体互操作性。 This means that the media stream provided by the camera needs to be made compatible with the WebRTC codecs and formats supported by browsers. 这意味着摄像机提供的媒体流需要与浏览器支持的WebRTC编解码器和格式兼容。 This means to translate whatever the IP camera speaks into whatever the WebRTC browser supports. 这意味着将IP摄像头所说的任何内容翻译成WebRTC浏览器支持的任何内容。 For this to happen, typically a piece of technology called a WebRTC Media Gateway is required. 为此,通常需要一种称为WebRTC媒体网关的技术。 For understanding what such a gateway does, observe the following. 要了解此类网关的作用,请遵守以下内容。

Most IP cameras available in the market (excluding exotic ones) publish media through any of these mechanisms: 市场上可用的大多数IP摄像机(不包括外来摄像机)通过以下任何机制发布媒体:

    RTSP/H.264: These types of cameras are typical for video surveillance applications. RTSP / H.264:这些类型的摄像机是视频监控应用的典型代表。 They use the RTSP protocol for establishing an RTP media session. 他们使用RTSP协议建立RTP媒体会话。 In other words, signaling takes place through RTSP while media transport itself is based on plain RTP. 换句话说,信令通过RTSP发生,而媒体传输本身基于普通RTP。 Different camera vendors may support different RTP profiles but, for most of the cameras I've seen, the AVP is the only available option. 不同的相机供应商可能支持不同的RTP配置文件,但对于我见过的大多数相机,AVP是唯一可用的选项。 In these cameras, and also typically, H.264 is the only option for the codec. 在这些相机中,通常情况下,H.264是编解码器的唯一选择。
    HTTP/MJPEG: These cameras use HTTP streaming for signaling and transport and encode video as a sequence of JPEG pictures. HTTP / MJPEG:这些摄像机使用HTTP流进行信令和传输,并将视频编码为JPEG图像序列。 The hardware for these cameras is simpler and requires fewer resources to operate. 这些摄像机的硬件更简单,操作资源更少。 This is why they are often used when battery consumption or weight is an issue (eg robotics, drones, etc.) As a drawback, the video quality tends to decrease significantly. 这就是为什么它们经常在电池消耗或重量成为问题时使用(例如机器人,无人机等)。作为缺点,视频质量趋于显着降低。

Doing it right with Kurento Media Server 使用Kurento Media Server正确完成

The Kurento Media Server toolbox makes possible to create rich WebRTC Media Gateways in a flexible way and programming in Java or JavaScript if you want. Kurento Media Server工具箱可以灵活地创建丰富的WebRTC媒体网关,并根据需要使用Java或JavaScript进行编程。 For an introduction on Kurento Media Server technologies, just take a look to the documentation. 有关Kurento Media Server技术的介绍,请查看文档。 Implementing a WebRTC Media Gateway for interoperating with IP cameras in Kurento is trivial and safe. 在Kurento中实现与IP摄像机互操作的WebRTC媒体网关是微不足道和安全的。 You need only take into consideration three aspects: 您只需要考虑三个方面:

    Kurento Media Server PlayerEndpoint supports reading video streams from different types of sources including RTSP/RTP and HTTP/MJPEG. Kurento Media Server PlayerEndpoint支持从不同类型的源(包括RTSP / RTP和HTTP / MJPEG)读取视频流。 In other words, the PlayerEndpoint is capable of managing the capture of media from the IP camera. 换句话说,PlayerEndpoint能够管理来自IP摄像机的媒体捕获。
    Kurento Media Server WebRtcEndpoint supports publishing media streams to WebRTC browsers with full termination of RTCP feedback. Kurento Media Server WebRtcEndpoint支持将媒体流发布到WebRTC浏览器,并完全终止RTCP反馈。 This means that, every time a PLI packet is received, the WebRtcEndpoint shall command the VP8 encoder to generate a new key frame. 这意味着,每次接收到PLI数据包时,WebRtcEndpoint都将命令VP8编码器生成新的关键帧。 This also means that REMB feedback and congestion control shall be honored by commanding the VP8 encoder to decrease its quality. 这也意味着应通过命令VP8编码器降低其质量来满足REMB反馈和拥塞控制。
    Kurento Media Server agnostic media capability performs, transparently for the developer, all the appropriate trans-codifications when two incompatible media elements are connected. 当连接两个不兼容的媒体元素时,Kurento Media Server不可知媒体功能可以为开发人员透明地执行所有适当的转码。 Hence, in this case, just by connecting the PlayerEndpoint source to the WebRtcEndpoint sink the H.264/MJPEG to VP8 transcoding shall take place. 因此,在这种情况下,只需将PlayerEndpoint源连接到WebRtcEndpoint接收器,就可以进行H.264 / MJPEG到VP8的转码。

在此输入图像描述

The souce code of a JavaScript application implementing this logic is sketched below: 实现此逻辑的JavaScript应用程序的源代码如下所示:

    var pipeline = ...//Use Kurento Client API for obtaining your pipeline.

//Create the PlayerEndpoint for receiving from the IP camera. HTTP and RTSP uris are supportd
pipeline.create("PlayerEndpoint", {uri: "rtsp://your.rtsp.address"}, function(error, playerEndpoint){

    //Create the WebRtcEndpoint
    pipeline.create("WebRtcEndpoint", function(error, webRtcEndpoint){

    //If working with trickle ice, some code for candidate management is required here.

        //Connect playerEndpoint to webRtcEndpoint. This connection activates the agnostic media
        //capability and the appropriate transcodings are configured and activated.
    playerEndpoint.connect(webRtcEndpoint, function(error){

                //Media starts flowing ... enjoy
        player.play(function(error){
        });
    });
    });
});

If you want a fully working example in JavaScript, you can take a look to this GitHub repository 如果您想在JavaScript中使用完全可用的示例,可以查看此GitHub存储库

This should provide a solution to your needs, comment if you have any problems. 这应该为您的需求提供解决方案,如果您有任何问题,请发表评论。

Good luck! 祝好运!

Can someone point me to an example that streams video from an RTSP stream provided by an IP Camera? 有人能指出我从IP Camera提供的RTSP流中传输视频的示例吗?

Since you've tagged Javascript you've got to realise that rtsp:// is not an expected video source within the HTML5 environment. 由于您已经标记了Javascript您必须意识到rtsp://不是HTML5环境中的预期视频源。 There isn't a specific example for RTSP stream from camera. 没有来自摄像机的RTSP流的具体示例。

possible solution : 解决方案:
The only solution I can think of is to use a virtual webcam software that outputs a video stream/file instead of showing feed from device webcam. 我能想到的唯一解决方案是使用虚拟网络摄像头软件输出视频流/文件而不是显示来自设备网络摄像头的信息。

The virtual webcam would be detected like a normal webcam (by browser / webRTC), but instead of showing your face, it shows a pre-recorded stream/file. 虚拟网络摄像头将像普通网络摄像头一样被检测到(通过浏览器/ webRTC),但它不会显示您的面部,而是显示预先录制的流/文件。 If you involve FFmpeg you could replace MP4 file with your RTSP live-stream. 如果你涉及FFmpeg,你可以用你的RTSP直播替换MP4文件。

On the Twilio / HTML5 code side, you simply select the "virtual cam" as if real webcam, now this way you can send RTSP feed as if it's your webcam feed. 在Twilio / HTML5代码方面,您只需选择“虚拟摄像头”就像真正的网络摄像头一样,现在通过这种方式您可以发送RTSP源,就好像它是您的网络摄像头源。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM