MediaStreamRecorder API is webRTC API that supports recording streams with getUserMedia or remote streams passed over peerconnection session.
<script language="javascript" type="text/javascript">
function onVideoFail(e) {
console.log('webcam fail!', e);
};
function hasGetUserMedia() {
// Note: Opera is unprefixed.
return !!(navigator.getUserMedia || navigator.webkitGetUserMedia ||
navigator.mozGetUserMedia || navigator.msGetUserMedia);
}
if (hasGetUserMedia()) {
// Good to go!
} else {
alert('getUserMedia() is not supported in your browser');
}
window.URL = window.URL || window.webkitURL;
navigator.getUserMedia = navigator.getUserMedia ||
navigator.webkitGetUserMedia ||
navigator.mozGetUserMedia ||
navigator.msGetUserMedia;
var video = document.querySelector('video');
var streamRecorder;
var webcamstream;
if (navigator.getUserMedia) {
navigator.getUserMedia({audio: true, video: true}, function(stream) {
video.src = window.URL.createObjectURL(stream);
webcamstream = stream;
// streamrecorder = webcamstream.record();
}, onVideoFail);
} else {
alert ('failed');
}
function startRecording() {
streamRecorder = webcamstream.record();
setTimeout(stopRecording, 10000);
}
function stopRecording() {
streamRecorder.getRecordedData(postVideoToServer);
}
function postVideoToServer(videoblob) {
var data = {};
data.video = videoblob;
data.metadata = 'test metadata';
data.action = "upload_video";
jQuery.post("uploadvideo.php", data, onUploadSuccess);
}
function onUploadSuccess() {
alert ('video uploaded');
}
</script>
"getRecorderdedData" return blob that was recorded.
<script language="javascript" type="text/javascript">
function onVideoFail(e) {
console.log('webcam fail!', e);
};
function hasGetUserMedia() {
// Note: Opera is unprefixed.
return !!(navigator.getUserMedia || navigator.webkitGetUserMedia ||
navigator.mozGetUserMedia || navigator.msGetUserMedia);
}
if (hasGetUserMedia()) {
// Good to go!
} else {
alert('getUserMedia() is not supported in your browser');
}
window.URL = window.URL || window.webkitURL;
navigator.getUserMedia = navigator.getUserMedia ||
navigator.webkitGetUserMedia ||
navigator.mozGetUserMedia ||
navigator.msGetUserMedia;
var video = document.querySelector('video');
var streamRecorder;
var webcamstream;
if (navigator.getUserMedia) {
navigator.getUserMedia({audio: true, video: true}, function(stream) {
video.src = window.URL.createObjectURL(stream);
webcamstream = stream;
// streamrecorder = webcamstream.record();
}, onVideoFail);
} else {
alert ('failed');
}
function startRecording() {
streamRecorder = webcamstream.record();
setTimeout(stopRecording, 10000);
}
function stopRecording() {
streamRecorder.getRecordedData(postVideoToServer);
}
function postVideoToServer(videoblob) {
var data = {};
data.video = videoblob;
data.metadata = 'test metadata';
data.action = "upload_video";
jQuery.post("uploadvideo.php", data, onUploadSuccess);
}
function onUploadSuccess() {
alert ('video uploaded');
}
</script>
<video autoplay></video>
<div id="webcamcontrols">
<button class="recordbutton" onclick="startRecording();">RECORD</button>
</div>
<div id="webcamcontrols">
<button class="recordbutton" onclick="startRecording();">RECORD</button>
</div>
"getRecorderdedData" return blob that was recorded.
15 comments
commentsHello! What must be in uploadvideo.php? And why it is nothing happends when recordbutton is clicked?
Replyuploadvideo.php is to store recorded blob in file. MediaStreamRecorder API is still under implementation, use chrome canary, it helps you to build advanced apps.
Replywhat code should contain uploadvideo.php, to save blub in a file? or it is not already running in normal chrome? because when i press the record button nothing happens. It is only for canary?
ReplyI'm trying to make the video comments service. Аre there other ways of recording video with sound, without the use of flash (for cross platform)?
ReplyThank you.
can you please give me the uploadvideo.php code or uploadvideo.jsp code
Replyplease send it at gunturumanohar2@gmail.com
What about encoding ? In your exemple, what is the default mediat format ? Raw ? How can you encode before uploading ?
ReplyHi,
ReplyThis is ganesan,I am trying to capture Audio and video from webcam using HTML5, But I can see video, Audio is not coming, My aim is like live streaming with audio and video and save it to server, I am using following url for reference as http://html5-demos.appspot.com/static/getusermedia/record-user-webm.html
Please Share your source, I am struck with implementation, Kindly share your Email Address
as he/she would make to put a camera ip?
ReplyHi,
ReplyPlease help me to download the recorded audio without using libraries in javascript
Hi,
ReplyPlease help me to download the recorded video without using libraries in javascript
hi,
Replyplease help me to download the video and playback the video i.e.,convert the recorded audio from webcam to webm format using javascript or html5 that to without using any of the libraries.
webcamstream.record is not a function on RECORD button click
ReplyHi,
ReplyDid you find a solution for this ?
I am also getting this error message.
I am also getting the same error as "webcamstream.record is not a function", Please guide me to resolve this error or suggest me any other way to achieve this functionality.
Reply