最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Stream video from a canvas element using WebRTC - Stack Overflow

programmeradmin2浏览0评论

I am using WebRTC for peer-to-peer video munication, and I would like to apply video filters to local webcam video before sending it to a remote peer.

The approach that I am considering is to send the local webcam video to a canvas element, where I will apply javascript filters to the video. Then I would like to stream the video from the canvas element to the peer using WebRTC. However, it is not clear to me if this is possible.

Is it possible to stream video from a canvas element using WebRTC? If so, how can this be done? Alternatively, are there any other approaches that I might consider to acplish my objective?

I am using WebRTC for peer-to-peer video munication, and I would like to apply video filters to local webcam video before sending it to a remote peer.

The approach that I am considering is to send the local webcam video to a canvas element, where I will apply javascript filters to the video. Then I would like to stream the video from the canvas element to the peer using WebRTC. However, it is not clear to me if this is possible.

Is it possible to stream video from a canvas element using WebRTC? If so, how can this be done? Alternatively, are there any other approaches that I might consider to acplish my objective?

Share Improve this question edited Jul 26, 2014 at 6:49 Alexander Marquardt asked Jul 26, 2014 at 6:37 Alexander MarquardtAlexander Marquardt 1,53916 silver badges30 bronze badges 1
  • 1 Instead of sending processed stream you may apply CSS3 filters on the remote peer's side if standard filters (such as grayscale, blur, sepia, etc.) are enough for you. – Oleg Commented Jul 27, 2014 at 10:46
Add a ment  | 

3 Answers 3

Reset to default 2

It's April 2020; you can achieve this with the canvas.captureStream() method.

There is an excellent article on how to use it, along with several demos on github. See the following links:

Capture Stream

Stream from a canvas element to peer connection

So, basically, you can apply all the transformations on the canvas and stream from the canvas to remote peer.

my solution would be, send the normal stream to the peer, also transmit, how it has to be modified, so on the other side, instead of showing in a video element directly( play the video n hide the element), you would keep drawing in a canvas( after processing) with settimeout/requestAnimationFrame.

mozCaptureStreamUntilEnded is supported on firefox but resulting stream can't be attached to peer connection.

Playing over <canvas> is easier however streaming media from a <video> element requires Media Processing API (capture-stream-until-ended) along with RTCPeerConnection (with all features support).

We can get images from <canvas> however I'm not sure if we can generate MediaStream from <canvas>.

So, mozCaptureStreamUntilEnded is useful only wth pre-recorded media streaming.

发布评论

评论列表(0)

  1. 暂无评论