Data storage method, device, equipment and storage medium
By reading and recombining keyframes and virtual frames in the storage space in the video recorder, the problems of picture discontinuity and storage space squeezing caused by traditional frame extraction storage methods are solved, and more efficient storage and more continuous playback effects are achieved.
Patent Information
- Application Number
- CN202411887513.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-20
- Publication Date
- 2025-04-08
AI Technical Summary
When existing video recorders store code stream data, traditional frame extraction storage methods lead to discontinuity of playback screens, or increasing the encoding frequency of I frames leads to excessive code stream data, squeezing the storage space of newly received data.
When the remaining capacity of the storage space is less than or equal to the preset threshold, the key frames and virtual frames in the storage space are read, reorganized, and the reorganized code stream data is obtained, and the target code stream data is overwritten and written into the storage space.
The continuity of the corresponding picture of the reorganized code stream data is improved, the storage space is reduced, and the storage space of newly received data is ensured.
Smart Images

Figure CN119788800A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to but is not limited to the field of data processing technology, and in particular to a data storage method, device, equipment and storage medium. Background Art
[0002] At present, the recorder usually writes all the bitstream data into the hard disk in the order in which the bitstream data is transmitted in the network. When the hard disk is full and needs to continue to store the newly received bitstream data, a traditional storage method is to extract only the I frame (Intra-coded Frame) and rewrite it for storage. Since the encoding frequency of the I frame is low, the subsequent playback picture is discontinuous. Another traditional storage method is to increase the encoding frequency of the I frame, but it will result in a larger bitstream data stored in the extracted frame, squeezing the storage space of the newly received bitstream data. Summary of the invention
[0003] The following is a summary of the subject matter described in detail herein. This summary is not intended to limit the scope of the claims.
[0004] The embodiments of the present application provide a data storage method, apparatus, device and storage medium, which can improve the continuity of the pictures corresponding to the code stream data stored by frame extraction during playback.
[0005] To achieve the above-mentioned purpose, a first aspect of an embodiment of the present application proposes a data storage method, comprising: receiving target bitstream data; when the remaining capacity of a storage space is less than or equal to a preset capacity threshold, reading key frames and virtual frames in original bitstream data stored in the storage space, wherein the original bitstream data is encoded by inserting the virtual frames at intervals between predicted frames corresponding to the key frames; recombining the key frames and the virtual frames to obtain recombined bitstream data corresponding to the original bitstream data; and writing the recombined bitstream data and the target bitstream data to overwrite the space occupied by the original bitstream data in the storage space.
[0006] In some embodiments, the storage space stores original time slice data corresponding to the original code stream data, and when the remaining capacity of the storage space is less than or equal to a preset capacity threshold, reading the key frames and virtual frames in the original code stream data stored in the storage space includes: when the remaining capacity of the storage space is less than or equal to the preset capacity threshold, reading the original time slice data stored in the storage space, wherein the original time slice data includes a first storage position corresponding to the key frame and a second storage position corresponding to the virtual frame in the storage space; reading the key frame in the original code stream data stored in the storage space based on the first storage position, and reading the virtual frame in the original code stream data stored in the storage space based on the second storage position.
[0007] In some embodiments, the original time slice data includes timestamps corresponding to the key frames and the virtual frames respectively, and the recombining the key frames and the virtual frames to obtain the recombined code stream data corresponding to the original code stream data includes: sorting the key frames and the virtual frames based on the order between the timestamps; and combining the sorted key frames and the virtual frames to obtain the recombined code stream data.
[0008] In some embodiments, after writing the reorganized code stream data and the target code stream data over the space occupied by the original code stream data in the storage space, the data storage method further comprises: updating the original time slice data based on the storage position of the reorganized code stream data in the storage space to determine the reorganized time slice data corresponding to the reorganized code stream data; determining the target time slice data corresponding to the target code stream data based on the storage position of the target code stream data in the storage space; and writing the reorganized time slice data and the target time slice data over the space occupied by the original time slice data in the storage space.
[0009] In some embodiments, the reading of the key frame in the original code stream data stored in the storage space based on the first storage position, and the reading of the virtual frame in the original code stream data stored in the storage space based on the second storage position, comprises: when the original time slice data does not include a reassembly mark, reading the key frame in the original code stream data stored in the storage space based on the first storage position, and reading the virtual frame in the original code stream data stored in the storage space based on the second storage position, wherein the reassembly mark is used to indicate that the original code stream data is reassembled code stream data.
[0010] In some embodiments, the step of reading the key frame in the original code stream data stored in the storage space based on the first storage position and reading the virtual frame in the original code stream data stored in the storage space based on the second storage position further includes: when the original time slice data includes the reorganization mark, writing the target code stream data over the space occupied by the original code stream data in the storage space.
[0011] In some embodiments, the storage space includes multiple independent candidate subspaces, and when the remaining capacity of the storage space is less than or equal to a preset capacity threshold, reading the key frames and virtual frames in the original code stream data stored in the storage space includes: determining at least one target subspace for writing the target code stream data among the multiple candidate subspaces; for each of the target subspaces, when the remaining capacity of the target subspace is less than or equal to the preset capacity threshold, reading the key frames and virtual frames in the original code stream data stored in the target subspace.
[0012] To achieve the above-mentioned purpose, a second aspect of an embodiment of the present application proposes a data storage device, comprising: a receiving module, configured to receive target bitstream data; a reading module, configured to read key frames and virtual frames in original bitstream data stored in the storage space when the remaining capacity of the storage space is less than or equal to a preset capacity threshold, wherein the original bitstream data is encoded by inserting the virtual frames at intervals between predicted frames corresponding to the key frames; a reorganization module, configured to reorganize the key frames and the virtual frames to obtain reorganized bitstream data corresponding to the original bitstream data; and an overwriting module, configured to write the reorganized bitstream data and the target bitstream data into the space occupied by the original bitstream data in the storage space.
[0013] To achieve the above-mentioned purpose, the third aspect of an embodiment of the present application proposes an electronic device, which includes a memory and a processor, the memory stores a computer program, and the processor implements the data storage method described in the first aspect when executing the computer program.
[0014] To achieve the above-mentioned purpose, the fourth aspect of an embodiment of the present application proposes a storage medium, which is a computer-readable storage medium, and the storage medium stores a computer program. When the computer program is executed by a processor, it implements the data storage method described in the first aspect above.
[0015] The embodiment of the present application at least has the following beneficial effects: receiving target bitstream data, when the remaining capacity of the storage space is less than or equal to a preset capacity threshold, reading key frames and virtual frames in the original bitstream data stored in the storage space, wherein the original bitstream data is encoded by inserting virtual frames between predicted frames corresponding to the key frames, and then recombining the key frames and virtual frames to obtain recombined bitstream data corresponding to the original bitstream data; since the recombined bitstream data does not include predicted frames, compared with the original bitstream data, the recombined bitstream data occupies a smaller space in the storage space, which is equivalent to providing space for storing the target bitstream data, and the recombined bitstream data and the target bitstream data can be written to cover the space occupied by the original bitstream data in the storage space; and since the recombined bitstream data includes key frames and virtual frames, and the space occupied by virtual frames is smaller than that of key frames, and the picture information provided by virtual frames is richer than that of predicted frames, therefore, when the space occupied by the recombined bitstream data remains relatively stable, each virtual frame can more completely inherit the picture of the previous key frame, thereby improving the continuity of the picture corresponding to the recombined bitstream data during playback.
[0016] Other features and advantages of the present application will be described in the following description, and partly become apparent from the description, or understood by practicing the present application. The purpose and other advantages of the present application can be realized and obtained by the structures specifically pointed out in the description, claims and drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] The accompanying drawings are used to provide further understanding of the technical solution of the present application and constitute a part of the specification. Together with the embodiments of the present application, they are used to explain the technical solution of the present application and do not constitute a limitation on the technical solution of the present application.
[0018] Figure 1 A schematic diagram of an optional flow chart of a data storage method provided in an embodiment of the present application;
[0019] Figure 2 A schematic diagram of an optional process for extracting key frames and virtual frames provided in an embodiment of the present application;
[0020] Figure 3 An optional flow chart of reorganizing key frames and virtual frames provided in an embodiment of the present application;
[0021] Figure 4 A schematic diagram of an optional process of writing time slice data provided in an embodiment of the present application;
[0022] Figure 5 An optional specific flow chart of extracting key frames and virtual frames provided in an embodiment of the present application;
[0023] Figure 6 A schematic diagram of an optional process of directly writing target code stream data provided in an embodiment of the present application;
[0024] Figure 7 A schematic diagram of an optional flow chart of extracting frames in a target subspace provided in an embodiment of the present application;
[0025] Figure 8 An optional framework schematic diagram of a data storage system provided in an embodiment of the present application;
[0026] Fig. 9 A schematic diagram of an optional process for encoding a network camera provided in an embodiment of the present application;
[0027] Fig.10 A schematic diagram of an optional process for storing data in a network video recorder provided in an embodiment of the present application;
[0028] Fig.11 A schematic diagram of an optional structure of a data storage device provided in an embodiment of the present application;
[0029] Fig.12 A schematic diagram of an optional hardware structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0030] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0031] It should be noted that in each specific embodiment of the present application, when it comes to the need to perform relevant processing based on data related to target object characteristics such as target object attribute data or attribute data set, the permission or consent of the target object will be obtained first, and the collection, use and processing of these data will comply with relevant laws, regulations and standards. Among them, the target object can be a user. In addition, when the embodiment of the present application needs to obtain target object attribute data, a separate permission or separate consent of the target object will be obtained by means of a pop-up window or jumping to a confirmation page, and after clearly obtaining the separate permission or separate consent of the target object, the necessary target object-related data for enabling the normal operation of the embodiment of the present application will be obtained.
[0032] In the description of this application, “several” means one or more, “more” means more than two, “greater than”, “less than”, “exceed”, etc. are understood to exclude the number, and “above”, “below”, “within”, etc. are understood to include the number.
[0033] It should be noted that, although the functional modules are divided in the device schematic diagram and the logical order is shown in the flowchart, in some cases, the steps shown or described may be performed in a different order than the module division in the device or the order in the flowchart. The terms "first", "second", etc. in the specification, claims or the above drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence.
[0034] At present, the recorder usually writes all the bitstream data into the hard disk in the order in which the bitstream data is transmitted in the network. When the hard disk is full and needs to continue to store the newly received bitstream data, a traditional storage method is to extract only the I frame and rewrite it for storage. Since the encoding frequency of the I frame is low, the subsequent playback picture is discontinuous. Another traditional storage method is to increase the encoding frequency of the I frame, but it will result in a larger bitstream data stored in the extracted frame, squeezing the storage space of the newly received bitstream data.
[0035] In order to solve the problems of discontinuous playback images and large bitstream data stored by frame extraction, the present application provides a data storage method, device, equipment and storage medium, the method comprising: receiving target bitstream data; when the remaining capacity of the storage space is less than or equal to a preset capacity threshold, reading key frames and virtual frames in the original bitstream data stored in the storage space, wherein the original bitstream data is encoded based on inserting virtual frames at intervals between predicted frames corresponding to the key frames; recombining the key frames and the virtual frames to obtain recombined bitstream data corresponding to the original bitstream data; and writing the recombined bitstream data and the target bitstream data to overwrite the space occupied by the original bitstream data in the storage space. According to the solution provided by the embodiment of the present application, the target bitstream data is received, and when the remaining capacity of the storage space is less than or equal to the preset capacity threshold, the key frames and virtual frames in the original bitstream data stored in the storage space are read, wherein the original bitstream data is encoded by inserting virtual frames between the predicted frames corresponding to the key frames, and then the key frames and the virtual frames are reorganized to obtain the reorganized bitstream data corresponding to the original bitstream data. Since the reorganized bitstream data does not include the predicted frames, the reorganized bitstream data occupies a smaller space in the storage space than the original bitstream data, which is equivalent to providing a space for storing the target bitstream data, and the reorganized bitstream data and the target bitstream data can be written to cover the space occupied by the original bitstream data in the storage space. Since the reorganized bitstream data includes the key frames and the virtual frames, and the space occupied by the virtual frames is smaller than that of the key frames, and the picture information provided by the virtual frames is richer than that of the predicted frames, each virtual frame can more completely take over the picture of the previous key frame when the space occupied by the reorganized bitstream data remains relatively stable, thereby improving the continuity of the picture corresponding to the reorganized bitstream data during playback.
[0036] The data storage method, apparatus, device and storage medium provided in the embodiments of the present application are specifically described through the following embodiments. First, the data storage method in the embodiments of the present application is described.
[0037] The data storage method provided in the embodiment of the present application relates to the field of computer technology. The data storage method provided in the embodiment of the present application can be applied to a terminal, can be applied to a server side, or can be software running in a terminal or a server side. In some embodiments, the terminal can be a network video recorder, a smart phone, a tablet computer, a laptop computer, a desktop computer, etc.; the server side can be configured as an independent physical server, or can be configured as a server cluster or a distributed system composed of multiple physical servers, and can also be configured as a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, CDN, and big data and artificial intelligence platforms; the software can be an application that implements the data storage method, etc., but is not limited to the above forms.
[0038] The present application can be used in many general or special computer system environments or configurations. For example: personal computers, server computers, handheld or portable devices, tablet devices, multiprocessor systems, microprocessor-based systems, set-top boxes, programmable consumer electronics, network PCs, minicomputers, mainframe computers, distributed computing environments including any of the above systems or devices, etc. The present application can be described in the general context of computer-executable instructions executed by a computer, such as program modules. Generally, program modules include routines, programs, objects, components, data structures, etc. that perform specific tasks or implement specific abstract data types. The present application can also be practiced in distributed computing environments, in which tasks are performed by remote processing devices connected through a communication network. In a distributed computing environment, program modules can be located in local and remote computer storage media including storage devices.
[0039] The embodiments of the present application are further described below in conjunction with the accompanying drawings.
[0040] like Figure 1 As shown, Figure 1 An optional flow chart of a data storage method provided in an embodiment of the present application, the data storage method can be executed by a server, or can also be executed by a terminal, or can also be executed by a server in cooperation with a terminal, the data storage method includes but is not limited to the following steps S110 to S140:
[0041] Step S110, receiving target code stream data.
[0042] Step S120: when the remaining capacity of the storage space is less than or equal to a preset capacity threshold, read the key frames and virtual frames in the original bitstream data stored in the storage space.
[0043] The original bitstream data is encoded by inserting virtual frames at intervals between prediction frames corresponding to key frames.
[0044] The target stream data may be sent by a network camera or received and stored by a network video recorder, which is not limited in the embodiments of the present disclosure.
[0045] It should be noted that a key frame can also be called an intra-coded frame (Intra-coded Frame), abbreviated as I frame; a virtual frame can also be called a virtual intra-coded frame (Intra-coded Frame), virtual I frame; a predicted frame can also be called a predicted coded frame (Predicted Frame), abbreviated as P frame.
[0046] It should be noted that a key frame is an image frame that contains all the information of the picture image at a certain moment and does not rely on any other frame for decoding; a predicted frame is a frame constructed by referring to one or more reference frames. For example, a predicted frame can be constructed by referring to one or more previous key frames, and the predicted frame only records the difference with the reference frame; a virtual frame is an approximate image frame generated by one or more previous and subsequent reference frames. The virtual frame uses the information of the reference frame and uses techniques such as motion compensation and inter-frame prediction to infer an approximate image.
[0047] It should be noted that the target code stream data is sent after the code stream sender encodes the original video data using the same encoding method as the original code stream data, and the target code stream data also includes key frames, virtual frames and predicted frames.
[0048] The space occupied by the virtual frame is smaller than that of the key frame, and the space occupied by the virtual frame is slightly larger than that of the P frame. For example, the storage space occupied by the key frame is 50KB, the storage space occupied by the P frame is 10KB, and the storage space occupied by the virtual frame is 15KB.
[0049] Among them, in the target bitstream data and the original bitstream data, the number of virtual frames is greater than the number of key frames, and the number of virtual frames is less than the number of predicted frames. For example, in a certain target bitstream data or the original bitstream data, the number of key frames is 10, the number of virtual frames is 18, and the number of predicted frames is 63.
[0050] It should be noted that the capacity threshold may be 0, indicating that there is no remaining capacity in the storage space; the capacity threshold may also be a certain value, for example, the capacity threshold may be 8 KB, indicating that 8 KB of storage space needs to be reserved.
[0051] It can be understood that when the remaining capacity of the storage space is less than or equal to the preset capacity threshold, it means that the remaining capacity of the storage space cannot accommodate the target code stream data, and a series of operations are required to provide space for storing the target code stream data. The operations during this period are such as: reading the key frames and virtual frames in the original code stream data stored in the storage space to maximize the retention of the picture information of the original code stream data, so that the subsequent playback pictures will not be stuck, and the continuity of the playback pictures can be improved.
[0052] Step S130, recombining the key frame and the virtual frame to obtain recombined bitstream data corresponding to the original bitstream data.
[0053] It can be understood that the reconstructed bitstream data only includes key frames and virtual frames, but does not include predicted frames. Since the number of predicted frames in the original bitstream data is relatively large, the space occupied by the reconstructed bitstream data is significantly reduced compared with the original bitstream data, and the picture information retained in the key frames and virtual frames is relatively rich. The playback pictures corresponding to the reconstructed bitstream data have good continuity, thereby improving the utilization efficiency of the storage space.
[0054] Step S140: writing the reorganized bitstream data and the target bitstream data into the storage space occupied by the original bitstream data.
[0055] After the target code stream data is written into the storage space, the target code stream data needs to be read and the target code stream data needs to be regarded as the original code stream data.
[0056] It should be noted that the space occupied by the original bitstream data in the storage space can be discrete or continuous. When the reorganized bitstream data or the target bitstream data cannot be written in one space as a whole, the reorganized bitstream data and the target bitstream data need to be segmented according to the size of the space to be written, and then written into multiple spaces respectively.
[0057] The writing order of the reorganized bitstream data and the target bitstream data may not be in particular order, and the embodiment of the present disclosure does not limit this. However, before writing the target bitstream data, the key frames and virtual frames in the original bitstream data stored in the storage space need to be read first.
[0058] Based on this, the target bitstream data is received, and when the remaining capacity of the storage space is less than or equal to the preset capacity threshold, the key frames and virtual frames in the original bitstream data stored in the storage space are read, wherein the original bitstream data is encoded by inserting virtual frames between the predicted frames corresponding to the key frames, and then the key frames and virtual frames are reorganized to obtain the reorganized bitstream data corresponding to the original bitstream data. Since the reorganized bitstream data does not include the predicted frames, the reorganized bitstream data occupies a smaller space in the storage space than the original bitstream data, which is equivalent to providing a space for storing the target bitstream data, and the reorganized bitstream data and the target bitstream data can be written to cover the space occupied by the original bitstream data in the storage space. Since the reorganized bitstream data includes the key frames and virtual frames, and the space occupied by the virtual frames is smaller than that of the key frames, and the picture information provided by the virtual frames is richer than that of the predicted frames, each virtual frame can more completely take over the picture of the previous key frame when the space occupied by the reorganized bitstream data remains relatively stable, thereby improving the continuity of the picture corresponding to the reorganized bitstream data during playback.
[0059] In addition, refer to Figure 2 In one embodiment, the storage space stores original time slice data corresponding to the original code stream data. When the remaining capacity of the storage space is less than or equal to a preset capacity threshold, the key frames and virtual frames in the original code stream data stored in the storage space are read, including but not limited to the following steps:
[0060] Step S210: when the remaining capacity of the storage space is less than or equal to a preset capacity threshold, the original time slice data stored in the storage space is read.
[0061] Step S220, reading the key frame in the original code stream data stored in the storage space based on the first storage location, and reading the virtual frame in the original code stream data stored in the storage space based on the second storage location.
[0062] The original time slice data includes but is not limited to the first storage locations corresponding to the following step key frames and the second storage locations corresponding to the virtual frames in the storage space.
[0063] The original time slice also includes the frame category of each data frame in the original code stream data, and the data frame in the storage space is determined to be one of a key frame, a predicted frame and a virtual frame according to the frame category in the original time slice.
[0064] The first storage location is bound to the frame category of the key frame, and the second storage location is bound to the frame category of the virtual frame.
[0065] The first storage location records the offset address of the key frame relative to the starting position of the storage space, and the second storage location records the offset address of the virtual frame relative to the starting position of the storage space.
[0066] It should be noted that the storage space stores multiple original code stream data from different channels, and the original code stream data are mixed with each other. The frame category is also configured with a channel identifier for determining the source of the corresponding original code stream data. The sources of the code stream data corresponding to each channel are different. For example, the code stream data source of channel A is camera A, the code stream data source of channel B is camera B, the code stream data source of channel C is mobile terminal C, and the code stream data source of channel D is server D. Assuming that each segment of code stream data of channel A is a, each segment of code stream data of channel B is b, each segment of code stream data of channel C is c, and each segment of code stream data of channel D is d, the distribution of a segment of data in the storage space may be: adbaccdb.
[0067] It should be noted that, since the target code stream data is usually received in segments, the original code stream data is usually distributed discretely in the storage space in various data segments.
[0068] It should be noted that the original time slice data is equivalent to the index of the original code stream data. The method for reading the original time slice can be to set a time slice reading address, and data can be read from this address until an original time slice is read.
[0069] Based on this, by reading the original time slice data stored in the storage space, the corresponding original code stream data can be indexed through the original time slice data, and the key frames in the original code stream data stored in the storage space are read based on the first storage position. The virtual frames in the original code stream data stored in the storage space are read based on the second storage position. The corresponding original code stream data can be read frame by frame, so that the original code stream data of each channel can be easily separated. In addition, since the code stream data usually needs to be received and stored in segments, the code stream data of each channel are mixed in the storage space, which can reduce cache overhead and improve storage performance.
[0070] In addition, refer to Figure 3 In one embodiment, the original time slice data includes timestamps corresponding to key frames and virtual frames, and the key frames and virtual frames are reassembled to obtain reassembled code stream data corresponding to the original code stream data, including but not limited to the following steps:
[0071] Step S310, sorting the key frames and virtual frames based on the order of the timestamps.
[0072] Step S320, combining the sorted key frames and virtual frames to obtain reorganized bitstream data.
[0073] The timestamp is used to indicate the playback time of the key frame or virtual frame in the video. The timestamp of the key frame is bound to the first storage location, and the timestamp of the virtual frame is bound to the second storage location.
[0074] Based on this, the key frames and virtual frames are sorted based on the order between each time stamp, and then the sorted key frames and virtual frames are combined to obtain reorganized code stream data, so that the storage position of each frame in the reorganized code stream data is consistent with the playback order. During playback, there is no need to additionally determine the playback order of each frame, which can reduce the performance requirements for the player.
[0075] In addition, refer to Figure 4 In one embodiment, after the reorganized code stream data and the target code stream data are written to overwrite the space occupied by the original code stream data in the storage space, the data storage method further includes but is not limited to the following steps:
[0076] Step S410: based on the storage position of the reorganized code stream data in the storage space, the original time slice data is updated to determine the reorganized time slice data corresponding to the reorganized code stream data.
[0077] Step S420: determining target time slice data corresponding to the target code stream data based on the storage location of the target code stream data in the storage space.
[0078] Step S430, writing the reorganized time slice data and the target time slice data over the space occupied by the original time slice data in the storage space.
[0079] Among them, the update operation of the original time slice data is as follows: update the first storage position corresponding to the key frame according to the storage position of the key frame in the storage space, update the second storage position corresponding to the virtual frame according to the storage position of the virtual frame in the storage space, and the frame category and timestamp bound to the first storage position and the second storage position respectively do not need to be changed; the relevant data of the original time slice data about the predicted frame is eliminated; the original time slice data also includes a start time and an end time, the start time is the timestamp corresponding to the first frame of the original code stream data, and the end time is the timestamp corresponding to the last frame of the original code stream data. It is also necessary to update the start time and end time of the original time slice data according to the timestamp corresponding to the first frame of the reorganized code stream data and the timestamp corresponding to the last frame.
[0080] It should be noted that when receiving target bitstream data, each frame of the target bitstream data carries a corresponding coding sequence number, which is used to indicate the order in which each frame appears in the video. The timestamp corresponding to the received frame can be determined by the coding sequence number and the frame rate.
[0081] The frame rate may be preset or carried by the target bitstream data, which is not limited in the embodiments of the present disclosure.
[0082] It is understandable that it is also possible to determine whether each frame is lost through the coding sequence number. When it is found that some frames are lost, you can choose to ignore them or issue a request for re-acquisition. The embodiment of the present disclosure is not limited here.
[0083] It is understandable that due to objective factors such as network delays, the frames in the received target code stream data may be out of order. The frames can be reordered by coding sequence number, or the corresponding timestamps can be determined for each frame according to the coding sequence number of each frame, and then the frames can be stored in a storage space in a disorderly order. The embodiments of the present disclosure are not limited here.
[0084] The process of determining the target time slice data corresponding to the target code stream data is as follows: respectively binding the storage position of each frame of the target code stream data in the storage space with the timestamp of each frame and the frame category as frame reference information, combining each frame reference information according to the front-to-back relationship between the storage positions of each frame, and respectively generating the start time and the end time according to the timestamp corresponding to the first frame and the timestamp corresponding to the last frame.
[0085] It should be noted that the space occupied by the target time slice data is much smaller than the space occupied by the target code stream data. Therefore, multiple target code stream data can be stored first. When the remaining capacity of the storage space is smaller than the space occupied by the target code stream data to be stored, each target time slice data is stored.
[0086] Among them, the storage position of the original code stream data can be the starting position of the storage space, and the time slice reading address can be the end position of the storage space. Therefore, the target code stream data can be stored from the starting position to the end position of the storage space, and the target time slice is stored from the end position to the starting position of the storage space.
[0087] It can be understood that, since the target time slice data is continuous in the storage space and the target code stream data may be discrete in the storage space, the target time slice data is easier to read than the target code stream data.
[0088] Based on this, based on the storage position of the reorganized code stream data in the storage space, the original time slice data is updated to determine the reorganized time slice data corresponding to the reorganized code stream data. The reorganized time slice records the storage position of the reorganized code stream data in the storage space, and collects the time information of the reorganized code stream data in the original time slice data, so that the index of the reorganized code stream data can be realized through the reorganized time slice data. Then, based on the storage position of the target code stream data in the storage space, the target time slice data corresponding to the target code stream data is determined. The index of the target code stream data can be realized through the target time slice data. Since the target time slice data is easier to read than the target code stream data, the target code stream data is indexed through the target time slice data to improve the efficiency of reading the target code stream data. The reorganized code stream data is indexed through the reorganized time slice data to improve the consistency of the code stream data reading method, so as to improve the maintainability of the storage system.
[0089] In addition, refer to Figure 5 In one embodiment, the key frame in the original code stream data stored in the storage space is read based on the first storage location, and the virtual frame in the original code stream data stored in the storage space is read based on the second storage location, including but not limited to the following steps:
[0090] Step S510, when the original time slice data does not include the reassembly mark, read the key frame in the original code stream data stored in the storage space based on the first storage position, and read the virtual frame in the original code stream data stored in the storage space based on the second storage position.
[0091] The reassembly flag is used to indicate that the original code stream data is reassembled code stream data.
[0092] It should be noted that when generating reassembled code stream data, a reassembly mark needs to be added to the corresponding reassembled time slice data. Therefore, when the original time slice data does not include the reassembly mark, it means that the original code stream data has not been reassembled.
[0093] Based on this, when the original time slice data does not include a reassembly mark, the key frame in the original code stream data stored in the storage space is read based on the first storage position, and the virtual frame in the original code stream data stored in the storage space is read based on the second storage position, ensuring that frame extraction and subsequent reassembly operations will not involve the reassembled code stream data, avoiding unnecessary numerical processing and improving data processing efficiency.
[0094] In addition, refer to Figure 6 In one embodiment, the key frame in the original code stream data stored in the storage space is read based on the first storage location, and the virtual frame in the original code stream data stored in the storage space is read based on the second storage location, and further includes but is not limited to the following steps:
[0095] Step S610: When the original time slice data includes a reassembly mark, the target code stream data is written over the space occupied by the original code stream data in the storage space.
[0096] It should be noted that when the original time slice data includes a reassembly mark, the original code stream data has been reassembled.
[0097] Based on this, the target bitstream data is directly written to overwrite the space occupied by the original bitstream data in the storage space, which avoids the reorganized bitstream data from being reorganized again and rewritten into the storage space. The reorganized bitstream data in the storage space can be overwritten in time, which improves the timeliness of the bitstream data. In addition, since the data quality of the reorganized bitstream data is worse than that of the target bitstream data, the numerical quality of the bitstream data can also be improved, thereby improving the quality of the played video.
[0098] In addition, refer to Figure 7 In one embodiment, the storage space includes a plurality of mutually independent candidate subspaces. When the remaining capacity of the storage space is less than or equal to a preset capacity threshold, the key frames and virtual frames in the original bitstream data stored in the storage space are read, including but not limited to the following steps:
[0099] Step S710: Determine at least one target subspace for writing target code stream data from among multiple candidate subspaces.
[0100] Step S720: for each target subspace, when the remaining capacity of the target subspace is less than or equal to a preset capacity threshold, read the key frames and virtual frames in the original bitstream data stored in the target subspace.
[0101] Among them, the first storage address of each candidate subspace is increased in sequence. If the remaining capacity of the current candidate subspace is less than or equal to the space occupied by the target code stream data, it is determined whether the remaining capacity of the next candidate subspace is greater than the space occupied by the target code stream data; if the remaining capacity of the current candidate subspace is less than or equal to the space occupied by the target code stream data, the target code stream data is written into the current candidate subspace.
[0102] It should be noted that if the remaining capacity of each candidate subspace is less than or equal to the space occupied by the target code stream data, the first candidate subspace is determined as the target subspace, and the write operation on the target subspace is an overwrite write. In one round, each candidate subspace is determined as the target subspace in turn.
[0103] Based on this, the amount of data in the candidate subspace can be used as the amount of data written to the storage space each time, which can reduce the number of writes to the storage space, thereby improving the storage efficiency of the data. In addition, each candidate subspace is independent of each other, which can achieve isolation between data blocks and prevent damage to another data block when one data block is damaged, thereby improving the reliability and fault tolerance of the data.
[0104] It should be noted that the reference Figure 8 , Figure 8 An optional framework diagram of a data storage system provided in an embodiment of the present application, wherein multiple network cameras are connected to a switch, the switch is connected to a network video recorder, and the network video recorder is connected to a hard disk. Therefore, the image data captured by the network camera can be transmitted to the network video recorder via the switch, and the network video recorder can store the image data in the hard disk.
[0105] It should be noted that the reference Fig. 9 , Fig. 9 An optional flow chart of encoding for a network camera provided in an embodiment of the present application, wherein an I frame is a key frame, a virtual I frame is a virtual frame, and a P frame is a predicted frame. The network camera will encode the captured video screen, encode an I frame every 60 seconds, encode a virtual I frame every 1 second, and encode the P frame according to the frame rate. The specific process is as follows: if the encoding time from the previous I frame is greater than or equal to 60 seconds, encode an I frame; if the encoding time from the previous I frame is less than 60 seconds, and the time from the previous virtual I frame is greater than or equal to 1 second, encode a virtual I frame; if the encoding time from the previous I frame is less than 60 seconds, and the time from the previous virtual I frame is less than 1 second, encode a P frame; then combine the encoded frames into target code stream data, send the target code stream data to the network video recorder through the network, and then continue to encode the captured video screen.
[0106] It should be noted that the reference Fig.10 , Fig.10 A schematic diagram of an optional process for storing in a network video recorder provided in an embodiment of the present application, first, the hard disk is formatted, the storage space is divided into large blocks, and then each large block is divided into small blocks. The storage space of the present application can be the storage space of the hard disk, and the candidate subspace is equivalent to the small block of the hard disk. For example, the hard disk is divided into several large blocks according to the size of a 16G block, and each 16G large block is further divided into 256 small blocks, and each small block stores certain stream data and time slice information corresponding to the stream data;
[0107] Then, the network video recorder network receives target code stream data sent by multiple network cameras, and determines at least one target subspace for writing the target code stream data from multiple candidate subspaces;
[0108] Among them, the target subspace is also equivalent to a small block in the hard disk;
[0109] When the remaining capacity of the target subspace is less than or equal to a preset capacity threshold, the original time slice data stored in the target subspace is read, and the key frame and the virtual frame in the original bitstream data are located and extracted based on the original time slice data;
[0110] If the extracted key frames and virtual frames are reorganized, the target code stream data is directly written into the target subspace;
[0111] If the extracted key frames and virtual frames are not reassembled, reassembled code stream data is generated based on the extracted key frames and virtual frames, and reassembled time slice data is obtained through the original time slice, and a reassembly mark is added to the reassembled time slice data, and then the reassembled code stream data and the reassembled time slice data are written into the target subspace, and then the target code stream data are mixed and written into the target subspace, and then the code stream is continued to be received;
[0112] It should be noted that the time slice data is a segment containing the current code stream information, which is used for playback and search of video images; in addition, the reorganization mark on the original time slice can be used to determine whether the extracted key frames and virtual frames are reorganized.
[0113] In addition, refer to Fig.11 The present application also provides a data storage device 1100, including:
[0114] The receiving module 1110 is used to receive target code stream data;
[0115] The reading module 1120 is configured to read key frames and virtual frames in the original bitstream data stored in the storage space when the remaining capacity of the storage space is less than or equal to a preset capacity threshold, wherein the original bitstream data is encoded by inserting virtual frames at intervals between predicted frames corresponding to the key frames;
[0116] The reassembly module 1130 is used to reassemble the key frame and the virtual frame to obtain reassembled bitstream data corresponding to the original bitstream data;
[0117] The overwriting module 1140 is used to write the reorganized code stream data and the target code stream data into the space occupied by the original code stream data in the storage space.
[0118] It can be understood that the specific implementation of the data storage device 1100 is basically the same as the specific implementation of the above-mentioned data storage method, and will not be repeated here.
[0119] In addition, refer to Fig.12 , Fig.12 The hardware structure of an electronic device of another embodiment is illustrated, and the electronic device includes:
[0120] The processor 1201 may be implemented by a general-purpose CPU (Central Processing Unit), a microprocessor, an application-specific integrated circuit (ASIC), or one or more integrated circuits, and is used to execute relevant programs to implement the technical solutions provided in the embodiments of the present application;
[0121] The memory 1202 can be implemented in the form of a read-only memory (ROM), a static storage device, a dynamic storage device, or a random access memory (RAM). The memory 1202 can store an operating system and other application programs. When the technical solution provided in the embodiment of this specification is implemented by software or firmware, the relevant program code is stored in the memory 1202, and the processor 1201 calls and executes the data storage method of the embodiment of the present application.
[0122] Input / output interface 1203, used to implement data input and output;
[0123] The communication interface 1204 is used to realize the communication interaction between the device and other devices. The communication can be realized through a wired manner (such as USB, network cable, etc.) or a wireless manner (such as mobile network, WIFI, Bluetooth, etc.);
[0124] A bus 1205 , which transmits data between various components of the device (e.g., the processor 1201 , the memory 1202 , the input / output interface 1203 , and the communication interface 1204 );
[0125] The processor 1201 , the memory 1202 , the input / output interface 1203 and the communication interface 1204 are connected to each other in communication within the device via the bus 1205 .
[0126] An embodiment of the present application also provides a storage medium, which is a computer-readable storage medium used for computer-readable storage. The storage medium stores one or more programs, and the one or more programs can be executed by one or more processors to implement the above-mentioned data storage method.
[0127] The memory, as a non-transient computer-readable storage medium, can be used to store non-transient software programs and non-transient computer executable programs. In addition, the memory may include a high-speed random access memory, and may also include a non-transient memory, such as at least one disk storage device, a flash memory device, or other non-transient solid-state storage device. In some embodiments, the memory may optionally include a memory remotely disposed relative to the processor, and these remote memories may be connected to the processor via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0128] The embodiments described in the embodiments of the present application are intended to more clearly illustrate the technical solutions of the embodiments of the present application and do not constitute a limitation on the technical solutions provided in the embodiments of the present application. Those skilled in the art will appreciate that with the evolution of technology and the emergence of new application scenarios, the technical solutions provided in the embodiments of the present application are also applicable to similar technical problems.
[0129] It can be understood by those skilled in the art that Figures 1 to 12 The technical solutions shown in the figure do not constitute a limitation on the embodiments of the present application, and may include more or fewer steps than those shown in the figure, or a combination of certain steps, or different steps.
[0130] The device embodiments described above are merely illustrative, and the units described as separate components may or may not be physically separated, that is, they may be located in one place or distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0131] Those skilled in the art will appreciate that all or some of the steps in the methods disclosed above, and the functional modules / units in the systems and devices may be implemented as software, firmware, hardware, or a suitable combination thereof.
[0132] The terms "first", "second", "third", "fourth", etc. (if any) in the specification of the present application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments of the present application described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device comprising a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0133] It should be understood that in the present application, "at least one (item)" means one or more, and "plurality" means two or more. "And / or" is used to describe the association relationship of associated objects, indicating that three relationships may exist. For example, "A and / or B" can mean: only A exists, only B exists, and A and B exist at the same time, where A and B can be singular or plural. The character " / " generally indicates that the objects associated before and after are in an "or" relationship. "At least one of the following" or similar expressions refers to any combination of these items, including any combination of single or plural items. For example, at least one of a, b or c can mean: a, b, c, "a and b", "a and c", "b and c", or "a and b and c", where a, b, c can be single or multiple.
[0134] In the several embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the above units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.
[0135] The units described above as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0136] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0137] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including multiple instructions to enable a computer device (which can be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods of various embodiments of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (Read-Only Memory, referred to as ROM), random access memory (Random Access Memory, referred to as RAM), disk or optical disk and other media that can store programs.
[0138] The preferred embodiments of the present application are described above with reference to the accompanying drawings, but the scope of the rights of the present application is not limited thereto. Any modification, equivalent substitution and improvement made by a person skilled in the art without departing from the scope and essence of the present application should be within the scope of the rights of the present application.
Claims
1. A data storage method, characterized in that: include: Receive target code stream data; When the remaining capacity of the storage space is less than or equal to a preset capacity threshold, reading key frames and virtual frames in the original bitstream data stored in the storage space, wherein the original bitstream data is encoded by inserting the virtual frames at intervals between the predicted frames corresponding to the key frames; Recombining the key frame and the virtual frame to obtain recombined bitstream data corresponding to the original bitstream data; The reorganized code stream data and the target code stream data are written to overwrite the space occupied by the original code stream data in the storage space.
2. The data storage method according to claim 1, characterized in that: The storage space stores original time slice data corresponding to the original code stream data, and when the remaining capacity of the storage space is less than or equal to a preset capacity threshold, reading key frames and virtual frames in the original code stream data stored in the storage space includes: When the remaining capacity of the storage space is less than or equal to the preset capacity threshold, reading the original time slice data stored in the storage space, wherein the original time slice data includes the first storage location corresponding to the key frame and the second storage location corresponding to the virtual frame in the storage space; The key frame in the original code stream data stored in the storage space is read based on the first storage position, and the virtual frame in the original code stream data stored in the storage space is read based on the second storage position.
3. The data storage method according to claim 2, characterized in that: The original time slice data includes timestamps corresponding to the key frame and the virtual frame respectively, and the key frame and the virtual frame are reassembled to obtain reassembled code stream data corresponding to the original code stream data, including: Sorting the key frames and the virtual frames based on the order of the timestamps; The sorted key frames and the virtual frames are combined to obtain the reorganized code stream data.
4. The data storage method according to claim 3, characterized in that: After writing the reorganized code stream data and the target code stream data over the space occupied by the original code stream data in the storage space, the data storage method further comprises: Based on the storage position of the reorganized code stream data in the storage space, the original time slice data is updated to determine the reorganized time slice data corresponding to the reorganized code stream data; Determining target time slice data corresponding to the target code stream data based on a storage location of the target code stream data in the storage space; The reorganized time slice data and the target time slice data are written to overwrite the space occupied by the original time slice data in the storage space.
5. The data storage method according to claim 2, characterized in that: The step of reading the key frame in the original code stream data stored in the storage space based on the first storage position, and reading the virtual frame in the original code stream data stored in the storage space based on the second storage position, comprises: When the original time slice data does not include a reassembly mark, the key frame in the original code stream data stored in the storage space is read based on the first storage position, and the virtual frame in the original code stream data stored in the storage space is read based on the second storage position, wherein the reassembly mark is used to indicate that the original code stream data is reassembled code stream data.
6. The data storage method according to claim 5, characterized in that: The method of reading the key frame in the original code stream data stored in the storage space based on the first storage position, and reading the virtual frame in the original code stream data stored in the storage space based on the second storage position, further includes: When the original time slice data includes the reassembly mark, the target code stream data is written to overwrite the space occupied by the original code stream data in the storage space.
7. The data storage method according to claim 1, characterized in that: The storage space includes a plurality of mutually independent candidate subspaces, and when the remaining capacity of the storage space is less than or equal to a preset capacity threshold, reading key frames and virtual frames in the original bitstream data stored in the storage space includes: Determine at least one target subspace for writing the target code stream data among the plurality of candidate subspaces; For each of the target subspaces, when the remaining capacity of the target subspace is less than or equal to a preset capacity threshold, key frames and virtual frames in the original bitstream data stored in the target subspace are read.
8. A data storage device, characterized in that: include: A receiving module, used for receiving target code stream data; a reading module, configured to read key frames and virtual frames in the original bitstream data stored in the storage space when the remaining capacity of the storage space is less than or equal to a preset capacity threshold, wherein the original bitstream data is encoded by inserting the virtual frames at intervals between the predicted frames corresponding to the key frames; A recombining module, used for recombining the key frame and the virtual frame to obtain recombined bitstream data corresponding to the original bitstream data; The overwriting writing module is used to write the reorganized code stream data and the target code stream data into the space occupied by the original code stream data in the storage space.
9. An electronic device, characterized in that: The electronic device comprises a memory and a processor, the memory stores a computer program, and the processor implements the data storage method according to any one of claims 1 to 7 when executing the computer program.
10. A storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the data storage method according to any one of claims 1 to 7 is implemented.