Video segmentation recording method and device, electronic equipment and readable storage medium
By using double buffer queue technology in video segment recording, the video data is written and read alternately in loops, the problem of seconds and frame drops in video segment recording is solved, ensuring the continuity and integrity of the video.
Patent Information
- Application Number
- CN202411863179.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-17
- Publication Date
- 2025-03-11
AI Technical Summary
During the video segment recording process, the prior art has problems of seconds and frame drops, resulting in discontinuity of videos.
By setting up a data cache area with two data cache queues, the two data cache queues are used to alternately complete the writing and reading of video data, ensuring that the video data is cached before encoding, thereby avoiding data loss when the recorder and encoder restart.
It realizes that there is no problem of missing seconds and frames during video segment recording, ensuring the integrity of the video.
Smart Images

Figure CN119603469A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of video recording technology, and in particular to a method, device, electronic device and readable storage medium for segmented video recording. Background Art
[0002] In the process of recording surveillance video, in order to facilitate subsequent storage, search or playback, the video is generally recorded and saved in segments according to time.
[0003] However, during the segmented video recording process, the recording needs to be stopped and then restarted, and restarting the recording takes a certain amount of time. This will cause the two videos to be discontinuous during the segmented recording, resulting in problems such as lost seconds and frames. Summary of the invention
[0004] The present application provides a video segment recording method, device, electronic device and readable storage medium, which are used to solve the technical problems of lost seconds and frames in the prior art when performing video segment recording.
[0005] According to the first aspect disclosed in the present application, the present application provides a video segment recording method, comprising:
[0006] Execute a video processing task; wherein the video processing task includes calling a producer thread to write the original video data collected by the camera into a data cache queue in a data cache area as a write queue; calling a consumer thread to read the original video data in a data cache queue in a data cache area as a read queue, and inputting the original video data into an encoder for encoding to obtain an encoded video stream; and when the queue lengths of the two data cache queues meet the queue exchange condition, cyclically exchanging the identities of the two data cache queues;
[0007] Execute a video recording task; wherein the video recording task includes calling a recorder to write the encoded video stream into multimedia files in segments to generate multiple video files.
[0008] In a feasible implementation manner, the queue switching condition includes that the queue length of the data cache queue serving as a read queue is zero, and the queue length of the data cache queue serving as a write queue is not zero.
[0009] In a feasible implementation manner, the queue switching condition also includes that a queue length of a data cache queue serving as a write queue is greater than a preset length.
[0010] In a feasible implementation manner, the method further includes:
[0011] If the consumer thread is in the awake state, when the queue length of the read queue is zero and the queue length of the write queue is less than a preset length, the consumer thread is controlled to enter the sleep state;
[0012] If the consumer thread is in a dormant state, when the queue length of the read queue is not zero, the consumer thread is controlled to enter a wake-up state.
[0013] In a feasible implementation manner, the method further includes:
[0014] If the producer thread is in the awake state, when the queue length of the write queue is greater than the queue capacity of the write queue, control the producer thread to enter the sleep state;
[0015] If the producer thread is in a dormant state, when the queue length of the write queue is less than the queue capacity of the write queue, the producer thread is controlled to enter a wake-up state.
[0016] In a feasible implementation manner, calling a recorder to write the encoded video stream into multimedia files in segments to generate multiple video files includes:
[0017] Calling a recorder to write the encoded video stream into a multimedia file to generate a video file;
[0018] When the duration of the current video file reaches the preset segment duration, the recorder is restarted, and after the recorder is restarted, the process jumps to the step of calling the recorder to write the encoded video stream into a multimedia file to generate the next video file.
[0019] In a feasible implementation manner, before executing the video processing task, the method further includes:
[0020] Initialize a data cache area, and create two data cache queues in the data cache area; wherein one data cache queue is used as a write queue, and the other data cache queue is used as a read queue;
[0021] A producer thread and a consumer thread are created; wherein the producer thread is used to write data into the write queue, and the consumer thread is used to read data from the read queue.
[0022] According to a second aspect disclosed in the present application, the present application provides a video segment recording device, comprising:
[0023] The video processing module is used to perform video processing tasks; wherein the video processing tasks include calling a producer thread to write the original video data collected by the camera into a data cache queue in a data cache area as a write queue; calling a consumer thread to read the original video data in a data cache queue in the data cache area as a read queue, and inputting the original video data into an encoder for encoding to obtain an encoded video stream; and when the queue lengths of the two data cache queues meet the queue exchange condition, the two data cache queues are cyclically exchanged for identity;
[0024] The video generation module is used to execute a video recording task; wherein the video recording task includes calling a recorder to write the encoded video stream into multimedia files in segments to generate multiple video files.
[0025] According to a third aspect disclosed in the present application, the present application provides an electronic device, including a processor, and a memory communicatively connected to the processor;
[0026] The memory stores computer-executable instructions;
[0027] The processor executes the computer-executable instructions stored in the memory to implement the method according to any one of the first aspects.
[0028] According to the fourth aspect disclosed in the present application, the present application provides a computer-readable storage medium, in which computer-executable instructions are stored. When the computer-executable instructions are executed, they are used to implement any method in the first aspect.
[0029] According to a fifth aspect disclosed in the present application, the present application provides a computer program product, including a computer program, and when the computer program is executed, it is used to implement any one of the methods in the first aspect.
[0030] Compared with the prior art, this application has the following beneficial effects:
[0031] The present application provides a video segment recording method, device, electronic device and readable storage medium, which, by setting a data cache area with two data cache queues, uses the two data cache queues to cyclically and alternately complete the writing and reading of video data. Since the cached data is before encoding, restarting the recorder and encoder will not affect the continuity of the data. This ensures that there will be no problems of lost seconds and frames during the video segment recording process, thereby ensuring the integrity of the video. BRIEF DESCRIPTION OF THE DRAWINGS
[0032] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.
[0033] Figure 1 A schematic diagram of a flow chart of a video segment recording method provided in an embodiment of the present application;
[0034] Figure 2 A flowchart of another video segment recording method provided in an embodiment of the present application;
[0035] Figure 3 A flowchart of another video segment recording method provided in an embodiment of the present application;
[0036] Figure 4 A schematic diagram of the structure of a video segment recording device provided in an embodiment of the present application;
[0037] Figure 5 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application.
[0038] The above drawings have shown clear embodiments of the present application, which will be described in more detail later. These drawings and text descriptions are not intended to limit the scope of the present application in any way, but to illustrate the concept of the present application to those skilled in the art by referring to specific embodiments. DETAILED DESCRIPTION
[0039] Exemplary embodiments will be described in detail herein, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, the same numbers in different drawings represent the same or similar elements unless otherwise indicated. The implementations described in the following exemplary embodiments do not represent all implementations consistent with the present application. Instead, they are merely examples of devices and methods consistent with some aspects of the present application as detailed in the appended claims.
[0040] In the process of recording surveillance video, in order to facilitate subsequent storage, search or playback, the video is generally recorded and saved in segments according to time.
[0041] However, during the segmented video recording process, the recording needs to be stopped and then restarted, and restarting the recording takes a certain amount of time. This will cause the two videos to be discontinuous during the segmented recording, resulting in problems such as lost seconds and frames.
[0042] For example, taking the widely used Android system as an example, the existing video recording API of the Android system, whether it is MediaRecorder or MediaCodec+MediaMuxer, needs to start and stop the recorder when recording the next video segment, and the restart of the recorder takes a certain amount of time, which will cause the two videos to be discontinuous during segmented recording, and there will be a certain amount of lost seconds and frames. However, the above phenomenon is unacceptable in the field of monitoring (or driving recorders), because in the field of monitoring, lost seconds and frames may cause the loss of key monitoring information, making the monitoring ineffective.
[0043] In response to the above technical problems, the present application proposes a video segment recording method, which sets up a data cache area with two data cache queues, and uses the two data cache queues to cyclically alternately complete the writing and reading of video data, so that there will be no problems of lost seconds and frames during the video segment recording process, thereby ensuring the integrity of the video.
[0044] The technical solution of the video segment recording method provided by the present application is described in detail below through specific embodiments. It should be noted that the following embodiments can exist independently or in combination with each other, and the same or similar content may not be repeatedly described in different embodiments.
[0045] It should be noted that the executor of the video segment recording method provided in the embodiment of the present application is a video recording device, and correspondingly, the video segment recording device is also arranged in the video recording device.
[0046] Specifically, the video recording device is connected to the camera and is used to receive the original video data captured by the camera.
[0047] Figure 1 A schematic diagram of a video segment recording method provided in an embodiment of the present application is provided in Figure 1 In some embodiments, the process of the video segment recording method includes the following tasks:
[0048] S101, execute video processing tasks; wherein the video processing tasks include calling a producer thread to write the original video data collected by the camera into a data cache queue in a data cache area as a write queue; calling a consumer thread to read the original video data in a data cache queue in a data cache area as a read queue, and inputting the original video data into an encoder for encoding to obtain an encoded video stream; and when the queue lengths of the two data cache queues meet the queue exchange conditions, the two data cache queues are cyclically exchanged for identity.
[0049] Among them, combined Figure 3During the video recording process, the camera sends the collected raw video data to the video recording device. The producer thread in the video recording device writes the raw video data into the data cache queue in the data cache area as a write queue. At the same time, the consumer thread in the video recording device reads the raw video data in the data cache queue in the data cache area as a read queue, and inputs the raw video data into the encoder for encoding to obtain the encoded video stream.
[0050] During the video processing, when the queue lengths of the two data cache queues meet the queue exchange condition, the two data cache queues are cyclically exchanged. After the exchange, the data cache queue as the write queue is changed to the read queue, and the data cache queue as the read queue is changed to the write queue.
[0051] By cyclically exchanging the two data cache queues, the original video data can be continuously cached in the data cache area for subsequent recording during the video segment recording process. This is because, during the video segment recording process, even if the recorder and encoder are restarted, the producer thread can continue to write the original video data captured by the camera into the data cache queue as the write queue for caching, so that the subsequent consumer thread can perform video encoding processing, so that the writing of the original video data will not be suspended during the restart of the recorder and encoder, avoiding the problem of lost seconds and frames in subsequent recording.
[0052] Preferably, the queue switching condition includes that the queue length of the data cache queue serving as the read queue is zero, and the queue length of the data cache queue serving as the write queue is not zero.
[0053] Among them, when the queue length of the data cache queue serving as a read queue is zero, it means that the data in the current read queue has been read, and when the queue length of the data cache queue serving as a write queue is not zero, it means that there is data in the current write queue. The two data cache queues can be cyclically exchanged to change the current write queue to a read queue for the consumer thread to record the video.
[0054] Preferably, the queue switching condition also includes that the queue length of the data cache queue serving as the write queue is greater than a preset length.
[0055] Among them, adding a queue length of the data cache queue serving as a write queue greater than a preset length as a queue exchange condition can reduce the exchange frequency of the data cache queue and improve system stability.
[0056] Specifically, a video encoder is usually used to compress and encode the collected audio and video signals so that they can be transmitted over a network or stored on a storage device. The compression process usually involves lossy data compression, which aims to reduce the file size while maintaining the video quality as much as possible. Among them, the original video data format before encoding can be in YUV format data, and the encoded video stream data format after encoding can be in H264 format data or H265 format data. YUV format data can effectively ensure the integrity of the data when the encoder is restarted.
[0057] Preferably, the producer (data generation thread) uses the write queue, and the consumer (encoding thread) uses the read queue, and the two threads do not need synchronization protection. When the read queue is consumed, the read and write queues are swapped, the producer uses an empty read queue, and the consumer uses the write queue. The double-buffered queue only needs to perform thread synchronization protection on the read and write queues when swapping. This can effectively reduce the resource consumption caused by thread synchronization or repeated comparisons and improve performance.
[0058] S102, executing a video recording task; wherein the video recording task includes calling a recorder to write the encoded video stream into multimedia files in segments to generate multiple video files.
[0059] Among them, combined Figure 3 , call the recorder to write the encoded video stream into multimedia files in segments, generate multiple video files, and complete the segmented recording of the video.
[0060] Exemplarily, the recorder of the Android system is a file combiner, such as MediaMuxer.
[0061] In this embodiment, a data cache area with two data cache queues is provided, and the two data cache queues are used to cyclically and alternately complete the writing and reading of video data. Since the cached data is before encoding, restarting the recorder and the encoder will not affect the continuity of the data. This ensures that there will be no problem of lost seconds and frames during the video segment recording process, thereby ensuring the integrity of the video.
[0062] exist Figure 1 Based on the embodiment shown, the following Figure 2 , the technical solution of the above-mentioned video segment recording method is further introduced.
[0063] Figure 2 A flowchart of another video segment recording method provided in an embodiment of the present application is shown in FIG. Figure 2 In some embodiments, the process of the video segment recording method includes the following tasks:
[0064] S201, initialize a data cache area, and create two data cache queues in the data cache area; wherein one data cache queue is used as a write queue, and the other data cache queue is used as a read queue.
[0065] The data buffer area in the video recording device is initialized, and two data buffer queues are created, which are used as a write queue and a queue respectively.
[0066] S202, creating a producer thread and a consumer thread; wherein the producer thread is used to write data into the write queue, and the consumer thread is used to read data from the read queue.
[0067] Among them, two data threads are created, one is a producer thread for writing data to the write queue, and the other is a consumer thread for reading data from the read queue.
[0068] S203, calling the producer thread to write the original video data collected by the camera into the data cache area as a data cache queue of the write queue.
[0069] S204, calling the consumer thread to read the original video data in the data cache queue in the data cache area as a read queue, and inputting the original video data into the encoder for encoding to obtain an encoded video stream.
[0070] S205: When the queue lengths of the two data cache queues meet the queue exchange condition, the two data cache queues are cyclically exchanged for identity.
[0071] S206, calling a recorder to write the encoded video stream into a multimedia file to generate a video file.
[0072] S207, when the duration of the current video file reaches the preset segment duration, the recorder is restarted, and after the recorder is restarted, the process jumps to the step of calling the recorder to write the encoded video stream into the multimedia file to generate the next video file.
[0073] When the duration of the recorded video file reaches the preset segment duration, the recorder is restarted. After the restart, the recorder starts recording again to generate the next video file, and the cycle continues until multiple video files are recorded.
[0074] Preferably, the encoder is restarted or replaced based on user instructions, and after the encoder is restarted or replaced, the process jumps to the step of calling the recorder to write the encoded video stream into a multimedia file to generate the next video file.
[0075] Among them, the prior art caches the video stream data output by the encoder. During its operation, the encoder must remain in operation. If the encoder needs to be replaced or restarted, data will be lost, which will cause video seconds to be lost. In the present application, after the encoder is adjusted or replaced based on user instructions, the recorder will be restarted to start recording the video again. Therefore, after the encoder is restarted or replaced, it will also jump to the step of calling the recorder to write the encoded video stream into the multimedia file to generate the next video file.
[0076] Preferably, during the video recording process, the consumer thread can also be managed: if the consumer thread is in an awake state, when the queue length of the read queue is zero and the queue length of the write queue is less than a preset length, the consumer thread is controlled to enter a sleep state; if the consumer thread is in a sleep state, when the queue length of the read queue is not zero, the consumer thread is controlled to enter an awake state.
[0077] When the queue length of the read queue is zero and the queue length of the write queue is less than the preset length, it means that the consumer thread has no data to process. At this time, the consumer thread in the awakened state is adjusted to the dormant state.
[0078] When the queue length of the read queue has data again, the consumer thread in the dormant state is awakened again to resume the encoding operation of the original video data.
[0079] Preferably, during the video recording process, the producer thread can also be managed: if the producer thread is in an awake state, then when the queue length of the write queue is greater than the queue capacity of the write queue, the producer thread is controlled to enter a sleep state; if the producer thread is in a sleep state, then when the queue length of the write queue is less than the queue capacity of the write queue, the producer thread is controlled to enter an awake state.
[0080] Among them, when the queue length of the write queue is greater than the queue capacity of the write queue, it means that no new data can be written to the write queue, and the producer thread in the awake state is adjusted to the sleep state. Generally speaking, the reading efficiency of the consumer thread is much greater than the writing efficiency of the producer thread, so generally speaking, the queue length of the write queue will not be greater than the queue capacity of the write queue, unless there is a special situation such as a failure of the video recording device. At this time, putting the producer thread to sleep can reduce the device load. The video loss caused by this is caused by the special reason of the device failure, and does not belong to the problem of lost seconds in video recording.
[0081] When the queue length of the write queue is less than the queue capacity again, the producer thread in the dormant state is reawakened to resume the writing operation of the original video data.
[0082] In this embodiment, a data cache area with two data cache queues is set up, and the two data cache queues are used to cyclically alternately complete the writing and reading of video data, so that there will be no problems of lost seconds and frames during the video segment recording process, thereby ensuring the integrity of the video.
[0083] Figure 4 is a schematic diagram of the structure of a video segment recording device provided in an embodiment of the present application, see Figure 4 The video segment recording device includes various functional modules for implementing the aforementioned video segment recording method, and any functional module can be implemented by software and / or hardware.
[0084] In some embodiments, the video segment recording device 400 includes a video processing module 401 and a video generation module 402. Among them:
[0085] The video processing module 401 is used to perform video processing tasks; wherein the video processing tasks include calling a producer thread to write the original video data collected by the camera into a data cache queue in the data cache area as a write queue; calling a consumer thread to read the original video data in the data cache queue in the data cache area as a read queue, and inputting the original video data into the encoder for encoding to obtain an encoded video stream; and when the queue lengths of the two data cache queues meet the queue exchange condition, the two data cache queues are cyclically exchanged for identity;
[0086] The video generation module 402 is used to execute a video recording task; wherein the video recording task includes calling a recorder to write the encoded video stream into multimedia files in segments to generate multiple video files.
[0087] In some embodiments, the queue switching condition includes that a queue length of the data cache queue as a read queue is zero, and a queue length of the data cache queue as a write queue is not zero.
[0088] In some embodiments, the queue switching condition further includes that a queue length of a data cache queue serving as a write queue is greater than a preset length.
[0089] In some embodiments, the apparatus 400 further includes a thread management module 403, and the thread management module 403 is specifically used to:
[0090] If the consumer thread is in the awake state, when the queue length of the read queue is zero and the queue length of the write queue is less than the preset length, the consumer thread is controlled to enter the sleep state;
[0091] If the consumer thread is in a dormant state, when the queue length of the read queue is not zero, the consumer thread is controlled to enter a wake-up state.
[0092] In some embodiments, the thread management module 403 is further used to:
[0093] If the producer thread is in the awake state, when the queue length of the write queue is greater than the queue capacity of the write queue, the producer thread is controlled to enter the sleep state;
[0094] If the producer thread is in a dormant state, when the queue length of the write queue is less than the queue capacity of the write queue, the producer thread is controlled to enter a wake-up state.
[0095] In some embodiments, the video recording module 402 is specifically used to:
[0096] Call the recorder to write the encoded video stream into a multimedia file to generate a video file;
[0097] When the duration of the current video file reaches the preset segment duration, the recorder is restarted, and after the recorder is restarted, the process jumps to the step of calling the recorder to write the encoded video stream into the multimedia file to generate the next video file.
[0098] In some embodiments, the apparatus further includes a function creation module 404, wherein the function creation module 404 is specifically configured to:
[0099] Initialize the data cache area and create two data cache queues in the data cache area; one data cache queue is used as a write queue and the other data cache queue is used as a read queue;
[0100] Create a producer thread and a consumer thread; the producer thread is used to write data to the write queue, and the consumer thread is used to read data from the read queue.
[0101] The video segment recording device 400 provided in the embodiment of the present application is used to execute the technical solution provided in the aforementioned video segment recording method embodiment. Its implementation principle and technical effect are similar to those in the aforementioned method embodiment and will not be repeated here.
[0102] It should be noted that it should be understood that the division of the various modules of the above device is only a division of a logical function. When actually implemented, it can be fully or partially integrated into a physical entity, or it can be physically separated. And these modules can all be implemented in the form of software called by a processing element, or all in the form of hardware, or some modules can be implemented in the form of software called by a processing element, and some modules can be implemented in the form of hardware. For example, the video processing module 401 can be a processing element established separately, or it can be integrated in a certain chip of the above device to be implemented. In addition, it can also be stored in the memory of the above device in the form of program code, and a certain processing element of the above device can call and execute the function of the above video processing module 401. The implementation of other modules is similar. In addition, these modules can be fully or partially integrated together, or they can be implemented independently. The processing element here can be an integrated circuit with signal processing capabilities. In the implementation process, each task of the above method or each of the above modules can be completed by the integrated logic circuit of the hardware in the processor element or the instruction in the form of software.
[0103] Figure 5 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application, see Figure 5 The electronic device 500 includes a processor 501 and a memory 502 communicatively connected to the processor 501;
[0104] Memory 502 stores computer executable instructions;
[0105] The processor 501 executes the computer-executable instructions stored in the memory 502 to implement the technical solution of the aforementioned video segment recording method.
[0106] In the above-mentioned electronic device 500, the memory 502 and the processor 501 are electrically connected directly or indirectly to realize data transmission or interaction. For example, these elements can be electrically connected to each other through one or more communication buses or signal lines, such as through a bus. The bus can be an Industry Standard Architecture (ISA) bus, a Peripheral Component Interconnect (PCI) bus, or an Extended Industry Standard Architecture (EISA) bus, etc. The bus can be divided into an address bus, a data bus, a control bus, etc., but it does not mean that there is only one bus or one type of bus. The memory 502 stores computer execution instructions for implementing the aforementioned video segment recording method, including at least one software function module that can be stored in the memory 502 in the form of software or firmware. The processor 501 executes various functional applications and data processing by running the software programs and modules stored in the memory 502.
[0107] The memory 502 includes at least one type of readable storage medium, including but not limited to random access memory (RAM), read only memory (ROM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), and electrically erasable read-only memory (EEPROM). The memory 502 is used to store programs, and the processor 501 executes the programs after receiving the execution instruction. Furthermore, the software programs and modules in the above-mentioned memory 502 may also include an operating system, which may include various software components and / or drivers for managing system tasks (such as memory management, storage device control, power management, etc.), and may communicate with various hardware or software components to provide an operating environment for other software components.
[0108] The processor 501 may be an integrated circuit chip having the ability to process signals. The above-mentioned processor 501 may be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), a digital signal processor (DSP), an application-specific integrated circuit (ASIC), etc. The disclosed methods, tasks and logic block diagrams in the embodiments of the present application may be implemented or executed. The general-purpose processor may be a microprocessor, or the processor 501 may be any conventional processor, etc.
[0109] The electronic device 500 is used to execute the technical solution provided by the aforementioned video segment recording method embodiment. Its implementation principle and technical effect are similar to those in the aforementioned method embodiment and will not be repeated here.
[0110] An embodiment of the present application also provides a computer-readable storage medium, in which computer-executable instructions are stored. When the computer-executable instructions are executed, they are used to implement the technical solution of the aforementioned video segment recording method.
[0111] The computer-readable storage medium mentioned above can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic memory, flash memory, magnetic disk or optical disk. The computer-readable storage medium can be any available medium that can be accessed by a general or special-purpose computer.
[0112] An exemplary readable storage medium is coupled to a processor so that the processor can read information from the readable storage medium and write information to the readable storage medium. Of course, the readable storage medium can also be a component of the processor. The processor and the readable storage medium can be located in an application specific integrated circuit (Application Specific Integrated Circuits, abbreviated as: ASIC). Of course, the processor and the readable storage medium can also exist as discrete components in the control device of the video segment recording device.
[0113] An embodiment of the present application also provides a computer program product, including a computer program, which, when executed, is used to implement the technical solution of the aforementioned video segment recording method.
[0114] In the above embodiments, those skilled in the art will appreciate that the implementation of the above method embodiments can be implemented in whole or in part by software, hardware, firmware or any combination thereof. When implemented using software, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the process or function according to the embodiment of the present application is generated in whole or in part. The computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions may be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions may be transmitted from a website site, a computer, a server or a data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless network, microwave, etc.) mode to another website site, computer, server or data center. The computer-readable storage medium may be any available medium that a computer can access or a data storage device such as a server or a data center that includes one or more available media integrated. The available medium may be a magnetic medium (eg, a floppy disk, a hard disk, a magnetic tape), an optical medium (eg, a DVD), or a semiconductor medium (eg, a solid state disk (SSD)).
[0115] In the above embodiments, the description of each embodiment has its own emphasis. For the part not described in detail in a certain embodiment, please refer to the relevant description of other embodiments. The technical features of the above embodiments can be combined arbitrarily. In order to make the description concise, all possible combinations of the technical features in the above embodiments are not 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 specification.
[0116] Those skilled in the art will readily appreciate other embodiments of the present application after considering the specification and practicing the invention disclosed herein. The present application is intended to cover any modification, use or adaptation of the present application, which follows the general principles of the present application and includes common knowledge or customary techniques in the art that are not disclosed in the present application. The specification and examples are intended to be exemplary only, and the true scope and spirit of the present application are indicated by the appended claims.
[0117] It should be understood that the present application is not limited to the precise structures that have been described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof. The scope of the present application is limited only by the appended claims.
Claims
1. A video segment recording method, characterized in that: include: Execute a video processing task; wherein the video processing task includes calling a producer thread to write the original video data collected by the camera into a data cache queue in a data cache area as a write queue; calling a consumer thread to read the original video data in a data cache queue in a data cache area as a read queue, and inputting the original video data into an encoder for encoding to obtain an encoded video stream; and when the queue lengths of the two data cache queues meet the queue exchange condition, cyclically exchanging the identities of the two data cache queues; Execute a video recording task; wherein the video recording task includes calling a recorder to write the encoded video stream into multimedia files in segments to generate multiple video files.
2. The method according to any one of claim 1, characterized in that: The queue switching condition includes that the queue length of the data cache queue as a read queue is zero, and the queue length of the data cache queue as a write queue is not zero.
3. The method according to claim 2, characterized in that The queue switching condition also includes that the queue length of the data cache queue serving as a write queue is greater than a preset length.
4. The method according to claim 3, characterized in that The method further comprises: If the consumer thread is in the awake state, when the queue length of the read queue is zero and the queue length of the write queue is less than a preset length, the consumer thread is controlled to enter the sleep state; If the consumer thread is in a dormant state, when the queue length of the read queue is not zero, the consumer thread is controlled to enter a wake-up state.
5. The method according to any one of claims 1 to 4, characterized in that: The method further comprises: If the producer thread is in the awake state, when the queue length of the write queue is greater than the queue capacity of the write queue, control the producer thread to enter the sleep state; If the producer thread is in a dormant state, when the queue length of the write queue is less than the queue capacity of the write queue, the producer thread is controlled to enter a wake-up state.
6. The method according to any one of claims 1 to 4, characterized in that: Calling a recorder to write the encoded video stream into multimedia files in segments, generating multiple video files, including: Calling a recorder to write the encoded video stream into a multimedia file to generate a video file; When the duration of the current video file reaches the preset segment duration, the recorder is restarted, and after the recorder is restarted, the process jumps to the step of calling the recorder to write the encoded video stream into a multimedia file to generate the next video file.
7. The method according to any one of claims 1 to 4, characterized in that: Before executing the video processing task, the method further includes: Initialize a data cache area, and create two data cache queues in the data cache area; wherein one data cache queue is used as a write queue, and the other data cache queue is used as a read queue; A producer thread and a consumer thread are created; wherein the producer thread is used to write data into the write queue, and the consumer thread is used to read data from the read queue.
8. A video segment recording device, characterized in that: include: The video processing module is used to perform video processing tasks; wherein the video processing tasks include calling a producer thread to write the original video data collected by the camera into a data cache queue in a data cache area as a write queue; calling a consumer thread to read the original video data in a data cache queue in the data cache area as a read queue, and inputting the original video data into an encoder for encoding to obtain an encoded video stream; and when the queue lengths of the two data cache queues meet the queue exchange condition, the two data cache queues are cyclically exchanged for identity; The video generation module is used to execute a video recording task; wherein the video recording task includes calling a recorder to write the encoded video stream into multimedia files in segments to generate multiple video files.
9. An electronic device, characterized in that: comprising a processor, and a memory communicatively connected to the processor; The memory stores computer-executable instructions; The processor executes the computer-executable instructions stored in the memory to implement the method according to any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer-executable instructions, and when the computer-executable instructions are executed, they are used to implement the method according to any one of claims 1 to 7.