Pure js stream from webcamera to server

后端 未结 1 1099
时光取名叫无心
时光取名叫无心 2021-02-09 00:48

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:17

    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)
提交回复
热议问题