Video storage method and device
By decomposing the recording process into planned recording and alarm recording, and using the state machine to realize the dual cycle process, the stability and accuracy problems caused by mixed recording in the storage product are solved, ensuring that no video and alarm recording are lost for 7*24 hours Accuracy meets high stability and performance requirements.
Patent Information
- Application Number
- CN202411089134.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-09
- Publication Date
- 2024-12-06
AI Technical Summary
When existing storage products mix storage plan video recording and alarm video recording, they lead to difficulty in searching, errors, unstable memory and disk operations, making it difficult to meet the accuracy and stability requirements of long-term recording, especially in consumer products with limited resources. .
Decompose the video recording process into a planned video recording process and an alarm video recording process, and decompose the alarm video recording process into a pre-recording write cache process and an alarm file writing process. The state machine is used to decompose the process into multiple substeps to realize the dual cycle process to ensure 7* The accuracy of recording and alarm recording is not lost for 24 hours.
By decomposing the process and introducing the state machine, the parallel separate operation of planned video recording and alarm video is achieved, ensuring the accuracy of no loss of video recording and alarm video for 7*24 hours, meeting the high requirements for stability of the storage system, and improving the System performance and development efficiency.
Smart Images

Figure CN119094676A_ABST
Abstract
Description
Technical Field
[0001] The invention belongs to the field of storage technology, and in particular relates to a method and device for storing video recordings. Background Art
[0002] Storage technology is developing in two directions: one is towards massive data, and the other is towards consumption or intelligence. Our topic today is security storage products, so it is consumer storage products.
[0003] Storage products are mainly used to store video recordings from cameras (ipc: ip camera, digital video camera), and ultimately write the ipc's audio and video streams to disk in the form of files. Disk operations have high requirements for memory and stability.
[0004] Recording is divided into scheduled recording and alarm recording. Scheduled recording is characterized by low resolution and low bit rate, while alarm recording is generally high resolution and high bit rate. Therefore, for the same time, scheduled recording occupies much less disk space than alarm recording. Therefore, scheduled recording is used for 7*24 hours of uninterrupted recording; while alarm recording is used for emergencies, and the duration is generally in seconds or minutes.
[0005] The characteristics of consumer products are limited resources, that is, limited resources such as CPU and memory, but the requirements are not low. Because they are closer to users and are used more frequently, they have higher requirements for product stability and performance. Storage products have higher requirements for memory and disk operation stability. General storage products often mix scheduled recordings and alarm recordings together or just separate them by file, which will make it difficult to separate the search, slow and error-prone, affecting the user experience; the lack of an effective method in the process will also lead to unstable memory and disk operations, resulting in lost recordings, making it difficult to meet the accuracy of long-term scheduled recordings and alarm recordings, and difficult to meet the requirements of stability and performance of the entire storage. Therefore, we need to propose a method and device for storing recordings to solve the problems existing in the prior art, so that it can not only ensure that recordings are not lost 7*24 hours, but also ensure that alarm recordings are accurate and meet the high requirements of storage systems for stability. Summary of the invention
[0006] The purpose of the present invention is to provide a method and device for storing video recordings, which can not only ensure that the video recordings are not lost 24 hours a day, but also ensure that the alarm recordings are accurate, meet the high requirements of the storage system for stability, and solve the problems raised in the above-mentioned background technology.
[0007] To achieve the above object, the present invention adopts the following technical solutions:
[0008] A method for storing video recordings comprises the following steps:
[0009] S1. Decompose the video recording process into a planned video recording process and an alarm video recording process, and then decompose the alarm video recording process into a pre-recording cache writing process and an alarm video recording file writing process;
[0010] S2, decomposing the planned video recording process into multiple planned video recording sub-steps by using the common video recording and writing file method;
[0011] S3, decomposing the pre-recording writing cache file process and forming multiple alarm pre-recording sub-steps;
[0012] S4, the alarm video recording file writing process reuses the common video recording file writing process in S2 to form the alarm recording file writing sub-step, and connects the alarm pre-recording sub-step with the alarm recording file writing sub-step to form an overall alarm recording process.
[0013] Preferably, the planned recording process is decomposed into multiple planned sub-steps and the alarm recording process is decomposed into a pre-recording write cache process and an alarm recording write file process, which are performed in parallel and completely separately. The pre-recording write cache process and the alarm recording write file process constitute a double-loop alarm recording, and the planned recording process and the alarm recording process constitute a double-loop process.
[0014] Preferably, when the recording process is decomposed into a planned recording process and an alarm recording process, an efficient and stable state machine is introduced to decompose a single process into multiple sub-steps, each sub-step is identified by a state, and each state corresponds to a single operation, so that the operation can be switched freely and flexibly according to business needs.
[0015] Preferably, during the pre-recording write cache process, first confirm whether the camera stream acquisition is completed. When the camera stream acquisition is completed, it is necessary to determine whether it needs to be written to the cache. If it needs to be written to the cache, determine whether the cache duration reaches 3 seconds. If the cache duration reaches 3 seconds, the cache is overwritten in a loop and it is determined whether an alarm is generated. If an alarm is generated, the video file is written and then the camera write cache process is entered. If no alarm is generated, the camera stream acquisition process is directly entered. If the cache duration does not reach 3 seconds, the cache is written sequentially, otherwise the cache is written in a loop.
[0016] Preferably, when acquiring the stream, the camera obtains the device service address through the IPC device, and then uses the device service address to call the GetCapabilities interface to obtain the media service address, and then uses the media service address to call the GetProfiles interface to obtain the media configuration information of the primary and secondary streams, the media configuration information includes the Profile Token, and the Profile Token is used to call the GetStreamUri interface to obtain the streaming media RTSP addresses of the primary and secondary streams, and the RTSP address is used to call the FFmpeg interface to read the video stream data.
[0017] Preferably, the planned recording process performs 7*24 hours of uninterrupted recording, and the alarm recording process performs 7*24 hours of standby service to be ready for alarm recording at any time. The pre-recording time is set to 3 seconds, that is, 3 seconds of recording is prepared waiting for the alarm. If an alarm is issued, the 3 seconds of recording is written to a file, and then the alarm recording continues until the alarm ends. After the alarm ends, the pre-recording is restarted, and the alarm recording is cycled again.
[0018] Preferably, the alarm recording file writing process includes the following steps:
[0019] B1. First confirm whether the camera has completed the streaming.
[0020] B2. When the camera stream acquisition process is completed, determine whether the file needs to be opened. If the file does not need to be opened, return to the camera stream acquisition process;
[0021] B3. When a file needs to be opened, determine whether the file needs to be written. If the file does not need to be written, close the file;
[0022] B4. When a file needs to be written, determine whether the file is full. If the file is full, close the file; if the file is not full, return to the camera stream acquisition process.
[0023] Preferably, the planned recording process and the alarm recording process can be reused but cannot be copied. The planned recording and alarm recording processes of each camera are the same, and are the same state machines, so there is no principled restriction on the number of cameras connected.
[0024] Preferably, when the planned recording sub-step and the alarm recording sub-step are connected, when an alarm notification is received, the cache data is first written to the disk, the cache writing is paused, and then the normal file writing through step S2 is started. When the pre-recording time reaches a total of 10 seconds, the file writing is completed, and then the cache writing process in step S3 is entered again, and then the next alarm notification is waited for, and the above operations are repeated.
[0025] Based on the above-described method for storing video recordings, the present invention also provides a device for storing video recordings, including a control unit, and a planned video recording loop unit and an alarm video recording loop unit bidirectionally connected to the control unit, the alarm video recording loop unit including an alarm pre-recording module and an alarm file writing module, the alarm file writing module is used to write to a corresponding cache and a corresponding video file according to an IPC, the alarm pre-recording module is used to control a pre-recording cycle waiting for the alarm video recording cache, and the planned video recording loop unit is used to write files during planned recording.
[0026] The video storage method and device proposed by the present invention have the following advantages compared with the prior art:
[0027] The present invention decomposes a recording process into a planned recording process and an alarm recording process, and then decomposes the alarm recording process into a pre-recording cache writing process and an alarm recording file writing process, decomposes the planned recording process into a plurality of planned recording sub-steps by adopting a common recording file writing method, decomposes the pre-recording cache file writing process and forms a plurality of alarm recording sub-steps and connects the alarm recording sub-steps, so that the planned recording process is decomposed into a plurality of planned sub-steps and the alarm recording process is decomposed into a pre-recording cache writing process and an alarm recording file writing process, and the decomposition is performed in parallel and completely separately, which not only ensures that the recording is not lost 7*24 hours, but also ensures that the alarm recording is accurate, meets the high requirements of the storage system for stability, and has no principled restriction on the number of channels of connected cameras, because the planned recording and alarm recording processes of the cameras on each channel are the same, and are the same state machines, so the high standard of the system for performance is guaranteed, and the efficiency of development and maintenance is improved. BRIEF DESCRIPTION OF THE DRAWINGS
[0028] Figure 1 It is a flowchart of the present invention;
[0029] Figure 2 A layout diagram of a state machine in horizontal space of the present invention;
[0030] Figure 3 A schematic diagram of a file flow chart for the planned video recording process of the present invention;
[0031] Figure 4 This is a schematic diagram of the pre-recording and writing cache process of the present invention. DETAILED DESCRIPTION
[0032] The following will be combined with the accompanying drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, rather than all the embodiments. The specific embodiments described herein are only used to explain the present invention and are not used to limit the present invention. Based on the embodiments in the present invention, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of the present invention.
[0033] The present invention provides Figure 1-4 A method for storing video recordings shown includes the following steps:
[0034] S1. Decompose the video recording process into a planned video recording process and an alarm video recording process, and then decompose the alarm video recording process into a pre-recording cache writing process and an alarm video recording file writing process;
[0035] When the recording process is decomposed into the planned recording process and the alarm recording process, an efficient and stable state machine needs to be introduced to decompose a single process into multiple sub-steps. Each sub-step is identified by a state, and each state corresponds to a single operation, so that it can be switched freely and flexibly in the operation according to business needs.
[0036] S2, decomposing the planned video recording process into multiple planned video recording sub-steps by using the common video recording and writing file method;
[0037] The alarm recording file writing process includes the following steps:
[0038] B1. First confirm whether the camera has completed the streaming.
[0039] B2. When the camera stream acquisition process is completed, determine whether the file needs to be opened. If the file does not need to be opened, return to the camera stream acquisition process;
[0040] B3. When a file needs to be opened, determine whether the file needs to be written. If the file does not need to be written, close the file;
[0041] B4. When a file needs to be written, determine whether the file is full. If the file is full, close the file; if the file is not full, return to the camera stream acquisition process.
[0042] When acquiring the stream, the camera obtains the device service address through the IPC device, and then uses the device service address to call the GetCapabilities interface to obtain the media service address, and then uses the media service address to call the GetProfiles interface to obtain the media configuration information of the primary and secondary streams. The media configuration information includes the Profile Token. The Profile Token is used to call the GetStreamUri interface to obtain the streaming media RTSP addresses of the primary and secondary streams, and the RTSP address is used to call the FFmpeg interface to read the video stream data.
[0043] S3, decomposing the pre-recording writing cache file process and forming multiple alarm pre-recording sub-steps;
[0044] During the pre-recording write cache process, first confirm whether the camera stream is completed. When the camera stream is completed, it is necessary to determine whether it needs to be written to the cache. If it needs to be written to the cache, determine whether the cache duration reaches 3 seconds. If the cache duration reaches 3 seconds, the cache is overwritten in a loop, and it is determined whether an alarm is generated. If an alarm is generated, the video file is written and then the camera write cache process is entered. If no alarm is generated, the camera stream is directly entered. If the cache duration does not reach 3 seconds, the cache is written sequentially. Otherwise, the cache is written in a loop, and the alarm pre-recording, alarm recording and planned recording are each written into a process. Planned recording is a normal state, and pre-recording and planned recording are two normal states that exist at the same time; while alarm recording and planned recording are performed in parallel and are completely separate, but together they form the engine and engine mechanism of the storage device.
[0045] S4, the alarm video recording file writing process reuses the common video recording file writing process in S2 to form the alarm recording file writing sub-step, and connects the alarm pre-recording sub-step with the alarm recording file writing sub-step to form an overall alarm recording process.
[0046] When the planned recording sub-step and the alarm recording sub-step are connected, when an alarm notification is received, the cache data is first written to the disk, the cache writing is paused, and then the normal file writing through step S2 is started. When the pre-recording time reaches a total of 10 seconds, the file writing is completed. At this time, the cache writing process in step S3 is entered again, and then the next alarm notification is waited for, and the above operations are repeated.
[0047] The planned recording process is decomposed into multiple planned sub-steps and the alarm recording process is decomposed into a pre-recording write cache process and an alarm recording write file process, which are carried out in parallel and completely separately. The pre-recording write cache process and the alarm recording write file process constitute a double-loop alarm recording, and the planned recording process and the alarm recording process constitute a double-loop process.
[0048] Step S1 and step S4 determine the overall direction of the planned recording process, the alarm recording process, and the pre-recording cache file writing process, and then specifically decompose multiple planned recording sub-steps and alarm recording sub-steps. Each sub-step needs to cover various possibilities of recording as much as possible, including normal and abnormal situations. Because recording is a background service in storage, the mechanism is relatively fixed and is not affected by the business. The storage device business is concentrated in the search and playback modules, which rely on the lower-level recording modules.
[0049] The planned recording process performs 7*24 hours of uninterrupted recording, and the alarm recording process performs 7*24 hours of standby service to be ready for alarm recording at any time. The pre-recording time is set to 3 seconds, that is, 3 seconds of recording is prepared to wait for the alarm. If an alarm is issued, the 3 seconds of recording is written into a file, and then the alarm recording continues until the alarm ends. After the alarm ends, the pre-recording is restarted, and the alarm recording is cycled again.
[0050] The planned recording process and the alarm recording process can be reused but cannot be copied. The planned recording and alarm recording processes of each camera are the same, and are the same state machines, so there is no principled restriction on the number of cameras connected.
[0051] Through the above steps, the planned recording process is decomposed into multiple planned sub-steps and the alarm recording process is decomposed into the pre-recording write cache process and the alarm recording write file process in parallel and completely separated. This not only ensures that there is no loss of recording 24 hours a day, but also ensures that the alarm recording is accurate, meeting the high requirements of the storage system for stability. There is no principled restriction on the number of connected cameras, because the planned recording and alarm recording processes of each camera are the same, and they are all the same state machines, so the system's high performance standards are guaranteed, and the efficiency of development and maintenance is improved. In addition, it is also beneficial to the scalability of the storage system. There is no difference in the storage of various types of cameras and various types of alarms. The camera access protocol is compatible and the alarm type is well defined, but it has no impact on the storage system.
[0052] like Figure 2As shown in the figure, pre-recording is a separate loop, a separate state machine, and its main steps are writing to the cache, repeatedly writing to the cache, and writing to the cache in a cycle. The pre-recording time is generally a few seconds. Assume that 3 seconds is taken, that is, we always prepare 3 seconds of video and wait for the alarm. If the alarm comes, the 3 seconds of video will be written to the file, and then the alarm recording will continue until the alarm ends; and after the alarm recording ends, the pre-recording will be restarted. The process of alarm recording here is similar to the planned recording, but it is different. The planned recording needs to be stored in a cycle 7*24 hours a day, while the alarm recording is only stored in seconds or levels, so 10 seconds is taken. Therefore, the normal state of alarm recording is actually alarm pre-recording (where the normal state is alarm pre-recording, that is, alarm recording writes to the cache). Therefore, planned recording and alarm recording are different, which is also different from the traditional storage process: alarm pre-recording, alarm recording and planned recording are written into one process, and planned recording is a normal state. Now separate them, so pre-recording and planned recording are two simultaneous normal states, that is, alarm recording and planned recording are parallel and completely separate. Therefore, pre-recording write cache + alarm recording write file constitutes alarm recording, which is a double loop, a 1+1 loop. And planned recording and alarm recording constitute a double loop, which is also a 1+1 loop.
[0053] Then, the entire storage device is a (1+1)+1 cycle, see Figure 3 This is a layout of a state machine in horizontal space, and also a combined model of a state machine, so it can also be called a state machine (1+1)+1 model. Each 1 is an efficient state machine, but each is independent, does not interfere with each other, and is completely parallel. Together, they form the engine and engine mechanism of our storage device, the state machine, which represents a mathematical model of a finite number of states and the transitions and actions between these states; so the present invention is a (1+1)+1 type composite model of the state machine in spatial layout.
[0054] Based on the above-described method for storing video recordings, the present invention also provides a device for storing video recordings, including a control unit, and a planned video recording loop unit and an alarm video recording loop unit bidirectionally connected to the control unit, the alarm video recording loop unit including an alarm pre-recording module and an alarm file writing module, the alarm file writing module is used to write to a corresponding cache and a corresponding video file according to an IPC, the alarm pre-recording module is used to control a pre-recording cycle waiting for the alarm video recording cache, and the planned video recording loop unit is used to write files during planned recording.
[0055] The loop recording process of scheduled recording and the loop recording process of alarm recording can be divided into pre-recording writing cache and alarm recording writing file. The three processes are parallel and do not interfere with each other or overlap. The alarm recording business is more complicated than scheduled recording, but scheduled recording can be used as the process of ordinary recording, which is the basis and the method can be reused.
[0056] Finally, it should be noted that the above is only a preferred embodiment of the present invention and is not intended to limit the present invention. Although the present invention has been described in detail with reference to the aforementioned embodiments, it is still possible for those skilled in the art to modify the technical solutions described in the aforementioned embodiments or to make equivalent substitutions for some of the technical features therein. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present invention should be included in the protection scope of the present invention.
Claims
1. A method for storing video recordings, characterized in that: The steps include: S1. Decompose the video recording process into a planned video recording process and an alarm video recording process, and then decompose the alarm video recording process into a pre-recording cache writing process and an alarm video recording file writing process; S2, decomposing the planned video recording process into multiple planned video recording sub-steps by using the common video recording and writing file method; S3, decomposing the pre-recording writing cache file process and forming multiple alarm pre-recording sub-steps; S4, the alarm video recording file writing process reuses the common video recording file writing process in S2 to form the alarm recording file writing sub-step, and connects the alarm pre-recording sub-step with the alarm recording file writing sub-step to form an overall alarm recording process.
2. A method for storing video recordings according to claim 1, characterized in that: The planned recording process is decomposed into multiple planned sub-steps and the alarm recording process is decomposed into a pre-recording write cache process and an alarm recording write file process, which are carried out in parallel and completely separately. The pre-recording write cache process and the alarm recording write file process constitute a double-loop alarm recording, and the planned recording process and the alarm recording process constitute a double-loop process.
3. A method for storing video recordings according to claim 2, characterized in that: In step S1, when the recording process is decomposed into the planned recording process and the alarm recording process, an efficient and stable state machine needs to be introduced to decompose a single process into multiple sub-steps. Each sub-step is identified by a state, and each state corresponds to a single operation, so that it can be switched freely and flexibly in operation according to business needs.
4. A method for storing video recordings according to claim 3, characterized in that: During the pre-recording write cache process, first confirm whether the camera stream acquisition is completed. When the camera stream acquisition is completed, it is necessary to determine whether it needs to be written to the cache. If it needs to be written to the cache, determine whether the cache duration reaches 3 seconds. If the cache duration reaches 3 seconds, the cache is overwritten in a loop and it is determined whether an alarm is generated. If an alarm is generated, the video file is written and then the camera write cache process is entered. If no alarm is generated, the camera stream acquisition process is directly entered. If the cache duration does not reach 3 seconds, the cache is written sequentially, otherwise the cache is written in a loop.
5. A method for storing video recordings according to claim 4, characterized in that: When acquiring the stream, the camera obtains the device service address through the IPC device, and then uses the device service address to call the GetCapabilities interface to obtain the media service address, and then uses the media service address to call the GetProfiles interface to obtain the media configuration information of the primary and secondary streams. The media configuration information includes the Profile Token. The Profile Token is used to call the GetStreamUri interface to obtain the streaming media RTSP addresses of the primary and secondary streams, and the RTSP address is used to call the FFmpeg interface to read the video stream data.
6. A method for storing video recordings according to claim 5, characterized in that: The planned recording process performs 7*24 hours of uninterrupted recording, and the alarm recording process performs 7*24 hours of standby service to be ready for alarm recording at any time. The pre-recording time is set to 3 seconds, that is, 3 seconds of recording is prepared to wait for the alarm. If an alarm is issued, the 3 seconds of recording is written into a file, and then the alarm recording continues until the alarm ends. After the alarm ends, the pre-recording is restarted, and the alarm recording is cycled again.
7. A method for storing video recordings according to claim 6, characterized in that: The alarm recording file writing process includes the following steps: B1. First confirm whether the camera has completed the streaming. B2. When the camera stream acquisition process is completed, determine whether the file needs to be opened. If the file does not need to be opened, return to the camera stream acquisition process; B3. When a file needs to be opened, determine whether the file needs to be written. If the file does not need to be written, close the file; B4. When a file needs to be written, determine whether the file is full. If the file is full, close the file; if the file is not full, return to the camera stream acquisition process.
8. A method for storing video recordings according to claim 7, characterized in that: The planned recording process and the alarm recording process can be reused but cannot be copied. The planned recording and alarm recording processes of each camera are the same, and are the same state machines, so there is no principled restriction on the number of cameras connected.
9. A method for storing video recordings according to claim 8, characterized in that: When the planned recording sub-step and the alarm recording sub-step are connected, when an alarm notification is received, the cache data is first written to the disk, the cache writing is paused, and then the normal file writing through step S2 is started. When the pre-recording time reaches a total of 10 seconds, the file writing is completed. At this time, the cache writing process in step S3 is entered again, and then the next alarm notification is waited for, and the above operations are repeated.
10. A video storage device, based on a video storage method according to any one of claims 1 to 9, characterized in that: It includes a control unit, and a planned recording loop recording unit and an alarm recording loop recording unit bidirectionally connected to the control unit. The alarm recording loop recording unit includes an alarm pre-recording module and an alarm file writing module. The alarm file writing module is used to write the corresponding cache and the corresponding recording file according to the IPC. The alarm pre-recording module is used to control the pre-recording cycle waiting for the alarm recording cache, and the planned recording loop recording unit is used to write files during planned recording.
