RTP RTSP implementation in javascript

2020-08-03 03:10发布

问题:

I have a client program and a server program. The server is on my localhost and it has my .mpeg video.

Using node JS I am supposed to stream a video from a server. The client requests messages, such as play/pause/resume/rewind etc. so I guess I have to use RTSP, to figure out what to send over the RTP. But I don't know from where to start.

All I have so far is the RegEx to filter the message, for example on the client there are buttons like play/pause/setup etc. so I can grab that text. And I have a switch. But if I get setup what I should I do?

P.S I am not allowed to use RTSP modules or RTP modules. Gotta do it all from scratch.

回答1:

When streaming mpeg file over the wire you will have to tackle RTSP and RTP separately. RTSP is used for signaling, session establishing and starting the underlying RTP stream.If you need to do this in node.js, I recommend loading a library that already implements RTSP/RTP(creating your own is quite a undertaking, but it is doable as well).

Some info on loading c++ libraries in node.js that: How can I use a C++ library from node.js?

So basically, from you mpeg file, you need to extract raw h264 stream. For this I recommend ffmpeg or some other libraries/code that understands mpeg file structure. Then you need to packetize the encoded frames inside of RTP packets; which you will then send back to the client from the server. The client will then depacketize the encoded frames into actual frame; and then decoded/display them on the screen .

I recommend reading http://www.ietf.org/rfc/rfc3984.txt for info on standard way to packetize H264 video.

This is all very general approach, but it gives you a general idea. Hopefully this info helps, good luck.