我正在尝试记录<video>
标记的内容并以.webm
格式下载文件。这是我的代码:
return new Promise(async resolve => {
const stream = await navigator.mediaDevices.getUserMedia({
video: true,
audio: true
});
const mediaRecorder = new MediaRecorder(document.getElementById('#my-video-tag').captureStream());
const audioChunks = [];
mediaRecorder.addEventListener('dataavailable', event => {
audioChunks.push(event.data);
});
const start = () => mediaRecorder.start();
const stop = () =>
new Promise(resolve2 => {
mediaRecorder.addEventListener('stop', () => {
const audioBlob = new Blob(audioChunks);
resolve2({ audioBlob });
});
mediaRecorder.stop();
});
resolve({ start, stop });
});
这是问题所在:
const mediaRecorder = new MediaRecorder(document.getElementById('#my-video-tag').captureStream());
以上内容仅从video标签下载1帧,因此基本上是静止图像。如何使其正常工作,以便下载整个视频?