简体   繁体   English

来自android webview的peerjs webrtc流媒体视频太慢了

[英]streaming video with peerjs webrtc from android webview is too slow

I have an android application that sends the camera stream through a webview through peerjs (webrtc) the web application on the browser receives the video and streams it. 我有一个Android应用程序,通过webjc(webrtc)通过webview发送摄像头流,浏览器上的Web应用程序接收视频并流式传输。

Things are working but the video on the web is too slow and the image freezes for some time before getting the second image... 事情正在发挥作用,但网络上的视频太慢,图像冻结了一段时间后才获得第二张图片......

Is there a way to make the resolution lower ? 有没有办法降低分辨率? or buffer the video on the web application ? 或缓冲网络应用程序上的视频? or can it be something wrong with my implementation ? 或者我的实施可能有问题吗?

Android Webview code: Android Webview代码:

        initVideo = function(videoSourceValue) {

        var video = document.querySelector('video');
        navigator.getUserMedia({video:  {optional: [{
                                                    sourceId: videoSourceValue
                                                     }]
                                          }
                                },function(stream) {
        video.src = window.URL.createObjectURL(stream);
        $('#peerId').text("calling : " + SERVER_PEER_ID);
         var mediaConnection = peer.call(SERVER_PEER_ID, stream);
          mediaConnection.on('stream', function(remoteStream) {
            // Show stream in some video/canvas element.
          });
        },function(e){
                console.log('failed',e);
        });
    }

Web part: 网页部分:

   function getVideoStream() {
    PEER.on('call', function(call) {
        var mediaConnection = navigator.getUserMedia({video: true}, function(stream) {
            call.answer(stream); // Answer the call with an A/V stream.
            call.on('stream', onReceiveStream);
        }, function(err) {
            console.log('Failed to get local stream' ,err);
        });
    });
}


    function onReceiveStream(stream){
        console.log('received stream');
        $('video').prop('src',window.URL.createObjectURL(stream));

}

Thanks 谢谢

Update 1 更新1

I tried to add {reliable : true} , still having the same issue. 我试图添加{reliable : true} ,仍然有同样的问题。

I'm also sending location data to the server, and it seems that the video streams and location data are sent together periodically (the chart on the web showing speed and the video move at the same time) but the frame rate is too slow. 我也将位置数据发送到服务器,似乎视频流和位置数据定期一起发送(网络上的图表显示速度和视频同时移动),但帧速率太慢。

When you establish the video/audio stream you can specify some constraints... 建立视频/音频流时,您可以指定一些约束...

var videoOptions = (isCordova) ? {audio: true, video: true} :
                    {  audio: true, 
                      video: {
                        mandatory: {
                               maxWidth: 640,
                               maxHeight: 360,
                               // maxAspectRatio:4/3,
                               // maxFrameRate:1
                              },
                        quality: 7,
                        width: { ideal: 320 },
                        height: { ideal: 240 }
                      }
                    };

navigator.getUserMedia(videoOptions, function (stream) {

In the above code, if you are on a device (android/ios) you don't get to choose, but you can control it on the browser. 在上面的代码中,如果你在设备(android / ios)上,你无法选择,但你可以在浏览器上控制它。 A quality of 5 is the level that the video driver author deemed as an acceptable trade off between quality and bandwidth. 质量为5是视频驱动程序作者认为在质量和带宽之间可接受的折衷的级别。 Limiting the dimensions of the picture helps too. 限制图片的尺寸也有帮助。

See this link for mode details: https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getUserMedia 有关模式详细信息,请参阅此链接: https//developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getUserMedia

My issue was completely unrelated to bandwidth, I simply didn't put autoplay on the video tag , so the video was only refreshing when a redraw was happening. 我的问题与带宽完全无关,我只是没有在视频标签上放置自动播放,因此视频只在刷新时才会刷新。

Thanks a lot for your answers they really give insight on how things work in webrtc. 非常感谢您的回答,他们真正了解了webrtc中的工作原理。

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

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