A method for synchronously recording audio and video based on recording terminal
By using multi-threads on the recording terminal to process the collection, encoding and decoding of audio and video data, and calculating the time difference to adjust the data writing sequence, the problem of poor audio and video synchronization is solved, synchronous recording and playback of audio and video are realized, and the efficiency is improved User experience.
Patent Information
- Application Number
- CN202210131505.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-02-11
- Publication Date
- 2024-09-17
- Estimated Expiration
- 2042-02-11
AI Technical Summary
In the existing audio and video recording technology, the synchronization of audio and video data is poor, resulting in the audio and video being out of sync during playback, affecting the user experience, and the prolonged data acquisition time leads to serious synchronization problems.
Using a multi-thread processing mechanism, the audio and video data collection, encoding and decoding threads are respectively established on the recording terminal. The data writing sequence is adjusted by calculating the encoding and decoding time difference to ensure synchronous audio and video recording, and the absolute time is calculated through the formula. Process the addition or discarding of video data frames to achieve audio and video synchronization.
It effectively avoids the extension of audio and video data acquisition time, improves the synchronization effect of audio and video, ensures lip synchronization, and improves the user experience.
Smart Images

Figure CN114501095B
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of audio and video recording, and in particular to an audio and video synchronous recording method based on a recording terminal. Background Art
[0002] In recent years, with the development of the Internet, video recording / recording and broadcasting has been more and more widely used. For example, in education and online or offline linear conferences, the synchronization requirements for audio and video recording are getting higher and higher, requiring the current playback picture and audio to accurately correspond, and the corresponding accuracy requirements are getting higher and higher. The corresponding accuracy is reflected in the fact that when watching the recorded video, the audio can be synchronized with the lip sounds (lip shape) in the video to avoid the situation where the person in the video has already spoken but the audio has not yet been played, that is, to avoid the phenomenon of audio and video being out of sync, which leads to a poor experience for the audience.
[0003] In addition, most of the audio and video recordings on the current market process and send the data immediately after it is acquired, and then the receiving end obtains the data and decodes and plays it. This prolongs the time for acquiring audio and video, resulting in a larger time difference in acquiring audio and video data, which will gradually cause audio and video to become out of sync. Summary of the invention
[0004] In view of the deficiencies in the prior art, the purpose of the present invention is to provide an audio and video synchronous recording method based on a recording terminal, which can solve the problem in the prior art that the audio and video recording is not synchronized, resulting in the playback picture and audio being not synchronized.
[0005] The technical solution to achieve the purpose of the present invention is: a method for synchronously recording audio and video based on a recording terminal, comprising the following steps:
[0006] Step 1: Initialize the recording terminal, which includes an audio and video acquisition module, an audio and video encoding module, and an audio and video decoding module;
[0007] Step 2: Pre-establish the first thread, the second thread, the third thread and the fourth thread in the recording terminal. On the first thread, write the audio data collected by the audio and video acquisition module into the first linked list. On the second thread, write the video data collected by the audio and video module into the second linked list.
[0008] On the third thread, the audio data in the first linked list is read, and the audio data is encoded to obtain the successful encoding time t of the audio data. sc ,
[0009] The encoded audio data is processed by the service, and the audio decoding module decodes the audio data after the service processing and obtains the successful decoding time p of the audio data sc ,
[0010] On the fourth thread, the video data in the second linked list is read, and the read video data is encoded to obtain the successful encoding time t of the video data. vc ,
[0011] The encoded video data is processed by the service, and the video decoding module decodes the video data after the service processing and obtains the successful decoding time p of the video data vc ;
[0012] Step 3: Calculate the first successful encoding time t sc and the first successful encoding time t vc The time difference t svc , that is, t svc =t vc -t sc ,
[0013] If t svc ≥0, the decoded audio data is written into the decoded video data to form an audio and video recording file.
[0014] If t svc <0, then end the processing.
[0015] Furthermore, in step 3, if t svc ≥0, the decoded audio data is written into the decoded video data to form an audio and video recording file. The specific implementation process includes the following steps:
[0016] According to formula ①, the absolute time T is calculated. The absolute time T represents the cumulative playback time from the start of video data playback to the current writing of audio data:
[0017]
[0018] In the formula, AudioNum represents the number of audio data blocks, AudioLen represents the total length of the decoded audio data in frames, and R represents the audio sampling rate.
[0019] The number of frames of the video data written for the first time in the absolute time is used as the standard data value. If the video data currently written is less than the standard data value in the absolute time, a frame of video is added after the last frame of the current video data. The added video frame is a copy of the current last frame of video.
[0020] If the currently written video data is greater than the standard data value within the absolute time, the last video frame is discarded from the video data.
[0021] If the currently written video data is the same as the standard data value within the absolute time, there is no need to discard or supplement the video frame to the video data.
[0022] Furthermore, the audio acquisition and video acquisition are integrated modules together, or are separate modules.
[0023] Furthermore, the audio and video encoding module and the audio and video decoding module are integrated modules integrated together, or are separate modules.
[0024] Furthermore, in step 2, the first thread and the second thread are performed simultaneously.
[0025] Furthermore, in step 2, the first thread and the third thread are performed synchronously, and the second thread and the fourth thread are performed synchronously.
[0026] The beneficial effect of the present invention is that the present invention can effectively avoid the problem of prolonged acquisition time of audio and video data, realize lip synchronization of audio and video, and thus improve the synchronization effect of audio and video. BRIEF DESCRIPTION OF THE DRAWINGS
[0027] Figure 1 It is a schematic diagram of the process of the present invention. DETAILED DESCRIPTION
[0028] In order to make the purpose, technical scheme and advantages of the present application clearer, the specific embodiments of the present application are further described in detail below in conjunction with the accompanying drawings. It is understood that the specific embodiments described herein are only used to explain the present application, rather than to limit the present application. It should also be noted that, for the convenience of description, only the part related to the present application but not all the contents are shown in the accompanying drawings. Before discussing the exemplary embodiments in more detail, it should be mentioned that some exemplary embodiments are described as processes or methods depicted as flow charts. Although the flow chart describes each operation (or step) as a sequential process, many of the operations therein can be implemented in parallel, concurrently or simultaneously. In addition, the order of each operation can be rearranged. The process can be terminated when its operation is completed, but it can also have additional steps not included in the accompanying drawings. The process can correspond to a method, a function, a procedure, a subroutine, a subprogram, etc.
[0029] like Figure 1 As shown, a method for synchronously recording audio and video based on a recording terminal includes the following steps:
[0030] Step 1: Initialize the recording terminal so that the audio and video acquisition module, audio and video encoding module and audio and video decoding module in the recording terminal can start working normally. The audio and video acquisition module can be an integrated module integrating audio acquisition and video acquisition, or a separate module, and the same is true for the audio and video encoding module and the audio and video decoding module.
[0031] Step 2: The first thread, the second thread, the third thread and the fourth thread are pre-established in the recording terminal. On the first thread, the audio data collected by the audio and video acquisition module is written into the first linked list, and on the second thread, the video data collected by the audio and video module is written into the second linked list, so that the audio data and the video data are stored in the first linked list and the second linked list respectively. The first thread and the second thread are performed simultaneously, that is, the audio data and the video data are collected simultaneously, and the audio data and the video data are stored simultaneously.
[0032] Among them, on the first thread and the second thread, audio data and video data are continuously collected, and the collected audio data and video data are continuously written into the corresponding linked list, which is equivalent to being able to continuously loop on the first thread and the second thread, which is equivalent to realizing the asynchronous acquisition of audio and video data.
[0033] On the third thread, the audio data in the first linked list is read, and the audio data is encoded to obtain the successful encoding time t of the audio data. sc The successful encoding time of the audio data refers to the moment when the current audio data is encoded, and after the encoded audio data is processed by the service management chip in the recording terminal, the audio decoding module decodes the processed audio data and obtains the successful decoding time p of the audio data. sc , successful decoding time p sc That is, the time when the service management chip transmits the audio data to the audio decoding module for decoding and successfully decodes the audio data, that is, the time when the current audio data is decoded. sc The decoded audio data can then be sent out.
[0034] On the fourth thread, the video data in the second linked list is read, and the read video data is encoded to obtain the successful encoding time t of the video data. vc The successful encoding time of the video data is the moment when the current video data is encoded, and the encoded video data is processed by the service management chip in the recording terminal, and the video decoding module decodes the processed video data and obtains the successful decoding time p of the video data. vc , successful decoding time p vcThat is, the time when the service management chip transmits the video data to the video decoding module for decoding and successfully decodes the video data, that is, the time when the current video data is decoded. vc The decoded video data can then be sent out.
[0035] In this step, for audio data, two threads are used to process respectively, one thread is responsible for the collection and storage of audio data, and the other thread is responsible for reading the stored audio data and then encoding and decoding it in turn, and sending the decoded audio data, so that each thread can continuously collect audio data and encode and decode audio data, and send the decoded audio data. Since a single thread can only re-enter the next round of audio data collection after collecting audio data and completing encoding and decoding to send data, compared to using a single thread, the processing time required for the collection, encoding and decoding and sending of audio data can be greatly saved. For video data, the same is true, compared to using a single thread, the processing time required for the collection, encoding and decoding and sending of video data can be greatly saved.
[0036] The first thread and the third thread are performed synchronously, and the second thread and the fourth thread are also performed synchronously.
[0037] Step 3: Calculate the first successful encoding time t sc and the first successful encoding time t vc The time difference t svc , that is, t svc =t vc -t sc , the time difference t svc As hardware duration, hardware duration refers to the time length from the first completion of audio decoding to the first completion of video encoding after initialization. Hardware duration is mainly used as a time reference point to determine the time difference of audio and video encoding.
[0038] If the hardware duration is too long, the last frame of the decoded video data is discarded; if the hardware duration is too short, the video is added to the last frame of the decoded video data, and the frame takes the original last frame.
[0039] If t svc≥0, that is, if the hardware duration is greater than or equal to 0 (indicating that the audio encoding time is longer than the video encoding time), the decoded audio data is written into the decoded video data to form an audio and video recording file. Specifically, the audio data is written into the video data according to the absolute time, and for each audio data stream written into the audio data, the absolute time of the video data is calculated based on the cumulative value of the audio sampling frequency and the audio data length. Specifically, the absolute time T can be calculated according to formula ①. The absolute time T represents the cumulative playback time of the video data from the start of playback to the current written audio data. Among them, the calculation formula of formula ① is as follows:
[0040]
[0041] Wherein, AudioNum represents the number of audio data blocks, AudioLen represents the total length of the decoded audio data in frames, and R represents the audio sampling rate.
[0042] If t svc <0, no processing is performed, that is, there is no need to discard the current video frame to the current video data, nor is there any need to add a video frame to the current video data frame.
[0043] Step 4: Take the number of frames of video data written for the first time within the absolute time as the standard data value. If within the absolute time, the currently written video data is less than the standard data value, then add a frame of video after the last frame of the current video data. The added video frame is a copy of the current last frame of video. If within the absolute time, the currently written video data is greater than the standard data value, then discard the last frame of video from the video data; if within the absolute time, the currently written video data is the same as the standard data value, there is no need to discard or add video frames to the video data.
[0044] The present invention is described with reference to flowcharts and / or block diagrams of methods, devices (systems), and computer program products according to embodiments of the present invention. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0045] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0046] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0047] Although the preferred embodiments of the present invention have been described, those skilled in the art may make additional changes and modifications to these embodiments once they have learned the basic creative concept. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments and all changes and modifications that fall within the scope of the present invention.
[0048] Obviously, those skilled in the art can make various changes and modifications to the present invention without departing from the spirit and scope of the present invention. Thus, if these modifications and variations of the present invention fall within the scope of the claims of the present invention and their equivalents, the present invention is also intended to include these modifications and variations.
Claims
1. A method for synchronously recording audio and video based on a recording terminal, characterized in that: The following steps are involved: Step 1: Initialize the recording terminal, which includes an audio and video acquisition module, an audio and video encoding module, and an audio and video decoding module; Step 2: Pre-establish the first thread, the second thread, the third thread and the fourth thread in the recording terminal. On the first thread, write the audio data collected by the audio and video acquisition module into the first linked list. On the second thread, write the video data collected by the audio and video module into the second linked list. On the third thread, the audio data in the first linked list is read, and the audio data is encoded to obtain the successful encoding time t of the audio data. sc , The encoded audio data is processed by the service, and the audio decoding module decodes the audio data after the service processing and obtains the successful decoding time p of the audio data sc , On the fourth thread, the video data in the second linked list is read, and the read video data is encoded to obtain the successful encoding time t of the video data. vc , The encoded video data is processed by the service, and the video decoding module decodes the video data after the service processing and obtains the successful decoding time p of the video data vc ; Step 3: Calculate the first successful encoding time t sc and the first successful encoding time t vc The time difference t svc , that is, t svc =t vc -t sc , If svc ≥0, the decoded audio data is written into the decoded video data to form an audio and video recording file. If svc <0, then end the processing.
2. The method for synchronously recording audio and video based on a recording terminal according to claim 1, characterized in that: In step 3, if t svc ≥0, the decoded audio data is written into the decoded video data to form an audio and video recording file. The specific implementation process includes the following steps: According to formula ①, the absolute time T is calculated. The absolute time T represents the cumulative playback time from the start of video data playback to the current writing of audio data: In the formula, AudioNum represents the number of audio data blocks, AudioLen represents the total length of the decoded audio data in frames, and R represents the audio sampling rate. The number of frames of video data written for the first time in absolute time is used as the standard data value. If the current video data written in absolute time is less than the standard data value, a frame of video is added after the last frame of the current video data. The added video frame is a copy of the current last frame of video. If the currently written video data is greater than the standard data value within the absolute time, the last video frame is discarded from the video data. If the currently written video data is the same as the standard data value within the absolute time, there is no need to discard or supplement the video frame to the video data.
3. The method for synchronously recording audio and video based on a recording terminal according to claim 1, characterized in that: The audio acquisition and video acquisition are integrated modules or separate modules.
4. The method for synchronously recording audio and video based on a recording terminal according to claim 1 or 3, characterized in that: The audio and video encoding module and the audio and video decoding module are integrated modules integrated together, or are separate modules.
5. The method for synchronously recording audio and video based on a recording terminal according to claim 1, characterized in that: In step 2, the first thread and the second thread are performed simultaneously.
6. The method for synchronously recording audio and video based on a recording terminal according to claim 1 or 5, characterized in that: In step 2, the first thread and the third thread are performed synchronously, and the second thread and the fourth thread are performed synchronously.
