Audio and video recording method and related device
By replacing two audio and video mixers during the audio and video recording process, data is saved and initialized simultaneously, which solves the problem of excessive gaps in the recording stage in traditional technology and improves the stability and user-friendliness of audio and video segmented recording. experience.
Patent Information
- Application Number
- PCT/CN2023/128822
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- Priority Date
- 2023-03-15
- Filing Date
- 2023-10-31
- Publication Date
- 2024-09-19
AI Technical Summary
The traditional audio and video synchronous loop segment recording solution has frame loss problems, resulting in poor user experience.
By pre-creating two audio and video mixers during the audio and video recording process, using one mixer to perform audio and video mixing operations and saving the data at the end of its recording phase, while initializing the other mixer for direct use in the next phase, it is achieved The recording of adjacent segments is performed simultaneously.
It effectively reduces the frame loss problem during the audio and video segmentation recording process, shortens the gap in the recording stage, and improves the user experience. Moreover, this method can be implemented in the upper-layer APP without modifying the system framework.
Smart Images

Figure CN2023128822_19092024_PF_FP_ABST
Abstract
Description
Audio and video recording method and related equipment
[0001] This application claims priority to the Chinese patent application filed with the China Patent Office on March 15, 2023, with application number 2023102516911 and application name “A method for audio and video recording and related equipment”, the entire contents of which are incorporated by reference into this application. Technical Field
[0002] The present application relates to the field of multimedia technology, and in particular to an audio and video recording method, and also to an audio and video recording device, an electronic device, and a computer-readable storage medium. Background Art
[0003] With the rapid development of multimedia technology, audio and video recording is becoming increasingly popular, finding applications in surveillance scenarios such as law enforcement, education, and healthcare. Since recorded audio and video are often used as backups and potentially downloaded and viewed by numerous users, excellent recording quality has become a paramount requirement in the field of audio and video recording and broadcasting technology. However, traditional synchronous, looped, and segmented audio and video recording solutions still suffer from frame loss, resulting in a poor user experience.
[0004] Therefore, how to effectively solve the problem of frame loss during audio and video segment recording is an urgent problem to be solved by those skilled in the art.
[0005] This application
[0006] The purpose of this application is to provide an audio and video recording method, which can effectively solve the frame loss problem in the process of audio and video segmented recording, thereby ensuring user experience; another purpose of this application is to provide an audio and video recording device, electronic device and computer-readable storage medium, all of which have the above-mentioned beneficial effects.
[0007] In a first aspect, the present application provides an audio and video recording method, comprising:
[0008] When the recording mode is a segmented recording mode, determining a segmentation condition corresponding to the segmented recording mode, and initializing a first audio and video mixer;
[0009] Using the first audio and video mixer, the audio data recorded by the audio thread and the video data recorded by the video thread are combined to generate first audio and video data;
[0010] When the real-time recording condition satisfies the segmentation condition, saving the first audio and video data as a first audio and video file, and initializing a second audio and video mixer;
[0011] Using the second audio and video mixer, the audio data recorded by the audio thread and the video data recorded by the video thread are combined to generate second audio and video data;
[0012] When the real-time recording condition satisfies the segmentation condition, saving the second audio and video data as a second audio and video file, and initializing the first audio and video mixer;
[0013] Return to the step of using the first audio and video mixer to generate first audio and video data from the audio data recorded by the audio thread and the video data recorded by the video thread.
[0014] Optionally, before saving the first audio and video data as a first audio and video file, the method further includes:
[0015] Control the audio thread and the video thread to stop recording;
[0016] Accordingly, before using the second audio and video mixer to generate the second audio and video data from the audio data recorded by the audio thread and the video data recorded by the video thread, the method further includes:
[0017] Control the audio thread and the video thread to start recording.
[0018] Optionally, controlling the audio thread and the video thread to stop recording includes:
[0019] A stop instruction is issued to the audio thread and the video thread to stop recording the audio thread and set a stop flag, so that the video thread stops recording when the stop flag in the audio thread is detected.
[0020] Optionally, after controlling the audio thread and the video thread to stop recording, the method further includes:
[0021] Control the first audio and video mixer to stop running.
[0022] Optionally, after saving the first audio and video data as a first audio and video file, the method further includes:
[0023] Release resources of the first audio and video mixer.
[0024] Optionally, the audio and video recording method further includes:
[0025] Controlling the audio thread to set an important audio frame flag for the first audio frame in the audio data;
[0026] The video thread is controlled to set a key video frame flag for the first frame of video in the video data.
[0027] Optionally, the segmentation condition is a segmentation condition of a preset recording duration, or a segmentation condition of a preset file size, or a segmentation condition of a preset file length.
[0028] In a second aspect, the present application further discloses an audio and video recording device, comprising:
[0029] A first initialization module is used to determine a segmentation condition corresponding to the segmented recording mode and initialize a first audio and video mixer when the recording mode is a segmented recording mode;
[0030] A first recording generation module is used to generate first audio and video data by using the first audio and video mixer to record the audio data of the audio thread and the video data of the video thread;
[0031] a second initialization module, configured to save the first audio and video data as a first audio and video file and initialize a second audio and video mixer when the real-time recording condition satisfies the segmentation condition;
[0032] A second recording generation module is used to generate second audio and video data by using the second audio and video mixer to record the audio data of the audio thread and the video data of the video thread;
[0033] a third initialization module, configured to save the second audio and video data as a second audio and video file and initialize the first audio and video mixer when the real-time recording condition satisfies the segmentation condition;
[0034] The loop module is used to return to the step of using the first audio and video mixer to generate the first audio and video data by the audio data recorded by the audio thread and the video data recorded by the video thread.
[0035] In a third aspect, the present application further discloses an electronic device, comprising:
[0036] memory for storing computer programs;
[0037] A processor is used to implement the steps of any of the above-mentioned audio and video recording methods when executing the computer program.
[0038] In a fourth aspect, the present application further discloses a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps of any of the audio and video recording methods described above are implemented.
[0039] The present application provides an audio and video recording method, comprising: when the recording mode is a segmented recording mode, determining the segmentation conditions corresponding to the segmented recording mode, and initializing a first audio and video mixer; using the first audio and video mixer to generate first audio and video data from the audio data recorded by the audio thread and the video data recorded by the video thread; when the real-time recording condition meets the segmentation condition, saving the first audio and video data as a first audio and video file, and initializing a second audio and video mixer; using the second audio and video mixer to generate second audio and video data from the audio data recorded by the audio thread and the video data recorded by the video thread; when the real-time recording condition meets the segmentation condition, saving the second audio and video data as a second audio and video file, and initializing the first audio and video mixer; returning to the step of using the first audio and video mixer to generate first audio and video data from the audio data recorded by the audio thread and the video data recorded by the video thread.
[0040] By applying the technical solution provided in the present application, in order to realize synchronous segmented recording of audio and video, two audio and video mixers can be created in advance, namely the first audio and video mixer and the second audio and video mixer mentioned above, and the audio and video recording of adjacent segments can be realized by using them in a replacement manner. In the first recording stage, the initialized first audio and video mixer is used to perform the audio and video mixing operation, and the first audio and video data is saved after the first recording stage ends. At the same time, the second audio and video mixer is initialized so that when entering the second recording stage, the second audio and video mixer can be directly used to perform the audio and video mixing operation, thereby realizing the second stage recording. Obviously, the setting of the two audio and video mixers realizes that the saving operation of the first audio and video mixed data in the first audio and video mixer and the initialization operation of the second audio and video mixer can be carried out simultaneously. Compared with the implementation method of using one audio and video mixer to first save the audio and video data and then perform the audio and video mixer initialization operation in the traditional technology, the gap between the first recording stage and the second recording stage is effectively shortened, thereby effectively reducing the frame loss problem in the audio and video segmented recording process, thereby ensuring user experience. In addition, the audio and video recording method provided in the embodiment of the present application can be implemented in the upper-layer APP without any modification or adaptation of the system framework layer, and has high practicality.
[0041] The audio and video recording device, electronic device, and computer-readable storage medium provided in this application also have the above-mentioned technical effects, which will not be described in detail in this application. BRIEF DESCRIPTION OF THE DRAWINGS
[0042] In order to more clearly illustrate the technical solutions in the prior art and the embodiments of the present application, the following is a brief introduction to the drawings required for describing the prior art and the embodiments of the present application. Of course, the drawings described below in connection with the embodiments of the present application are only part of the embodiments of the present application. For those skilled in the art, other drawings can be obtained based on the provided drawings without inventive effort, and the obtained other drawings also fall within the scope of protection of the present application.
[0043] FIG1 is a flow chart of an audio and video recording method provided by the present application;
[0044] FIG2 is a schematic structural diagram of an audio and video recording device provided by the present application;
[0045] FIG3 is a schematic structural diagram of an electronic device provided in this application. DETAILED DESCRIPTION
[0046] The core of this application is to provide an audio and video recording method, which can effectively solve the frame loss problem in the process of audio and video segmented recording, thereby ensuring user experience; another core of this application is to provide an audio and video recording device, electronic device and computer-readable storage medium, all of which have the above-mentioned beneficial effects.
[0047] In order to describe the technical solutions in the embodiments of the present application more clearly and completely, the technical solutions in the embodiments of the present application will be introduced below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of this application.
[0048] An embodiment of the present application provides an audio and video recording method.
[0049] Please refer to FIG1 , which is a flow chart of an audio and video recording method provided in the present application. The audio and video recording method may include the following S101 to S105 .
[0050] S101: When the recording mode is a segmented recording mode, determining a segmentation condition corresponding to the segmented recording mode, and initializing a first audio and video mixer.
[0051] This step is intended to determine the recording mode. It is understandable that, during the audio and video recording process, the recording mode can be divided into a segmented recording mode and a real-time recording mode, wherein the segmented recording mode means that during the audio and video recording process, whenever a preset segmentation condition is met (such as the recording duration reaches a preset duration), the recording data is saved once, and the recording data saved each time is the audio and video data recorded in each recording stage; the real-time recording mode means that real-time recording is performed during the audio and video recording process, and the recording data is saved at the end of the complete recording, and the saved recording data is the audio and video data recorded during the entire recording process.
[0052] Specifically, the user can select the recording mode according to actual needs. When it is determined that the recording mode selected by the user is the segmented recording mode, the segmentation conditions corresponding to the segmented recording mode can be further determined. The specific content of the segmentation conditions does not affect the implementation of this technical solution. The user can set it according to his or her actual needs. For example, segmented recording can be performed for each preset duration, or segmented recording can be performed according to a preset recording data size, etc.
[0053] Furthermore, while determining the segmentation conditions corresponding to the segmented recording mode, the first audio and video mixer can be initialized. The first audio and video mixer is used to implement mixing processing of audio data and video data to generate audio and video mixed data (herein referred to as the first audio and video data). It is understandable that simultaneously determining the segmentation conditions and initializing the first audio and video mixer helps improve audio and video recording efficiency.
[0054] S102: Using a first audio and video mixer, the audio data recorded by the audio thread and the video data recorded by the video thread are combined to generate first audio and video data.
[0055] This step is intended to achieve the generation of the first audio and video data, and this process is implemented based on the above-mentioned initialized first audio and video mixer. Specifically, after receiving the recording instruction, the system will start the audio thread and the video thread, wherein the audio thread is used to perform audio recording and obtain audio data; the video thread is used to perform video recording and obtain video data. Furthermore, after completing the initialization operation of the first audio and video mixer, the first audio and video mixer can be used to mix the audio data recorded by the audio thread and the video data recorded by the video thread to obtain the first audio and video data.
[0056] S103: When the real-time recording condition meets the segmentation condition, the first audio and video data is saved as a first audio and video file, and a second audio and video mixer is initialized.
[0057] This step is intended to achieve storage processing of the first audio and video data. It is understandable that, since it is a segmented recording mode, during the audio and video recording process, the recorded data will be saved once each time the preset segmentation conditions are met. Based on this, the real-time recording conditions can be monitored in real time to determine whether the real-time recording conditions meet the segmentation conditions, for example, to determine whether the real-time recording time reaches the preset time, to determine whether the real-time recording data size meets the preset data size, etc. Further, when it is monitored that the real-time recording conditions meet the segmentation conditions, the first audio and video data can be converted into a first audio and video file. Of course, the file type corresponding to the first audio and video file is not limited in this application. In one possible implementation method, it can be saved in MP4 format.
[0058] Furthermore, while the first audio and video data are being saved, the second audio and video mixer can be initialized, and the second audio and video mixer is used to implement mixing processing of audio data and video data so as to generate audio and video mixed data (here referring to the second audio and video data described below). It can be understood that initializing the second audio and video mixer while saving the first audio and video data, that is, initializing the second audio and video mixer before the start of the next recording phase, can effectively avoid performing the audio and video mixer initialization operation again in the next recording phase, thereby effectively shortening the gap between two adjacent recording stages, thereby effectively reducing the frame loss problem in the audio and video segmented recording process.
[0059] S104: Using a second audio and video mixer, the audio data recorded by the audio thread and the video data recorded by the video thread are combined to generate second audio and video data.
[0060] This step is intended to achieve the generation of the second audio and video data, and the process is implemented based on the second audio and video mixer after the above initialization. It is understandable that after completing the initialization processing of the second audio and video mixer, the next segmented recording phase is entered. In this recording phase, the second audio and video mixer can be directly used (without the need to perform the initialization operation of the audio and video mixer in this recording phase) to mix the audio data recorded by the audio thread and the video data recorded by the video thread to obtain the second audio and video data.
[0061] S105: When the real-time recording condition meets the segmentation condition, the second audio and video data is saved as a second audio and video file, and the first audio and video mixer is initialized, and the process returns to S102.
[0062] This step is intended to achieve cyclic segmented recording of audio and video. As mentioned above, during the audio and video recording process, the recording data will be saved once each time the preset segmentation conditions are met. Therefore, in the current audio and video recording stage, the real-time recording conditions will also be monitored, and when the real-time recording conditions meet the segmentation conditions, the second audio and video data will be saved as a second audio and video file. At the same time, the first audio and video mixer is initialized so that the first audio and video mixer can be used to perform audio and video mixing processing in the next segmented recording stage. Thus, by setting up two audio and video mixers, the audio and video recording of adjacent segments is achieved in a replacement manner, which helps to reduce the problem of frame loss in the audio and video segmented recording process.
[0063] It can be seen that the audio and video recording method provided in the embodiment of the present application can pre-create two audio and video mixers, namely the first audio and video mixer and the second audio and video mixer, to realize the audio and video recording of adjacent segments in an alternative manner in order to realize the synchronous segmented recording of audio and video. In the first recording stage, the initialized first audio and video mixer is used to perform the audio and video mixing operation, and the first audio and video data is saved after the first recording stage ends. At the same time, the second audio and video mixer is initialized so that when entering the second recording stage, the second audio and video mixer can be directly used to perform the audio and video mixing operation, thereby realizing the second stage recording. Obviously, the setting of the two audio and video mixers realizes that the saving operation of the first audio and video mixed data in the first audio and video mixer and the initialization operation of the second audio and video mixer can be carried out simultaneously. Compared with the implementation method of using one audio and video mixer to first save the audio and video data and then perform the audio and video mixer initialization operation in the traditional technology, the gap between the first recording stage and the second recording stage is effectively shortened, thereby effectively reducing the frame loss problem in the audio and video segmented recording process, thereby ensuring user experience. In addition, the audio and video recording method provided in the embodiment of the present application can be implemented in the upper-layer APP without any modification or adaptation of the system framework layer, and has high practicality.
[0064] Based on the above embodiment:
[0065] In one embodiment of the present application, before saving the first audio and video data as the first audio and video file, the method may further include: controlling the audio thread and the video thread to stop recording;
[0066] Accordingly, before using the second audio and video mixer to generate the second audio and video data from the audio data recorded by the audio thread and the video data recorded by the video thread, the method may further include: controlling the audio thread and the video thread to start recording.
[0067] In order to further reduce the frame loss problem during audio and video recording, the audio and video recording method provided in the embodiment of the present application can further realize the control function of the audio thread and the video thread, and the control function mainly includes the control thread start function and the control thread stop function.
[0068] Specifically, before saving the first audio and video data as a first audio and video file, the audio thread and the video thread can be controlled to stop recording, that is, stop recording the audio data and the video data. This operation can also effectively avoid the problem of audio and video recording exceeding the recording conditions; further, after saving the first audio and video data as a first audio and video file and initializing the second audio and video mixer, before using the second audio and video mixer to generate the second audio and video data, the audio thread and the video thread can be controlled to start recording, that is, restart the recording of the audio data and the video data.
[0069] It should be noted that the above control of the audio thread and video thread is applicable to each segmented recording stage.
[0070] In one embodiment of the present application, the above-mentioned control of the audio thread and the video thread to stop recording may include: sending a stop instruction to the audio thread and the video thread to make the audio thread stop recording and set a stop flag, so that the video thread stops recording when the stop flag in the audio thread is detected.
[0071] The embodiment of the present application provides an implementation method for controlling the audio thread and the video thread to stop recording. Specifically, when it is determined that the real-time recording conditions meet the segmentation conditions, a stop instruction can be issued to the audio thread and the video thread at the same time; for the audio thread, after receiving the stop instruction, it can immediately respond to the stop instruction to stop the audio recording, and set a stop flag for itself at the same time; for the video thread, after receiving the stop instruction, it can immediately respond to the high stop instruction to monitor the audio thread to determine whether the stop flag in the audio thread can be monitored. If the stop flag is monitored, it means that the audio thread has indeed successfully stopped recording. At this time, the video thread can stop recording the video data; on the contrary, if the video thread does not monitor the stop flag in the audio thread, it means that the audio thread has failed to stop recording and is still recording audio data. At this time, the video thread does not stop recording the video data. Among them, the real-time monitoring of the stop instruction by the two can be achieved by setting the run function in the video thread and the audio thread. Of course, the restart of the video thread and the audio thread can also be achieved based on the above method.
[0072] Obviously, based on the above implementation, it can be ensured that the audio thread and the video thread can stop recording and restart recording at the same time, thereby ensuring the synchronization of the audio thread and the video thread.
[0073] Furthermore, it should be noted that the aforementioned embodiment of the application uses the method of having the video thread monitor the audio thread to achieve synchronization between the video and audio threads. Of course, the reverse operation can also be used, that is, using the audio thread to monitor the video thread to achieve synchronization between the two, and this application does not limit this. However, in actual operation, the sampling rate of the audio thread is much higher than that of the video thread. Therefore, using the video thread to monitor the audio thread to ensure that the audio thread stops running before the video thread is more helpful in reducing frame loss.
[0074] In one embodiment of the present application, after controlling the audio thread and the video thread to stop recording, the method may further include: controlling the first audio and video mixer to stop running.
[0075] It can be understood that after controlling the audio thread and the video thread to stop recording, the operation process of saving the first audio and video data in the first audio and video mixer will be entered. At this time, in order to avoid the first audio and video mixer being in a running state affecting the saving operation of the first audio and video data, the first audio and video mixer can be controlled to stop running after controlling the audio thread and the video thread to stop recording and before saving the first audio and video data.
[0076] In one embodiment of the present application, after the first audio and video data is saved as the first audio and video file, the method may further include: releasing resources of the first audio and video mixer.
[0077] To avoid unnecessary resource occupation, after the first audio and video data is saved as the first audio and video file, the first audio and video mixer may be further freed of resources to provide audio and video mixing processing services for subsequent new segmented recording stages.
[0078] In one embodiment of the present application, the audio and video recording method may further include: controlling the audio thread to set a key audio frame flag for the first frame of audio in the audio data; and controlling the video thread to set a key video frame flag for the first frame of video in the video data.
[0079] The audio and video recording method provided in the embodiment of the present application can further realize the function of setting the key frame during the segmented recording process. That is, in each recording stage, the audio thread will be controlled to set the first frame of audio in the audio data recorded in the current recording stage as the key audio frame, and the video thread will be controlled to set the first frame of video in the video data recorded in the current recording stage as the key video frame. This process can be achieved by setting the key flag for the first frame of video and the first frame of audio.
[0080] It can be understood that based on this implementation method, when playing the recorded audio and video, if you need to fast forward or rewind the playback screen, each fast forward operation or rewind operation can make the playback screen fast forward or rewind to the first frame of audio and video of a certain audio and video file, and can ensure the synchronization of the played audio and video.
[0081] In one embodiment of the present application, the above-mentioned segmentation condition may be a segmentation condition of a preset recording duration, a segmentation condition of a preset file size, or a segmentation condition of a preset file length.
[0082] The embodiments of the present application provide several different types of segmentation conditions, namely, segmentation conditions based on preset recording duration, segmentation conditions based on preset file size, and segmentation conditions based on preset file length. The segmentation condition based on preset recording duration means that whenever the recording duration reaches the preset recording duration, the segmentation condition is deemed to be satisfied, the current recording phase ends, and the next recording phase begins; the segmentation condition based on preset file size means that whenever the size of the recorded audio or video file reaches the preset file size, the segmentation condition is deemed to be satisfied, the current recording phase ends, and the next recording phase begins; the segmentation condition based on preset file length means that whenever the length of the recorded audio or video file reaches the preset file length, the segmentation condition is deemed to be satisfied, the current recording phase ends, and the next recording phase begins.
[0083] It should be noted that the specific values of the preset recording time, preset file size, and preset file length do not affect the implementation of this technical solution, and can be customized by technical personnel according to actual needs. This application does not limit this.
[0084] Based on the above embodiments:
[0085] The present application provides another audio and video recording method. The implementation process of the audio and video recording method is as follows:
[0086] (1) Set two Muxer hybrid encoders (the first audio and video mixer and the second audio and video mixer), and the default value of mMuxerCount is 2;
[0087] (2) upon receiving a recording instruction, determining a recording mode and initializing a first audio and video mixer;
[0088] (3) When the recording mode is a segmented recording mode, determining a segmentation condition;
[0089] (4) using an audio thread to record audio data, using a video thread to record video data, controlling the audio thread to set the first audio frame of the current recording phase as a key audio frame, controlling the video thread to set the first video frame of the current recording phase as a key video frame, and using a first video encoder to encode the audio data and the video data to obtain first audio and video data;
[0090] (5) When the segmentation conditions are detected, a stop instruction is sent to the audio thread and the video thread;
[0091] (6) The audio thread automatically stops running in response to the stop instruction and sets the stop flag; the video thread automatically stops running when the stop flag is detected in response to the stop instruction;
[0092] (7) Control the first audio and video mixer to stop running, release its resources, save the first video data as an MP4 file, and initialize the second audio and video mixer;
[0093] (8) issuing a restart instruction to the audio thread and the video thread, using the audio thread to record audio data, using the video thread to record video data, controlling the audio thread to set the first audio frame of the current recording phase as the key audio frame, controlling the video thread to set the first video frame of the current recording phase as the key video frame, and using the second video encoder to encode the audio data and the video data to obtain second audio and video data;
[0094] (9) When the segmentation conditions are met, a stop instruction is issued to the audio thread and the video thread;
[0095] (10) The audio thread automatically stops running in response to the stop instruction and sets the stop flag; the video thread automatically stops running when the stop flag is detected in response to the stop instruction;
[0096] (11) Control the second audio and video mixer to stop running, release its resources, save the second video data as an MP4 file, and initialize the first audio and video mixer;
[0097] (12) Send a restart instruction to the audio thread and the video thread, and return to (4).
[0098] It can be seen that the audio and video recording method provided in the embodiment of the present application can pre-create two audio and video mixers, namely the first audio and video mixer and the second audio and video mixer, to realize the audio and video recording of adjacent segments in an alternative manner in order to realize the synchronous segmented recording of audio and video. In the first recording stage, the initialized first audio and video mixer is used to perform the audio and video mixing operation, and the first audio and video data is saved after the first recording stage ends. At the same time, the second audio and video mixer is initialized so that when entering the second recording stage, the second audio and video mixer can be directly used to perform the audio and video mixing operation, thereby realizing the second stage recording. Obviously, the setting of the two audio and video mixers realizes that the saving operation of the first audio and video mixed data in the first audio and video mixer and the initialization operation of the second audio and video mixer can be carried out simultaneously. Compared with the implementation method of using one audio and video mixer to first save the audio and video data and then perform the audio and video mixer initialization operation in the traditional technology, the gap between the first recording stage and the second recording stage is effectively shortened, thereby effectively reducing the frame loss problem in the audio and video segmented recording process, thereby ensuring user experience. In addition, the audio and video recording method provided in the embodiment of the present application can be implemented in the upper-layer APP without any modification or adaptation of the system framework layer, and has high practicality.
[0099] An embodiment of the present application provides an audio and video recording device.
[0100] Please refer to FIG2 , which is a schematic diagram of the structure of an audio and video recording device provided by the present application. The audio and video recording device may include:
[0101] The first initialization module 100 is used to determine the segmentation conditions corresponding to the segmented recording mode and initialize the first audio and video mixer when the recording mode is the segmented recording mode;
[0102] A first recording generation module 200 is configured to generate first audio and video data by using a first audio and video mixer to combine the audio data recorded by the audio thread and the video data recorded by the video thread;
[0103] A second initialization module 300 is configured to save the first audio and video data as a first audio and video file and initialize a second audio and video mixer when the real-time recording condition satisfies the segmentation condition;
[0104] The second recording generation module 400 is used to generate second audio and video data by using the second audio and video mixer to record the audio data of the audio thread and the video data of the video thread;
[0105] The third initialization module 500 is used to save the second audio and video data as a second audio and video file and initialize the first audio and video mixer when the real-time recording condition meets the segmentation condition;
[0106] The loop module 600 is used to return to the step of using the first audio and video mixer to generate the first audio and video data by combining the audio data recorded by the audio thread and the video data recorded by the video thread.
[0107] It can be seen that the audio and video recording device provided in the embodiment of the present application can pre-create two audio and video mixers, namely the first audio and video mixer and the second audio and video mixer, in order to realize synchronous segmented recording of audio and video, so as to realize audio and video recording of adjacent segments in an alternative manner. In the first recording stage, the initialized first audio and video mixer is used to perform the audio and video mixing operation, and the first audio and video data is saved after the first recording stage ends. At the same time, the second audio and video mixer is initialized so that when entering the second recording stage, the second audio and video mixer can be directly used to perform the audio and video mixing operation, thereby realizing the second stage recording. Obviously, the setting of the two audio and video mixers realizes that the saving operation of the first audio and video mixed data in the first audio and video mixer and the initialization operation of the second audio and video mixer can be carried out simultaneously. Compared with the implementation method of using one audio and video mixer to first save the audio and video data and then perform the audio and video mixer initialization operation in the traditional technology, the gap between the first recording stage and the second recording stage is effectively shortened, thereby effectively reducing the frame loss problem in the audio and video segmented recording process, thereby ensuring user experience. In addition, the audio and video recording method provided in the embodiment of the present application can be implemented in the upper-layer APP without any modification or adaptation of the system framework layer, and has high practicality.
[0108] In one embodiment of the present application, the audio and video recording device may further include a first control module for controlling the audio thread and the video thread to stop recording before the first audio and video data is saved as the first audio and video file; and controlling the audio thread and the video thread to start recording before the second audio and video data is generated by the second audio and video mixer using the audio data recorded by the audio thread and the video data recorded by the video thread.
[0109] In one embodiment of the present application, the above-mentioned first control module can be specifically used to send a stop instruction to the audio thread and the video thread, so that the audio thread stops recording and sets a stop flag, and the video thread stops recording when it detects the stop flag in the audio thread.
[0110] In one embodiment of the present application, the audio and video recording device may further include a second control module, configured to control the first audio and video mixer to stop running after the audio thread and the video thread are controlled to stop recording.
[0111] In one embodiment of the present application, the audio and video recording device may further include a resource releasing module, configured to release resources of the first audio and video mixer after the first audio and video data is saved as the first audio and video file.
[0112] In one embodiment of the present application, the audio and video recording device may further include a third control module for controlling the audio thread to set an important audio frame flag for the first frame of audio in the audio data; and controlling the video thread to set an important video frame flag for the first frame of video in the video data.
[0113] In one embodiment of the present application, the above-mentioned segmentation condition can be a segmentation condition of a preset recording duration, a segmentation condition of a preset file size, or a segmentation condition of a preset file length.
[0114] For an introduction to the apparatus provided in the embodiments of this application, please refer to the above method embodiments, which will not be elaborated in this application.
[0115] An embodiment of the present application provides an electronic device.
[0116] Please refer to FIG3 , which is a schematic diagram of the structure of an electronic device provided by the present application. The electronic device may include:
[0117] memory for storing computer programs;
[0118] The processor is used to implement the steps of any of the above-mentioned audio and video recording methods when executing a computer program.
[0119] 3 is a schematic diagram of the structure of an electronic device, which may include a processor 10, a memory 11, a communication interface 12, and a communication bus 13. The processor 10, the memory 11, and the communication interface 12 communicate with each other via the communication bus 13.
[0120] In the embodiment of the present application, the processor 10 may be a central processing unit (CPU), an application-specific integrated circuit, a digital signal processor, a field programmable gate array, or other programmable logic devices.
[0121] The processor 10 may call a program stored in the memory 11. Specifically, the processor 10 may execute the operations in the embodiment of the audio and video recording method.
[0122] The memory 11 is used to store one or more programs. The program may include program code, and the program code includes computer operating instructions. In the embodiment of the present application, the memory 11 stores at least a program for implementing the following functions:
[0123] When the recording mode is the segmented recording mode, determining a segmentation condition corresponding to the segmented recording mode, and initializing the first audio and video mixer;
[0124] Using a first audio and video mixer, the audio data recorded by the audio thread and the video data recorded by the video thread are combined to generate first audio and video data;
[0125] When the real-time recording condition satisfies the segmentation condition, the first audio and video data is saved as a first audio and video file, and a second audio and video mixer is initialized;
[0126] Using a second audio and video mixer, the audio data recorded by the audio thread and the video data recorded by the video thread are combined to generate second audio and video data;
[0127] When the real-time recording condition satisfies the segmentation condition, the second audio and video data is saved as a second audio and video file, and the first audio and video mixer is initialized;
[0128] Return to the step of using the first audio and video mixer to generate first audio and video data from the audio data recorded by the audio thread and the video data recorded by the video thread.
[0129] In one possible implementation, the memory 11 may include a program storage area and a data storage area, wherein the program storage area may store an operating system and an application required for at least one function, etc.; the data storage area may store data created during use.
[0130] In addition, the memory 11 may include a high-speed random access memory and may also include a non-volatile memory, such as at least one disk storage device or other volatile solid-state storage device.
[0131] The communication interface 12 may be an interface of a communication module, and is used to connect to other devices or systems.
[0132] Of course, it should be noted that the structure shown in FIG3 does not constitute a limitation on the electronic device in the embodiment of the present application. In actual applications, the electronic device may include more or fewer components than those shown in FIG3, or combine certain components.
[0133] An embodiment of the present application provides a computer-readable storage medium.
[0134] The computer-readable storage medium provided in the embodiment of the present application stores a computer program, and when the computer program is executed by a processor, the steps of any of the above-mentioned audio and video recording methods can be implemented.
[0135] The computer-readable storage medium may include: a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disk, etc., which can store program codes.
[0136] For an introduction to the computer-readable storage medium provided in the embodiments of the present application, please refer to the above method embodiments, and this application will not elaborate on them here.
[0137] The various embodiments in this specification are described in a progressive manner, with each embodiment focusing on the differences from other embodiments. Reference can be made to the common and similar parts between the various embodiments. For the devices disclosed in the embodiments, since they correspond to the methods disclosed in the embodiments, the description is relatively simple, and the relevant parts can be referred to the method description.
[0138] Professionals may further appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the above description has generally described the components and steps of each example according to their functions. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professionals and technicians may use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.
[0139] The steps of the methods or algorithms described in conjunction with the embodiments disclosed herein may be implemented directly using hardware, a software module executed by a processor, or a combination of the two. The software module may be placed in random access memory (RAM), internal memory, read-only memory (ROM), electrically programmable ROM, electrically erasable programmable ROM, registers, a hard disk, a removable disk, a CD-ROM, or any other form of storage medium known in the art.
[0140] The above is a detailed introduction to the audio and video recording method, device, electronic device, and computer-readable storage medium provided by the present application. Specific examples are used herein to illustrate the principles and implementation methods of the present application. The description of the above embodiments is only used to help understand the method and core ideas of the present application. It should be pointed out that for ordinary technicians in this technical field, without departing from the principles of the present application, several improvements and modifications can be made to the present application, and these improvements and modifications also fall within the scope of protection of the present application.
Claims
1. An audio and video recording method, comprising: When the recording mode is a segmented recording mode, determining a segmentation condition corresponding to the segmented recording mode, and initializing a first audio and video mixer; Using the first audio and video mixer to generate first audio and video data from the audio data recorded by the audio thread and the video data recorded by the video thread; When the real-time recording condition meets the segmentation condition, the first audio and video data is saved as a first audio and video file, and a second audio and video mixer is initialized; Using the second audio and video mixer to generate second audio and video data from the audio data recorded by the audio thread and the video data recorded by the video thread; When the real-time recording condition meets the segmentation condition, the second audio and video data is saved as a second audio and video file, and the first audio and video mixer is initialized; Return to the step of using the first audio and video mixer to generate first audio and video data from the audio data recorded by the audio thread and the video data recorded by the video thread.
2. The audio and video recording method according to claim 1, characterized in that: Before saving the first audio and video data as a first audio and video file, the method further includes: Control the audio thread and the video thread to stop recording; Correspondingly, before using the second audio and video mixer to generate the second audio and video data from the audio data recorded by the audio thread and the video data recorded by the video thread, the method further includes: Control the audio thread and the video thread to start recording.
3. The audio and video recording method according to claim 2, characterized in that: The controlling the audio thread and the video thread to stop recording includes: A stop instruction is issued to the audio thread and the video thread, so that the audio thread stops recording and sets a stop flag, and the video thread stops recording when the stop flag in the audio thread is detected.
4. The audio and video recording method according to claim 2, characterized in that: After controlling the audio thread and the video thread to stop recording, the method further includes: Control the first audio and video mixer to stop running.
5. The audio and video recording method according to claim 1, characterized in that: After the first audio and video data is saved as a first audio and video file, the method further includes: Release resources of the first audio and video mixer.
6. The audio and video recording method according to any one of claims 1 to 5, characterized in that: Also includes: Control the audio thread to set an important audio frame flag for the first audio frame in the audio data; The video thread is controlled to set an important video frame flag for the first frame of video in the video data.
7. The audio and video recording method according to claim 1, characterized in that: The segmentation condition is a segmentation condition of a preset recording duration, or a segmentation condition of a preset file size, or a segmentation condition of a preset file length.
8. An audio and video recording device, comprising: A first initialization module, used for determining a segmentation condition corresponding to the segmentation recording mode and initializing a first audio and video mixer when the recording mode is a segmentation recording mode; A first recording generation module, used to generate first audio and video data by using the first audio and video mixer to record audio data recorded by the audio thread and video data recorded by the video thread; A second initialization module, used for saving the first audio and video data as a first audio and video file and initializing a second audio and video mixer when the real-time recording condition meets the segmentation condition; A second recording generation module, used to generate second audio and video data by using the second audio and video mixer to generate the audio data recorded by the audio thread and the video data recorded by the video thread; A third initialization module, used for saving the second audio and video data as a second audio and video file and initializing the first audio and video mixer when the real-time recording condition meets the segmentation condition; The loop module is used to return to the step of using the first audio and video mixer to generate the first audio and video data from the audio data recorded by the audio thread and the video data recorded by the video thread.
9. An electronic device, comprising: Memory for storing computer programs; A processor, configured to implement the steps of the audio and video recording method as described in any one of claims 1 to 7 when executing the computer program.
10. A computer-readable storage medium having a computer program stored thereon, wherein the computer program, when executed by a processor, implements the steps of the audio and video recording method according to any one of claims 1 to 7.
Citation Information
Patent Citations
Method and device for generating media data
CN103974143A
Recording method and device for audio and video code stream
CN105791951A
Method, device, electronic device and computer readable storage medium for recording video
CN107800988A
Method and system for circularly recording video
CN114615451A
Audio and video recording method and related equipment
CN116233344A
