In the process of using EasyNVR, some users urgently hope that we can provide video stream to enable the video recording function in real time, and at the same time click to end the video recording, the video file of this period can be directly downloaded to the user’s local. After evaluating this requirement, we decided to implement this feature, so here’s how we did it.
As EasyNVR’s existing template recording function is realized by nginx’s recording template, it does not support real-time recording function, so it needs another independent module to realize this function. The method is to directly obtain the stream data through GO terminal and convert it through FMPAG, and finally save it into the specified video file.
This function does not rely on the original ChannelInfo information, but only needs to find the StreamClient to enable real-time recording by device ID and save the corresponding stream data, so it can be designed separately.
After receiving the real-time video recording request from the front end, it firstly determines whether there is a corresponding video recording task in the task pool. If not, start a new video task and automatically generate a video file name according to the request time.
The backend accepts the stream data structure:
When receiving stream data, judge whether the stream ID has a real-time video task, if so, write the stream data into the corresponding file.
After receiving the request to stop recording, transcode the saved file and delete the recording task.