Target event video acquisition method and device, electronic equipment and readable storage medium
By determining the start frame and end frame of the target event in the cached video stream, and using the video frame lookup table to obtain the target video stream from the cached video stream, the problem of excessive consumption of target event recording resources in the prior art is solved, and the resource consumption is reduced.
Patent Information
- Application Number
- CN202411955236.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-27
- Publication Date
- 2025-03-28
AI Technical Summary
In the prior art, the recording method of target event video recording leads to excessive resource consumption, especially due to the increase in the size of the video file caused by continuous video recording, and excessive storage resource consumption.
By obtaining the first starting video frame and the first ending video frame of the target event in the cached video stream, and determining the second starting video frame and the second ending video frame according to the pre-recording time and the video frame look-up table, the corresponding target video stream is obtained from the cached video stream and stored, and recording and acquisition of the target event is achieved.
Reduced resource consumption, by constructing a video frame lookup table to record the frame position of the target video frame in the cached video stream, and based on the start frame and end frame of the target event, the target video stream is determined from the cached video stream as the recording of the target event, thereby realizing the reduction of resource consumption.
Smart Images

Figure CN119729102A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of video image processing, and in particular to a method, device, electronic device, computer-readable storage medium and computer program product for acquiring a target event video recording. Background Art
[0002] With the development of video recording technology, surveillance videos have become important data for event tracing and anomaly analysis. For some important places, it is necessary to record abnormal situations on site more effectively so as to conduct subsequent anomaly analysis and tracing. At present, the method of recording target events in important places and other locations is usually to record continuously. However, the method of continuous recording will result in larger recorded video files and increase storage resource consumption.
[0003] Therefore, the current method for recording target event videos has the defect of excessively high resource consumption. Summary of the invention
[0004] Based on this, it is necessary to provide a method, device, electronic device, computer-readable storage medium and computer program product for obtaining target event video recordings that can reduce resource consumption in response to the above technical problems.
[0005] In a first aspect, the present application provides a method for acquiring a target event video recording, comprising:
[0006] Obtaining a first start video frame and a first end video frame corresponding to the target event in the cached video stream;
[0007] Determine a second starting video frame according to the first starting video frame, the pre-recording time and each frame position in a video frame query table; the video frame query table stores each frame position corresponding to each target video frame in the cached video stream;
[0008] Determining a second end video frame according to the first end video frame and the delay time;
[0009] According to the second start video frame and the second end video frame, the corresponding target video stream is obtained from the cache video stream and stored to obtain a video recording corresponding to the target event.
[0010] In one embodiment, the method further comprises:
[0011] Acquire a video stream acquired by an image acquisition device, and cache each video frame in the video stream to obtain a cached video stream;
[0012] Marking each of the video frames in the cached video stream according to a preset period to obtain an identifier of each video frame;
[0013] A video frame lookup table is generated according to each video frame identifier corresponding to each target video frame and each frame position of each target video frame in the cached video stream.
[0014] In one embodiment, caching each video frame in the video stream to obtain a cached video stream includes:
[0015] For each video frame in the video stream, determining a frame position corresponding to the video frame according to a position of a previous video frame corresponding to the video frame in a cache queue;
[0016] Replace the content in the frame position with the video frame and cache it at the frame position;
[0017] A cached video stream is obtained according to each video frame in the cache queue.
[0018] In one of the embodiments, determining the frame position corresponding to the video frame according to the position of a previous video frame corresponding to the video frame in a cache queue includes:
[0019] If the previous video frame corresponding to the video frame is not the last frame in the cache queue, determining the frame position corresponding to the video frame according to the frame position of the previous video frame in the cache queue;
[0020] If the previous video frame corresponding to the video frame is the last frame in the cache queue, the starting frame position of the cache queue is used as the frame position corresponding to the video frame.
[0021] In one embodiment, marking each of the video frames in the cached video stream according to a preset period to obtain each video frame identifier includes:
[0022] For each of the video frames, if the video frame is the first video frame of the preset period, determining that the video frame belongs to a target video frame and adding a video frame mark corresponding to the target video frame;
[0023] If the video frame is not the first video frame of the preset period, it is determined that the video frame does not belong to the target video frame and a video frame mark corresponding to the non-target video frame is added.
[0024] In one embodiment, determining the second starting video frame according to the first starting video frame, the pre-recording time and the positions of each frame in the video frame query table includes:
[0025] Determining the number of pre-recorded video frames according to the pre-recording time and the frame interval information of the cached video stream;
[0026] Determine, according to the number of pre-recorded video frames and the first starting video frame, a candidate starting video frame before the first starting video frame in the cached video stream;
[0027] If the frame identification representation of the candidate starting video frame does not belong to the target video frame, query the video frame query table according to the candidate frame position of the candidate starting video frame to determine the target frame position of the nearest target video frame; the nearest target video frame representation is a target video frame that is before the candidate frame position and is closest to the candidate frame position;
[0028] A target video frame corresponding to the target frame position is obtained from the cached video stream as the second starting video frame.
[0029] In one embodiment, determining the second end video frame according to the first end video frame and the delay time includes:
[0030] Determine the number of delayed video frames according to the delayed time and the frame interval information of the cached video stream;
[0031] Obtaining the last cached video frame in the cached video stream, and determining the number of video frames between the last cached video frame and the first end video frame;
[0032] If the number of video frames is less than the number of delayed video frames, the second end video frame is determined according to the last buffered video frame.
[0033] In a second aspect, the present application further provides a device for acquiring a target event video recording, the device comprising:
[0034] An acquisition module, used to acquire a first start video frame and a first end video frame corresponding to a target event in a cached video stream;
[0035] A first determination module is used to determine a second starting video frame according to the first starting video frame, the pre-recording time and each frame position in a video frame query table; the video frame query table stores each frame position corresponding to each target video frame in the cached video stream;
[0036] A second determining module, configured to determine a second ending video frame according to the first ending video frame and the delay time;
[0037] A recording module is used to obtain and store the corresponding target video stream from the cache video stream according to the second starting video frame and the second ending video frame, so as to obtain a video recording corresponding to the target event.
[0038] In a third aspect, the present application further provides an electronic device, comprising a memory and a processor, wherein the memory stores a computer program, and the processor implements the steps of the above method when executing the computer program.
[0039] In a fourth aspect, the present application further provides a computer-readable storage medium having a computer program stored thereon, wherein the computer program implements the steps of the above method when executed by a processor.
[0040] In a fifth aspect, the present application also provides a computer program product, including a computer program, which implements the steps of the above method when executed by a processor.
[0041] The above-mentioned method, device, electronic device, computer-readable storage medium and computer program product for obtaining a video recording of a target event determine the second starting video frame through the first starting video frame of the target event in the cached video stream, the pre-recording time and each frame position in the video frame query table, determine the second ending video frame according to the first ending video frame and the delayed time, obtain the corresponding target video stream from the cached video stream and store it according to the second starting video frame and the second ending video frame, and obtain the video recording of the target event. Compared with the traditional method of continuously recording, this solution records the frame position of the target video frame in the cached video stream by constructing a video frame query table, and based on the starting frame and ending frame of the target event, combined with the position of the target video frame in the cached video stream, determines the target video stream from the cached video stream as the video recording of the target event, thereby achieving the technical effect of reducing resource consumption. BRIEF DESCRIPTION OF THE DRAWINGS
[0042] In order to more clearly illustrate the technical solutions in the embodiments of the present application or related technologies, the drawings required for use in the embodiments of the present application or related technical descriptions will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without paying creative work.
[0043] Figure 1 It is a flowchart of a method for acquiring a target event video in one embodiment;
[0044] Figure 2 A schematic diagram of a structure for caching a video stream in one embodiment;
[0045] Figure 3 A schematic diagram of a video storage step in one embodiment;
[0046] Figure 4 It is a flowchart of a method for acquiring a target event video in another embodiment;
[0047] Figure 5It is a structural block diagram of a device for acquiring a target event video in one embodiment;
[0048] Figure 6 FIG. 4 is a diagram showing the internal structure of an electronic device in one embodiment. DETAILED DESCRIPTION
[0049] 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.
[0050] Camera alarm pre-recording means that the camera starts recording video before it detects an alarm event (such as intrusion, motion detection, etc.), so that when an alarm event occurs, it can be traced back to a period of time before the event occurs, thereby obtaining more comprehensive monitoring information. This function is of great significance to improving the security and effectiveness of the monitoring system.
[0051] In order to enable the camera to have the pre-recording function, this usually requires hardware support, such as sufficient cache space to store pre-recorded videos. However, in order to pursue lower costs, the embedded operating system of the camera often has very limited memory resources and CPU (Central Processing Unit) computing resources. However, in order to provide a better user experience and improve the security and effectiveness of the monitoring system, it is very important to support longer video pre-recording. Therefore, it is very important to improve the efficiency of video pre-recording and realize video pre-recording within limited memory and CPU (Central Processing Unit) resources.
[0052] In order to cache a sufficiently long video stream in limited physical memory resources, it is an important means to use a cheaper SD (Secure Digital Memory Card) memory card instead of internal memory to temporarily store video stream data. However, compared with internal memory, the external memory card has a slow reading and writing speed, especially for high-resolution and high-bitrate video streams. That is, it is impossible to write the pre-recorded video stream temporarily stored in the SD memory card to the video file in a timely and complete manner before the alarm event video frame is written into the video file, resulting in high resource consumption.
[0053] In this regard, the present application constructs a video frame query table to record the frame position of the target video frame in the cached video stream, and based on the start frame and end frame of the abnormal event and the position of the target video frame in the cached video stream, determines the target video stream from the cached video stream as the recording of the abnormal event, thereby achieving the technical effect of reducing resource consumption.
[0054] In one embodiment, Figure 1As shown, a method for obtaining a target event video recording is provided. This embodiment uses the method applied to a terminal as an example for explanation. The terminal may be a video camera, a camera, or other equipment. It is understandable that the method may also be applied to a server, or to a system including a terminal and a server, and is implemented through the interaction between the terminal and the server, including the following steps S202 to S208. Among them:
[0055] Step S202: Obtain a first start video frame and a first end video frame corresponding to the target event in the buffered video stream.
[0056] Among them, in order to improve the traceability of target events in important places, such as tracing and judging intrusions and motion detection, the target event needs to be recorded completely, and the complete video file needs to be recorded before the target event is detected, so that when an alarm event occurs, it can be traced back to a period of time before the event occurs, so as to obtain more comprehensive monitoring information. The terminal can be a terminal connected to an image acquisition device, and the image acquisition device can be set in the above-mentioned important place. The terminal can collect video streams of important places through the image acquisition device, and the terminal can also cache the collected video streams to obtain cached video streams. Among them, an external storage device can be set in the terminal, such as an external SD memory card. The terminal can cache the video stream to a cheaper SD memory card instead of temporarily saving the video stream in the memory, thereby reducing resource consumption.
[0057] When it is necessary to record the target event that occurs, the terminal can determine the first start video frame and the first end video frame corresponding to the target event in the cached video stream. The first start video frame represents the video frame when the target event is triggered, and the first end video frame represents the video frame when the target event ends. The first start video frame and the first end video frame can be determined from the cached video stream.
[0058] Step S204, determining the second starting video frame according to the first starting video frame, the pre-recording time and the frame positions in the video frame lookup table; the video frame lookup table stores the frame positions corresponding to the target video frames in the cached video stream.
[0059] After the terminal determines the first starting video frame and the first ending video frame of the target event, in order to improve the integrity of the target event in the video recording, the terminal needs to further obtain the pre-recorded video and the delayed video of the target event. The pre-recorded video refers to the video of a period of time before the target event occurs, and the delayed video refers to the video of a period of time after the target event occurs. Then the starting video frame of the pre-recorded video can be called the second starting video frame, and the ending video frame of the delayed video can be called the second ending video frame.
[0060] Among them, each video frame in the cached video stream has a corresponding frame identifier and information such as a frame position in the cached video stream. The terminal can create a video frame query table corresponding to the cached video stream in the memory, and record the frame positions corresponding to each target video frame in the cached video stream in the video frame query table in combination with the frame identifier of the target video frame. Among them, each video frame in the cached video stream can have different frame identifiers to represent different types of video frames. The target video frame represents a video frame whose type of video frame is a preset frame type. The cached video stream can be a ring buffer, that is, when the space of the cached video stream is occupied, the terminal can start from the starting point of the cached video stream and cover the earlier cached video stream with the real-time video stream to achieve a ring buffer. The video frame query table can also be a table based on overlay records. For example, when a target video frame in the cached video stream is overwritten by a new video frame, the frame identifier and frame position corresponding to the target video frame in the video frame query table can be deleted and replaced with the frame identifier and frame position of the new target video frame.
[0061] The terminal can determine the second starting video frame according to the first starting video frame, the pre-recording time and the positions of each frame in the video frame query table. The second starting video frame can be the starting video frame when pre-recording is performed before the target event occurs, and the pre-recording time can be the pre-set time when pre-recording is required when the target event occurs. The above second starting video frame can be determined in the cached video stream.
[0062] Step S206: Determine a second end video frame according to the first end video frame and the delay time.
[0063] The second end video frame may be an end video frame that needs to be recorded after a certain period of time after the target event ends to ensure the integrity of the target event. The terminal may determine the second end video frame based on the first end video frame and the delay time. The delay time may be a preset time for delayed recording when the target event occurs. The second end video frame may be determined in the cached video stream.
[0064] Step S208: According to the second starting video frame and the second ending video frame, the corresponding target video stream is obtained from the buffered video stream and stored to obtain a video recording corresponding to the target event.
[0065] Among them, after the terminal determines the second starting video frame and the second ending video frame, it can obtain the starting video frame corresponding to the recording of the target event based on the above-mentioned second starting video frame from the cached video stream, and based on the second ending video frame, obtain the ending video frame corresponding to the recording of the target event based on the above-mentioned second ending video frame from the cached video stream, so that the terminal can use the target video stream between the above-mentioned second starting video frame and the second ending video frame as the complete video stream of the target event, and the terminal can store the above-mentioned target video stream, for example, in a truly saved video file, to form a video recording corresponding to the target event.
[0066] In the above-mentioned method for acquiring a target event video recording, the second starting video frame is determined by the first starting video frame of the target event in the cached video stream, the pre-recording time, and each frame position in the video frame query table, the second ending video frame is determined according to the first ending video frame and the delayed time, and the corresponding target video stream is acquired from the cached video stream and stored according to the second starting video frame and the second ending video frame, thereby obtaining a video recording of the target event. Compared with the traditional method of manually triggering the recording, this solution records the frame position of the target video frame in the cached video stream by constructing a video frame query table, based on the starting frame and ending frame of the target event, combined with the position of the target video frame in the cached video stream, the target video stream is determined from the cached video stream as the video recording of the target event, thereby achieving the technical effect of reducing resource consumption.
[0067] In one embodiment, the method further includes: acquiring a video stream captured by an image acquisition device, caching each video frame in the video stream to obtain a cached video stream; marking each video frame in the cached video stream according to a preset period to obtain each video frame identifier; generating a video frame query table according to each video frame identifier corresponding to each target video frame and each frame position of each target video frame in the cached video stream.
[0068] In this embodiment, the terminal can generate a video frame query table based on the cached video stream. The video frame query table stores the frame identifier of the target video frame and its frame position in the cached video stream. The target video frame can be a video frame whose frame type belongs to the target type. The terminal can first obtain the video stream captured by the image acquisition device, and cache each video frame in the video stream to obtain a cached video stream. The cached video stream can be cached in an SD memory card.
[0069] The terminal may also mark each video frame in the cached video stream. The terminal may mark each video frame in the cached video stream according to a preset period. For example, the terminal may determine the frame identifier of each video frame in a preset period based on the position of each video frame in the preset period. That is, determine which of the video frames belongs to the target video frame and which does not belong to the target video frame.
[0070] In one embodiment, each video frame in the cached video stream is marked according to a preset period to obtain each video frame identifier, including: for each video frame, if the video frame is the first video frame of the preset period, determining that the video frame belongs to a target video frame and adding a video frame identifier corresponding to the target video frame; if the video frame is not the first video frame of the preset period, determining that the video frame does not belong to the target video frame and adding a video frame identifier corresponding to a non-target video frame.
[0071] In this embodiment, when the terminal determines the frame type of the video frame, it can be determined based on the position of the video frame in the preset period. The above-mentioned preset period can be the time of the preset target video frame interval. For example, 3 seconds or 5 seconds. The terminal can judge whether each video frame in the cached video stream belongs to the target video frame. For example, for each video frame in the cached video stream, if the terminal detects that the video frame is the first video frame of the preset period, the terminal can determine that the video frame belongs to the target video frame and add a video frame mark corresponding to the target video frame to it; if the terminal detects that the above video frame is not the first video frame of the preset period, the terminal can determine that the above video frame does not belong to the target video frame, and add a video frame mark corresponding to the non-target video frame to it. Thus, the terminal can complete the marking of each video frame in the cached video stream based on the above steps.
[0072] Specifically, the target video frame may represent a video frame whose video frame type is an I frame (Intra Frame), and the video frame identifier of the target video frame may be recorded as I; and the non-target video frame represents a video frame whose video frame type is a P frame (Predictive Frame), and the video frame identifier of the non-target video frame may be recorded as P. Among them, an I frame is an independent frame in video compression, called an intra-coded frame, which uses complete information to describe the image and therefore does not depend on any previous frame. A P frame is a predicted frame, which depends on the previous frame (usually an I frame or a P frame) for encoding. A P frame reduces redundant data by recording the difference with a reference frame.
[0073] The terminal can set the interval between every two I frames as a preset period, so that each I frame can be followed by multiple P frames, that is, each target video frame is followed by multiple non-target video frames. Among them, the terminal can greatly improve the efficiency of video encoding by combining I frames and P frames. I frames provide the starting point of the video sequence to ensure the accuracy and recoverability of video decoding. P frames compress a large amount of repeated information by utilizing the redundancy between the previous and next frames, saving resource consumption.
[0074] After the terminal determines the video frame identifiers corresponding to the target video frames, it can generate a video frame query table according to the video frame identifiers corresponding to the target video frames and the frame positions of the target video frames in the cached video stream. The frame position indicates the position of the target video frame in the cached video stream, that is, the number of bytes offset from the file header. The terminal can store the video frame query table in the memory.
[0075] Through the above embodiment, the terminal can cache the video stream, mark the video frame as a target video frame, and generate a video frame query table using the frame mark and the frame position. The video frame query table is used to determine the position of the target video frame when acquiring the target event video recording to obtain the target video stream, thereby reducing resource consumption.
[0076] In one embodiment, each video frame in a video stream is cached to obtain a cached video stream, including: for each video frame in the video stream, determining a frame position corresponding to the video frame according to a position of a previous video frame corresponding to the video frame in a cache queue; replacing the content in the frame position with the video frame and caching it to the frame position; and obtaining a cached video stream according to each video frame in the cache queue.
[0077] In this embodiment, when the terminal caches the video stream, a circular cache method may be used. The terminal may cache the video stream in a circular cache area in the SD memory card, and the area has a fixed size. Each video frame in the video stream may be cached in the above area in a queue in chronological order. When caching, for each video frame in the video stream, the terminal may determine the frame position corresponding to the video frame according to the position of the previous video frame corresponding to the video frame in the cache queue. If the position of the previous video frame in the cache queue is different, the terminal will have different cache positions for the video frame. After the terminal determines the frame position of the video frame, the video frame may be replaced with the content in the frame position and cached to the frame position.
[0078] Among them, if there is no cached video frame in the above frame position, the terminal directly stores the above video frame to the above frame position; if there is a cached video frame in the above frame position, the terminal deletes the cached video frame in the above frame position, and replaces the cached video frame with the new video frame for cache.
[0079] In one embodiment, the frame position corresponding to the video frame is determined according to the position of the previous video frame corresponding to the video frame in the cache queue, including: if the previous video frame corresponding to the video frame is not the last frame in the cache queue, then the frame position corresponding to the video frame is determined according to the frame position of the previous video frame in the cache queue; if the previous video frame corresponding to the video frame is the last frame in the cache queue, then the starting frame position of the cache queue is used as the frame position corresponding to the video frame.
[0080] In this embodiment, the terminal may determine the frame position of the video frame that currently needs to be cached based on the position of the previous video frame of the video frame that currently needs to be cached. The cache queue may be a queue of a fixed size in the annular cache area. If the terminal detects that the previous video frame corresponding to the video frame is not the last frame in the cache queue, the terminal determines the frame position corresponding to the video frame according to the frame position of the previous video frame in the cache queue, for example, the terminal caches the video frame at the frame position of the next frame of the previous video frame.
[0081] If the terminal detects that the previous video frame corresponding to the video frame is the last frame in the cache queue, it means that the cache queue is full and the terminal can overwrite from the beginning, that is, the terminal can use the starting frame position of the cache queue as the frame position corresponding to the video frame.
[0082] The terminal may cache multiple video frames in the video stream according to the above steps, so that the terminal may obtain a cached video stream according to each video frame in the cache queue.
[0083] Specifically, Figure 2 As shown, Figure 2 It is a structural diagram of caching video stream in one embodiment. The above-mentioned target video frame can be represented as an I frame, and the non-target video frame can be represented as a P frame. The above-mentioned cached video stream can be a temporary file, and the cached video stream can be called tmp.mp4. The terminal continuously receives the real-time video stream through task thread 1 and saves it in the cache queue. When the content length of the cache queue of the temporary file reaches the maximum value, that is, all frame positions in the cache queue have cached the corresponding video frames, the terminal can overwrite and write from the beginning. Among them, for the video frame representing the end of the video stream, that is, the latest video frame in the video stream, the terminal can record the frame position of the latest video frame in the cached video stream as F_lastframe, which can be used to quickly find the latest video frame after overwriting. Among them, whether the above-mentioned video frame belongs to an I frame or a P frame can be determined based on a preset period. When the terminal caches an I frame, that is, when caching the target video frame, the terminal can save the I frame and its frame position in the tmp.mp4 file to the I frame position query table, that is, the above-mentioned video frame query table. When overwriting, after overwriting the data at the corresponding frame position, the terminal obtains the file write pointer, and the terminal can traverse the I frame position query table, delete the overwritten I frame items in the table, and add the current I frame identifier and frame position to the I frame position query table.
[0084] Through the above embodiment, the terminal can cache the video stream and generate a video frame query table using the relevant information of the target video frame, and store the recording of the target event based on the cached video stream and the video frame query table, thereby reducing the resource consumption when acquiring the recording of the target event.
[0085] In one embodiment, a second starting video frame is determined based on a first starting video frame, a pre-recording time, and each frame position in a video frame query table, including: determining the number of pre-recorded video frames based on the pre-recording time and the frame interval information of a cached video stream; determining a candidate starting video frame before the first starting video frame in the cached video stream based on the number of pre-recorded video frames and the first starting video frame; if a frame identifier representation of the candidate starting video frame does not belong to a target video frame, querying a video frame query table based on the candidate frame position of the candidate starting video frame to determine a target frame position of the nearest target video frame; the nearest target video frame representation is a target video frame that is before the candidate frame position and is closest to the candidate frame position; and obtaining a target video frame corresponding to the target frame position from the cached video stream as the second starting video frame.
[0086] In this embodiment, the terminal can pre-record the target event. To determine the starting point of the pre-recording, the terminal can determine the number of pre-recorded video frames according to the pre-recording time and the frame interval information of the cached video stream. The frame interval information can be the time interval between two adjacent frames in the video, and the number of pre-recorded video frames indicates how many frames need to be recorded in advance when pre-recording the target event.
[0087] The terminal may determine the candidate starting video frame before the first starting video frame in the cached video stream according to the number of pre-recorded video frames and the first starting video frame. For example, the terminal traces back the first starting video frame by the number of pre-recorded video frames and uses the video frame obtained after tracing back as the candidate starting video frame.
[0088] The terminal also needs to determine the frame type of the candidate video frame. For a video frame that does not belong to the target video frame, it cannot be encoded independently, that is, it needs to refer to the previous frame to be encoded, so it cannot be used as the second starting video frame. If the terminal detects that the frame identifier of the above candidate starting video frame represents that it belongs to the target video frame, the terminal can use the candidate starting video frame as the second starting video frame.
[0089] If the terminal detects that the frame identification representation of the candidate starting video frame does not belong to the target video frame, the terminal can query the video frame query table according to the candidate frame position of the candidate starting video frame to determine the target frame position of the nearest target video frame. The nearest target video frame representation is a target video frame that is before the candidate frame position and is closest to the candidate frame position. Thus, the terminal can obtain the target video frame corresponding to the target frame position from the cached video stream as the second starting video frame.
[0090] In one embodiment, a second end video frame is determined based on a first end video frame and a delay time, including: determining the number of delayed video frames based on the delay time and frame interval information of a cached video stream; obtaining the last cached video frame in the cached video stream, and determining the number of video frames between the last cached video frame and the first end video frame; if the number of video frames is less than the number of delayed video frames, determining the second end video frame based on the last cached video frame.
[0091] In this embodiment, the terminal can also perform a delayed recording of the target event to ensure the integrity of the target event in the recorded video of the target event. To determine the end point of the delayed recording, the terminal can determine the number of delayed video frames based on the delayed time and the frame interval information of the cached video stream. The number of delayed video frames indicates how many frames need to be delayed for recording when the target event is delayed. The terminal can obtain the last cached video frame in the cached video stream and determine the number of video frames between the last cached video frame and the first end video frame.
[0092] If the number of video frames is greater than or equal to the number of delayed video frames, the terminal may delay the first end video frame by the number of delayed video frames, and use the delayed video frame as the second end video frame. If the terminal detects that the number of video frames is less than the number of delayed video frames, it means that there are not enough video frames to be used as delayed video frames, and the terminal may determine the second end video frame based on the last cached video frame.
[0093] Specifically, Figure 3 As shown, Figure 3 It is a schematic diagram of the video storage step in an embodiment. After the target event occurs, the terminal can read the video segment in the temporary file tmp.mp4 and write it into the real saved video file to form the video corresponding to the target event. Among them, 001.mp4 is a file for permanently saving the video, that is, the video corresponding to the above target event. When the target event is triggered, the terminal marks the real-time video frame at this moment as E1, that is, the first starting video frame mentioned above; when the event ends, the terminal marks the real-time video frame at this moment as E2, that is, the first ending video frame mentioned above.
[0094] The terminal can calculate the video stream frame range [F1, F2] to be saved and the corresponding range position FO [Foffset1, Foffset2] in the temporary file tmp.mp4 according to the preset pre-recording time Tpre and delay time Tdelay of the target event. Specifically, it can be expressed as: F1 = Tpre / Frame_interval; F2 = Tdelay / Frame_interval.
[0095] Among them, F1 represents the first frame of the pre-recorded video stream that needs to be saved, that is, the candidate start video frame mentioned above. Because it depends on the I frame when playing, if the position calculated by Tpre / Frame_interval is a P frame, since the P frame cannot be encoded independently, the terminal needs to continue to trace back and find the position Foffset1 of the most recent I frame through the I frame position query table, that is, the second start video frame mentioned above. Frame_interval represents the frame interval information, and F2 represents the last frame of the pre-recorded video stream that needs to be saved, that is, the video frame after the first end video frame mentioned above plus the number of delayed video frames.
[0096] The terminal copies the cache file content specified by FO[Foffset1, Foffset2] from tmp.mp4 to the real video file 001.mp4 through task thread 2. For example, when the target event occurs, Foffset1 is known, and the terminal can start reading the video data of tmp.mp4 from the position of Foffset1 and write it to the 001.mp4 file through thread 2 until the second end video frame is read, including the position of the last cached video frame F_lastframe or the video frame Foffset2 after the first end video frame plus the number of delayed video frames.
[0097] Through the above embodiment, the terminal uses the starting video frame of the target event in combination with the video frame query table for pre-recording and post-recording, thereby obtaining the target event in the cached video stream, reducing resource consumption when obtaining the target event.
[0098] In an exemplary embodiment, Figure 4 As shown, Figure 4 1 is a flow chart of a method for acquiring a target event video in another embodiment. In this embodiment, the terminal may include task thread 1 and task thread 2. The cached video stream may be referred to as tmp.mp4, and the video of the target event may be referred to as 001.mp4. The terminal saves the real-time video stream continuously received in real time to tmp.mp4 through task thread 1, and reads the video data from the temporary cache file tmp.mp4 and writes it to the video file 001.mp4 through task thread 2.
[0099] Specifically, the terminal can establish a video frame query table in the memory, create a temporary file in the SD card as a circular buffer space to cache real-time video, and realize the pre-recording of the target event.
[0100] The terminal creates a temporary file in the SD card and sets an upper limit size as a circular buffer space to temporarily save the real-time video stream data as a cached video stream. After the video frames cached in the above circular buffer space reach the upper limit of the file size, the terminal can overwrite and write from the beginning. The terminal can also write the frame identifier and frame position in the real-time video stream data. If the I frame is written, the I frame is numbered. Each time an I frame is written, the I frame number is incremented by 1, and the I frame number and the position of the I frame in the temporary file (i.e., how many bytes are offset from the file header) are saved to the memory in the form of a video frame query table. The terminal can record the table as an I frame position query table, which can also be called a video frame query table. When the I frame in the cached video stream is overwritten, the terminal can delete the item of the I frame overwritten in the I frame position query table. The function of the I frame position query table is to quickly query the file location of a certain I frame in the temporary file and the relationship between the I frame and the previous and next frames. After the target event occurs, the terminal can read the video segment to be recorded in the temporary file and write it to the real saved video file as the video of the target event.
[0101] Through the above embodiment, the terminal records the frame position of the target video frame in the cached video stream by constructing a video frame query table, and based on the start frame and end frame of the target event, combined with the position of the target video frame in the cached video stream, determines the target video stream from the cached video stream as the recording of the target event, thereby achieving the technical effect of reducing resource consumption. In addition, a cheaper SD memory card is used instead of the memory to temporarily store the video stream data, combined with the above pre-recording and delayed recording, the pre-recorded video stream temporarily stored in the SD card is written to the recording file in a timely and complete manner before the target event video frame is written into the recording file, thereby improving the recording efficiency of the target event.
[0102] It should be understood that, although the steps in the flowcharts involved in the above embodiments are displayed in sequence according to the indication of the arrows, these steps are not necessarily executed in sequence according to the order indicated by the arrows. Unless there is a clear explanation in this article, the execution of these steps is not strictly limited in order, and these steps can be executed in other orders. Moreover, at least a part of the steps in the flowcharts involved in the above embodiments may include multiple steps or multiple stages, and these steps or stages are not necessarily executed at the same time, but can be executed at different times, and the execution order of these steps or stages is not necessarily carried out in sequence, but can be executed in turn or alternately with other steps or at least a part of the steps or stages in other steps.
[0103] Based on the same inventive concept, the embodiment of the present application also provides a target event video recording acquisition device for implementing the target event video recording acquisition method involved above. The implementation scheme for solving the problem provided by the device is similar to the implementation scheme recorded in the above method, so the specific limitations in one or more target event video recording acquisition device embodiments provided below can refer to the limitations of the target event video recording acquisition method above, and will not be repeated here.
[0104] In an exemplary embodiment, Figure 5 As shown, a device for acquiring a target event video recording is provided, comprising: an acquisition module 500, a first determination module 502, a second determination module 504 and a recording module 506, wherein:
[0105] The acquisition module 500 is used to acquire a first start video frame and a first end video frame corresponding to a target event in a cached video stream.
[0106] The first determination module 502 is used to determine the second starting video frame according to the first starting video frame, the pre-recording time and the frame positions in the video frame query table; the video frame query table stores the frame positions corresponding to the target video frames in the cached video stream.
[0107] The second determining module 504 is configured to determine a second ending video frame according to the first ending video frame and the delay time.
[0108] The recording module 506 is used to obtain and store the corresponding target video stream from the cache video stream according to the second starting video frame and the second ending video frame, so as to obtain a video recording corresponding to the target event.
[0109] In one embodiment, the above-mentioned device also includes: a generation module, which is used to obtain a video stream captured by an image acquisition device, cache each video frame in the video stream, and obtain a cached video stream; mark each video frame in the cached video stream according to a preset period to obtain each video frame identifier; generate a video frame query table according to each video frame identifier corresponding to each target video frame, and each frame position of each target video frame in the cached video stream.
[0110] In one embodiment, the above-mentioned generation module is used to determine, for each video frame in the video stream, the frame position corresponding to the video frame according to the position of the previous video frame corresponding to the video frame in the cache queue; replace the content in the frame position with the video frame and cache it to the frame position; and obtain a cached video stream according to each video frame in the cache queue.
[0111] In one embodiment, the above-mentioned generation module is used to determine the frame position corresponding to the video frame according to the frame position of the previous video frame in the cache queue if the previous video frame corresponding to the video frame is not the last frame in the cache queue; if the previous video frame corresponding to the video frame is the last frame in the cache queue, the starting frame position of the cache queue is used as the frame position corresponding to the video frame.
[0112] In one embodiment, the above-mentioned generation module is used to, for each video frame, if the video frame is the first video frame of a preset period, determine that the video frame belongs to a target video frame and add a video frame mark corresponding to the target video frame; if the video frame is not the first video frame of the preset period, determine that the video frame does not belong to the target video frame and add a video frame mark corresponding to a non-target video frame.
[0113] In one embodiment, the above-mentioned first determination module 502 is used to determine the number of pre-recorded video frames according to the pre-recorded time and the frame interval information of the cached video stream; determine the candidate starting video frame before the first starting video frame in the cached video stream according to the number of pre-recorded video frames and the first starting video frame; if the frame identification representation of the candidate starting video frame does not belong to the target video frame, query the video frame query table according to the candidate frame position of the candidate starting video frame to determine the target frame position of the nearest target video frame; the nearest target video frame representation is a target video frame that is before the candidate frame position and is closest to the candidate frame position; and obtain the target video frame corresponding to the target frame position from the cached video stream as the second starting video frame.
[0114] In one embodiment, the second determination module 504 is used to determine the number of delayed video frames based on the delay time and the frame interval information of the cached video stream; obtain the last cached video frame in the cached video stream, and determine the number of video frames between the last cached video frame and the first end video frame; if the number of video frames is less than the number of delayed video frames, determine the second end video frame based on the last cached video frame.
[0115] Each module in the above-mentioned target event video recording acquisition device can be implemented in whole or in part by software, hardware or a combination thereof. Each of the above-mentioned modules can be embedded in or independent of a processor in an electronic device in the form of hardware, or can be stored in a memory in an electronic device in the form of software, so that the processor can call and execute the operations corresponding to each of the above modules.
[0116] In an exemplary embodiment, an electronic device is provided. The electronic device may be a terminal, and its internal structure diagram may be as shown in FIG. Figure 6As shown. The electronic device includes a processor, a memory, an input / output interface, a communication interface, a display unit and an input device. The processor, the memory and the input / output interface are connected through a system bus, and the communication interface, the display unit and the input device are connected to the system bus through the input / output interface. The processor of the electronic device is used to provide computing and control capabilities. The memory of the electronic device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The input / output interface of the electronic device is used to exchange information between the processor and an external device. The communication interface of the electronic device is used to communicate with an external terminal in a wired or wireless manner, and the wireless manner can be implemented through WIFI, a mobile cellular network, near field communication (NFC) or other technologies. When the computer program is executed by the processor, a method for acquiring a target event video is implemented. The display unit of the electronic device is used to form a visually visible picture, which can be a display screen, a projection device or a virtual reality imaging device. The display screen can be a liquid crystal display screen or an electronic ink display screen, and the input device of the electronic device can be a touch layer covering the display screen, or a button, trackball or touchpad set on the electronic device casing, or an external keyboard, touchpad or mouse.
[0117] Those skilled in the art will understand that Figure 6 The structure shown in the figure is merely a block diagram of a partial structure related to the scheme of the present application, and does not constitute a limitation on the electronic device to which the scheme of the present application is applied. The specific electronic device may include more or fewer components than shown in the figure, or combine certain components, or have a different arrangement of components.
[0118] In an exemplary embodiment, an electronic device is provided, including a memory and a processor, wherein a computer program is stored in the memory, and the processor implements the above-mentioned method for acquiring a video recording of a target event when executing the computer program.
[0119] In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the above-mentioned method for acquiring a video recording of a target event is implemented.
[0120] In one embodiment, a computer program product is provided, including a computer program, which implements the above-mentioned method for acquiring a target event video recording when executed by a processor.
[0121] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with relevant regulations.
[0122] A person of ordinary skill in the art can understand that all or part of the processes in the above-mentioned embodiment method can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to the memory, database or other medium used in the embodiments provided in the present application can include at least one of non-volatile memory and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetic random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. As an illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM). The database involved in each embodiment provided in this application may include at least one of a relational database and a non-relational database. Non-relational databases may include distributed databases based on blockchains, etc., but are not limited to this. The processor involved in each embodiment provided in this application may be a general-purpose processor, a central processing unit, a graphics processor, a digital signal processor, a programmable logic device, a data processing logic device based on quantum computing, an artificial intelligence (AI) processor, etc., but are not limited to this.
[0123] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this application.
[0124] The above-described embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the present application. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the attached claims.
Claims
1. A method for acquiring a target event video, characterized in that: The method comprises: Obtaining a first start video frame and a first end video frame corresponding to the target event in the cached video stream; Determine a second starting video frame according to the first starting video frame, the pre-recording time and each frame position in a video frame query table; the video frame query table stores each frame position corresponding to each target video frame in the cached video stream; Determining a second end video frame according to the first end video frame and the delay time; According to the second start video frame and the second end video frame, the corresponding target video stream is obtained from the cache video stream and stored to obtain a video recording corresponding to the target event.
2. The method according to claim 1, characterized in that The method further comprises: Acquire a video stream acquired by an image acquisition device, and cache each video frame in the video stream to obtain a cached video stream; Marking each of the video frames in the cached video stream according to a preset period to obtain an identifier of each video frame; A video frame lookup table is generated according to each video frame identifier corresponding to each target video frame and each frame position of each target video frame in the cached video stream.
3. The method according to claim 2, characterized in that The step of caching each video frame in the video stream to obtain a cached video stream includes: For each video frame in the video stream, determining a frame position corresponding to the video frame according to a position of a previous video frame corresponding to the video frame in a cache queue; Replace the content in the frame position with the video frame and cache it at the frame position; A cached video stream is obtained according to each video frame in the cache queue.
4. The method according to claim 3, characterized in that The determining the frame position corresponding to the video frame according to the position of the previous video frame corresponding to the video frame in the cache queue includes: If the previous video frame corresponding to the video frame is not the last frame in the cache queue, determining the frame position corresponding to the video frame according to the frame position of the previous video frame in the cache queue; If the previous video frame corresponding to the video frame is the last frame in the cache queue, the starting frame position of the cache queue is used as the frame position corresponding to the video frame.
5. The method according to claim 2, characterized in that: The step of marking each of the video frames in the cached video stream according to a preset period to obtain an identifier of each video frame includes: For each of the video frames, if the video frame is the first video frame of the preset period, determining that the video frame belongs to a target video frame and adding a video frame mark corresponding to the target video frame; If the video frame is not the first video frame of the preset period, it is determined that the video frame does not belong to the target video frame and a video frame mark corresponding to the non-target video frame is added.
6. The method according to any one of claims 1 to 5, characterized in that: The determining the second starting video frame according to the first starting video frame, the pre-recording time and the positions of each frame in the video frame query table comprises: Determining the number of pre-recorded video frames according to the pre-recording time and the frame interval information of the cached video stream; Determine, according to the number of pre-recorded video frames and the first starting video frame, a candidate starting video frame before the first starting video frame in the cached video stream; If the frame identification representation of the candidate starting video frame does not belong to the target video frame, query the video frame query table according to the candidate frame position of the candidate starting video frame to determine the target frame position of the nearest target video frame; the nearest target video frame representation is a target video frame that is before the candidate frame position and is closest to the candidate frame position; A target video frame corresponding to the target frame position is obtained from the cached video stream as the second starting video frame.
7. The method according to any one of claims 1 to 5, characterized in that: The determining the second end video frame according to the first end video frame and the delay time includes: Determine the number of delayed video frames according to the delayed time and the frame interval information of the cached video stream; Obtaining the last cached video frame in the cached video stream, and determining the number of video frames between the last cached video frame and the first end video frame; If the number of video frames is less than the number of delayed video frames, the second end video frame is determined according to the last buffered video frame.
8. A device for acquiring a target event video, characterized in that: The device comprises: An acquisition module, used to acquire a first start video frame and a first end video frame corresponding to a target event in a cached video stream; A first determination module is used to determine a second starting video frame according to the first starting video frame, the pre-recording time and each frame position in a video frame query table; the video frame query table stores each frame position corresponding to each target video frame in the cached video stream; A second determining module, configured to determine a second ending video frame according to the first ending video frame and the delay time; A recording module is used to obtain and store the corresponding target video stream from the cache video stream according to the second starting video frame and the second ending video frame, so as to obtain a video recording corresponding to the target event.
9. An electronic device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 7 are implemented.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 7 are implemented.