无法通过 RTCPeerConnection 发送 CanvasCaptureMediaStreamTrack

发布于 2025-01-16 23:46:32 字数 1049 浏览 0 评论 0原文

我在两个对等点之间有一个简单的 RTCPeerConnection,用于传输视频。

该连接与 MediaStream 类型完美配合。视频和摄像机流正在通过并接收。

但是,当我尝试发送包含 CanvasCaptureMediaStreamTrackMediaStream 时,接收方 pc2 没有发出任何有用的信息。 MediaStream 到达,但是当我将其附加到 元素时,它什么也没有显示(甚至没有空白图片),并且有一个 MediaRecorder 也不记录任何内容(0 字节)。与此同时,流中似乎还出现了一段视频轨道。

画布不是空的。它的宽度为 320x200,包含一个填充的矩形,上面有文本。我可以将捕获的画布流直接发送到 元素,并且它显示正确。

通过 RTC 连接发送 CanvasCaptureMediaStreamTrack 显然并非不可能,如下所示: https://webrtc.github.io/samples/src/content /capture/canvas-pc/

当我查看源代码时,我没有看到任何新内容。这就是演示捕获画布流并将其传递给 RTCPeerConnection 的方式:

const pc1 = new RTCPeerConnection(null);
const stream = canvas.captureStream();

stream.getTracks().forEach(track => {
  pc1.addTrack(track, stream);
});

我缺少什么吗?当演示工作时,为什么我的画布流无法通过连接?

I have a simple RTCPeerConnection between two peers, to stream video.

The connection works perfectly with MediaStream types. Video and camera streams are going through and received.

However, when I try to send a MediaStream that contains a CanvasCaptureMediaStreamTrack, nothing useful comes out of pc2, the receiving peer. A MediaStream arrives, but when I attach it to a <video> element, it shows nothing (not even a blank picture), and a MediaRecorder also records nothing (0 bytes). At the same time, there seems to be a video track in the stream.

The canvas isn't empty. It has a width of 320x200, and contains a filled rectangle, with a text on it. I can send the captured canvas stream directly to a <video> element, and it appears correctly.

It's apparently not impossible to send a CanvasCaptureMediaStreamTrack through an RTC connection, as it's demonstrated here:
https://webrtc.github.io/samples/src/content/capture/canvas-pc/

When I looked into the source code, I saw nothing new. This is how the demo captures the canvas stream, and passes it to the RTCPeerConnection:

const pc1 = new RTCPeerConnection(null);
const stream = canvas.captureStream();

stream.getTracks().forEach(track => {
  pc1.addTrack(track, stream);
});

Is there something I'm missing? Why won't my canvas stream go through the connection, while the demo works?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文