HTML5 Video stream from websocket via MediaSource and MediaSourceBuffer

后端 未结 1 1336
难免孤独
难免孤独 2021-01-16 04:23

I\'m trying to play video from websocket





        
相关标签:
1条回答
  • 2021-01-16 04:50

    The fundamental problem here is you cannot stream those data coming out of MediaRecorder and expect the other end to play it; it is not a complete video. It will only work if the receiving end is able to receive the initialization bytes--which I doubt that will work in a real-world scenario.

    What you can do is to create an interval that will start/stop the MediaRecorder for example every 1 second to make 1 second video chunks that you can transmit over the wire (best I know and tested is websockets)

    I strongly suggest not to use MediaRecorder is you are doing real-time video streaming which was not indicated in your post, but if yes, it would be better that you create a canvas to copy the stream and do some requestAnimationFrame stuff that can capture your video stream into a something you can transmit.

    Take a look at this demo for reference: https://github.com/cyberquarks/quarkus-websockets-streamer/blob/master/src/main/resources/META-INF/resources/index.html

    MediaRecorder in my experience response is delayed that would generally add quite a delay in the video, not to mention the delay that the socket would also introduce.

    Generally, other developers would suggest that you just take the WebRTC route, however based on my experience also WebRTC is not generally faster.

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