使用 MediaRecorder 以 MP4 格式录制来自网络摄像头的视频 [英] Recording video from webcam in MP4 format with MediaRecorder

查看:450
本文介绍了使用 MediaRecorder 以 MP4 格式录制来自网络摄像头的视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在支持 MP4 和 MediaRecorder(Linux 上的 Firefox)的浏览器中使用 JS MediaRecorder 以 MP4 格式录制网络摄像头时,网络摄像头启动但不录制.

When I use the JS MediaRecorder to record webcam in MP4 format in a browser supporting MP4 and MediaRecorder (Firefox on Linux), the webcam starts but it does not record.

当 MediaRecorder 的 mimeType 设置为 video/webm 时,录制工作正常,但是当我将 mimeType 设置为 video/mp4 时,就会出现问题.

Recording has worked when the mimeType of the MediaRecorder is set to video/webm but when I set the mimeType to video/mp4 the problem occurs.

我用以下代码录制:

if (navigator.mediaDevices) {
        var constraints = {audio: true, video: true};
        navigator.mediaDevices.getUserMedia(constraints).then(function (stream) {
            mediaRecorder = new MediaRecorder(stream, {mimeType: "video/mp4"});
            mediaRecorder.start();
});
} else {
console.log("media recorder is not supported");
}

当代码在支持的浏览器中执行时,我希望网络摄像头开始录制,但是 console.log 没有输出,并且在控制台中出现了以下错误:

I expect the webcam to start recording when the code is executed in a supporting browser, but the console.log is not output and in the console there is the error of :

NotSupportedError: 不支持操作

我知道我的浏览器同时支持 mp4 和 MediaRecorder:

I know that my browser supports both mp4 and MediaRecorder:

MP4:https://caniuse.com/#search=mp4MediaRecorder:https://caniuse.com/#search=mediarecorder

MP4: https://caniuse.com/#search=mp4 MediaRecorder: https://caniuse.com/#search=mediarecorder

但只有 webm 录制有效.

but only webm recording works.

推荐答案

我发现 Chromium 也不支持 mp4 录制,所以我决定在视频上传后在服务器端进行转换.

I found that Chromium doesn't support mp4 recording either, so I decided to do the conversion on the server side after the video was uploaded.

由于是 GNU/Linux,所以为了加快转换速度,我使用了:

Since it is GNU/Linux, to speed up the conversion I used:

ffmpeg -i input.webm -preset superfast output.mp4

如果有更快的方法,我想知道它们.

If there are faster approaches I would like to know them.

这篇关于使用 MediaRecorder 以 MP4 格式录制来自网络摄像头的视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆