最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Pure js stream from webcamera to server - Stack Overflow

programmeradmin7浏览0评论

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.

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.

Share Improve this question asked Dec 13, 2019 at 12:26 KandratKandrat 4741 gold badge7 silver badges17 bronze badges 0
Add a ment  | 

1 Answer 1

Reset to default 6

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)

  1. 暂无评论