Pure js stream from webcamera to server

后端 未结 1 755
星月不相逢
星月不相逢 2021-02-09 00:54

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

1条回答
  •  走了就别回头了
    2021-02-09 01:15

    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 .

    0 讨论(0)
提交回复
热议问题