简体   繁体   English

录制视频和音频

[英]Recording video and audio

Fiddle小提琴

I followed this fiddle.我跟着这个小提琴。 In this it has the video and audio capturing.其中它具有视频和音频捕获。 But it won't let me record the video and send it to php for further processing using ffmpeg and save it.但它不会让我录制视频并将其发送到 php 以使用 ffmpeg 进行进一步处理并保存。 I want to know that how am i able to record the video and send it to php and save it ?我想知道如何录制视频并将其发送到 php 并保存?

var btnVideoCapture = document.getElementById('btn-capture-video');
btnVideoCapture.addEventListener('click', showUserMedia, false);

var btnScreenshot = document.getElementById('btn-screenshot');
btnScreenshot.addEventListener('click', snapshot, false);

var btnStopVideo = document.getElementById('btn-stop-video');
btnStopVideo.addEventListener('click', stopUserMedia, false);

var onFailSoHard = function (e) {
    console.log('Reeeejected!', e);
};
var video = document.querySelector('video');
var canvas = document.querySelector('canvas');
var ctx = canvas.getContext('2d');
var localMediaStream = null;


function showUserMedia() {
    window.URL = window.URL || window.webkitURL;
    navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia;
    if (navigator.getUserMedia) {
        navigator.getUserMedia({
            audio: true,
            video: true
        }, function (stream) {
            video.src = window.URL.createObjectURL(stream);
            video.controls = true;
            localMediaStream = stream;
        }, onFailSoHard);
        // console.log('Good to go!');
    } else {
        video.src = 'somevideo.webm'; // fallback.
        //console.log('getUserMedia() is not supported in your browser');
    }
}

function snapshot() {
    canvas.width = video.videoWidth;
    canvas.height = video.videoHeight;
    if (localMediaStream) {
        ctx.drawImage(video, 0, 0);
        // "image/webp" works in Chrome 18. In other browsers, this will fall back to image/png.
        document.querySelector('img').src = canvas.toDataURL('image/webp');
    }
}

function stopUserMedia() {
    video.pause();
    localMediaStream.stop();
    video.src = '';
}

The code you posted only accesses the webcam and displays the video stream in the <video> element ( showUserMedia() function).您发布的代码仅访问网络摄像头并在<video>元素( showUserMedia()函数)中显示视频流。 It doesn't record the video or POSTs the data to a web server.它不会录制视频或将数据发布到 Web 服务器。

To record the video (and audio) you need to use the Media Recorder API which is now supported by Chrome (49+) and Firefox(30+).录制视频(和音频),您需要使用 Chrome(49+)和 Firefox(30+)现在支持的Media Recorder API Both browsers record to .webm and you can POST the file to a web server for further processing.两个浏览器都记录到.webm ,您可以将文件 POST 到 Web 服务器以进行进一步处理。

This article covers the spec in detail and here's a live demo + GitHub project .本文详细介绍了规范,这里有一个现场演示+ GitHub 项目

Take a look at RecordRTC看一下RecordRTC

You may want to take a look at this too: How to record webcam and audio using webRTC and a server-based Peer connection您可能还想看看这个: 如何使用 webRTC 和基于服务器的对等连接录制网络摄像头和音频

I think this serves your specific need : https://github.com/muaz-khan/WebRTC-Experiment/tree/master/RecordRTC/RecordRTC-to-PHP我认为这可以满足您的特定需求https : //github.com/muaz-khan/WebRTC-Experiment/tree/master/RecordRTC/RecordRTC-to-PHP

Here's an example of recording video and audio: opentokrtc.com这是录制视频和音频的示例:opentokrtc.com

1- First you would do recording using javascript 2- then set a hidden mutipart hidden form in page 3- When a video has recorded then you trigger an event which render the recorded video to form. 1- 首先,您将使用 javascript 2- 然后在第 3 页中设置一个隐藏的多部分隐藏表单- 录制视频后,您将触发一个事件,将录制的视频呈现为表单。 4 - then here you can manually submit this video to PHP script 4 - 然后在这里您可以手动将此视频提交到 PHP 脚本

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM