javascript - 在 Safari 14.0.2 上,MediaRecorder dataavailable 处理程序捕获空 blob
问题描述
我正在使用 MediaRecorder API 从 Safari (v14.0.2) 录制网络摄像头会话。将handleDataAvailable
每 500 毫秒收集一次流数据并将 blob 推送到recordedBlobs
数组中。
this.recordedBlobs = []
this.mediaRecorder = new window.MediaRecorder(this.stream, {mimeType: "video/mp4;codecs=avc1"})
this.mediaRecorder.addEventListener('stop', this.handleStop)
this.mediaRecorder.addEventListener('error', this.handleError)
this.mediaRecorder.addEventListener(
'dataavailable',
this.handleDataAvailable
)
this.mediaRecorder.start(500) // Collect blob data every 500ms
handleDataAvailable = (event) => {
this.recordedBlobs.push(event.data)
}
但是我从控制台日志中观察到的是,一些 blob 的大小为 0 并且类型为“”。空 blob 随机发生;有时没有,有时数组内部有很多。
当我连接所有 blob 以创建一个全新的 blob 时,它会产生更大的问题,新 blob 已损坏。在以下情况下,第二个 blob 的大小为 0,每个 blob 持续时间为 500 毫秒,视频应该有 5 秒的持续时间,但我只能播放前 500 毫秒。
该问题仅发生在 Safari 上,Chrome 工作正常。任何指针将不胜感激!
Array (11)
0 Blob {size: 402074, type: "video/mp4", slice: function, text: function, arrayBuffer: function}
1 Blob {size: 0, type: "", slice: function, text: function, arrayBuffer: function}
2 Blob {size: 726104, type: "video/mp4", slice: function, text: function, arrayBuffer: function}
3 Blob {size: 355672, type: "video/mp4", slice: function, text: function, arrayBuffer: function}
4 Blob {size: 374119, type: "video/mp4", slice: function, text: function, arrayBuffer: function}
5 Blob {size: 369714, type: "video/mp4", slice: function, text: function, arrayBuffer: function}
6 Blob {size: 378604, type: "video/mp4", slice: function, text: function, arrayBuffer: function}
7 Blob {size: 381219, type: "video/mp4", slice: function, text: function, arrayBuffer: function}
8 Blob {size: 434928, type: "video/mp4", slice: function, text: function, arrayBuffer: function}
9 Blob {size: 359651, type: "video/mp4", slice: function, text: function, arrayBuffer: function}
10 Blob {size: 217731, type: "video/mp4", slice: function, text: function, arrayBuffer: function}
解决方案
推荐阅读
- css - 未应用 Firebase CSS 媒体查询
- excel - 将数据透视图标签“附加”到图表底部
- python - 尝试在树莓派上托管 python 套接字服务器时出现 ConnectionRefusedError
- powershell - 有没有办法可以进行多行输入?
- linux - 如何在 bash 中获取 tsv 文件中的第二列和最后一列内容?
- javascript - 我编写了一个用户填写的 HTML 表单,但是如果他们再次访问该页面,我如何证明他们已经提交了该表单?
- angular - Angular RXJS 长轮询
- python - 直方图未出现在 Python 屏幕上
- c# - MSBUILD 无法使用混合平台构建解决方案?
- excel - 我可以通过在 VBA 中使用索引来获取第一个单元格值,但不能在该范围内使用稍后的单元格值