简体   繁体   English

如何在WebRtc中流式传输canvas元素?

[英]How to stream a canvas element in WebRtc?

I was searching about WebRtc and I found this great project on GitHub: 我正在搜索WebRtc,我在GitHub上发现了这个伟大的项目:

https://github.com/mexx91/basicVideoRTC https://github.com/mexx91/basicVideoRTC

The communication between 2 cameras works great using node.js. 使用node.js,两台摄像机之间的通信效果很好。

It's possible to before stream a getuserMedia modify it in a canvas element and so stream this object? 流式传输getuserMedia之前可以在canvas元素中修改它,然后传输这个对象吗?

Thanks 谢谢

It seems currently this is not possible in a cross-browser compatible fashion. 目前看来这在跨浏览器兼容的方式中是不可能的。

But it may be in the future, you can take a glimpse at the HTMLCanvasElement.captureStream interface as implemented by recent Firefox browsers, see https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/captureStream . 但是可能在将来,您可以HTMLCanvasElement.captureStream最近的Firefox浏览器实现的HTMLCanvasElement.captureStream接口,请参阅https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/captureStream

It allows you to capture the content of a canvas to a stream that can be send wia WebRTC to your peer then. 它允许您将画布的内容捕获到可以通过WebRTC发送给您的同级的流。

By getUserMedia() method we can get the audio and video stream in codec format through the microphone and webcam respectively. 通过getUserMedia()方法,我们可以分别通过麦克风和网络摄像头获取编解码格式的音频和视频流。

After converted this codec format in url of user video, it would assigned into source tag under the video element to make complete video. 在用户视频的url中转换此编解码器格式后,它将被分配到视频元素下的源标记中以制作完整的视频。

So the video we are getting from getUserMedia() api is like other usual video eg:- 因此,我们从getUserMedia()api获取的视频与其他常见视频一样,例如: -

<video width="320" height="240" controls>
  <source src="http://www.w3schools.com/tags/movie.mp4" type="video/mp4">
  <source src="http://www.w3schools.com/tags/movie.ogg" type="video/ogg">
  Your browser does not support the video tag.
</video>

http://jsfiddle.net/ez3pA/2/ http://jsfiddle.net/ez3pA/2/

So you can do various things about video and canvas element together. 所以你可以一起做有关视频和画布元素的各种事情。 We can get good examples of this on a site http://html5doctor.com/video-canvas-magic/ 我们可以在网站上找到很好的例子http://html5doctor.com/video-canvas-magic/

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

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