A video encoding and decoding method, system, device and storage medium
By combining the first and second encoding algorithms and using a timestamp switching mechanism based on keyframe markers, the problem of balancing image quality and bandwidth requirements in video encoding and decoding technology is solved, achieving high-quality image transmission and smoothness under low bandwidth conditions.
Patent Information
- Application Number
- CN202111597414.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-24
- Publication Date
- 2024-11-05
- Estimated Expiration
- 2041-12-24
AI Technical Summary
Existing video encoding and decoding technologies struggle to balance image quality and bandwidth requirements, especially in scenarios involving text display where image quality is poor and bandwidth requirements are high.
The first encoding algorithm is used for continuous frame compression, and the second encoding algorithm is used for non-continuous frame compression based on key frame markers. The display is automatically switched through a unified reference timestamp, which combines the advantages of different encoding methods and adapts to the dynamic and static characteristics of video data.
Achieving high-quality image transmission in low-bandwidth environments, balancing image quality and video smoothness, and optimizing the user viewing experience.
Smart Images

Figure CN114286098B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of video data communication technology, and more specifically, to a video encoding and decoding method, system, device and storage medium. Background Art
[0002] Video encoding and decoding processing is widely used, and there are two main solutions: one is called deep compression, which uses the H264 / H265 encoding format to compress video images. Its advantages are high compression ratio and low bandwidth occupation, and its disadvantage is poor image quality, especially in the scene of displaying text; the other is called shallow compression, which generally uses JPEG2000, VC-2, SDVoE and other encoding technologies to compress video images. Its advantage is good image quality, but its disadvantage is high bandwidth requirements, and some even require 10 Gigabit switches. Summary of the invention
[0003] The present invention aims to overcome at least one defect (shortcoming) of the above-mentioned prior art and provide a video encoding and decoding method, system, device and storage medium for integrating the advantages of different encoding methods and optimizing video data transmission.
[0004] In a first aspect, the present invention provides a video encoding method, comprising:
[0005] Encoding the image frames of the video data according to a first encoding algorithm to form a first code stream;
[0006] The initial value of the preset key frame flag is valid;
[0007] Determine whether the current key frame flag is valid;
[0008] If yes, encode the current image frame of the video data according to the second encoding algorithm, determine the next image frame of the current image frame as a new current image frame, and set the current key frame flag to invalid;
[0009] If not, then calculating the difference between the current image frame of the video data and the image frame before the current image frame, encoding the difference according to the second encoding algorithm, and determining the first image frame or the xth image frame after the current image frame as the new current image frame according to the data amount of the encoded difference, where x is an integer greater than 1, and when determining that the new current image frame is the xth image frame after the current image frame, setting the current key frame flag to be valid;
[0010] Continue to determine whether the current key frame flag is valid to form a second code stream;
[0011] The data frames of the first code stream and the data frames of the second code stream use the same reference timestamp.
[0012] In a second aspect, the present invention provides a video decoding method, comprising:
[0013] Obtain the first code stream and the second code stream as described in the first aspect;
[0014] Decoding the first code stream to obtain a first image frame, and placing the first image frame into a first image frame queue;
[0015] Decoding the second code stream to obtain a second image frame, and placing the second image frame into a second image frame queue;
[0016] Acquire the first image frame frame by frame from the first image frame queue according to the timestamp of the first image frame;
[0017] Acquire the second image frames frame by frame from the second image frame queue according to the timestamp of the second image frame;
[0018] If the first image frame and the second image frame are acquired at the same time at the same timestamp, the second image frame is displayed; otherwise, the first image frame is displayed.
[0019] In a third aspect, the present invention provides a video encoding system, comprising:
[0020] A video encoding module, used for encoding image frames of video data according to a first encoding algorithm to form a first code stream;
[0021] A flag preset module is used to preset the initial value of the key frame flag to be valid;
[0022] The image encoding module is used to determine whether the current key frame flag is valid; if so, encode the current image frame of the video data according to the second encoding algorithm, and determine that the next image frame of the current image frame is a new current image frame; if not, calculate the difference between the current image frame of the video data and the previous image frame of the current image frame, encode the difference according to the second encoding algorithm, and determine that the first image frame or the xth image frame after the current image frame is the new current image frame according to the data amount of the encoded difference, where x is an integer greater than 1, and when it is determined that the new current image frame is the xth image frame after the current image frame, set the current key frame flag to be valid; continue to determine whether the current key frame flag is valid to form a second code stream;
[0023] The data frames of the first code stream and the data frames of the second code stream use the same reference timestamp.
[0024] In a fourth aspect, the present invention provides a video decoding system, comprising:
[0025] A code stream acquisition module, used to acquire the first code stream and the second code stream as described in the third aspect;
[0026] A first decoding module, used for decoding the first code stream to obtain a first image frame, and putting the first image frame into a first image frame queue;
[0027] A second decoding module, used for decoding the second code stream to obtain a second image frame, and putting the second image frame into a second image frame queue;
[0028] An image display module is used to obtain the first image frame frame by frame from the first image frame queue according to the timestamp of the first image frame; and to obtain the second image frame frame by frame from the second image frame queue according to the timestamp of the second image frame; if the first image frame and the second image frame are obtained at the same time at the same timestamp, the second image frame is displayed, otherwise the first image frame is displayed.
[0029] In a fifth aspect, the present invention provides an electronic device, comprising a memory and a processor, wherein the memory stores a computer program, and when the processor executes the computer program, the video encoding method as described in the first aspect or the video decoding method as described in the second aspect is implemented.
[0030] In a sixth aspect, the present invention provides a computer-readable storage medium having a computer program stored thereon, wherein when the computer program is executed by a processor, the video encoding method as described in the first aspect or the video decoding method as described in the second aspect is implemented.
[0031] Compared with the prior art, the beneficial effects of the present invention are as follows: the present invention adopts a first encoding algorithm to perform continuous frame compression to form a first code stream, and adopts a second encoding algorithm to perform non-continuous frame compression based on a key frame mark. When the first code stream and the second code stream use a unified reference timestamp, they can automatically switch to each other for display according to the timestamp according to the dynamic and static characteristics of the video data. When the video data is biased towards static pictures, a higher image quality is guaranteed, and when the video data is biased towards dynamic pictures, a higher quality compression effect is achieved, and video data can be transmitted under low bandwidth while taking into account image quality, image delay and video smoothness, and high-quality picture transmission can be achieved under a bandwidth environment almost equivalent to shallow compression. BRIEF DESCRIPTION OF THE DRAWINGS
[0032] Figure 1 This is a first flow chart of a video encoding method according to an embodiment of the present invention.
[0033] Figure 2 This is a second flow chart of the video encoding method according to an embodiment of the present invention.
[0034] Figure 3The flowchart of the video decoding method according to the embodiment of the present invention is shown in FIG.
[0035] Figure 4 FIG. 4 is a composition diagram of a video encoding system according to an embodiment of the present invention.
[0036] Figure 5 FIG. 4 is a composition diagram of a video decoding system according to an embodiment of the present invention.
[0037] Figure 6 FIG. 1 is a diagram showing the composition of an electronic device according to an embodiment of the present invention. DETAILED DESCRIPTION
[0038] The drawings of the present invention are only for illustrative purposes and should not be construed as limiting the present invention. In order to better illustrate the following embodiments, some parts of the drawings may be omitted, enlarged or reduced, and do not represent the size of the actual product; it is understandable to those skilled in the art that some well-known structures and their descriptions in the drawings may be omitted.
[0039] The present embodiment provides a video encoding method, which can be applied to an encoding end, and the encoding end is responsible for collecting image data and compressing it into a specified format code stream. Specifically, the video encoding method provided in the present embodiment is used to encode image frames in video data, and the encoded video data can achieve data compression, so that the bandwidth occupied by transmitting the video data is smaller.
[0040] The video encoding method provided in this embodiment adopts two encoding modes simultaneously, the first encoding mode is continuous inter-frame compression, and the second encoding mode is discontinuous inter-frame compression. This embodiment realizes the integration of the first encoding mode and the second encoding mode, which can not only meet the compression requirements and reduce the bandwidth requirements for transmitting video data, but also ensure the image quality to a certain extent and optimize the user's experience of watching videos.
[0041] Figure 1 This is the first flow chart of the video encoding method provided in this embodiment. Figure 1 As shown, the video encoding method includes:
[0042] The first encoding method is used to encode to form a first code stream, which specifically includes the following steps:
[0043] S101. Encode image frames of video data according to a first encoding algorithm to form a first code stream.
[0044] The first code stream is a data stream formed by encoding the video data in a first encoding method. The first code stream includes a plurality of data frames, and the video data includes a plurality of image frames. The image frames in the video data are encoded into data frames in the first code stream. The first code stream can be transmitted to a decoding end, and the decoding end is decoded to restore the data frames in the first code stream into image frames of the video data, thereby realizing the transmission of the video data. In the specific implementation process, the first encoding algorithm can be an H264 encoding algorithm or an H265 encoding algorithm.
[0045] The second encoding method is used to encode to form a second code stream, which specifically includes the following steps:
[0046] S102. The initial value of the preset key frame flag is valid.
[0047] When the key frame flag of an image frame is valid, it indicates that the image frame can be encoded (intra-frame compression) only for the data of this image frame during encoding, and does not need to refer to the data of other image frames during decoding, and only the data of this image frame is needed to complete the decoding.
[0048] When the key frame flag of an image frame is invalid, it indicates that the image frame needs to refer to the data of other image frames during encoding to complete the encoding of the image frame (inter-frame compression), and also needs to refer to the data of other image frames during decoding to complete the decoding of the image frame.
[0049] The initial value of the key frame flag is preset to be valid so that subsequent encoding can be started.
[0050] S103. Determine whether the current key frame flag is valid, if so, execute S104, if not, execute S105 and S106 to form a second code stream.
[0051] When it is determined that the current key frame flag is valid, step S104 is executed to directly perform intra-frame compression on the current image frame according to the second encoding algorithm without referring to data of other image frames, and to encode the current image frame according to the second encoding algorithm.
[0052] When it is determined that the current key frame flag is invalid, step S105 is executed to perform inter-frame compression on the current image frame with reference to the data of the previous image frame of the current image frame, and encode the difference between the current image frame and the previous image frame according to the second encoding algorithm.
[0053] The second code stream is a data stream formed by encoding the video data according to the second encoding method. Similar to the first code stream, the second code stream includes a plurality of data frames. Some image frames in the video data are encoded into data frames in the first code stream. The second code stream can be transmitted to the decoding end, and decoded by the decoding end to restore the data frames in the second code stream into image frames of the video data, thereby realizing the transmission of the video data.
[0054] During specific implementation, the second encoding algorithm may be one of a run-length encoding algorithm, a JPEG encoding algorithm, a VC-2 encoding algorithm, and an SDVoE encoding algorithm.
[0055] S104. Encode the current image frame of the video data according to the second encoding algorithm, determine the next image frame of the current image frame as a new current image frame, set the current key frame flag to invalid, and return to execute S103.
[0056] In step S104, when it is determined that the new current image frame is the next image frame of the current image frame, the current key frame flag is set to invalid, so that the next image frame of the image frame that has implemented intra-frame compression will implement inter-frame compression, thereby switching from intra-frame compression to inter-frame compression.
[0057] S105. Calculate the difference between the current image frame of the video data and the image frame before the current image frame, encode the difference according to the second encoding algorithm, and determine the first image frame or the xth image frame after the current image frame as the new current image frame according to the data amount of the encoded difference, where x is an integer greater than 1;
[0058] In step S105, the new current image frame can be determined based on the amount of data of the encoded difference. When the amount of data of the encoded difference is small, the first image frame after the current image frame can be determined as the new current image frame; when the amount of data of the encoded difference is large, the xth image frame after the current image frame can be determined as the new current image frame, which is equivalent to skipping x-1 frames of image frames and pausing the encoding of the second encoding method for a period of time. Image frames that are not encoded using the second encoding method will be encoded and transmitted using the first encoding method. In this way, adding a mechanism for pausing encoding using the second encoding method can take into account the compression effect and image quality required for both static and dynamic scenes in video data.
[0059] It can be understood that the premise for calculating the difference between the current image frame of the video data and the image frame before the current image frame is that there is an image frame before the current image frame.
[0060] It can be understood that the premise for determining the first image frame after the current image frame as the new current image frame is that there is still one image frame after the current image frame; the premise for determining the xth image frame after the current image frame as the new current image frame is that there are still x image frames after the current image frame.
[0061] x can take values according to actual conditions. During the entire encoding process, x can remain unchanged or change according to certain rules.
[0062] S106. Determine whether the new current image frame is the xth image frame after the current image frame. If so, execute S107; otherwise, return to execute S103.
[0063] S107. Set the current key frame flag to be valid, and return to execute S103.
[0064] When it is determined that the new current image frame is the x-th image frame after the current image frame, the current key frame flag is set to be valid, so that after skipping the x-1 frame image frame and not encoding it, the x-th image frame will be intra-frame compressed, thereby switching from inter-frame compression to intra-frame compression.
[0065] After encoding, the data frames of the first code stream and the data frames of the second code stream need to be timestamped, and the data frames of the first code stream and the data frames of the second code stream use the same reference timestamp. During the decoding process, if the timestamp of the data frame of the second code stream is consistent with the timestamp of the data frame of the first code stream, the data frame of the second code stream is displayed, otherwise the data frame of the first code stream is displayed.
[0066] This embodiment supports the use of a first encoding method of continuous frame compression to achieve better compression effects when the video data tends to be dynamic images, and a second encoding method of non-continuous frame compression to ensure higher image quality when the video data tends to be static images. The first bit stream formed by the first encoding method and the second bit stream formed by the second encoding method can be automatically switched to each other according to the timestamp based on the dynamic and static characteristics of the video data for display, thereby achieving transmission of video data under low bandwidth while taking into account image quality, image delay and video smoothness, and achieving transmission of high-quality images under a bandwidth environment almost equivalent to shallow compression.
[0067] Figure 2The second flow chart of the video encoding method provided in this embodiment is based on the first flow chart of the video encoding method, and further refines how to determine the new current image frame after encoding the difference according to the second encoding algorithm, that is, how to determine the new current image frame according to the data amount of the encoded difference in step S105. In step S105, determining the first image frame or the xth image frame after the current image frame as the new current image frame according to the data amount of the encoded difference may include: determining the first image frame or the xth image frame after the current image frame as the new current image frame according to the data amount of the difference after several consecutive encodings. More specifically, Figure 2 As shown, according to the data amount of the difference after several consecutive encodings, determining the first image frame or the xth image frame after the current image frame as the new current image frame may include:
[0068] S151. Determine whether the amount of data of the encoded difference is greater than a preset threshold, if so, execute S152, if not, execute S155.
[0069] When the amount of data of the encoded difference is greater than the preset threshold, it indicates that the current compression effect is not good enough, so step S152 can be executed to count the cumulative consecutive times that the amount of data of the encoded difference is greater than the preset threshold; when the amount of data of the encoded difference is not greater than the preset threshold, it indicates that the current compression effect is relatively good, so step S115 can be executed to continue encoding.
[0070] S152. Add 1 to the cumulative consecutive number and determine whether the cumulative consecutive number exceeds the preset number. If so, execute S153; otherwise, execute S154.
[0071] The cumulative continuous number is the number of consecutive times that the amount of data of the encoded difference is greater than the preset threshold. Therefore, when it is determined that the amount of data of the encoded difference is greater than the preset threshold, the cumulative continuous number is increased by 1. By judging whether the cumulative continuous number exceeds the preset number, it is determined whether to suspend encoding for a period of time. The preset number can be set according to the requirements for video data compression or the bandwidth requirements for transmitting video data.
[0072] S153. Determine the xth image frame after the current image frame as a new current image frame, and reset the accumulated consecutive times to an initial value.
[0073] When it is determined that the cumulative continuous times exceed the preset times, it indicates that the image being encoded is relatively dynamic, and the x-1 image frames are skipped and not encoded, and the xth frame after the current image frame is used as the new current image frame. The cumulative continuous times are reset to the initial value, and after the x-1 image frames are skipped and not encoded, the cumulative continuous times when the amount of data of the difference after encoding is greater than the preset threshold can be recalculated.
[0074] S154. Determine the first image frame after the current image frame as a new current image frame;
[0075] When it is determined that the accumulated consecutive times do not exceed the preset times, there is no need to skip the image frame, and the new current image frame is determined to be the first image frame after the current image frame.
[0076] S155. Determine the first image frame after the current image frame as a new current image frame, and reset the accumulated number of consecutive times to an initial value.
[0077] When it is determined that the data amount of the encoded difference is not greater than the preset threshold, there is no need to skip the image frame. The new current image frame is determined to be the first image frame after the current image frame, and the cumulative consecutive times are reset to the initial value. The cumulative consecutive times that the data amount of the encoded difference is greater than the preset threshold can be recalculated.
[0078] Through steps S151 to S155, when the amount of difference data after encoding for a preset number of consecutive times is greater than a preset threshold, the encoding of the second encoding method is suspended for a period of time, and x-1 frames of image frames are skipped and not encoded by the second encoding method. The image frames that are not encoded by the second encoding method will be encoded and transmitted in the first encoding method. In this way, a mechanism for suspending encoding by the second encoding method is added, which can take into account the compression effect and image quality required for both static and dynamic images in the video data.
[0079] This embodiment also provides a video decoding method, which can be applied to a decoding end, which is responsible for decoding compressed data and displaying it according to specified rules. Specifically, the video decoding method provided by this embodiment is used to decode video data encoded using the video encoding method provided by this embodiment. Figure 3 This is a flow chart of the video decoding method provided in this embodiment. Figure 3 As shown, the video decoding method includes:
[0080] S201. Obtain a first code stream formed by the video encoding method provided by this embodiment, decode the first code stream to obtain a first image frame, and put the first image frame into a first image frame queue.
[0081] S202. Obtain a second code stream formed by the video encoding method provided in this embodiment, decode the second code stream to obtain a second image frame, and put the second image frame into a second image frame queue.
[0082] Specifically, through communication with the encoding end, a first code stream and a second code stream are obtained from the encoding end, and the first code stream and the second code stream respectively include a plurality of data frames. The first code stream and the second code stream are decoded, and the data frames in the first code stream and the second code stream are decoded into a first image frame and a second image frame respectively, and are put into a first image frame queue and a second image frame queue respectively.
[0083] It is understandable that the timestamps of the data frames in the first bitstream and the second bitstream are still retained after decoding, becoming the timestamps of the first image frame and the second image frame. After the first image frame queue and the second image frame queue are put into place, the following steps can be followed to fetch frames for display:
[0084] S203. Acquire the first image frame frame by frame from the first image frame queue according to the timestamp of the first image frame.
[0085] S204. Acquire the second image frames frame by frame from the second image frame queue according to the timestamp of the second image frame.
[0086] S205. Determine whether the first image frame and the second image frame are acquired at the same time at the same timestamp. If so, execute S206; otherwise, execute S207.
[0087] S206. Send the second image frame for display.
[0088] S207. Send the first image frame for display.
[0089] According to the system time, frames are extracted from the first image frame queue and the second image frame queue according to the timestamp. If the timestamp of the second image frame is consistent with the timestamp of the first image frame, the second image frame is displayed so that the video data segment of the static image can be clearer. Otherwise, the first image frame is displayed so that the video data segment of the dynamic image can be smoother. Therefore, this embodiment can automatically switch the first image frame and the second image frame according to the timestamp according to the dynamic and static characteristics of the video data for transmission and display, so as to realize the transmission of video data under low bandwidth while taking into account image quality, image delay and video smoothness, and can realize the transmission of high-quality images under a bandwidth environment almost equivalent to shallow compression.
[0090] This embodiment also provides a video encoding system. Figure 4 The video encoding system provided in this embodiment is as follows: Figure 4 As shown, the video encoding system includes:
[0091] The video encoding module 301 is used to encode the image frames of the video data according to the first encoding algorithm to form a first code stream;
[0092] A flag preset module 302, used to preset an initial value of a key frame flag as valid;
[0093] The image encoding module 303 is used to determine whether the current key frame flag is valid; if so, encode the current image frame of the video data according to the second encoding algorithm, and determine that the next image frame of the current image frame is a new current image frame; if not, calculate the difference between the current image frame of the video data and the previous image frame of the current image frame, encode the difference according to the second encoding algorithm, and determine that the first image frame or the xth image frame after the current image frame is the new current image frame according to the data amount of the encoded difference, where x is an integer greater than 1, and when it is determined that the new current image frame is the xth image frame after the current image frame, set the current key frame flag to be valid; continue to determine whether the current key frame flag is valid to form a second code stream;
[0094] The data frames of the first code stream and the data frames of the second code stream use the same reference timestamp.
[0095] In some optional implementations, the image encoding module 303 is used to determine a new current frame according to the amount of data of the encoded difference, specifically including:
[0096] The image encoding module 303 is used to determine the first image frame or the xth image frame after the current image frame as a new current image frame according to the data amount of the difference after several consecutive encodings.
[0097] In some optional implementations, the image encoding module 303 is used to determine, according to the data amount of the difference after several consecutive encodings, the first image frame or the xth image frame after the current image frame as the new current image frame, specifically including:
[0098] The image encoding module 303 is used to determine whether the data amount of the encoded difference is greater than a preset threshold; when the data amount of the encoded difference is greater than the preset threshold, the cumulative consecutive number is increased by 1, and it is determined whether the cumulative consecutive number exceeds the preset number; if so, the x-th image frame after the current image frame is determined to be the new current image frame, and the cumulative consecutive number is reset to the initial value; if not, the first frame after the current image frame is determined to be the new current image frame; when the data amount of the encoded difference is not greater than the preset threshold, the first frame after the current frame is determined to be the new current image frame, and the cumulative consecutive number is reset to the initial value.
[0099] In the image encoding module 303, the first encoding algorithm may be an H264 encoding algorithm or an H265 encoding algorithm, and the second encoding algorithm may be one of a run-length encoding algorithm, a JPEG encoding algorithm, a VC-2 encoding algorithm, and an SDVoE encoding algorithm.
[0100] The implementation principle and technical effect of the video encoding system provided in this embodiment are similar to those of the video encoding method provided in this embodiment, and will not be described in detail here.
[0101] This embodiment also provides a video decoding system. Figure 5 The video decoding system provided in this embodiment is shown in FIG. Figure 5 As shown, the video decoding system includes:
[0102] The bitstream acquisition module 401 is used to acquire the first bitstream and the second bitstream generated by the video encoding system provided by this embodiment;
[0103] A first decoding module 402 is used to decode the first code stream to obtain a first image frame, and put the first image frame into a first image frame queue;
[0104] A second decoding module 403 is used to decode the second code stream to obtain a second image frame, and put the second image frame into a second image frame queue;
[0105] The image display module 404 is used to obtain the first image frame frame by frame from the first image frame queue according to the timestamp of the first image frame; and to obtain the second image frame frame by frame from the second image frame queue according to the timestamp of the second image frame; if the first image frame and the second image frame are obtained at the same time at the same timestamp, the second image frame is displayed, otherwise the first image frame is displayed.
[0106] The implementation principle and technical effect of the video decoding system provided in this embodiment are similar to those of the video decoding method provided in this embodiment, and will not be described in detail here.
[0107] This embodiment also provides an electronic device, which can be structured as follows: Figure 6 As shown, the system includes a processor 501 and a memory. The memory may include a non-volatile storage medium 520 and an internal memory 530. The non-volatile storage medium 520 stores a computer program 521. The internal memory 530 provides an environment for the operation of the computer program 521 in the non-volatile storage medium 520.
[0108] The processor 501 is used to provide computing and control capabilities, and the computer program 521 can implement the video encoding method and / or video decoding method provided in this embodiment when executed by the processor 501. The processor 501 can communicate with the external device 550 through the communication interface 540.
[0109] In some optional implementations, the external device 550 may include a display, which may be a liquid crystal display or an electronic ink display, etc. The processor 501 is connected to the display via the communication interface 540. When implementing the video decoding method provided in this embodiment, the processor 501 sends the first image frame or the second image frame to the display via the communication interface 540 for display.
[0110] In some optional implementations, the external device 550 may include a computer. When implementing the video encoding method provided in this embodiment, the computer sends the video data to be encoded to the processor 501 through the communication interface 540. If the computer is equipped with a display, when implementing the video decoding method provided in this embodiment, the processor 501 may also send the first image frame or the second image frame to the computer through the communication interface 540, so that the first image frame or the second image frame is displayed on the display configured by the computer.
[0111] The implementation principle and technical effect of the electronic device provided in this embodiment are similar to the video decoding method and video encoding method provided in this embodiment, and will not be repeated here.
[0112] This embodiment further provides a computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processor, the video encoding method and / or video decoding method provided in this embodiment is implemented.
[0113] The implementation principle and technical effect of the computer-readable storage medium provided in this embodiment are similar to those of the video decoding method and the video encoding method provided in this embodiment, and will not be described in detail here.
[0114] Obviously, the above embodiments of the present invention are merely examples for clearly illustrating the technical solution of the present invention, and are not intended to limit the specific implementation methods of the present invention. Any modifications, equivalent substitutions and improvements made within the spirit and principles of the claims of the present invention shall be included in the protection scope of the claims of the present invention.
Claims
1. A video encoding method, characterized in that: include: Encoding the image frames of the video data according to a first encoding algorithm to form a first code stream; The initial value of the preset key frame flag is valid; Determine whether the current key frame flag is valid; If yes, encode the current image frame of the video data according to the second encoding algorithm, determine the next image frame of the current image frame as a new current image frame, and set the current key frame flag to invalid; If not, then calculating the difference between the current image frame of the video data and the image frame before the current image frame, encoding the difference according to the second encoding algorithm, and determining the first image frame or the xth image frame after the current image frame as the new current image frame according to the data amount of the encoded difference, where x is an integer greater than 1, and when determining that the new current image frame is the xth image frame after the current image frame, setting the current key frame flag to be valid; Continue to determine whether the current key frame flag is valid to form a second code stream; The data frames of the first code stream and the data frames of the second code stream use the same reference timestamp; The step of determining, according to the amount of data of the encoded difference, the first image frame or the xth image frame after the current image frame as a new current image frame comprises: According to the data amount of the difference after several consecutive encodings, determining the first image frame or the xth image frame after the current image frame as a new current image frame; The step of determining the first image frame or the xth image frame after the current image frame as a new current image frame according to the data amount of the difference after several consecutive encodings includes: Determining whether the amount of data of the encoded difference is greater than a preset threshold; When the amount of data of the encoded difference value is greater than a preset threshold, the cumulative consecutive number is increased by 1, and it is determined whether the cumulative consecutive number exceeds a preset number; If yes, determine that the x-th image frame after the current image frame is a new current image frame, and reset the accumulated consecutive times to an initial value; If not, determining the first image frame after the current image frame as a new current image frame; When the data amount of the encoded difference is not greater than a preset threshold, the first image frame after the current image frame is determined to be a new current image frame, and the accumulated number of consecutive times is reset to an initial value.
2. The video encoding method according to claim 1, characterized in that The first encoding algorithm is an H264 encoding algorithm or an H265 encoding algorithm.
3. The video encoding method according to claim 1, characterized in that: The second encoding algorithm is one of a run-length encoding algorithm, a JPEG encoding algorithm, a VC-2 encoding algorithm, and a SDVoE encoding algorithm.
4. A video decoding method, characterized in that: include; Obtain the first code stream and the second code stream as described in any one of claims 1 to 3; Decoding the first code stream to obtain a first image frame, and placing the first image frame into a first image frame queue; Decoding the second code stream to obtain a second image frame, and placing the second image frame into a second image frame queue; Acquire the first image frame frame by frame from the first image frame queue according to the timestamp of the first image frame; Acquire the second image frames frame by frame from the second image frame queue according to the timestamp of the second image frame; If the first image frame and the second image frame are acquired at the same time at the same timestamp, the second image frame is displayed; otherwise, the first image frame is displayed.
5. A video encoding system, characterized in that: include: A video encoding module, used for encoding image frames of video data according to a first encoding algorithm to form a first code stream; A flag preset module is used to preset the initial value of the key frame flag to be valid; The image encoding module is used to determine whether the current key frame flag is valid; if so, encode the current image frame of the video data according to the second encoding algorithm, determine the next image frame of the current image frame to be a new current image frame, and set the current key frame flag to be invalid; if not, calculate the difference between the current image frame of the video data and the previous image frame of the current image frame, encode the difference according to the second encoding algorithm, and determine the first image frame or the xth image frame after the current image frame to be the new current image frame according to the data amount of the encoded difference, where x is an integer greater than 1, and when it is determined that the new current image frame is the xth image frame after the current image frame, set the current key frame flag to be valid; continue to determine whether the current key frame flag is valid to form a second code stream; The data frames of the first code stream and the data frames of the second code stream use the same reference timestamp; The step of determining, according to the amount of data of the encoded difference, the first image frame or the xth image frame after the current image frame as the new current image frame comprises: Determining whether the amount of data of the encoded difference is greater than a preset threshold; When the amount of data of the encoded difference value is greater than a preset threshold, the cumulative consecutive number is increased by 1, and it is determined whether the cumulative consecutive number exceeds a preset number; If yes, determine that the x-th image frame after the current image frame is a new current image frame, and reset the accumulated consecutive times to an initial value; If not, determining the first image frame after the current image frame as a new current image frame; When the data amount of the encoded difference is not greater than a preset threshold, the first image frame after the current image frame is determined to be a new current image frame, and the accumulated number of consecutive times is reset to an initial value.
6. The video encoding system according to claim 5, characterized in that The first encoding algorithm is an H264 encoding algorithm or an H265 encoding algorithm.
7. The video encoding system according to claim 5, characterized in that The second encoding algorithm is one of a run-length encoding algorithm, a JPEG encoding algorithm, a VC-2 encoding algorithm, and a SDVoE encoding algorithm.
8. A video decoding system, characterized in that: include: A code stream acquisition module, used to acquire the first code stream and the second code stream as claimed in claim 5; A first decoding module, used for decoding the first code stream to obtain a first image frame, and putting the first image frame into a first image frame queue; A second decoding module, used for decoding the second code stream to obtain a second image frame, and putting the second image frame into a second image frame queue; An image sending and displaying module, used for acquiring the first image frame frame by frame from the first image frame queue according to the timestamp of the first image frame; Acquire the second image frames frame by frame from the second image frame queue according to the timestamp of the second image frame; If the first image frame and the second image frame are acquired at the same time at the same timestamp, the second image frame is displayed; otherwise, the first image frame is displayed.
9. An electronic device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the video encoding method according to any one of claims 1 to 3 or the video decoding method according to claim 4 is implemented.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the video encoding method according to any one of claims 1 to 3 or the video decoding method according to claim 4 is implemented.
