The storage method and device of a kind of monitoring video
Technical field
The present invention relates to the storage method and device in monitoring technology field, more particularly to a kind of monitoring video.
Background technology
Video monitoring system is generally made up of parts such as server, monitor terminal, control clients.Wherein, server is
State, the attribute information of one Centroid, maintenance terminal and client, also can extract video file from terminal and be deposited into standby
Storage device.Client can be configured and be controlled to monitor terminal by server.Monitor terminal is typically an insertion
Formula system, is made up of central processing unit, internal memory, video acquisition unit, video encoding unit, video record unit etc..Monitoring is eventually
Software control video acquisition unit collection video is held, the original video data collected is input to video encoder and compiled
Code, it is encoded after data input to video record unit, video record unit is set with certain stored in file format to storage
In standby.Storage device is typically the equipment such as hard disk or SD card, TF cards, CF cards, USB flash disk, and its memory capacity is certain.With video recording
The accumulation of file, when amount of storage reaches the capacity of storage device, new video file will be stored without space.
To solve this problem, it is necessary to which the memory space for having a method to discharge storage device is used to record new record
Picture.At present, common method has:
(1) deletion ancient deed is carried out by video time order.
(2) after the importance sorting of video recording, unessential video recording is preferentially deleted.
The shortcoming of method (one) is possible the more early but important video resource of some recording times to be deleted, method (two)
It is capable of the shortcoming of avoiding method (one), video recording storage is reasonably managed, under some more important video resources is preserved
Come, but how the importance exactly to video file is judged not to be resolved.
The content of the invention
In view of this, the technical problem to be solved in the present invention is to provide a kind of storage method of monitoring video and device, with
Solve to can not be exactly to video file the technical problem that is judged of importance.
The technical scheme that present invention solution above-mentioned technical problem is used is as follows:
According to an aspect of the present invention there is provided the storage method of monitoring video a kind of comprise the following steps:
In video process, the frequency of active frame is recorded, wherein, active frame refers to that size exceeds the pass of tranquil scope
Key frame;
According to the activity concentration degree in the time of origin of active frame and default time interval statistics video file block;
When being stored to video file, by the recording time of video file, the frequency and active set of active frame
Moderate is associated storage using the importance basis for estimation as video file.
Preferably, this method also includes:
Before next video file is set up or in preservation after a video file, according to default video recording plan
Slightly, the required space for storing next video file is calculated;
When the remaining space of storage device is less than required space, the low history video recording text of importance is deleted successively in order
Part, untill remaining space is more than required space.
Preferably, the low history video file of importance is deleted successively by importance order to further comprise:
The history video file that active frame frequency is 0 is obtained, and oldest history is deleted successively by video time and is recorded
As file;
When the remaining space still not up to required space of storage device, the frequency for obtaining active frame is not 0
Video recording list, deletes the few history video file of the frequency of the active frame of unit time successively.
Preferably, the above method also includes:When the generation time of the active frame of the unit time of history video file
When number is identical, the low history video file of preferential censored mean concentration degree.
Preferably, also include before this method:
Receive the video recording strategy that user is set;Wherein, strategy of recording a video includes video recording coded system, video recording duration, recorded a video most
Long holding time and the time interval of activity statistics;
One section of duration of Video Pre-recording under the tranquil environment in monitoring place, and count the maximum and minimum value of key frame;
Using maximum and minimum value as the higher limit and lower limit of the tranquil scope of key frame, with video recording coding staff
Formula associated storage together.
According to another aspect of the present invention there is provided a kind of monitoring video storage device include with lower module:
Active frame number logging modle, in video process, recording the frequency of active frame, wherein, active frame
Refer to that size exceeds the key frame of tranquil scope;
Mobility statistical module, for the time of origin according to active frame and default time interval statistics video file block
In activity concentration degree;
Preserving module, for when being stored to video file, by the recording time of video file, the generation of active frame
Number of times and activity concentration degree are associated storage using the importance basis for estimation as video file.
Preferably, the device also includes:
Required space computing module, for before next video file is set up or preserve a video file it
Afterwards, according to default video recording strategy, the required space for storing next video file is calculated;
Judge module, for judging whether the remaining space of storage device is more than the required space of 1 video file;
Space release module, for when the remaining space of storage device is less than required space, deleting weight successively in order
Low history video file is spent, untill remaining space is more than required space.
Preferably, space release module further comprises:
First deletes unit module, for obtaining the history video file that active frame frequency is 0, and by video time
Oldest history video file is deleted successively;
Second deletes unit module, for when the remaining space of storage device is still not up to required space, obtaining and living
The frequency of dynamic frame is not 0 video recording list, and the few history video recording of the frequency of the active frame of unit time is deleted successively
File.
Preferably, the second deletion unit module is additionally operable to:When the generation of the active frame of the unit time of history video file
When number of times is identical, the low history video file of preferential censored mean concentration degree.
Preferably, the device includes initialization module, specifically for:
Receive the video recording strategy that user is set;Wherein, strategy of recording a video includes video recording coded system, video recording duration, recorded a video most
Long holding time and the time interval of activity statistics;
One section of duration of Video Pre-recording under the tranquil environment in monitoring place, and count the maximum and minimum value of key frame;
Using maximum and minimum value as the higher limit and lower limit of the tranquil scope of key frame, with video recording coded system
Associated storage together.
The storage method and device of the monitoring video of the embodiment of the present invention, pass through the change video file key frame, record
Time processed and activity concentration degree combine associated storage, and the importance for follow-up judgement video file provides foundation.In addition,
In the circulation storing process of monitoring video, the change of key frame and recording time are combined into judgement when an insufficient storage space exists
The importance of video file, so as to preferentially delete inessential low video file, is newly recorded a video with to guarantee Free up Memory typing
Meanwhile, important history video file will not be deleted.
Brief description of the drawings
Fig. 1 is a kind of flow chart of the storage method of monitoring video provided in an embodiment of the present invention;
Fig. 2 is activity concentration degree schematic diagram that the present invention is that embodiment is provided;
A kind of flow chart of the storage method for monitoring video that Fig. 3 provides for the preferred embodiment of the present invention;
The flow chart for the file delet method that Fig. 4 provides for the preferred embodiment of the present invention.
A kind of function structure chart of the storage device for monitoring video that Fig. 5 provides for the preferred embodiment of the present invention.
Embodiment
In order that technical problems, technical solutions and advantages to be solved are clearer, clear, tie below
Drawings and examples are closed, the present invention will be described in further detail.It should be appreciated that specific embodiment described herein is only
To explain the present invention, it is not intended to limit the present invention.
Embodiment one
As shown in figure 1, a kind of storage method of monitoring video provided in an embodiment of the present invention comprises the following steps:
S101, in video process, record active frame frequency.
Wherein, active frame refers to that size exceeds the key frame of tranquil scope, and the higher limit and lower limit of tranquil scope can be with
By one section of duration of Video Pre-recording under the tranquil scope environment in monitoring place, and count in this section of duration the maximum of key frame and
Minimum value is obtained., can be by setting a counter to carry out in video process, counter is initialized as 0, when video is compiled
When code unit exports lower limit small or bigger than the higher limit critical data frame of a tranquil scope, the value of counter adds 1.
Specifically, the common coded system of video data have H.264, MPEG-4, MPEG-2 etc., these coded systems
Generally all include key video sequence frame (or I frames), prediction frame (such as P frames, B frames).Key frame be in video pictures one it is complete
The coded frame of frame compression, is the complete image of restructural only with the data of an I frame.Predict that frame does not include whole letters of this frame
Breath, it is necessary to which script two field picture could be gone back after certain algorithm is calculated by relying on the key frame data of above or below.Monitoring is eventually
The video encoder at end presses frame output stream, in some more tranquil occasions, and the size generally change of key frame is little, when
(such as there is a moving object) when video pictures are changed, the complexity of picture will change, the size of key frame
It will change.Using this characteristic, it can obtain judging the foundation whether video file includes valuable information.In monitoring
Generally very tranquil place when, most of the time video pictures are static, and these videos are usual for monitoring system
It is that, without too big value, the characteristics of encoding obtained key frame is that size changes within limits, and model is changed with this
The bound enclosed is as threshold values.Generally it is exactly that monitoring system needs are monitored, more valuable when being changed in video pictures
Video, higher limit or lower limit will be deviateed by this moment encoding the size of obtained key frame.Crucial frame sign is exceeded tranquil model
The video record enclosed gets off, so, later delete old video recording when, can preferentially erasing time it is oldest, without departing from threshold values
The video file of scope, is remained with beyond tranquil scope, the video file that the time is newer.It can thus reach that we will retain
The purpose of newer, valuable video recording.
S102, the time of origin according to active frame and default time interval count the activity concentration degree of video file block.
Specifically, in video process, default time interval statistical activity concentration degree can also be passed through.Record key frame
Size assign the continuous time point less than default time interval as a time beyond the time point of higher limit or lower limit
Counter accumulated value within block, statistics this time block.An activity concentration degree table can be created in database, video recording is preserved
During file, while to preserve the activity concentration degree of the video file.
As shown in Figure 2, for example, the video recording of 1 hour, starting point is 0 second, and end point is 3600 seconds, default
Concentration degree time interval is 15 seconds, during 300 seconds to 600 seconds, the double key frame occurred beyond threshold range up and down
Time interval be both less than 15 seconds, then it is assumed that be within 300 seconds to 600 seconds the time block of continuously active, time block overall length is
(600-300)=300 second, the number of times occurred beyond threshold values is 220 times, then the activity concentration degree of this time block is 220/300=
0.73, similarly, it is that the concentration degree between 0.65,2700 seconds to 3300 seconds is to count the concentration degree between 1200 seconds to 2200 seconds
0.8。
When S103, preservation video file, by the recording time of video file, the frequency and active set of active frame
Degree is associated storage using the importance basis for estimation as video file.
Specifically, it can create a video information table in database to preserve filename, video time, active frame
Frequency and activity concentration degree.When preserving video file, video file can also be recorded in database in video information table
Filename, video time, the frequency of active frame, then create an activity concentration degree table, when preserving video file, simultaneously
Preserve the activity concentration degree of the video file.
Using the embodiment of the present invention, by the way that the change of video file key frame, recording time and activity concentration degree are combined
Get up and be associated storage, to judge that the importance of video file provides foundation.
Embodiment two
As shown in Fig. 2 a kind of storage method for monitoring video that the preferred embodiment of the present invention is provided comprises the following steps:
S201, the video recording strategy for receiving user's setting.
Specifically, the video recording strategy for being set by client is received, video recording strategy includes video recording coded system, single
Video file duration, the parameters such as most long holding time and concentration degree statistics time interval of recording a video.Wherein, video file duration, be
Refer to the content duration of 1 video file.The video recording most long holding time, refer to video file in storage device during most long preservation
Between, the video recording recorded before this time will be preferentially deleted.Such as:Coded system is H.264, code check is 1.5Mbps, single
A length of 1 hour during video recording, the most long holding time is 3 months, and concentration degree statistics time interval is 15 seconds, and concentration degree record number is 2
It is individual.
S202, the key frame scope for obtaining current deployed environment and the tranquil occasion under coded system.
This step further comprises:One section of duration of Video Pre-recording under the tranquil scope environment in monitoring place is obtained, and counts pass
The maximum and minimum value of key frame, using maximum and minimum value as the higher limit and lower limit of tranquil scope, with video recording
Coded system associated storage together.
For example, it is necessary to monitor one section of corridor in a mansion, usually less people passes through in the corridor, video pictures one
As in the case of be still frame.Terminal disposition of recording a video is in the top in corridor, to the corridor work video recording of 24 hours.Video recording terminal peace
Monitoring site is attached to, the camera of video acquisition unit is installed to the top in corridor.Debugging network is connected, and video recording terminal is connected
Upper monitoring system.Client is configured to video recording terminal, configuration record a video well used coded system, single video recording duration,
The parameters such as video file most long holding time.As one embodiment, coded system is set as H.264, code check is 1.5Mbps,
A length of 1 hour during single video recording, the most long holding time is 3 months, and concentration degree statistics time interval is 15 seconds, concentration degree record number
For 2.After installation and deployment record a video well terminal, (such as 5 points of the Video Pre-recording a bit of time under the tranquil environment in monitoring place
Clock), in the process, the maximum and minimum value of record key frame this period, using result as the tranquil model of key frame
Place limit value and lower limit is saved in the key frame threshold values table of database.Key frame threshold values table includes:Coded system, key frame
The fields such as the higher limit and lower limit of size.
As a kind of embodiment, for a video recording terminal, the coded system that its video encoding unit is used for
H.264, video record cell call interface function GetData (Byte*data, intlen) obtains packet, wherein data ginsengs
Number is incoming packet pointer, and len is data packet length.Perform an analysis processing to this packet according to the following steps:Definition 2 is whole
The variable MaxLen and MinLen of number type, are respectively intended to storage maximum data packet size and minimum data bag size, be initialized as-
1.Packet is obtained by interface function GetData (Byte*data, intlen), by preceding 5 bytes for judging parameter data
Value whether be 0x000x000x000x010x65, be if it is key frame, record len value, if MaxLen and
MinLen is -1, then preserve len value to variable into MaxLen and MinLen;If value not be -1, judge len and
MaxLen and MinLen magnitude relationship.Len is assigned to MaxLen if len is more than MaxLen, if len is less than
Len is then assigned to MinLen by MinLen.The video recording completed 5 minutes is performed repeatedly until, obtained MaxLen and MinLen is i.e.
For the maximum and minimum value of key frame data bag in this 5 minutes.
Following table is that MaxLen and MinLen pre-recorded an example of interior change at 5 minutes:
Packet order |
Crucial frame sign |
MaxLen values |
MinLen |
Initially |
|
-1 |
-1 |
1 |
173250 |
173250 |
173250 |
2 |
178430 |
178430 |
173250 |
3 |
177238 |
178430 |
173250 |
4 |
171320 |
178430 |
171320 |
… |
… |
… |
… |
… |
183253 |
183253 |
171320 |
… |
… |
… |
… |
… |
169882 |
183253 |
169882 |
… |
|
|
|
N |
175100 |
183253 |
169882 |
Key frame threshold values table have recorded currently employed coded system for H.264, and code check is 1.5Mbps, maximum and most
Small key frame value is higher limit and lower limit.Upper lower limit value is respectively 183253 and 169882 in embodiment.
For other coded systems, such as MPEG-4, the method for judging key frame is similar, but specific characteristic value has area
Not, whether it was found from MPEG-4 standard, it is I frames to judge MPEG-4 packets, it can be determined that 4 bytes that packet starts are
0x000x000x010xb6, the preceding 2bit of the 5th byte is then key frame if 0x00.
S203, according to default video recording strategy, calculate under present encoding mode and video recording duration, 1 video file must
Need space.
Such as, coded system preserves the video recording of 1 hour for H.264, code check is 1.5Mbps, a length of 1 hour during video recording, then
Memory space needed for file is:1500000*3600/8=675Mbytes.
S204, judge whether the remaining space of storage device is more than the required space of 1 video file, if it is, otherwise
Perform step S205.
Specifically, before video file is preserved, the remaining space of storage device is detected, the residue when storage facilities is judged
When space is less than required space, then judge that storage device space is exhausted, it is necessary to clear up the space of storage device.Certainly, cleaning is deposited
Storing up the space of equipment can also be carried out before 1 video file is set up or after 1 video file of preservation.Storage is obtained to set
Standby remaining space, such as, in Embedded Linux System, available system API statfs functions obtain the residue of storage device
Space.Space needed for 1 video recording is compared with the remaining space of storage device, if the remaining space of storage device is not enough
When 1 video file is preserved, then judge that deleting history video file carries out Free up Memory.
S205, delete the low history video file of importance successively by importance order, until remaining space be more than it is required
Space.
Wherein, importance order is in the following manner to video file by inessential as follows to important sequence:
A, recording time exceed most long holding time, the video recording of recording time earliest.
B, recording time exceed most long holding time, the video recording of recording time the latest.
The video recording of C, crucial frame sign without departing from tranquil scope, recording time earliest.
The video recording of D, crucial frame sign without departing from tranquil scope, recording time the latest.
E, crucial frame sign have beyond tranquil scope, the video recording of the frequency of unit time active frame at least.
F, crucial frame sign have beyond tranquil scope, the video recording of the frequency of unit time active frame at most.
G, crucial frame sign have the frequency beyond tranquil scope and unit time active frame identical, mean activity concentration
The minimum video recording of degree.
H, crucial frame sign have the frequency beyond tranquil scope and unit time active frame identical, mean activity concentration
Spend highest video recording.
In this step S205, all history video informations directly can be subjected to importance sorting by above-mentioned rule, according to
The low history video file of importance is deleted in secondary circulation, until remaining space is more than required space.
Referring to Fig. 4, as another preferred embodiment, this step S205 further comprises:
The history video file of S2051, deletion video time before the default most long holding time.
Specifically, video time is extracted from database video information table before the default video recording most long holding time
Video file list, is ranked up by video time, and circulation deletes wherein oldest video file to remaining space more than required
Space.
S2052, judge whether the remaining space of storage device is more than the required space of 1 video file, if it is, knot
Beam space is cleared up, and otherwise performs step S2053.
S2053, the frequency for obtaining active frame are 0 video recording list, and delete by video time oldest go through successively
History video file.
Specifically, after step S2051, if the remaining space of storage facilities is also less than required space,
The video file that Counter Value is 0 is extracted from database video information table, is ranked up by video time, oldest record is deleted
As file, deletion is repeated untill storage device remaining space is more than required space.
S2054, judge whether the remaining space of storage device is more than the required space of 1 video file, if it is, knot
Beam space is cleared up, and otherwise performs step S2055.
Specifically, after step S2051, the fruit space of release is still not enough to preserve 1 video file, then continues
Delete the higher leveled video file of importance.
S2055, the frequency of acquisition active frame are not 0 video recording list, and delete the active frame of unit time successively
The minimum history video file of frequency.
Specifically, after step S2053, if the remaining space of storage facilities is also less than required space, this
When storage device in be left not deleted video recording be all video recording of the Counter Value more than 0.Take out remaining from Video data storehouse again
The video time of video recording and the frequency of active frame/video recording duration) count results be ranked up, the smaller expression of end value
Video recording is newer, more multi-activity image, by the frequency (frequency of active frame/video recording duration) of the active frame of unit time
Be ranked up, the bigger expression of end value more multi-activity image, the importance of video recording is bigger.It is preferential to delete end value minimum
Video recording, untill the remaining space of storage facilities is more than required space.It is used as one embodiment:Video recording
30 points 0 second, is 2764800 apart from current time when A20140827103000.avi video time is August in 2014 27 days 10
Second, the Counter Value of video recording is 50, is 55296 by formula result of calculation;Video recording B20140905123000.avi video time
It it is 1980000 seconds away from current time, video recording Counter Value is 100, calculates and ties by formula 30 points during for September in 2014 5 days 12
Fruit is 19800, and its value is small than 55296, then video recording A is come before, record a video behind B comes.Delete the video recording after sequence
Video file above is come in list.
Wherein, when the frequency of the active frame of the unit time of history video file is identical, concentration degree is preferentially deleted
Low history video file.It is ranked up by activity concentration degree, the high reservation of concentration degree, the low preferential deletion of concentration degree.I.e.
From database take out video file concentration degree be ranked up, first compare the size of concentration degree 1, if concentration degree greatly if protect
Stay.If it is equal, then compare the size of concentration degree 2, then retain greatly.If still equal, random sequence is deleted.
Perform after above-mentioned steps S2051~S2055, necessarily can release the space for preserving 1 video file enough, open
Begin new video file.
S206, according to it is default video recording strategy recorded a video.
Specifically, by step S205, the enough spaces of storage device preserve 1 video file, in storage device
A new file is created, (such as 20140507103000.avi) can be named with current time, and record current time
It is used as video recording initial time.
S207, in video process, set a counter records active frame frequency.
Specifically, the video record unit of video recording terminal starts to receive the packet for coming from video encoding unit, number
Video file is written to according to bag.When receiving packet, analyse whether it is key frame, with the size and data of key frame data bag
The upper and lower threshold values of storehouse threshold values table compares, and if greater than upper threshold values or less than lower threshold values, then counter plus 1.
S208, the time point according to active frame and default time interval statistical activity concentration degree.
S209, preservation video file, and the recording time of associated storage video file, the frequency of active frame and activity
Concentration degree.
It should be noted that the space of cleaning storage device can be carried out before 1 video file is set up, can also be complete
Carried out after into 1 video file of preservation, so in another embodiment, step S203~S205 can move on to step S209
Afterwards.
The storage method of the monitoring video of the embodiment of the present invention, on the one hand, pass through the change video file key frame, record
Time processed and activity concentration degree, which combine, is associated storage, and the importance for follow-up judgement video file provides foundation.
On the other hand, in the circulation storing process of monitoring video, when an insufficient storage space exists by the change of key frame and recording time knot
The importance of video file is judged altogether, so that inessential low video file is preferentially deleted, to guarantee Free up Memory record
While entering new video recording, important history video file will not be deleted.
Embodiment three
As shown in figure 4, a kind of storage device for monitoring video that the preferred embodiment of the present invention is provided includes active frame number
Logging modle 10, mobility statistical module 20, preserving module 30, must space computing module 40, judge module 50 and space release
Amplification module 60, wherein:
Active frame number logging modle 10, in video process, recording the frequency of active frame, wherein, activity
Frame refers to that size exceeds the key frame of tranquil scope;
Mobility statistical module 20, is concentrated for the time of origin according to active frame and default time interval statistical activity
Degree;
Preserving module 30, for when being stored to video file, by the recording time of video file, the hair of active frame
Raw number of times and activity concentration degree are associated storage using the importance basis for estimation as video file.
Preferably, the device also includes required space computing module 40, space release module 50:
Required space computing module 40, for before 1 video file is set up or after preserving 1 video file,
According to default video recording strategy, the required space of present encoding mode and video recording lower 1 video file of duration is calculated;
Judge module 50, for judging whether the remaining space of storage device is more than the required space of 1 video file;
Space release module 60, for when the remaining space of storage device is less than required space, then by importance order
The low history video file of importance is deleted successively, untill remaining space is more than required space.
As a kind of preferred embodiment, space release module 60 further comprises the first deletion unit module 601 and second
Unit module 602 is deleted, wherein:
First deletes unit module 601, for obtaining the history video file that active frame frequency is 0, and by video recording
Time deletes oldest history video file successively;
Second delete unit module 602, for when storage device remaining space still be not up to the required space when,
The frequency for obtaining active frame is not 0 video recording list, and the frequency of the active frame of deletion unit time is few successively goes through
History video file.
Wherein, the second deletion unit module 602 is additionally operable to:When the hair of the active frame of the unit time of history video file
When life number of times is identical, the low history video file of preferential censored mean activity concentration degree.
In addition, said apparatus includes initialization module, the video recording strategy for receiving user's setting;In the flat of monitoring place
One section of duration of Video Pre-recording under stationary ring border, and count the maximum and minimum value of key frame;Using maximum and minimum value as
The higher limit and lower limit of key frame calmness scope, the associated storage together with video recording coded system, wherein, video recording strategy includes record
As the time interval of coded system, video recording duration, video recording most long holding time and activity statistics.
It should be noted that the technical characteristic in above method embodiment is corresponded in the present apparatus and is applicable, no longer weigh here
State.
Storage side's device of the monitoring video of the embodiment of the present invention, on the one hand, by the change of video file key frame,
Recording time and activity concentration degree combine associated storage, and the importance for follow-up judgement video file provides foundation.Separately
On the one hand, in the circulation storing process of monitoring video, the change of key frame and recording time are combined when an insufficient storage space exists
Get up to judge the importance of video file, so that inessential low video file is preferentially deleted, to guarantee Free up Memory typing
While new video recording, important history video file will not be deleted.
Can be with one of ordinary skill in the art will appreciate that realizing that all or part of step in above-described embodiment method is
Control the hardware of correlation to complete by program, described program can in a computer read/write memory medium is stored in,
Described storage medium, such as ROM/RAM, disk, CD.
Above by reference to the preferred embodiments of the present invention have been illustrated, not thereby limit to the interest field of the present invention.This
Art personnel do not depart from the scope of the present invention and essence, can have a variety of flexible programs to realize the present invention, for example as one
The feature of individual embodiment can be used for another embodiment and obtain another embodiment.All institutes within the technical concept with the present invention
Any modifications, equivalent substitutions and improvements made, all should be within the interest field of the present invention.