如何最简将HTML Canvas生成的MediaStream推流至VLC、YouTube/Facebook直播
Canvas 媒体流相关问题描述
我创建了一个简单的canvas元素,用于绘制字符串"Hello World",对应代码如下:
<!DOCTYPE html> <html> <body> <canvas id="myCanvas" width="200" height="100" style="border:1px solid #d3d3d3;"> Your browser does not support the HTML canvas tag.</canvas> <script> var c = document.getElementById("myCanvas"); var ctx = c.getContext("2d"); ctx.font = "30px Arial"; ctx.fillText("Hello World",10,50); </script> </body> </html>
我可以通过MediaStream接口,调用HTMLCanvasElement.captureStream()方法从该canvas创建媒体流,对应代码如下:
// Find the canvas element to capture var canvasElt = document.querySelector('myCanvas'); // Get the stream var stream = canvasElt.captureStream(25); // 25 FPS // Do things to the stream now
目前我不清楚如何使用该stream,让流内容可被VLC,或是YouTube、Facebook直播服务接收使用。我猜测MediaRecorder可提供相关支持,但不清楚具体实现方式;我找到的示例仓库操作流程复杂,并非我想要的简易实现方案。
内容的提问来源于stack exchange,提问作者Alok
相关产品推荐
相关产品推荐

