我写了一个html文件,用于在本地录制视频和下载录制的视频,我在safari和edge上都测试成功,并且下载为mp4文件,但是在Firefox上没能成功,下载为了webm格式,我不知道该如果修改,希望各位能指点迷津
stackoverflow:https://stackoverflow.com/questi ... -what-is-ok-in-othe
record codes:
- function startRecording() {
- clearRecordedData();
- navigator.mediaDevices.getUserMedia({ video: true, audio: true })
- .then((stream) => {
- mediaRecorder = new MediaRecorder(stream, recorderOptions);
- const liveCamera = document.getElementById('liveCamera');
- liveCamera.srcObject = stream;
-
- liveCamera.muted = true;
- mediaRecorder.ondataavailable = (event) => {
- if (event.data.size > 0) {
- recordedChunks.push(event.data);
- }
- };
- mediaRecorder.onstop = () => {
- recordedBlob = new Blob(recordedChunks, { type: 'video/mp4' });
- console.log(recordedBlob);
- console.log(recordedBlob.type);
- recordedVideo.src = URL.createObjectURL(recordedBlob);
- enableButtons(['startRecord', 'saveRecord', 'playRecord']);
- disableButtons(['stopRecord']);
- };
- mediaRecorder.start();
- recordedTime = 0;
- updateRecordedTime();
- disableButtons(['startRecord']);
- enableButtons(['stopRecord']);
- })
- .catch((error) => {
- console.error('getUserMedia error:', error);
- });
- }
复制代码
save codes:
- function saveRecording() {
- if (recordedBlob) {
- const url = URL.createObjectURL(recordedBlob);
- const a = document.createElement('a');
- a.href = url;
- var urlParams = new URLSearchParams(window.location.search);
- var sourceValue = urlParams.get('source');
- a.download = sourceValue + '.mp4';
- console.log(recordedBlob);
- console.log(a);
- document.body.appendChild(a);
- a.click();
- document.body.removeChild(a);
- }
- }
复制代码
|
|