A coding method, a coding method and a computer readable storage medium

By obtaining the image information of the first frame of the video, calculating its complexity accumulated value and performing encoding and quantization estimates, the problem of unreasonable quantization parameters setting in the prior art is solved, and the video encoding quality is improved.

CN114979640BActive Publication Date: 2025-03-04GUANGDONG OPPO MOBILE TELECOMMUNICATIONS CORP LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202210546977.8
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-07-17
Publication Date
2025-03-04
Estimated Expiration
2040-07-17

AI Technical Summary

Technical Problem

The prior art cannot adaptively adjust the quantization parameters according to the specific video content in video encoding, resulting in unreasonable settings during first frame encoding, resulting in waste of code rates and reducing video quality.

Method used

By obtaining the first frame image information of the video to be encoded, the complexity accumulated value is calculated, and the encoding quantization estimate is performed based on this, the initial quantization step size is obtained, and then encoding is performed.

Benefits of technology

It realizes adaptive setting of quantization parameters according to the complexity of the first frame, avoiding waste of code rates and improving the quality of encoded videos.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114979640B_ABST
    Figure CN114979640B_ABST
Patent Text Reader

Abstract

The embodiment of the present application discloses a coding method, an encoder and a computer-readable storage medium, which can improve the video quality of the encoded video. The method includes: when the current frame is the first frame in the video to be encoded, in the inter-frame level bit rate control process, obtaining the image information of the current frame; based on the image information of the current frame, calculating the complexity accumulation value of the current frame; based on the complexity accumulation value of the current frame, performing coding quantization estimation on the current frame to obtain the initial quantization step of the current frame; based on the initial quantization step of the current frame, encoding the current frame to obtain the encoding result of the current frame.
Need to check novelty before this filing date? Find Prior Art

Description

[0001] This application is based on the Chinese patent application with application number 202010693484.8, application date July 17, 2020, and application name “A Coding Method, Encoder and Computer-readable Storage Medium”, and a divisional case is proposed within the scope recorded in the Chinese patent application. The entire content of the Chinese patent application is hereby introduced into the present application as a reference. Technical Field

[0002] The present application relates to the field of audio and video coding, and in particular to a coding method, an encoder, and a computer-readable storage medium. Background Art

[0003] Video coding is a video compression technology that uses the temporal redundancy and spatial redundancy of video information to compress video, which can achieve the purpose of reducing the storage space and network bandwidth occupied by the video. Bit rate control is a key technology in video coding, and its purpose is to optimize the objective quality of the video while ensuring that the number of bits occupied by the video after compression is certain. The quantization parameter (QP) is a key parameter in video coding technology, which directly determines the compression degree of the video coding unit, thereby controlling the bit rate and video quality after video encoding. In the prior art, the initial value setting of the compression coefficient related to the quantization parameter is usually set manually, and it is impossible to provide information feedback according to the specific video content to achieve adaptive adjustment, which easily causes the QP set when encoding the first frame to be unreasonable, resulting in a waste of bit rate of the instantaneous decoding refresh (IDR) frame, thereby reducing the video quality. Summary of the invention

[0004] The embodiments of the present application are intended to provide a coding method, an encoder, and a computer-readable storage medium, which can improve the video quality of the encoded video.

[0005] The technical solution of this application is implemented as follows:

[0006] In a first aspect, an embodiment of the present application provides an encoding method, which is applied to an encoder, including:

[0007] When the current frame is the first frame in the video to be encoded, in the inter-frame level bit rate control process, image information of the current frame is obtained;

[0008] Calculating the complexity accumulation value of the current frame based on the image information of the current frame;

[0009] Based on the complexity accumulation value of the current frame, perform coding quantization estimation on the current frame to obtain an initial quantization step size of the current frame;

[0010] Based on the initial quantization step size of the current frame, the current frame is encoded to obtain an encoding result of the current frame.

[0011] In a second aspect, an embodiment of the present application provides an encoder, comprising: an acquisition unit, a calculation unit, a quantization unit and an encoding unit, wherein:

[0012] The acquisition unit is used to acquire image information of the current frame during the inter-frame level bit rate control process when the current frame is the first frame in the video to be encoded;

[0013] The calculation unit is used to calculate the complexity accumulation value of the current frame based on the image information of the current frame;

[0014] The quantization unit is used to perform coding quantization estimation on the current frame based on the complexity accumulation value of the current frame to obtain an initial quantization step size of the current frame;

[0015] The encoding unit is used to encode the current frame based on the initial quantization step size of the current frame to obtain an encoding result of the current frame.

[0016] In a third aspect, an embodiment of the present application provides an encoder, including:

[0017] A memory for storing executable data instructions;

[0018] The processor is used to implement any one of the encoding methods described above when executing the executable instructions stored in the memory.

[0019] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium storing executable instructions for causing a processor to execute and implement any of the encoding methods described above.

[0020] The embodiment of the present application provides a coding method, an encoder and a computer-readable storage medium, the method comprising: when the current frame is the first frame in the video to be encoded, in the process of inter-frame rate control, obtaining the image information of the current frame; based on the image information of the current frame, calculating the complexity accumulation value of the current frame; based on the complexity accumulation value of the current frame, performing coding quantization estimation on the current frame to obtain the initial quantization step of the current frame; based on the initial quantization step of the current frame, encoding the current frame to obtain the coding result of the current frame. Through the method in the embodiment of the present application, the complexity of the first frame can be estimated through the image information of the first frame, and the QP value can be reasonably set based on the complexity of the first frame in the actual video, so that the video encoding based on the reasonable QP value can obtain a more accurate coding result, and finally improve the video quality of the encoded video. BRIEF DESCRIPTION OF THE DRAWINGS

[0021] Figure 1 It is the encoding flow chart of the current X.264 encoding system;

[0022] Figure 2 A coding method provided in the embodiment of the present application Figure 1 ;

[0023] Figure 3 A coding process provided for the embodiment of the present application Figure 1 ;

[0024] Figure 4 A coding process provided for the embodiment of the present application Figure 2 ;

[0025] Figure 5 An implementation method of the macroblock level rate control process provided in the embodiment of the present application;

[0026] Figure 6 Another implementation method of the macroblock level rate control process provided in the embodiment of the present application;

[0027] Figure 7 A coding method provided in the embodiment of the present application Figure 2 ;

[0028] Figure 8 A coding method provided in the embodiment of the present application Figure 3 ;

[0029] Fig. 9 A coding method provided in the embodiment of the present application Figure 4 ;

[0030] Fig.10 A coding method provided in the embodiment of the present application Figure 5 ;

[0031] Fig.11 A schematic diagram of the structure of an encoder provided in an embodiment of the present application Figure 1

[0032] Fig.12 A schematic diagram of the structure of an encoder provided in an embodiment of the present application Figure 2 . DETAILED DESCRIPTION

[0033] The technical solutions in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application.

[0034] Before further describing the embodiments of the present application in detail, the nouns and terms involved in the embodiments of the present application are explained. The nouns and terms involved in the embodiments of the present application are subject to the following interpretations.

[0035] 1) H.264: A highly compressed digital video codec standard.

[0036] 2) X.264: Open source H.264 video encoding function library.

[0037] 3) SATD: Sum of Absolute Transformed Difference, the sum of the absolute values ​​of the prediction residuals of the 4×4 blocks after the Hadamard transform of the residual, is a simple time-frequency transform used to reflect the size of the generated bitstream.

[0038] 4) QP: quantization parameter, i.e. quantization step size. The smaller the QP value, the smaller the quantization step size, and the higher the quantization accuracy, which means that the amount of data generated may be larger under the same image quality.

[0039] 5) VBV: Video Buffering Verifier, used to ensure that the output encoded bitstream does not have buffer underflow at the receiving end.

[0040] 6)AQ: Adaptive Quantization, adaptive quantization.

[0041] 7)MB: Macro Block.

[0042] 8) RCEQ: Rate-Control Equation, rate control formula, RCEQ establishes a mapping model from motion complexity to quantization step size.

[0043] 9) PSNR: Peak Signal to Noise Ratio, an objective measurement method used to evaluate image quality.

[0044] H.264 uses the Lagrangian cost function to control encoding, which is one of the main reasons for the high encoding complexity of H.264. X.264, as the application version of H.264, uses SATD of half-precision frames as the main basis for QP selection. The X.264 rate control process is divided into inter-frame rate control process and macroblock level rate control process. The allocation of QP value for each frame is achieved by inter-frame rate control, while the allocation of QP value within each frame is achieved by macroblock level rate control. The X.264 rate control process mainly depends on two variables, one is the complexity of the video frame, and the other is the bit rate budget. Generally, the higher the complexity of the video frame, the more bits are required for encoding. For example Figure 1 As shown, Figure 1It is the encoding flow chart of the current X.264 encoding system. After the video to be encoded enters the encoding system, it will synchronously enter the inter-frame rate control process (i.e., frame-level rate control) and the macroblock-level rate control process. The inter-frame rate control process first provides a video frame buffer queue to the video to be encoded through the look ahead module 100 to assist in completing a more stable rate control, and then estimates the complexity of the current frame in the video to be encoded through the complexity estimation module 101. For example, the complexity of the current frame can be fuzzy complexity; the quantization level calculation module 103 is used to calculate the quantization level according to the complexity of the current frame output by the complexity estimation module 101, first obtain the quantization ratio corresponding to the current frame, and adjust the quantization ratio according to the rate factor (ratefactor) provided by the rate factor calculation module 102 to obtain the initial quantization level. quantization level; the rate factor calculation module 102 is used to calculate the complexity accumulation value of the current frame according to the feedback bit rate of the encoded frame, and then calculate the rate factor (ratefactor) according to the complexity accumulation value and provide it to the quantization level calculation module 103; the initial quantization level output by the quantization level calculation module 103 will be further adjusted by the cache control (VBV) module 104 based on the size of the buffer area at the receiving end to obtain the quantization level, and then the quantization level conversion module 105 will convert the quantization level into an initial quantization step and provide it to the macroblock level quantization step adjustment module 106. At the same time, the macroblock-level rate control process is carried out synchronously with the inter-frame level rate control process, wherein the macroblock calculation module 108 is used to calculate the macroblock structure (MBTree) of the current frame according to the image content of the current frame, and the adaptive quantization module 107 is used to calculate the average macroblock energy of the current frame according to the macroblock structure and image content of the current frame, and determine the preset quantization intensity factor corresponding to the average macroblock energy; the macroblock-level quantization step adjustment 106 is used to adjust the initial quantization step of the current frame according to the preset quantization intensity factor to obtain the quantization step corresponding to the current frame. Finally, the encoding module 109 encodes the current frame according to the quantization step corresponding to the current frame, and the above process is continued until all frames in the video to be encoded are encoded, and the encoded code stream is output.

[0045] from Figure 1It can be seen from the encoding method shown that, currently, in the frame-level bit rate control process, the bit rate factor calculation module 102 needs to calculate the bit rate factor according to the feedback of the encoding result of the previous frame, and then adjust the quantization ratio calculated in the quantization level calculation module 103 to obtain the initial quantization level. However, for the first frame such as the IDR frame, the first frame position where it is located cannot obtain the feedback of the encoding result of the previous frame. Therefore, the current implementation method is to manually set a fixed value as the initial value of the bit rate factor, and then gradually calculate the QP value of the first frame according to the fixed initial value of the bit rate factor. This will cause the QP value setting of the first frame to be unable to be adaptively adjusted according to the complexity, resulting in bit rate waste and reducing the overall video quality. Furthermore, at present, in the macroblock level bit rate control process, the quantization strength factor pre-calculated in the adaptive quantization module 107 is in a fixed state during the entire video encoding process, but the video content in actual encoding is constantly changing. If a larger quantization strength factor is used in a complex area, the quantization step size finally adjusted according to the quantization strength factor will increase significantly. Under the condition of low bit rate, it will cause serious blurring in the complex area, thereby further reducing the overall video quality.

[0046] The embodiment of the present application provides a coding method, which is applied to a coder, such as Figure 2 As shown:

[0047] S101. When the current frame is the first frame in the video to be encoded, in an inter-frame level bit rate control process, image information of the current frame is obtained.

[0048] In the embodiment of the present application, for the first frame in the video to be encoded, the encoder first obtains image information of the first frame.

[0049] In an embodiment of the present application, the image information includes any one of the average macroblock energy of the first frame, the gradient value of the first frame, the edge information of the first frame, and the histogram information of the first frame.

[0050] In some embodiments of the present application, based on Figure 1 In the rate control process shown in FIG. 1 , since the execution process of the macroblock calculation module 108 logically takes precedence over the inter-frame rate control process in the macro-level rate control process, Figure 1 In the process of , without increasing the amount of calculation, the encoder can use the average macroblock energy generated during the execution of the macroblock calculation module 108 as the image information of the current frame, so as to evaluate the complexity accumulation value of the first frame in the video to be encoded by the average macroblock energy, such as Figure 3 shown.

[0051] In the embodiment of the present application, Figure 3The macroblock calculation module 108 will feed back the calculated average macroblock energy to the rate factor calculation module 102 in the inter-frame level rate control process, so that the rate factor calculation module 102 can calculate the rate factor according to the average macroblock energy of the first frame, and then adjust the initial quantization step size corresponding to the first frame according to the rate factor.

[0052] In some other embodiments of the present application, when the image information of the current frame is a gradient value, edge information or histogram information, the encoder may be as follows: Figure 4 As shown, the image processing module 110 calculates the gradient value, edge information or histogram information of the current frame according to the pixel information contained in the current frame, and feeds back the gradient value, edge information or histogram information of the current frame to the rate factor calculation module 102, so that the rate factor calculation module 102 can calculate the rate factor according to the gradient value, edge information or histogram information of the first frame, and then adjust the initial quantization step size corresponding to the first frame according to the rate factor. Exemplarily, the encoder can calculate the grayscale change in the neighborhood of each pixel in the current frame according to the grayscale information in the pixel information, and then calculate the gradient value that can reflect the detail contrast degree and texture change characteristics of the current frame, and use the gradient value as the image information of the current frame; in other embodiments, the encoder can further obtain the edge information of the current frame according to the gradient value, and use the edge information as the image information of the current frame, so as to identify and analyze the content in the current frame according to the edge information; or, the encoder can also calculate the histogram information that can reflect the brightness and darkness of the current frame and the distribution of brightness and color levels according to the grayscale information in the pixel information, and use the histogram information as the image information of the current frame.

[0053] S102: Calculate the complexity accumulation value of the current frame based on the image information of the current frame.

[0054] In an embodiment of the present application, the encoder calculates the complexity accumulation value of the current frame based on the image information of the current frame, so that the bit rate factor can be reasonably initialized according to the complexity accumulation value of the first frame to adjust the quantization ratio of the first frame through the bit rate factor.

[0055] In an embodiment of the present application, for different types of image information, a corresponding objective function model can be established in advance, and the image information of the first frame is used as the input value of the objective function model, and the initial quantization step size is used as the output value of the objective function model, with the output initial quantization step size meeting the goal of low bit rate, high-quality video applications. The advantages and disadvantages of the output value of the initial quantization step size are analyzed through multiple simulation experiments, and the curve of the initial quantization step size and the image information is fitted by function fitting to obtain the functional relationship between the initial quantization step size and the image information corresponding to the optimal value of the initial quantization step size. Then, based on the functional relationship between the initial quantization step size and the image information, as well as the preset functional relationship between the initial quantization step size and the complexity cumulative value, the relationship formula between the image information of the current frame and the complexity cumulative value is derived, and the complexity cumulative value of the current frame is calculated based on the relationship formula.

[0056] It can be seen that since the relationship formula between the image information of the current frame and the complexity accumulation value is obtained by curve fitting the initial quantization step size and the image information through multiple simulation experiments, the complexity accumulation value calculated by the image information of the current frame can better adapt to the actual image content of the current frame, thereby ensuring that the bit rate factor calculated according to the complexity accumulation value and the initial quantization step size adjusted according to the bit rate factor are more accurate.

[0057] S103 . Based on the complexity accumulation value of the current frame, perform coding quantization estimation on the current frame to obtain an initial quantization step size of the current frame.

[0058] In an embodiment of the present application, when the current frame is the first frame, the encoder can calculate the complexity accumulation value of the first frame based on the image information of the first frame.

[0059] In an embodiment of the present application, when the current frame is not the first frame, the encoder may calculate the complexity accumulation value of the non-first frame in combination with the encoding result of the previous frame of the non-first frame.

[0060] In an embodiment of the present application, the encoder can first estimate the complexity of the current frame through the complexity estimation module, and calculate the quantization ratio of the current frame based on the complexity, and then calculate the bit rate factor corresponding to the first frame according to the cumulative value of the complexity of the current frame, and adjust the quantization ratio once according to the bit rate factor to obtain the initial quantization level, and then further adjust the initial quantization level through the cache control module to obtain the quantization level of the current frame, and then convert the quantization level into the initial quantization step according to the preset mapping relationship between the quantization level and the quantization step.

[0061] S104 . Encode the current frame based on the initial quantization step size of the current frame to obtain an encoding result of the current frame.

[0062] In an embodiment of the present application, after the encoder obtains the initial quantization step size, i.e., the QP value, of the current frame, the inter-frame level rate control process corresponding to the current frame is completed. The encoder can continue to adjust the initial quantization step size of the current frame through the macroblock level rate control process to obtain the quantization step size of the current frame.

[0063] In some embodiments of the present application, one implementation of the macroblock level rate control process may be as follows: Figure 5 As shown, in the macroblock-level rate control process 1, the encoder can perform a macroblock energy calculation process, divide the current frame into multiple different macroblocks according to the image content, and calculate the macroblock energy of each macroblock according to the pixel value and the square error sum of the pixels in each macroblock, thereby obtaining the average macroblock energy of the current frame. The average macroblock energy obtained in the macroblock energy calculation process will obtain the preset quantization intensity factor corresponding to the average macroblock energy in the adaptive quantization adjustment process according to the corresponding relationship between the average macroblock energy and the preset quantization intensity factor. Finally, in the quantization step adjustment process, the offset value of the initial quantization step is obtained by the preset quantization intensity factor, and the initial quantization step is adjusted by the offset value of the initial quantization step to obtain the quantization step of the current frame.

[0064] Generally, if the current frame has more dynamic images, the corresponding average macroblock energy is higher, and the encoder can select a lower preset quantization strength factor aq_strength value, and for example, select aq_strength between 0.6-0.8 to retain more high-frequency details and improve the overall video quality; and if the current frame has more static images, the corresponding average macroblock energy is lower, and the encoder can select a higher aq_strength value, and for example, the encoder can select aq_strength greater than or equal to 1 to prevent the dark part from generating color bands due to insufficient bits. In some embodiments, the above method process can be implemented by the following code:

[0065]

[0066] strength=h->param.rc.f_aq_strength*avg_adj; / / Adjust the quantization strength of the current frame by presetting the quantization strength factor aq_strength and the average macroblock energy avg_adj.

[0067]

[0068] qp_adj = strength*(qp_adj-avg_adj)+bias_strength*(1.f-14.f / (qp_adj*qp_adj)); / / QP offset value qp_adj setting

[0069] In the embodiment of the present application, for the above code, if qp_adj-avg_adj is greater than 0, the QP of the macroblock with large macroblock energy will be adjusted to be larger, so that the final calculated qp_offset is larger and the complex area is more blurred; if qp_adj-avg_adj is less than 0, the larger the strength, the smaller the qp_offset, the smaller the final QP, and the clearer the flat area. Since h->param.rc.f_aq_strength is a fixed aq_strength value set manually, it is difficult to adapt to the complexity changes in the video to be encoded.

[0070] In some other embodiments of the present application, another implementation of the macroblock level rate control process can be as follows: Figure 6 As shown, in the macroblock level bit rate control process 2, the encoder uses the macroblock energy of each macroblock calculated in the macroblock energy calculation process, obtains the content complexity of each macroblock through the complexity information calculation process, and divides the current frame into different regions based on the content complexity of each macroblock in the complexity benchmark adjustment process according to the preset complexity benchmark, and sets different preset quantization strength factors aq_strength in different regions through the adaptive quantization process, and finally adjusts the initial quantization step size through the quantization step size adjustment process according to the different preset quantization strength factors aq_strength of each region, and obtains the quantization step size corresponding to the region, thereby realizing the change of the preset quantization strength factor aq_strength with the image complexity, which can reduce the preset quantization strength factor of the complex region, reduce the blurring phenomenon in the complex region, and improve the adaptability of the preset quantization strength factor to the video content.

[0071] In the embodiment of the present application, after the encoder obtains the quantization step corresponding to each macroblock in the current frame according to the macro-level quantization step adjustment module, the encoder can encode the current frame based on the quantization step to obtain the encoding result of the current frame. Based on the encoding result of the current frame, the encoder encodes the next frame using the same bit rate control process until the encoding of the video to be encoded is completed.

[0072] It can be understood that in the embodiments of the present application, for the first frame of the video to be encoded, the encoder can obtain the complexity accumulation value corresponding to the first frame based on the image information of the first frame, and then further calculate the initial quantization step size of the first frame according to the complexity accumulation value, thereby realizing that the initial quantization step size setting of the first frame can be adaptively set according to the complexity of the first frame, avoiding the waste of bit rate caused by artificially setting an unreasonable initial quantization step size of the first frame, and improving the quality of the encoded video. Furthermore, in the process of macroblock-level bit rate control, the encoder can set the preset quantization strength factor for the current frame by region and scene according to the macroblock complexity, so that suitable quantization step sizes can be calculated for different complexity areas of the current frame according to different preset quantization strength factors, thereby realizing the adaptation of the preset quantization strength factor with the image complexity, improving the clarity of the image, and further improving the quality of the encoded video.

[0073] Below, the encoding method in the embodiment of the present application is further explained by taking the average macroblock energy of the first frame as an example.

[0074] In some embodiments of the present application, based on Figure 2 , when the current frame is the first frame in the video to be encoded, in the inter-frame level bit rate control process, the encoder in S101 obtains the image information of the current video through S1011-S1012, such as Figure 7 As shown:

[0075] S1011. In a macroblock-level bit rate control process, the current frame is divided into macroblocks to obtain at least one macroblock.

[0076] In the embodiment of the present application, the encoder divides the current frame into macroblocks based on the image content of the current frame through a macroblock calculation module to obtain at least one macroblock.

[0077] In some embodiments, at least one macroblock may be in the form of an MB tree.

[0078] S1012. Calculate average macroblock energy of at least one macroblock.

[0079] In an embodiment of the present application, the encoder can calculate the macroblock energy of each macroblock through the pixel value and the sum of square errors in each macroblock of at least one macroblock, and then obtain the average macroblock energy of at least one macroblock based on the macroblock energy of each macroblock.

[0080] It can be understood that the average macroblock energy is used as the image information of the first frame in the embodiment of the present application. The average macroblock energy calculated during the macroblock level bit rate control process can be directly used without the need for additional image processing, thereby reducing the amount of calculation of the encoder.

[0081] In some embodiments of the present application, based on Figure 2 or Figure 7 , when the current frame is the first frame in the video to be encoded, in the inter-frame level bit rate control process, the encoder in S102 calculates the complexity accumulation value of the current frame based on the image information of the current frame, which can be implemented by S1021-S1022, such as Figure 8 As shown:

[0082] S1021. Perform complexity evaluation on the current frame according to the average macroblock energy, the preset first frame coding bits and at least one preset fitting factor to obtain an estimated coding complexity of the current frame; the at least one preset fitting factor is used to fit the relationship curve between the average macroblock energy and the initial quantization step size.

[0083] In the embodiment of the present application, the encoder performs complexity evaluation on the current frame according to the average macroblock energy, the preset first frame coding bits and at least one preset fitting factor, and the specific process of obtaining the estimated coding complexity of the current frame can be: multiplying the average macroblock energy by the first fitting factor to obtain a first product result; multiplying the preset first frame coding bits by the second fitting factor to obtain a second product result; calculating the difference between the first product result and the second product result, and adding the difference to the third fitting factor to obtain the estimated coding complexity; wherein the at least one preset fitting factor includes the first fitting factor, the second fitting factor and the third fitting factor. As shown in formula (1):

[0084] cplxr_zero=s1×avg_energy-s2×wanted_bits_window+s3 (1)

[0085] In the above formula (1), avg_energy is the average macroblock energy of the current frame, i.e., the first frame, cplxr_zero is the estimated complexity of the current frame calculated based on the average macroblock energy, s1, s2, and s3 are at least one preset fitting factor. The at least one preset fitting factor in the embodiment of the present application is obtained by adjusting the relationship between the initial quantization step and avg_energy through a large number of simulation experiments to meet the goal of low bit rate and high quality video applications, analyzing the advantages and disadvantages of the initial quantization step of the test video, and fitting the QP-energy curve. That is to say, the preset fitting factor in the embodiment of the present application is the optimal value of the corresponding parameter item in formula (1) obtained by function curve fitting. In some embodiments, the value of s1 can be 13000, the value of s2 can be 0.3858, and the value of s3 can be 515000. It is also possible to calculate the values ​​of other preset fitting factors by function curve fitting according to the actual encoding target. The specific selection is based on the actual application, and the embodiment of the present application is not limited.

[0086] In formula (1), wanted_bits_window represents the target file size of the encoded frame, that is, the total bit value of the encoded frame. Wanted_bits_window can be obtained by formula (2), as follows:

[0087] wanted_bits_window=bitrate / fps (2)

[0088] The fps in formula (2) is the preset frame rate of the video to be encoded, bitrate represents the bit rate after encoding, the bitrate of the first frame is the preset value, and the bitrate of the non-first frame is the corresponding bit rate after encoding the previous frame. Therefore, the wanted_bits_window of the first frame is also equivalent to the preset value. In the embodiment of the present application, the preset first frame encoding bits are used as the wanted_bits_window value of the first frame.

[0089] S1022. Calculate the complexity accumulation value of the current frame based on the estimated coding complexity.

[0090] In the embodiment of the present application, the encoder may calculate the complexity accumulation value of the current frame based on the estimated coding complexity, which may include:

[0091] S10221. Obtain the number of macroblocks of at least one macroblock.

[0092] S10222. Perform an initial value calculation on the complexity accumulation value according to the estimated coding complexity, the number of macroblocks of at least one macroblock and a preset compression parameter to obtain a complexity accumulation value of the current frame.

[0093] In an embodiment of the present application, the encoder obtains the number of macroblocks of at least one macroblock obtained after the macroblock calculation module divides the macroblocks, and calculates the preset compression parameter as the power of the estimated coding complexity, and multiplies the calculation result with the preset coefficient and the power of half of the number of macroblocks to obtain the complexity accumulation value of the current frame.

[0094] Exemplarily, the above calculation process can be shown as formula (3):

[0095] cplxr_sum=0.01×cplxr_zero qcom ×(mbcount) 1 / 2 (3)

[0096] In formula (3), qcomp is a preset compression parameter. This parameter is externally adjustable and can take a value between 0 and 1. mbcount is the number of macroblocks of at least one macroblock.

[0097] In some embodiments, when the current frame is the first frame, the code implementation of the encoder calculating the complexity accumulation value cplxr_sum of the current frame through S1012 may be as follows:

[0098]

[0099] In the current frame-level bit rate control process, the calculation method for the complexity accumulation value cplxr_sum of the first frame is shown in formula (4):

[0100] cplxr_sum=0.01×(7×10 5 ) qcompress ×(mbcount) 1 / 2 (4)

[0101] The code implementation corresponding to formula (1) is as follows:

[0102]

[0103]

[0104] It is understandable that, in the current frame-level bit rate control process, the complexity accumulation value cplxr_sum of the first frame is initialized as a fixed value, and cannot be adaptively adjusted according to the actual complexity of the first frame. As a result, it is impossible to perform further calculations based on a reasonable compression coefficient, which affects the initial quantization step of the first frame that is finally calculated based on the compression coefficient, and reduces the quality of the encoded video. The calculation of the complexity accumulation value cplxr_sum of the first frame in the embodiment of the present application is obtained through the estimated complexity of the first frame, so that the initial quantization step of the first frame calculated based on the complexity accumulation value cplxr_sum can be adaptively adjusted following the complexity of the first frame, thereby improving the rationality of the initial quantization step setting of the first frame, saving the encoding bit rate, and improving the quality of the encoded video.

[0105] It should be noted that, in some embodiments of the present application, when the current frame is not the first frame in the video to be encoded, the encoder can perform a complexity accumulation process based on the number of bits of the previous frame encoded corresponding to the current frame and the quantization parameter of the previous frame to obtain the complexity accumulation value of the current frame. In other words, when the current frame is not the first frame, the encoder calculates the complexity accumulation value of the current frame based on the encoding result of the previous frame, as shown in formula (5):

[0106]

[0107] In formula (5), bits(i-1) is the actual number of bits obtained by encoding the previous frame, qscale_raw(i-1) is the quantization weight value of the previous frame without rate factor adjustment, qscale_adj(i-1) is the initial quantization level of the previous frame after rate factor adjustment, cplxr_sum(i-1) is the complexity accumulation value of the previous frame, and cplxr_sum(i) is the complexity accumulation value of the current frame.

[0108] It is understandable that the complexity accumulation value of the current frame is an iterative amount, which is gradually accumulated during the encoding process, so the complexity accumulation value setting of the first frame will affect the encoding quality of the entire video. The method in the embodiment of the present application calculates the complexity accumulation value of the first frame by averaging the macroblock energy, and can realize the adaptive adjustment of the complexity accumulation value of the first frame according to the complexity of the first frame, so that the setting of the complexity accumulation value of the first frame is more accurate, thereby improving the quality of the entire video encoding.

[0109] In some embodiments of the present application, based on Figure 8 In S103, the encoder performs encoding quantization estimation on the current frame based on the complexity accumulation value of the current frame, and obtaining the initial quantization step size of the current frame can be achieved through S1031-S1034, such as Fig. 9 As shown:

[0110] S1031 . Estimating the blur complexity of the current frame, and compressing the estimated blur complexity to calculate the complexity of the current frame.

[0111] In an embodiment of the present application, the encoder performs sampling filtering on the current frame to obtain a small image with half the original resolution, makes a half-pixel precision prediction on the small image, subtracts it from the original image to obtain a residual, then performs a Hadamant transform on the residual and calculates the absolute sum to obtain SATD, and the blur complexity of the current frame can be obtained based on the weighted average of the SATD values ​​of the current frame and the SATD values ​​of the previous adjacent frames.

[0112] In the embodiment of the present application, the encoder may estimate the blur complexity of the current frame as shown in formula (6) and formula (7), as follows:

[0113] BlurCplx=Cplxsum / Cplxcount (6)

[0114]

[0115] In formula (6), BlurCplx represents blur complexity. The encoder can obtain BlurCplx by weighting the complexity of adjacent encoded frames according to formula (6). In formula (6), Cplxsum represents the weighted sum of encoding complexity, Cplxcount represents the weighted sum of the number of encoded frames, and the calculation method of Cplxsum and Cplxcount is shown in formula (7). In formula (7), i is the sequence number of the frame to be encoded, satd is the sum of the absolute values ​​of the residuals SATD after motion compensation of the current frame, the satd of the first frame is a preset value, and the satd of the non-first frame can be calculated according to the time-frequency transform method, which is used to reflect the size of the generated code stream.

[0116] In the embodiment of the present application, since the constant quality of the video frame does not mean that a constant QP value is used, according to the visual characteristics of the human eye, for a highly complex scene, it is difficult for the human eye to subjectively feel the loss of details. Therefore, the blur complexity of the current frame can be nonlinearly compressed to reduce the bit rate through the method of perceptual coding optimization, as shown in formula (8):

[0117] rceq = BlurCplx (1-qcomp) ,qcomp∈[0,1] (8)

[0118] In formula (8), rceq represents the complexity after perceptual coding optimization, which can be used as a quantization ratio to evaluate the quantizability of the current frame. The specific meaning of qcomp is that when qcomp is equal to 1, the quantization ratio of each frame, that is, rceq, is the same, and the bits allocated to the smooth frame and the complex frame are the same; when qcomp = 0, the quantization ratio of each frame is proportional to its blur complexity, and finally the QP value of each frame is equal, which is equivalent to turning off this perceptual coding optimization.

[0119] S1032: Calculate the ratio between the total bit value of the encoded frames in the video to be encoded and the complexity accumulation value to obtain the bit rate factor of the current frame.

[0120] In the embodiment of the present application, the encoder calculates the ratio between the total bit value of the encoded frame in the video to be encoded and the complexity accumulation value as the bit rate factor of the current frame, as shown in formula (9) and formula (10):

[0121] ratefactor=wanted_bits_window / cplxr_sum (9)

[0122] In formula (9), ratefactor is the rate factor of the current frame generated by the rate factor calculation module according to the bitrate of the encoded frame.

[0123] S1033. Obtain a quantization level of the current frame based on the complexity and the bit rate factor.

[0124] In the embodiment of the present application, the encoder may first use the ratio of the quantization weight to the bit rate factor as the initial quantization level of the current frame.

[0125] In the embodiment of the present application, the encoder can calculate the ratio of the quantization ratio rceq to the rate factor ratefactor through formula (10) to obtain the initial quantization level of the current frame:

[0126] qscale=rceq / ratefactor (10)

[0127] In formula (10), qscale is the initial quantization level of the current frame.

[0128] In the embodiment of the present application, after the encoder obtains the initial quantization level of the current frame, it can adjust the initial quantization level based on a preset target number of bits to obtain the quantization level of the current frame.

[0129] In an embodiment of the present application, the preset target bit number is the size of the receiving end buffer corresponding to the encoded video. The encoder can adjust the initial quantization level through the cache control module according to the deviation between the preset target bit number and the total bit value generated after the current frame is actually encoded, so as to obtain the quantization level of the current frame and make the generated code stream size stable.

[0130] S1034: based on the mapping relationship between the preset quantization level and the initial quantization step length, convert the quantization level of the current frame into the initial quantization step length.

[0131] In the embodiment of the present application, the mapping relationship between the preset quantization level and the initial quantization step size can be shown as formula (11):

[0132]

[0133] In formula (10), a, b, and c are empirical coefficients. In some embodiments, a may be 12, b may be 6, and c may be 0.85. qscale is the quantization level, and QP is the quantization step size converted from the quantization level.

[0134] Therefore, after the encoder calculates the quantization level, it can convert the quantization level of the current frame into the initial quantization step size based on the mapping relationship between the preset quantization level and the initial quantization step size.

[0135] In some embodiments of the present application, based on Figure 2 or Figure 7 In S104, the encoder encodes the current frame based on the initial quantization step size of the current frame, and the encoding result of the current frame can be obtained through S1041-S1044, such as Fig.10 As shown:

[0136] S1041. In macroblock-level rate control, after dividing the current frame into macroblocks, obtain the content complexity of each macroblock.

[0137] In an embodiment of the present application, in macroblock-level rate control, the encoder divides the current frame into macroblocks and calculates the complexity data generated when the energy of each macroblock is used as the content complexity corresponding to each macroblock.

[0138] S1042. Divide the current frame into regions according to the content complexity of each macroblock and a preset complexity threshold to obtain at least one region.

[0139] In the embodiment of the present application, the encoder first sets a preset complexity threshold. Usually, the preset complexity threshold may be an empirical value. Exemplarily, the preset complexity threshold may be a value between [80000, 85000]. Preferably, the preset complexity threshold may be 82400.

[0140] In the embodiment of the present application, the encoder divides the current frame into regions based on the comparison between the content complexity of each macroblock and the preset complexity threshold, and divides the macroblocks with complexity higher than and lower than the preset complexity threshold into different regions, thereby obtaining at least one region, wherein the complexity of each region in the at least one region is different.

[0141] In some embodiments, by presetting a complexity threshold, the encoder may divide the current frame into a high-complexity region and a low-complexity region.

[0142] S1043: Determine a preset quantization strength factor for each region in the at least one region, and adjust the initial quantization step size according to the preset quantization strength factor corresponding to each region to obtain a quantization step size corresponding to each region.

[0143] In the embodiment of the present application, the encoder first determines the region complexity of each region based on the content complexity of the macroblocks contained in each region.

[0144] In some embodiments, the encoder may calculate the mean of the content complexity of each macroblock contained in each region as the regional complexity of each region, or may use other measurement calculation methods, such as variance, etc. The specific selection is made based on actual conditions and is not limited in the embodiments of the present application.

[0145] In the embodiment of the present application, the encoder determines the preset quantization strength factor of each region according to the preset correspondence between the regional complexity and the preset quantization strength factor, wherein the preset quantization strength factor is inversely proportional to the regional complexity.

[0146] In the embodiment of the present application, the preset quantization strength factor aq_strength can be used to adjust the block effect of the flat area and the blur effect of the texture area. The higher the aq_strength, the more the high-frequency information of the complex area is reduced, but the clarity of the flat area is improved, which also means that the texture is more blurred. Conversely, the lower the aq_strength, the more high-frequency information of the complex area is retained, and the clarity of the flat area is reduced, that is, the texture area is clearer.

[0147] In some embodiments, the encoder may divide the current frame into a high complexity region and a low complexity region, and set the preset quantization strength factor aq_strength of the high complexity region to 0.5, and the preset quantization strength factor aq_strength of the low complexity region to 1.0, thereby reducing blurring through a lower aq_strength and improving the overall quality of the encoded video. The specific code is as follows:

[0148]

[0149]

[0150] In the above code, h->param.rc.f_aq_strength_cplx=0.5, which indicates the preset quantization strength factor aq_strength of the high-complexity area, frame->s_cplx is the regional complexity obtained according to the content complexity of each macroblock in the area. When the regional complexity is greater than the preset complexity threshold 82400, the encoder can use the high-complexity quantization strength factor aq_strength, that is, 0.5, to set the initial quantization step size of the high-complexity area to reduce the blurring phenomenon in the high-complexity area.

[0151] In the embodiment of the present application, the encoder determines the preset quantization strength factor set for each region according to the regional complexity of each region by the same method, and adjusts the initial quantization step size according to the preset quantization strength factor set for each region, and obtains the corresponding quantization step size for each region. That is, the quantization step size finally calculated for the current frame in the embodiment of the present application is at least one quantization step size, and the at least one quantization step size corresponds to the complexity of the content scene in the current frame, and can be adaptively adjusted according to the regional complexity of the content scene.

[0152] S1044. Encode each region of the current frame according to the quantization step size corresponding to each region to obtain an encoding result of the current frame.

[0153] In the embodiment of the present application, the encoder encodes each area of ​​the current frame according to the quantization step size corresponding to each area to obtain the encoding result of the current frame.

[0154] It can be understood that in the embodiment of the present application, the encoder divides the current frame into regions according to the macroblock complexity, so that when adjusting the quantization step size during the macroblock level bit rate control process, it can perform adaptive adjustment in different regions according to the complexity of the current frame, thereby improving the accuracy of the quantization step size and thus improving the accuracy of the encoded video.

[0155] In some embodiments, based on the encoding method provided in the embodiment of the present application, on the X.264 software encoding platform, common standard video data is used as a test sequence, the video resolution is fixedly set to 960*540, the encoding algorithm adopts the ABR mode, and the bit rate is set to a relatively low 1.2Mb / s. On this basis, the objective PSNR value and the corresponding bit rate control of the encoded video obtained by the current encoding method and the encoded video obtained by the encoding method in the embodiment of the present application are tested respectively, and the experimental results are shown in Table 1. Table 1 is a comparison of the bit rate and PSNR of the encoded video obtained by the current encoding method and the encoding method in the embodiment of the present application, as shown below:

[0156]

[0157] Table 1

[0158] From the comparison data in Table 1, it can be seen that the encoding scheme optimized by the embodiment of the present application can ensure the encoder's ability to control the bit rate, and will not cause the failure of the bit rate control due to the introduction of the algorithm. At the same time, the overall average improvement in the objective quality of PSNR is about 0.145dB. It can be concluded that the encoding method provided by the embodiment of the present application can improve the video quality of the encoded video without causing a compression rate burden.

[0159] The embodiment of the present application provides an encoder, Fig.11 A schematic diagram of the structure of an encoder provided in an embodiment of the present application Figure 1 ,like Fig.11 As shown, the encoder 110 includes: an acquisition unit 1101, a calculation unit 1102, a quantization unit 1103 and an encoding unit 1104, wherein:

[0160] The acquisition unit 1101 is used to acquire image information of the current frame during the inter-frame level bit rate control process when the current frame is the first frame in the video to be encoded;

[0161] The calculation unit 1102 is used to calculate the complexity accumulation value of the current frame based on the image information of the current frame;

[0162] The quantization unit 1103 is used to perform coding quantization estimation on the current frame based on the complexity accumulation value of the current frame to obtain an initial quantization step size of the current frame;

[0163] The encoding unit 1104 is used to encode the current frame based on the initial quantization step size of the current frame to obtain an encoding result of the current frame.

[0164] In some embodiments, the image information includes any one of average macroblock energy of the first frame, gradient value of the first frame, edge information of the first frame, and histogram information of the first frame.

[0165] In some embodiments, the image information is the average macroblock energy of the first frame, and the calculation unit 1102 is further used to perform complexity evaluation on the current frame according to the average macroblock energy, preset first frame coding bits and at least one preset fitting factor to obtain the estimated coding complexity of the current frame; the at least one preset fitting factor is used to fit the relationship curve between the average macroblock energy and the initial quantization step size; based on the estimated coding complexity, the complexity cumulative value of the current frame is calculated.

[0166] In some embodiments, the calculation unit 1102 is also used to multiply the average macroblock energy by a first fitting factor to obtain a first product result; multiply the preset first frame coding bit by a second fitting factor to obtain a second product result; calculate the difference between the first product result and the second product result, and add the difference to a third fitting factor to obtain the estimated coding complexity; wherein the at least one preset fitting factor includes the first fitting factor, the second fitting factor and the third fitting factor.

[0167] In some embodiments, the acquisition unit 1101 is further used to divide the current frame into macroblocks to obtain at least one macroblock during macroblock-level rate control, and calculate the average macroblock energy of the at least one macroblock.

[0168] In some embodiments, the calculation unit 1102 is also used to obtain the number of macroblocks of the at least one macroblock; perform an initial value calculation on the complexity cumulative value according to the estimated coding complexity, the number of macroblocks of the at least one macroblock and the preset compression parameter to obtain the complexity cumulative value of the current frame.

[0169] In some embodiments, the calculation unit 1102 is also used to calculate the preset compression parameter as the power of the estimated coding complexity, and multiply the calculation result with the preset coefficient and the power of half of the number of macroblocks to obtain the complexity accumulation value of the current frame.

[0170] In some embodiments, the acquisition unit 1101 is further used to calculate the gradient value, edge information or histogram information of the current frame according to the pixel information contained in the current frame.

[0171] In some embodiments, the encoding unit 1104 is also used to obtain the content complexity of each macroblock after dividing the current frame into macroblocks in macroblock-level bit rate control; divide the current frame into regions according to the content complexity of each macroblock and a preset complexity threshold to obtain at least one region; determine a preset quantization strength factor for each region in the at least one region, and adjust the initial quantization step size according to the preset quantization strength factor corresponding to each region to obtain a quantization step size corresponding to each region; encode each region of the current frame according to the quantization step size corresponding to each region to obtain an encoding result of the current frame.

[0172] In some embodiments, the encoding unit 1104 is further used to determine the regional complexity of each region according to the content complexity of the macroblocks contained in each region; determine the preset quantization strength factor of each region according to the preset correspondence between the regional complexity and the preset quantization strength factor; the preset quantization strength factor is inversely proportional to the regional complexity.

[0173] In some embodiments, the quantization unit 1103 is also used to estimate the blur complexity of the current frame, compress the estimated blur complexity, and calculate the complexity of the current frame; calculate the ratio between the total bit value of the encoded frames in the video to be encoded and the complexity cumulative value to obtain the bit rate factor of the current frame; based on the complexity and the bit rate factor, obtain the quantization level of the current frame; based on the mapping relationship between the preset quantization level and the initial quantization step, convert the quantization level of the current frame into the initial quantization step.

[0174] In some embodiments, the quantization unit 1103 is further used to use the ratio of the complexity to the bit rate factor as the initial quantization level of the current frame; based on a preset target number of bits, the initial quantization level is adjusted to obtain the quantization level of the current frame.

[0175] In some embodiments, the calculation unit 1102 is used to perform encoding quantization estimation on the current frame based on the complexity cumulative value of the current frame to obtain the initial quantization step of the current frame. When the current frame is not the first frame in the video to be encoded, the complexity is accumulated based on the number of bits encoded in the previous frame corresponding to the current frame and the quantization parameter of the previous frame to obtain the complexity cumulative value of the current frame.

[0176] It should be noted that the description of the above device embodiment is similar to the description of the above method embodiment, and has similar beneficial effects as the method embodiment. For technical details not disclosed in the device embodiment of the present application, please refer to the description of the method embodiment of the present application for understanding.

[0177] It should be noted that in the embodiment of the present application, if the above-mentioned information display method is implemented in the form of a software function module and sold or used as an independent product, it can also be stored in a computer-readable storage medium. Based on such an understanding, the technical solution of the embodiment of the present application can be essentially or partly embodied in the form of a software product that contributes to the prior art. The computer software product is stored in a storage medium, including several instructions to enable a computer device (which can be a terminal, a server, etc.) to execute all or part of the methods described in each embodiment of the present application. The aforementioned storage medium includes: various media that can store program codes, such as a U disk, a mobile hard disk, a read-only memory (ROM), a disk or an optical disk. In this way, the embodiment of the present application is not limited to any specific combination of hardware and software.

[0178] Correspondingly, an embodiment of the present application further provides a computer program product, which includes computer executable instructions, and the computer executable instructions are used to implement the steps in the encoding method provided in the embodiment of the present application.

[0179] Correspondingly, an embodiment of the present application further provides a computer storage medium, on which computer executable instructions are stored, and the computer executable instructions are used to implement the steps of the encoding method provided in the above embodiment.

[0180] The embodiment of the present application also provides an encoder, Fig.12 A schematic diagram of the structure of an encoder provided in an embodiment of the present application Figure 2 ,like Fig.12 As shown, the encoder 1200 includes: a memory 1201, for storing a computer program;

[0181] The processor 1202 is configured to implement the steps of the encoding method provided in the above embodiment when executing the computer program stored in the memory 1201;

[0182] The encoder 1200 further includes a communication bus 1203 , which is used to connect the memory 1201 and the processor 1202 , thereby realizing connection and communication between the memory 1201 and the processor 1202 .

[0183] The memory 1201 is configured to store computer programs and applications used by the processor 1202, and can also cache data to be processed or processed by the processor 1202 and various modules in the encoder (for example, image data, audio data, voice communication data, and video communication data), which can be implemented through flash memory (FLASH) or random access memory (Random Access Memory, RAM).

[0184] When the processor 1202 executes the program, the steps of any one of the above encoding methods are implemented.

[0185] The processor 1103 may be at least one of an application-specific integrated circuit (ASIC), a digital signal processor (DSP), a digital signal processing device (DSPD), a programmable logic device (PLD), a field programmable gate array (FPGA), a central processing unit (CPU), a controller, a microcontroller, and a microprocessor. It is understandable that the electronic device that implements the above-mentioned processor function may also be other, and the embodiments of the present application are not limited thereto.

[0186] The above-mentioned computer-readable storage medium / memory can be a read-only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM), a magnetic random access memory (FRAM), a flash memory (Flash Memory), a magnetic surface memory, an optical disk, or a compact disc read-only memory (CD-ROM) and the like; it can also be various terminals including one or any combination of the above-mentioned memories, such as mobile phones, computers, tablet devices, personal digital assistants, etc.

[0187] It should be noted here that the description of the above storage medium and device embodiments is similar to the description of the above method embodiments, and has similar beneficial effects as the method embodiments. For technical details not disclosed in the storage medium and device embodiments of this application, please refer to the description of the method embodiments of this application for understanding.

[0188] It should be understood that "one embodiment" or "an embodiment" mentioned throughout the specification means that specific features, structures or characteristics related to the embodiment are included in at least one embodiment of the present application. Therefore, "in one embodiment" or "in an embodiment" appearing throughout the specification does not necessarily refer to the same embodiment. In addition, these specific features, structures or characteristics can be combined in one or more embodiments in any suitable manner. It should be understood that in various embodiments of the present application, the size of the sequence number of the above-mentioned processes does not mean the order of execution, and the execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present application. The above-mentioned sequence numbers of the embodiments of the present application are only for description and do not represent the advantages and disadvantages of the embodiments.

[0189] It should be noted that, in this article, the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, an element defined by the sentence "comprises a ..." does not exclude the existence of other identical elements in the process, method, article or device including the element.

[0190] In the several embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. The device embodiments described above are only schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation, such as: multiple units or components can be combined, or can be integrated into another system, or some features can be ignored or not executed. In addition, the coupling, direct coupling, or communication connection between the components shown or discussed can be through some interfaces, and the indirect coupling or communication connection of the devices or units can be electrical, mechanical or other forms.

[0191] The units described above as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units; they may be located in one place or distributed on multiple network units; some or all of the units may be selected according to actual needs to achieve the purpose of the embodiment of the present application.

[0192] In addition, all functional units in the embodiments of the present application may be integrated into one processing unit, or each unit may be a separate unit, or two or more units may be integrated into one unit; the above-mentioned integrated units may be implemented in the form of hardware or in the form of hardware plus software functional units.

[0193] Alternatively, if the above-mentioned integrated unit of the present application is implemented in the form of a software function module and sold or used as an independent product, it can also be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the embodiment of the present application can essentially or in other words, the part that contributes to the relevant technology can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions for the automatic test line of the device to execute all or part of the methods described in each embodiment of the present application. The aforementioned storage medium includes: various media that can store program codes, such as mobile storage devices, ROMs, magnetic disks or optical disks.

[0194] The methods disclosed in several method embodiments provided in this application can be arbitrarily combined without conflict to obtain new method embodiments.

[0195] The features disclosed in several method or device embodiments provided in this application can be arbitrarily combined without conflict to obtain new method embodiments or device embodiments.

[0196] The above is only an implementation method of the present application, but the protection scope of the present application is not limited thereto. Any person skilled in the art who is familiar with the present technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.

Claims

1. A coding method, applied to an encoder, characterized in that: include: In the inter-frame level rate control process, based on the complexity accumulation value of the current frame, the current frame is coded and quantized to estimate, so as to obtain an initial quantization step size of the current frame; In macroblock-level bit rate control, after dividing the current frame into macroblocks, the content complexity of each macroblock is obtained; Based on the content complexity of each macroblock, the current frame is divided into at least one region, and a preset quantization strength factor corresponding to each region in the at least one region is determined; According to the preset quantization strength factor corresponding to each region, the initial quantization step size is adjusted to obtain the quantization step size corresponding to each region; Encoding each region of the current frame according to the quantization step size corresponding to each region to obtain an encoding result of the current frame; The step of performing encoding quantization estimation on the current frame based on the complexity accumulation value of the current frame to obtain an initial quantization step size of the current frame includes: Performing blur complexity estimation on the current frame, and compressing the estimated blur complexity to calculate the complexity of the current frame; Calculating the ratio between the total bit value of the encoded frames in the video to be encoded and the complexity accumulation value to obtain the bit rate factor of the current frame; Based on the complexity and the bit rate factor, obtaining a quantization level of the current frame; Based on a mapping relationship between a preset quantization level and the initial quantization step length, the quantization level of the current frame is converted into the initial quantization step length.

2. The method according to claim 1, characterized in that The dividing the current frame into at least one region based on the content complexity of each macroblock comprises: The current frame is divided into regions according to the content complexity of each macroblock and a preset complexity threshold to obtain the at least one region.

3. The method according to claim 1, characterized in that The determining of a preset quantization intensity factor for each of the at least one region comprises: Determining the region complexity of each region according to the content complexity of the macroblocks contained in each region; According to a preset corresponding relationship between the regional complexity and the preset quantization intensity factor, the preset quantization intensity factor of each region is determined; the preset quantization intensity factor is inversely proportional to the regional complexity.

4. The method according to any one of claims 1 to 3, characterized in that: Before performing encoding quantization estimation on the current frame based on the complexity accumulation value of the current frame to obtain an initial quantization step length of the current frame, the method further includes: When the current frame is the first frame in the video to be encoded, in an inter-frame level bit rate control process, obtaining image information of the current frame; Based on the image information of the current frame, a complexity accumulation value of the current frame is calculated.

5. The method according to claim 4, characterized in that The image information includes any one of average macroblock energy of the first frame, gradient value of the first frame, edge information of the first frame, and histogram information of the first frame.

6. The method according to claim 5, characterized in that The image information is the average macroblock energy of the first frame, and the complexity accumulation value of the current frame is calculated based on the image information of the current frame, including: Performing a complexity evaluation on the current frame according to the average macroblock energy, the preset first frame coding bits and at least one preset fitting factor to obtain an estimated coding complexity of the current frame; the at least one preset fitting factor is used to fit a relationship curve between the average macroblock energy and the initial quantization step size; Based on the estimated coding complexity, a complexity accumulation value of the current frame is calculated.

7. The method according to claim 6, characterized in that The performing complexity evaluation on the current frame according to the average macroblock energy, the preset first frame coding bits and at least one preset fitting factor to obtain the estimated coding complexity of the current frame includes: Multiplying the average macroblock energy by a first fitting factor to obtain a first product result; Multiplying the preset first frame coding bit by a second fitting factor to obtain a second product result; Calculate the difference between the first multiplication result and the second multiplication result, and add the difference to a third fitting factor to obtain the estimated coding complexity; wherein the at least one preset fitting factor includes the first fitting factor, the second fitting factor and the third fitting factor.

8. The method according to claim 6, characterized in that The obtaining of image information of the current frame includes: In the macroblock level bit rate control process, the current frame is divided into macroblocks to obtain at least one macroblock; An average macroblock energy of the at least one macroblock is calculated.

9. The method according to claim 8, characterized in that The calculating the complexity accumulation value of the current frame based on the estimated coding complexity includes: Obtaining the number of macroblocks of the at least one macroblock; An initial value calculation is performed on the complexity accumulation value according to the estimated coding complexity, the number of macroblocks of the at least one macroblock and a preset compression parameter to obtain the complexity accumulation value of the current frame.

10. The method according to claim 9, characterized in that The performing initial value calculation on the complexity accumulation value according to the estimated coding complexity, the number of macroblocks of the at least one macroblock and a preset compression parameter to obtain the complexity accumulation value of the current frame includes: The preset compression parameter is used as a power of the estimated coding complexity for calculation, and the calculation result is multiplied by a preset coefficient and a power of half of the number of macroblocks to obtain a complexity accumulation value of the current frame.

11. The method according to claim 5, characterized in that The obtaining of image information of the current frame includes: The gradient value, edge information or histogram information of the current frame is calculated according to the pixel information contained in the current frame.

12. The method according to claim 1, characterized in that The obtaining, based on the complexity and the bit rate factor, a quantization level of the current frame includes: Using the ratio of the complexity to the bit rate factor as the initial quantization level of the current frame; Based on a preset target number of bits, the initial quantization level is adjusted to obtain the quantization level of the current frame.

13. The method according to any one of claims 1 to 3, characterized in that: Before performing encoding quantization estimation on the current frame based on the complexity accumulation value of the current frame to obtain an initial quantization step length of the current frame, the method further includes: When the current frame is not the first frame in the video to be encoded, the complexity is accumulated based on the number of bits of the previous frame encoded corresponding to the current frame and the quantization parameter of the previous frame to obtain the complexity accumulation value of the current frame.

14. An encoder, characterized in that: include: Quantization unit and encoding unit, wherein, The quantization unit is used to perform coding quantization estimation on the current frame based on the complexity accumulation value of the current frame in the inter-frame level rate control process to obtain an initial quantization step size of the current frame; The quantization unit is specifically used to estimate the fuzzy complexity of the current frame, and compress the estimated fuzzy complexity to calculate the complexity of the current frame; calculate the ratio between the total bit value of the encoded frame in the video to be encoded and the complexity accumulation value to obtain the bit rate factor of the current frame; based on the complexity and the bit rate factor, obtain the quantization level of the current frame; based on the mapping relationship between the preset quantization level and the initial quantization step length, convert the quantization level of the current frame into the initial quantization step length; The encoding unit is used to obtain the content complexity of each macroblock after dividing the current frame into macroblocks in macroblock-level bit rate control; divide the current frame into at least one area based on the content complexity of each macroblock, and determine the preset quantization strength factor corresponding to each area in the at least one area; adjust the initial quantization step size according to the preset quantization strength factor corresponding to each area to obtain the quantization step size corresponding to each area; encode each area of ​​the current frame according to the quantization step size corresponding to each area to obtain the encoding result of the current frame.

15. An encoder, characterized in that: include: A memory for storing executable data instructions; A processor, configured to implement the method according to any one of claims 1 to 13 when executing the executable instructions stored in the memory.

16. A computer-readable storage medium, characterized in that: Executable instructions are stored, which are used to cause a processor to execute and implement the method described in any one of claims 1 to 13.

Citation Information

Patent Citations

  • Video coding method and device and electronic equipment

    CN102036062A

  • HEVC (High Efficiency Video Coding) code rate control method based on region-of-interest

    CN105049850A