使用 Twilio 从 IP 摄像机 RTSP 流式传输视频

Stream Video using Twilio from IP Camera RTSP

我能够找到的所有 Twilio 的可编程视频服务示例都演示了屏幕共享或网络摄像头媒体流。有人能给我指出一个从 IP 摄像机提供的 RTSP 流传输视频的示例吗?

我已经能够使用 Kurento 找到这种行为的示例并进行实验,所以我认为 Twilio-Video 可能会暴露相同的行为。参见 https://github.com/lulop-k/kurento-rtsp2webrtc

你看了吗this?

这是一篇关于这个问题的有趣且写得很好的文章。

来自有问题的link:

WebRTC Media Gateways for media interoperability For integrating an IP camera with a WebRTC application you first need to achieve media interoperability. This means that the media stream provided by the camera needs to be made compatible with the WebRTC codecs and formats supported by browsers. This means to translate whatever the IP camera speaks into whatever the WebRTC browser supports. For this to happen, typically a piece of technology called a WebRTC Media Gateway is required. For understanding what such a gateway does, observe the following.

市场上的大多数 IP 摄像机(不包括外来的)通过以下任何机制发布媒体:

    RTSP/H.264: These types of cameras are typical for video surveillance applications. They use the RTSP protocol for establishing an RTP media session. In other words, signaling takes place through RTSP while media transport itself is based on plain 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. In these cameras, and also typically, H.264 is the only option for the codec.
    HTTP/MJPEG: These cameras use HTTP streaming for signaling and transport and encode video as a sequence of JPEG pictures. 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 (e.g. robotics, drones, etc.) As a drawback, the video quality tends to decrease significantly.

正确使用 Kurento 媒体服务器

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. For an introduction on Kurento Media Server technologies, just take a look to the documentation. Implementing a WebRTC Media Gateway for interoperating with IP cameras in Kurento is trivial and safe. 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. In other words, the PlayerEndpoint is capable of managing the capture of media from the IP camera.
    Kurento Media Server WebRtcEndpoint supports publishing media streams to WebRTC browsers with full termination of RTCP feedback. This means that, every time a PLI packet is received, the WebRtcEndpoint shall command the VP8 encoder to generate a new key frame. This also means that REMB feedback and congestion control shall be honored by commanding the VP8 encoder to decrease its quality.
    Kurento Media Server agnostic media capability performs, transparently for the developer, all the appropriate trans-codifications when two incompatible media elements are connected. Hence, in this case, just by connecting the PlayerEndpoint source to the WebRtcEndpoint sink the H.264/MJPEG to VP8 transcoding shall take place.

实现此逻辑的 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){
        });
    });
    });
});

如果你想要 JavaScript 中的完整示例,你可以看看这个 GitHub repository

这应该可以解决您的需求,如果您有任何问题,请发表评论。

祝你好运!

Can someone point me to an example that streams video from an RTSP stream provided by an IP Camera?

由于您标记了 Javascript,您必须意识到 rtsp:// 不是 HTML5 环境中的预期视频源。没有 特定 来自相机的 RTSP 流的示例。

可能的解决方案:
我能想到的唯一解决方案是使用输出视频 stream/file 的虚拟网络摄像头软件,而不是显示来自设备网络摄像头的提要。

虚拟网络摄像头会像普通网络摄像头一样被检测到(通过浏览器/webRTC),但它不会显示您的脸,而是显示预先录制的 stream/file。如果你涉及 FFmpeg,你可以用你的 RTSP 实时流替换 MP4 文件。

在 Twilio / HTML5 代码方面,您只需 select "virtual cam" 就像真正的网络摄像头一样,现在您可以通过这种方式发送 RTSP 提要,就好像它是您的网络摄像头提要一样。