如何在javascript中获取HTML5视频元素的媒体流对象

所有

  我正在使用webRTC进行点对点通信,我们有来自getUserMedia的媒体流对象,它被作为输入流提供给peerconnection.在这里,我需要来自使用
HTML5的Video元素播放的本地驱动器中所选视频文件的视频流.

是否可以从视频标签创建媒体流对象?

谢谢,
苏瑞

最佳答案 目前你不能从视频标签添加媒体流,但将来应该可以,因为它在
MDN上有解释

MediaStream objects have a single input and a single output. A MediaStream object generated by getUserMedia() is called local, and has as its source input one of the user’s cameras or microphones. A non-local MediaStream may be representing to a media element, like or , a stream originating over the network, and obtained via the WebRTC PeerConnection API, or a stream created using the Web Audio API MediaStreamAudioSourceNode.

但是您可以使用Media Source Extensions API来执行您想要的操作:您必须将本地文件放入流中并附加到MediaSource对象中.您可以在此处了解有关MSE的更多信息:http://www.w3.org/TR/media-source/

您可以在here上找到该方法的演示和来源

点赞