Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pure js stream from webcamera to server

Is it possible to capture stream from webcamera(in front end) and stream it to server via hls or rtmp with pure js(no flash).
And if there are another protocol which let send stream as stream(unlike hls), will be prefered.

like image 363
Kandrat Avatar asked Dec 13 '19 12:12

Kandrat


1 Answers

I found solution. There is no (yet) any way to "convert" stream received from navigator.getUserMedia() to rtmp in front-end. But we can use MediaRecorder Api.
In client Side

const stream = await navigator.getUserMedia(options)
const recorder = new MediaRecorder(stream)
recorder.ondataavailable = (e) => { socket.emit('binaryData',e.data) }
recorder(start)

In backend

const ffmpegProcess = spawn('ffmpeg', ffmpegCommans)
socket.on('binaryData', (data) => { 
  ffmpegProcess.stdin.write(params.data)
})

FFmpeg will convert vp8 video stream to hls/rtmp/rtsp or whatever.

In this way we can get video stream with latency 3(average) second .

like image 67
Kandrat Avatar answered Oct 25 '22 18:10

Kandrat