3
nodejs를 사용하여 만든 웹 사이트에 랩톱 카메라를 사용하여 비디오를 녹화해야합니다. 이를 위해 webRTC를 사용하고 있습니다. 지금까지 랩톱 카메라를 사용하여 사진을 찍을 수는 있었지만 비디오를 녹화해야했습니다. 코드가 어떻게 될지에 대해 도움을 줄 수 있습니까? 내가 당신을 위해 코드를 작성하지 않을거야webrtc를 사용하여 비디오를 녹화하는 방법
<video id="video"></video>
<button id="startbutton">Take photo</button>
<button id="pausebutton">Pause</button>
<button id="resumebutton">Resume</button>
<canvas id="canvas"></canvas>
<script type="text/javascript">
(function() {
var streaming = false,
video = document.querySelector('#video'),
canvas = document.querySelector('#canvas'),
//photo = document.querySelector('#photo'),
startbutton = document.querySelector('#startbutton'),
width = 620,
height = 50;
navigator.getMedia = (navigator.getUserMedia ||
navigator.webkitGetUserMedia ||
navigator.mozGetUserMedia ||
navigator.msGetUserMedia);
navigator.getMedia(
{
video: true,
audio: false
},
function(stream) {
if (navigator.mozGetUserMedia) {
video.mozSrcObject = stream;
} else {
var vendorURL = window.URL || window.webkitURL;
video.src = vendorURL.createObjectURL(stream);
}
video.play();
},
function(err) {
console.log("An error occured! " + err);
}
);
video.addEventListener('canplay', function(ev){
if (!streaming) {
height = video.videoHeight/(video.videoWidth/width);
video.setAttribute('width', width);
video.setAttribute('height', height);
canvas.setAttribute('width', width);
canvas.setAttribute('height', height);
streaming = true;
}
}, false);
function takepicture() {
canvas.width = width;
canvas.height = height;
canvas.getContext('2d').drawImage(video, 0, 0, width, height);
var data = canvas.toDataURL('image/png');
// photo.setAttribute('src', data);
}
function pausevideo() {
canvas.width = width;
canvas.height = height;
video.pause();
}
function resumevideo() {
canvas.width = width;
canvas.height = height;
video.play();
}
startbutton.addEventListener('click', function(ev){
takepicture();
ev.preventDefault();
}, false);
pausebutton.addEventListener('click', function(ev){
pausevideo();
ev.preventDefault();
}, false);
resumebutton.addEventListener('click', function(ev){
resumevideo();
ev.preventDefault();
}, false);
})();
</script>
녹음 기능은 어디든지 갈 수 있습니다. 웹 소켓이나 블랍에 모든 데이터를 보내시겠습니까? [Record-rtc] (https://www.webrtc-experiment.com/RecordRTC/)는 blob 기록에 잘 작동하며 WebSocketRtcRecorders (https://github.com/Computician/WebSocketWebRTCRecorders)는 웹 소켓에서 작동합니다 (각 프레임 전송 websocket을 통해 서버로). –
비디오를 캡처하여 로컬 폴더에 저장하고 싶습니다. 코드를 도와 주시겠습니까? – user3768671
좋은 소식은 크롬이 [Blob-in-IndexedDB] (http://updates.html5rocks.com/2014/07/Blob-support-for-IndexedDB-landed-on-Chrome-Dev)를 지원하기 시작했다는 것입니다. [안정] (http://www.chromium.org/getting-involved/dev-channel#TOC-Channels) 채널에 착륙했을 때 RecordRTC에서 업데이트됩니다. 그런 다음, 우리는 기록 된 얼룩 (MediaRecorder 또는 비)을 인덱싱 된 DB에 직접 저장할 수 있습니다. –