Using getUserMedia I can capture video stream from client's webcam/camera. And using video
tag I can show it on client's browser. Code:
<video autoplay></video> <script type="text/javascript"> window.URL = window.URL || window.webkitURL; navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia; var video = $('video')[0]; var failed = function(e) { console.log('Denied!', e); }; if( navigator.getUserMedia ) { navigator.getUserMedia( {video: true, audio: true}, function( stream ) { video.src = window.URL.createObjectURL(stream); }, failed ) } else { console.log( 'Not supported!' ); } </script>
Now is it possible to send this video stream, either as a realtime feed or after user has done recording and decided to upload, to a server?
I found few examples of:
HTML5 is not itself a streaming protocol. Websites built with HTML5 can use several different streaming protocols to play video, including HTTP live streaming (HLS) and MPEG-DASH. This is configured on the server side, not in the HTML markup code.
Inside the <body> tag, create a <main> element with an ID of camera . Inside the <main id=”camera”> , create a <canvas> element with the ID of camera--sensor . Similar to a real camera sensor, the canvas element will grab a frame from the video stream when we tell it to, and draw it to the next element we'll create.
The webmasters need to use special HTML5 coding and include WebM, MP4 and OGG formats on their web pages. Before HTML5 videos were only played using the Flash Player. You can view HTML5 videos on all popular browsers such as Google Chrome, Internet Explorer, Mozilla Firefox, and Safari.
MediaStreamRecorder is a WebRTC API for recording getUserMedia() streams . It allows web apps to create a file from a live audio/video session.
<video autoplay></video> <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("http://www.kongraju.in/uploadvideo.php", data, onUploadSuccess); } function onUploadSuccess() { alert ('video uploaded'); } </script> <div id="webcamcontrols"> <button class="recordbutton" onclick="startRecording();">RECORD</button> </div>
Spec:
http://www.w3.org/TR/mediastream-recording/
you can send recorded file to server.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With