NodeJS get video source from webcam on the server for webRTC
NodeJS get video source from webcam on the server for webRTC
I want to get video source from webcam on NodeJS server to stream video to the client via WebRTC.
There is many examples how to implement this only for browser (client side) but I still can't find any reliable solution for NodeJS (server side).
In example this is the basic script for the client side to get video source:
navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia;
var constraints = {audio: false, video: true};
var video = document.querySelector("video");
function successCallback(stream) {
// stream available to console so you could inspect it and see what this object looks like
window.stream = stream;
if (window.URL) {
video.src = window.URL.createObjectURL(stream);
} else {
video.src = stream;
}
video.play();
}
function errorCallback(error) {
console.log("navigator.getUserMedia error: ", error);
}
navigator.getUserMedia(constraints, successCallback, errorCallback);
<div id='video-space'>
<video autoplay></video>
</div>
I suppose there is some simple way to implement the same thing but only for NodeJS on the server side since it based on V8 engine and probably has the same hardware api as in the browser. Please, correct me if I wrong.
I've already checked out serveral links (simple-peer, webcam-http-streaming, livecam, video stream e.t.c.) but none of them solves my problem, I'am confused.
So, does NodeJS have some native api to get video source for streaming via WebRTC on the server like in the browser or should I use some library/package for this purpose?
The goal is to plug-in usb webcam into the (i.e.) Raspberry Pi and stream video right from NodeJS server to the client.
I really don't want to use browser on the server for this purpose.
Any advice will be appreciated, thanks!
@Brad, thank you! I'll try this. Seems that the alternative approach is to use native c++ library for WebRTC on the server.
– mr.boris
Jul 1 at 20:07
You would be doing that anyway. There are really only two WebRTC stacks maintained today, as far as I know. Nobody is going to roll their own. Post back if you find anything new that could be used!
– Brad
Jul 1 at 20:10
@Brad, the "WebRTC Native" is a chunk of the Chrome browser. What is the other one? What Mozilla uses? (I can't locate the instructions for the source code)
– Velkan
Jul 2 at 7:05
github.com/centricular/gstwebrtc-demos
– Brad
2 days ago
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
There have been a couple experiments pop up over the years that attempted to build the RTC libraries for the MediaStream components and such, but none that I've seen that actually worked. (At least, none public or open source. No doubt people have done this for their own commercial endeavors.) I hope you're able to find something. If you're just using a Raspberry Pi though, there is code for this. github.com/kclyu/rpi-webrtc-streamer
– Brad
Jul 1 at 13:52