Monitoring video pre-recording method and device based on MP4 format and storage medium
By adopting a video pre-recording method based on MP4 format in the monitoring device and using the disk and memory indexing mechanism, the problem of memory occupancy and performance bottlenecks of traditional monitoring video pre-recording schemes is solved, and efficient storage and stable operation of video data is achieved.
Patent Information
- Application Number
- CN202411210146.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-30
- Publication Date
- 2024-12-24
AI Technical Summary
The pre-recording scheme of traditional surveillance videos occupies a large amount of memory and writes a large amount of data in a short period of time has led to challenges in the processing performance and stability of the surveillance device.
Using the MP4 format monitoring video pre-recording method, by creating pre-recorded files on disk, writing video data in sequence and recording indexes in memory, loop overwriting update mechanism, ensuring that data is updated cyclically within the pre-recording time, and When the official recording is triggered, the write position is offset to the end of the disk, the index information is updated, and the pre-recorded file is finally renamed to the official recording file.
It realizes discontinuous storage and efficient splicing of video data, reduces memory usage, avoids large amounts of data writing in a short period of time, and ensures the stable operation and data integrity of the monitoring system.
Smart Images

Figure CN119182951A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to video recording technology, and in particular to a monitoring video pre-recording method, device and storage medium based on MP4 format. Background Art
[0002] Home network smart cameras are becoming more and more common, and they usually have memory cards to store video data. For event-triggered video storage, the device often needs to save the video a few seconds before the event occurs, that is, the video pre-recording. By splicing the pre-recorded and triggered videos, you can get a complete video recording before and after the event.
[0003] At present, general surveillance videos are pre-recorded in memory first, and then converted into formal video files and written to the storage card after the event is triggered. However, the physical memory and processing performance of the surveillance equipment are very limited. This method not only takes up a large amount of memory, but also may write a large amount of data in a short period of time, which is time-consuming and poses severe challenges to the processing performance and stability of the surveillance equipment. Summary of the invention
[0004] The technical problem to be solved by the present invention is to propose a monitoring video pre-recording method, device and storage medium based on MP4 format, so as to solve the performance bottleneck problem existing in the traditional monitoring video pre-recording scheme that occupies a large amount of memory and writes a large amount of data into the storage card in a short time.
[0005] The technical solution adopted by the present invention to solve the above technical problems is:
[0006] On the one hand, the present invention provides a monitoring video pre-recording method based on MP4 format, which comprises the following steps:
[0007] A. Video pre-recording:
[0008] Create a pre-recorded file in MP4 format on disk;
[0009] Write the key frames and subsequent non-key frames within the pre-recording duration into the pre-recording file in sequence, and record the index of each frame in the memory;
[0010] When the frame data to be written exceeds the pre-recorded time or needs to overwrite the first key frame sequence, the index information of the first key frame sequence is deleted from the memory; the first key frame sequence includes the first key frame and its subsequent non-key frame video data;
[0011] If the frame data to be written is at the end of the pre-recorded file and does not exceed the pre-recorded duration after being written, the pre-recorded file will be automatically extended, otherwise the frame data whose index has been deleted will be directly overwritten;
[0012] B. Formal video recording:
[0013] When the formal recording signal is triggered, the write position is offset to the end of the pre-recorded data block on the disk, and the subsequent frame data is written continuously, and the index information is updated at the same time; after the recording is completed, the index information is written from the memory to the end of the file, and the pre-recorded file is renamed to the formal recording file.
[0014] Furthermore, the method for determining whether the frame data to be written needs to overwrite the first key frame sequence includes: if the frame data space of the last deleted index is insufficient to store the frame to be written and the storage space of the first key frame sequence data needs to be occupied, it is determined that the first key frame sequence needs to be overwritten.
[0015] In a second aspect, the present invention further provides a surveillance video pre-recording device based on the MP4 format, which includes a processor and a memory, wherein the memory stores a computer program, and the processor implements the steps of the above method by executing the computer program.
[0016] In a third aspect, the present invention further provides a storage medium having a computer program stored thereon, which implements the steps of the above method when the computer program is executed by a processor.
[0017] The beneficial effects of the present invention are:
[0018] The present invention utilizes the index-based video data access feature supported by MP4 files to achieve non-continuous storage and efficient splicing of video data. Since the data are written to the disk (storage card) in real time, data caching in the memory is avoided, and only the data index needs to be temporarily stored in the memory, which can reduce memory usage and avoid writing a large amount of data in a short time, thereby ensuring the stable operation of the monitoring system and the integrity of the data. BRIEF DESCRIPTION OF THE DRAWINGS
[0019] Figure 1 Schematic diagram of the video pre-recording process in an embodiment of the present invention. DETAILED DESCRIPTION
[0020] For recorded videos in MP4 encapsulation format, audio and video data can be stored in a non-sequential order, and can be correctly read as long as the starting position and size of the data in the index are correct. Under this premise, the cyclically pre-recorded file can be correctly played by the player. In view of this, the present invention provides a monitoring video pre-recording scheme based on the MP4 format, by creating a pre-recorded file in the MP4 format on the disk, writing the real-time video data into the pre-recorded file, and recording the relevant index in the memory. When writing data to the pre-recorded file, a cyclic overwrite update mechanism is adopted to ensure that the data is cyclically updated within the pre-recording time; when the position of the frame data to be written reaches the end of the pre-recorded file and does not exceed the pre-recording time, the pre-recorded file size is automatically expanded to ensure that the data is continuously written; when the formal recording signal is triggered, the writing position is offset to the end of the pre-recorded data block on the disk, and the subsequent frame data is continuously written, and the index information is updated at the same time; after the recording is completed, the index information is written from the memory to the end of the file, and the pre-recorded file is renamed as the formal recording file. The above-mentioned scheme of the present invention can solve the performance bottleneck problem caused by occupying a large amount of memory and writing a large amount of data into the storage card in a short time in the traditional monitoring video pre-recording scheme.
[0021] Example
[0022] The monitoring video pre-recording method based on MP4 format provided in this embodiment includes a video pre-recording process and a formal recording process, wherein the video pre-recording process is to update the recording of the real-time video within a predetermined recording time before triggering the formal recording. For its specific implementation, see Figure 1 , including the following processes:
[0023] Initialize: Create an MP4 file on disk for pre-recording.
[0024] Data writing: Write the key frames and non-key frame data within the pre-recorded time into the pre-recorded file in sequence, and record the data index of the video frame in real time to the memory buffer; among them, the key frame is the frame in the frame sequence where the graphics undergo a critical change, which determines the direction of development of an animation action; the non-key frame, also called the transition frame, plays the role of smoothing the picture.
[0025] Cyclic overwrite: When the data to be written exceeds the pre-recorded time or needs to overwrite the first key frame sequence, a cyclic overwrite update mechanism is used to delete the first key frame in the index and its sequence-related index information to ensure that the data is cyclically updated within the pre-recorded time; the method for determining whether the first key frame sequence needs to be overwritten is: if the frame data space of the last index deletion is not enough to save the frame to be written, and the storage space of the first key frame sequence data needs to be occupied, then it is determined that the first key frame sequence needs to be overwritten. Here, the first key frame sequence includes the first key frame and its subsequent non-key frames.
[0026] Frame data overwriting: For frame data that does not occupy the first key frame and its non-key frame position in the index, directly overwrite the frame data of the previously deleted index to achieve spatial reuse.
[0027] File extension: When the position of the frame data to be written reaches the end of the pre-recorded file and does not exceed the pre-recorded time, the pre-recorded file size is automatically extended to ensure continuous data writing.
[0028] The above process is the pre-recording process of real-time video within the predetermined recording time before triggering the formal recording. When the formal recording signal is triggered, the writing position is offset to the end of the pre-recorded data block, and the subsequent frame data is written continuously, and the index information in the memory is updated at the same time; after the recording is completed, the index information is written from the memory to the end of the file, and the pre-recorded file is renamed to the formal recording file for subsequent management and playback.
[0029] Finally, it should be noted that the above embodiments are only preferred implementations and are not intended to limit the present invention. It should be pointed out that for those skilled in the art, several modifications, equivalent replacements, improvements, etc. can be made without departing from the scope of the present invention and the scope of protection of the claims, and all of these should be included in the protection scope of the present invention.
Claims
1. A monitoring video pre-recording method based on MP4 format, characterized in that: The following steps are involved: A. Video pre-recording: Create a pre-recorded file in MP4 format on disk; Write the key frames and subsequent non-key frames within the pre-recording duration into the pre-recording file in sequence, and record the index of each frame in the memory; When the frame data to be written exceeds the pre-recorded time or needs to overwrite the first key frame sequence, the index information of the first key frame sequence is deleted from the memory; the first key frame sequence includes the first key frame and its subsequent non-key frame video data; If the frame data to be written is at the end of the pre-recorded file and does not exceed the pre-recorded duration after being written, the pre-recorded file will be automatically extended, otherwise the frame data whose index has been deleted will be directly overwritten; B. Formal video recording: When the formal recording signal is triggered, the write position is offset to the end of the pre-recorded data block on the disk, and the subsequent frame data is written continuously, and the index information is updated at the same time; after the recording is completed, the index information is written from the memory to the end of the file, and the pre-recorded file is renamed to the formal recording file.
2. A surveillance video pre-recording method based on MP4 format as claimed in claim 1, characterized in that: The method of determining whether the frame data to be written needs to overwrite the first key frame sequence includes: if the frame data space of the last deleted index is insufficient to store the frame to be written and needs to occupy the storage space of the first key frame sequence data, it is determined that the first key frame sequence needs to be overwritten.
3. A surveillance video pre-recording device based on MP4 format, comprising a processor and a memory, characterized in that: The memory stores a computer program, and the processor implements the steps of the monitoring video pre-recording method based on the MP4 format as claimed in claim 1 or 2 by executing the computer program.
4. A storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the monitoring video pre-recording method based on the MP4 format as claimed in claim 1 or 2 are implemented.
