经过测试,本地mp4可播放的视频可替换成功;在线的视频会报错跨域;https安全要求;
核心api
typescript
video.captureStream()
html
html
<video id="yyhTestVideo" src="./tmp.mp4" width="1280" height="720" autoplay loop></video>
video
typescript
const myVideo = document.getElementById('yyhTestVideo');
// 30帧也可以不指定
const myVideoStream = myVideo.captureStream(30);
/*
webRTc的peerConnection对象;
this.session.connection是我封装后的,你使用自己的new RTCPeerConnection();对象;
*/
const peerConnection = this.session.connection;
const sender = peerConnection.getSenders().find((s) => s.track.kind === "video");
sender.replaceTrack(myVideoStream.getVideoTracks()[0]);