preface

In the last tutorial, we implemented FFmpeg transcoding RTSP to RTMP, nginx distribution, and playing video on the page. However, RTMP also has some drawbacks, such as:

  • RTMP video streams can be played in Flash, so you have to have Flash installed on your computer, but the major browsers are ready to move away from Flash
  • RTMP video streaming is still implemented with a 2-3 second delay, which is still not ideal for real-time alarm systems.

So this tutorial is going to build a complete video system to optimize both of these problems.

The project address

Github.com/JackFlyL/no…

The project requirements

  • Multi-platform IPC real-time video playback
  • Historical video playback
  • Yuntai control
  • Polling transcoding task prevents video disconnection
  • Node.js implements interface interaction

The technical architecture

Skills of stack

Front end:

  • Jsmpeg. js (connect to wbesocket and draw video images)

Server (Node) :

  • Express (Static service, interface processing)
  • Body-parser (handles incoming data for interfaces)
  • Node-rtsp-stream-jsmpeg (deliver FFmpeg to create webSocke server)
  • Child_process (Start shell script directive)

Other:

  • FFmpeg(Video Stream code)
  • Pm2 (Node process daemon)
  • PTC control program (secondary development through THE SDK provided by the video manufacturer, through Ajax call)

The service side

  • Create a static server using Node.js

  • Receive parameters and cross-domain processing

  • Post Interface Cases

  • Node.js invokes shell scripts (child_process)

  • Start transcoding to create webSocket server

  • Periodically check and kill the FFmpeg process and restart websocket to prevent video disconnection

The client

Use jsmpeg.js to specify the websocket address and DOM and play happily!

Pm2 process daemon

  • Linux installs Node and NPM
  • npm install pm2 -g
  • Pm2 start xx.js
  • Pm2 stop xx.js
  • Pm2 List (Service List)
  • Pm2 log (Log output)
  • Pm2 MONIT (Service Monitoring)

This is probably a few commonly used commands, very simple to use pM2 detailed can go to the official website to see

Let’s see what happens

conclusion

So far, we use node full stack to achieve a simple video platform, advantages:

  • Also preview IPC videos and videos from Hikon, Dahua and others that can produce RTSP streams.
  • No plug-ins need to be installed
  • Does not rely on Flash to play video
  • The video delay is reduced to less than 1s

There are also known problems:

  • The performance consumption of primary code flow code is huge (each logical CPU usage reaches about 120, so try to use sub-code flow code, the performance consumption is about 20).
  • Historical video flow code only supports Hikon (some NVR does not support historical RTSP video output)
  • Memory overflow occurs due to frequent switching between front-end JSMPEG and Websocket connections. After refreshing, the memory overflow is displayed normally
  • Video has no sound

Finally, if the project needs For video and audio doesn’t require the package is very good, it has very good compatibility, mobile PC basically no restrictions, second delay is more ideal, after all through transcoding processing, certainly than the source video, but now he should delay time is ideal.