WebRTC将视频MediaStreamTracks合并到客户端

时间:2014-07-29 16:55:50

标签: javascript webrtc

如何在客户端将2个视频流合并为一个,并通过WebRTC PeerConnection发送?

例如,我有2个像这样的视频流

navigator.getUserMedia({ video: true }, successCamera, error);  //  capture camera

function successCamera(streamCamera) {
    vtCamera = streamCamera.getVideoTracks()[0]

    navigator.getUserMedia({  //  capture screen
        video: {   
            mandatory: {
                chromeMediaSource: 'screen',
                maxWidth: 1280,
                maxHeight: 720
            }
        }
    }, successScreen, error);

    function successScreen(streamScreen) {
        vtScreen = streamScreen.getVideoTracks()[0]

        mergedVideoTracks = vtScreen + vtCamera;   //  How i can merge tracks in one??

        finallyStream = streamScreen.clone()
        finallyStream.removeTrack( finallyStream.getVideoTracks()[0] )
        finallyStream.addTrack( mergedVideoTracks )

        finallyStream  // I need to send this through WebRTC PeerConnection

    }

}

function error(error) {
    console.error(error);
}

正如您所看到的,我将vtScreen和vtCamera作为MediaStreamTracks。我需要将屏幕设置为背景,将相机设置为右下角的小框架。并通过WebRTC PeerConnection作为一个流发送它

是的,我可以在画布上合并它,但我不知道如何将此画布作为MediaStreamTrack发送。 =(

0 个答案:

没有答案