WO2022012183A1 - Encoding method, encoder and computer readable storage medium - Google Patents

Encoding method, encoder and computer readable storage medium Download PDF

Info

Publication number
WO2022012183A1
WO2022012183A1 PCT/CN2021/096491 CN2021096491W WO2022012183A1 WO 2022012183 A1 WO2022012183 A1 WO 2022012183A1 CN 2021096491 W CN2021096491 W CN 2021096491W WO 2022012183 A1 WO2022012183 A1 WO 2022012183A1
Authority
WO
WIPO (PCT)
Prior art keywords
current frame
complexity
frame
macroblock
value
Prior art date
Application number
PCT/CN2021/096491
Other languages
French (fr)
Chinese (zh)
Inventor
谭皓
Original Assignee
Oppo广东移动通信有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Oppo广东移动通信有限公司 filed Critical Oppo广东移动通信有限公司
Publication of WO2022012183A1 publication Critical patent/WO2022012183A1/en

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04NPICTORIAL COMMUNICATION, e.g. TELEVISION
    • H04N19/00Methods or arrangements for coding, decoding, compressing or decompressing digital video signals
    • H04N19/10Methods or arrangements for coding, decoding, compressing or decompressing digital video signals using adaptive coding
    • H04N19/102Methods or arrangements for coding, decoding, compressing or decompressing digital video signals using adaptive coding characterised by the element, parameter or selection affected or controlled by the adaptive coding
    • H04N19/124Quantisation
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04NPICTORIAL COMMUNICATION, e.g. TELEVISION
    • H04N19/00Methods or arrangements for coding, decoding, compressing or decompressing digital video signals
    • H04N19/10Methods or arrangements for coding, decoding, compressing or decompressing digital video signals using adaptive coding
    • H04N19/134Methods or arrangements for coding, decoding, compressing or decompressing digital video signals using adaptive coding characterised by the element, parameter or criterion affecting or controlling the adaptive coding
    • H04N19/136Incoming video signal characteristics or properties
    • H04N19/14Coding unit complexity, e.g. amount of activity or edge presence estimation
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04NPICTORIAL COMMUNICATION, e.g. TELEVISION
    • H04N19/00Methods or arrangements for coding, decoding, compressing or decompressing digital video signals
    • H04N19/10Methods or arrangements for coding, decoding, compressing or decompressing digital video signals using adaptive coding
    • H04N19/169Methods or arrangements for coding, decoding, compressing or decompressing digital video signals using adaptive coding characterised by the coding unit, i.e. the structural portion or semantic portion of the video signal being the object or the subject of the adaptive coding
    • H04N19/17Methods or arrangements for coding, decoding, compressing or decompressing digital video signals using adaptive coding characterised by the coding unit, i.e. the structural portion or semantic portion of the video signal being the object or the subject of the adaptive coding the unit being an image region, e.g. an object
    • H04N19/172Methods or arrangements for coding, decoding, compressing or decompressing digital video signals using adaptive coding characterised by the coding unit, i.e. the structural portion or semantic portion of the video signal being the object or the subject of the adaptive coding the unit being an image region, e.g. an object the region being a picture, frame or field

Definitions

  • the present application relates to the field of audio and video encoding, and in particular, to an encoding method, an encoder, and a computer-readable storage medium.
  • Video coding is a video compression technology, which 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 a certain number of bits occupied after video compression.
  • the Quantization Parameter (QP) is a key parameter in the video coding technology, which directly determines the compression degree of the video coding unit, thereby controlling the bit rate and video quality after video coding.
  • the embodiments of the present application are expected to provide an encoding method, an encoder, and a computer-readable storage medium, which can improve the video quality of the encoded video.
  • an embodiment of the present application provides an encoding method, which is applied to an encoder, including:
  • the image information of the current frame is acquired;
  • the current frame is encoded to obtain an encoding result of the current frame.
  • an embodiment of the present application provides an encoder, including: an acquisition part, a calculation part, a quantization part, and an encoding part, wherein,
  • the acquisition part is configured to acquire image information of the current frame in the inter-frame-level code rate control process when the current frame is the first frame in the video to be encoded;
  • the calculation part is configured to calculate the complexity cumulative value of the current frame based on the image information of the current frame;
  • the quantization part is configured to perform coding and quantization estimation on the current frame based on the cumulative complexity value of the current frame to obtain an initial quantization step size of the current frame;
  • the encoding part is configured 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.
  • an encoder including:
  • a memory configured to store executable data instructions
  • the processor when configured to execute the executable instructions stored in the memory, implements any of the encoding methods described above.
  • an embodiment of the present application provides a computer-readable storage medium storing executable instructions configured to cause a processor to execute any of the encoding methods described above.
  • embodiments of the present application provide a computer program product, where the computer program product includes computer-readable codes, and when the computer-readable codes run in an encoder, processing in the encoder
  • the processor implements the encoding method as described in any of the above.
  • Embodiments of the present application provide an encoding method, an encoder, and a computer-readable storage medium.
  • the method includes: when the current frame is the first frame in the video to be encoded, in an inter-frame-level rate control process, obtaining the current frame's Image information; based on the image information of the current frame, calculate the cumulative complexity value of the current frame; based on the cumulative complexity value of the current frame, perform coding and quantization estimation on the current frame to obtain the initial quantization step size of the current frame; based on the initial quantization step size of the current frame
  • the quantization step size is used to encode the current frame to obtain the encoding result of the current frame.
  • the complexity accumulation value of the first frame can be evaluated by using the image information of the first frame, and the initial quantization step size, that is, the QP value, is reasonably set based on the complexity accumulation value of the first frame, thereby realizing
  • the QP value can be adaptively adjusted according to the image information of the first frame, so that the video encoding based on the QP value can obtain more accurate encoding results, and finally improve the video quality of the encoded video.
  • Fig. 1 is the coding flow chart of the current X.264 coding system
  • FIG. 2 is a flowchart 1 of an encoding method provided by an embodiment of the present application.
  • FIG. 3 provides a coding flow chart 1 of an embodiment of the present application
  • Fig. 4 is a kind of coding flow chart 2 provided by the embodiment of this application.
  • FIG. 5 is an implementation manner of a macroblock-level rate control process provided by an embodiment of the present application.
  • FIG. 6 is another implementation manner of a macroblock-level rate control process provided by an embodiment of the present application.
  • FIG. 7 is a second flowchart of an encoding method provided by an embodiment of the present application.
  • FIG. 9 is a fourth flowchart of an encoding method provided by an embodiment of the present application.
  • FIG. 10 is a flowchart 5 of an encoding method provided by an embodiment of the present application.
  • FIG. 11 is a schematic diagram 1 of the composition and structure of an encoder according to an embodiment of the application
  • FIG. 12 is a second schematic diagram of the composition and structure of an encoder according to an embodiment of the present application.
  • H.264 A highly compressed digital video codec standard.
  • X.264 Open source H.264 video encoding function library.
  • SATD Sum of Absolute Transformed Difference, the sum of the absolute values of the prediction residuals of the 4 ⁇ 4 blocks of which the residuals are Hardman transformed, is a simple time-frequency transform used to reflect the size of the generated code stream.
  • QP quantization parameter, that is, the quantization step size. The smaller the value of QP, 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.
  • VBV Video Buffering Verifier, a video buffering verifier, used to ensure that the output encoded stream does not underflow the buffer at the receiving end.
  • MB Macro Block, macro block.
  • RCEQ Rate-Control Equation, rate control formula, RCEQ establishes a mapping model from motion complexity to quantization step size.
  • PSNR Peak Signal to Noise Ratio
  • H.264 uses the Lagrangian cost function to control the encoding, which is one of the main reasons for the high coding complexity of H.264.
  • X.264 uses the SATD of the half-precision frame as the QP selection. main basis.
  • the X.264 rate control process is divided into an inter-frame-level rate control process and a macroblock-level rate control process.
  • the allocation of the QP value of each frame is realized by the inter-frame-level rate control, and the The assignment of QP values is implemented by macroblock-level rate control.
  • the X.264 bit rate control process mainly depends on two variables, one is the complexity of the video frame, and the other is the budget of the bit rate.
  • FIG. 1 is an encoding flow chart of the current X.264 encoding system.
  • the lookahead module 100 is configured to provide video frames for the to-be-encoded video.
  • the buffer queue assists in completing more stable bit rate control.
  • the complexity estimation module 101 is configured to estimate the complexity of the current frame in the video to be encoded.
  • the complexity of the current frame may be the fuzzy complexity; the quantization level
  • the calculation module 103 is configured to calculate the quantization level according to the complexity of the current frame output by the complexity estimation module 101, obtain the quantization proportion corresponding to the current frame, and calculate the code rate factor (ratefactor) provided by the code rate factor calculation module 102.
  • the quantization weight is adjusted to obtain the initial quantization level; the code rate factor calculation module 102 is configured to calculate the complexity accumulation value of the current frame according to the feedback code rate of the coded frame, and then calculate the code according to the complexity accumulation value.
  • the rate factor is provided to the quantization level calculation module 103; the buffer control (VBV) module 104 is configured to adjust the initial quantization level output by the quantization level calculation module 103 based on the size of the buffer area at the receiving end to obtain the quantization level; the quantization level The conversion module 105 is configured to convert the quantization level into an initial quantization step size and provide it to the macroblock-level quantization step size adjustment module 106 .
  • the rate control process at the macroblock level is performed synchronously with the rate control process at the inter-frame level, wherein the macroblock calculation module 108 is configured to calculate the macroblock structure of the current frame according to the image content of the current frame ( MBTree); the adaptive quantization module 107 is configured to calculate the average macroblock energy of the current frame according to the macroblock structure and the image content of the current frame, and determine the preset quantization intensity factor corresponding to the average macroblock energy; the macroblock The level quantization step size adjustment 106 is configured to adjust the initial quantization step size of the current frame according to the preset quantization intensity factor to obtain the quantization step size corresponding to the current frame; the encoding module 109 is configured to be configured according to the current frame. The corresponding quantization step size The current frame is long encoded, and the above process continues until all frames in the to-be-encoded video are encoded, and the encoded code stream is output.
  • the quantization level calculation module 103 needs to obtain the code calculated by the code rate factor calculation module 102 according to the feedback of the coding result of the previous frame.
  • the rate factor is used to adjust the quantization weight calculated by itself to obtain the initial quantization level.
  • the feedback of the encoding result of the previous frame cannot be obtained at the position of the first frame.
  • the initial quantization level of the first frame is calculated by the code rate factor of the value, and then the initial quantization step size, that is, the QP value, is calculated based on the initial quantization level.
  • the QP value of the first frame cannot be adaptively adjusted according to the complexity, resulting in a waste of bit rate and reducing the quality of the overall video.
  • the quantization intensity factor calculated in the adaptive quantization module 107 is in a fixed state during the entire video encoding process, but in actual encoding, the video to be encoded is in a fixed state. The video content is constantly changing.
  • the quantization step size adjusted according to the larger quantization intensity factor will increase significantly, which will lead to serious problems in the complex area under the condition of low bit rate. blurring, which further degrades the overall video quality.
  • An embodiment of the present application provides an encoding method, which is applied to an encoder, as shown in Figure 2:
  • the encoder first obtains image information of the first frame.
  • 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.
  • the execution process of the macroblock calculation module 108 is logically prior to the inter-frame-level rate control process , considering that in the process of FIG. 1, 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 to evaluate the average macroblock energy.
  • the accumulated complexity value of the first frame in the video to be encoded is shown in FIG. 3 .
  • the macroblock calculation module 108 in FIG. 3 feeds back the calculated average macroblock energy of the first frame to the rate factor calculation module 102 in the inter-frame-level rate control process, so that the rate factor
  • the calculation module 102 can calculate the code 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 code rate factor.
  • the encoder may, as shown in FIG. information, calculate the gradient value, edge information or histogram information of the current frame, and feed 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
  • the gradient value, edge information or histogram information of the first frame is used to calculate the bit rate factor, and then the initial quantization step size corresponding to the first frame is adjusted according to the bit rate factor.
  • 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 is used 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 determine the content of the current frame according to the edge information. Identify and analyze; or, the encoder can also calculate the histogram information that can reflect the brightness, brightness, and gradation distribution of the current frame according to the grayscale information in the pixel information, and use the histogram information as the image information of the current frame.
  • the encoder calculates the complexity cumulative 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 first frame complexity cumulative value, so that the first frame The quantitative proportions are adjusted.
  • a corresponding objective function model may be established in advance, 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 to output
  • the initial quantization step size meets the goal of low bit rate, high-quality video applications, and analyzes the pros and cons of the output initial quantization step size through multiple simulation experiments, and fits the initial quantization step size and the image through function fitting information curve, 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, and then according to the functional relationship between the initial quantization step size and the image information, and the initial quantization step size and the image information.
  • Based on the preset functional relationship between the accumulated complexity values a relationship formula between the image information of the current frame and the accumulated complexity value is derived, and the accumulated complexity value of the current frame is calculated based on the relationship formula.
  • the relationship formula between the image information of the current frame and the accumulated complexity value is obtained by curve fitting the initial quantization step size and image information through multiple simulation experiments, the image information of the current frame can be obtained by curve fitting.
  • the calculated cumulative complexity value can better adapt to the real image content of the current frame, thereby ensuring that the bit rate factor calculated according to the cumulative complexity value and the initial quantization step size adjusted according to the bit rate factor are more accurate.
  • the encoder may calculate the cumulative complexity value of the first frame based on the image information of the first frame.
  • the encoder may calculate the cumulative complexity value of the non-first frame in combination with the encoding result of the previous frame that is not the first frame.
  • the encoder may first estimate the complexity of the current frame through the complexity estimation module, calculate the initial quantization step size of the current frame according to the complexity, and then calculate the first frame according to the accumulated complexity value of the current frame For the corresponding bit rate factor, adjust the quantization weight 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.
  • the preset mapping relationship converts the quantization level into the initial quantization step size.
  • the encoder after the encoder obtains the initial quantization step size of the current frame, that is, the QP value, the code rate control process at the inter-frame level corresponding to the current frame is completed, and the encoder can continue to go through the macroblock-level code rate control process.
  • the initial quantization step size of the current frame is adjusted to obtain the quantization step size of the current frame.
  • an implementation manner of the macroblock-level rate control process may be as shown in FIG. 5 .
  • the encoder may perform a macroblock energy calculation process, The current frame is divided into a number of different macroblocks according to the image content, and the macroblock energy of each macroblock is calculated according to the pixel value and the square error sum of the pixels in each macroblock, and then the average macroblock of the current frame is obtained. energy.
  • the average macroblock energy obtained in the process of calculating the macroblock energy will, in the adaptive quantization adjustment process, obtain a preset quantization intensity factor corresponding to the average macroblock energy according to the correspondence between the average macroblock energy and the preset quantization intensity factor, and finally In the quantization step size adjustment process, the offset value of the initial quantization step size is obtained by the preset quantization intensity factor, and then the initial quantization step size is adjusted by the offset value of the initial quantization step size to obtain the quantization step size of the current frame.
  • the encoder can select a lower preset quantization strength factor aq_strength value, exemplarily, the selection value is 0.6-0.8 aq_strength in between, in order to retain more high-frequency details and improve the overall video quality; and if there are many static pictures in the current frame, the corresponding average macroblock energy is low, and the encoder can choose a higher aq_strength value, 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.
  • the above method and process can be implemented by the following code:
  • FIG. 6 another implementation manner of the macroblock-level rate control process may be as shown in FIG. 6 .
  • the encoder uses the macroblock energy calculation process
  • the calculated macroblock energy of each macroblock obtains the content complexity of each macroblock through the complexity information calculation process, and according to the preset complexity benchmark, in the complexity benchmark adjustment process, the current frame is based on each macroblock.
  • the content complexity of the macroblock is divided into different regions, and different preset quantization strength factors aq_strength are set in different regions through the adaptive quantization process.
  • the factor aq_strength adjusts the offset of the initial quantization step size to obtain the quantization step size corresponding to the area, so as to realize the change of the preset quantization strength factor aq_strength with the complexity of the image, which can reduce the preset quantization strength factor of complex areas and reduce the complexity of The blurring phenomenon of the area is improved, and the adaptability of the preset quantization intensity factor to the video content is improved.
  • the encoder can encode the current frame based on the quantization step size to obtain the encoding result of the current frame. Based on the encoding result of the current frame, the encoder performs the encoding of the next frame with the same rate control process until the encoding of the to-be-encoded video is completed.
  • the encoder can obtain the accumulated complexity value corresponding to the first frame based on the image information of the first frame, and then further calculates according to the accumulated complexity value to obtain the first frame.
  • the initial quantization step size of the first frame can be set adaptively according to the complexity of the first frame, so as to avoid the waste of bit rate caused by manually setting the unreasonable initial quantization step size of the first frame, and improve the The quality of the encoded video.
  • the encoder can perform preset quantization intensity factor settings for the current frame according to the complexity of the macroblock, so that the current frame can be set according to different preset quantization intensity factors. Appropriate quantization step sizes are calculated respectively for different complexity regions of the image, realizing the self-adaptation of the preset quantization intensity factor with the complexity of the image, improving the clarity of the image, and further improving the quality of the encoded video.
  • the encoding method in the embodiment of the present application is further described by taking the average macroblock energy of the first frame as the image information as an example.
  • the encoder in S101 obtains the image information of the current video through S1011- S1012 implementation, as shown in Figure 7:
  • the encoder divides the current frame into macroblocks based on the image content of the current frame through the macroblock calculation module to obtain at least one macroblock.
  • At least one macroblock may be in the form of an MB tree.
  • S1012. Calculate the average macroblock energy of at least one macroblock as image information of the current frame.
  • the encoder may calculate the macroblock energy of each macroblock by using the pixel value and the sum of squared errors in each macroblock of at least one macroblock, and then calculate the macroblock energy of each macroblock according to the macroblock energy of each macroblock.
  • the average macroblock energy of the at least one macroblock is obtained, and the average macroblock energy of the at least one macroblock is used as the image information of the current frame.
  • the average macroblock energy is used as the image information of the first frame, and the average macroblock energy calculated in the macroblock-level rate control process can be directly used, and additional image processing work is not required. the computational complexity of the encoder.
  • the encoder in S102 is based on the image information of the current frame, Calculating the complexity cumulative value of the current frame can be achieved through S1021-S1022, as shown in Figure 8:
  • 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
  • the process of obtaining the estimated coding complexity of the current frame may include: Multiply the average macroblock energy by the first fitting factor to obtain the first product result; multiply the preset first frame coded bits by the second fitting factor to obtain the second product result; calculate the first product result minus the second product The difference value of the results, and the difference value and the third fitting factor are added to obtain the estimated coding complexity; wherein, at least one preset fitting factor includes the first fitting factor, the second fitting factor and the third fitting factor. combination factor. As shown in formula (1):
  • cplxr_zero s 1 ⁇ avg_energy-s 2 ⁇ wanted_bits_window+s 3 (1)
  • avg_energy is the average macroblock energy of the current frame, that is, the first frame
  • cplxr_zero is the estimated complexity of the current frame calculated according to the average macroblock energy
  • s 1 , s 2 and s 3 are at least one The first fitting factor, the second fitting factor and the third fitting factor in the preset fitting factors.
  • At least one preset fitting factor in the embodiment of the present application is to adjust the relationship between the initial quantization step size and avg_energy through a large number of simulation experiments, so as to meet the low bit rate and high quality video application as the goal, analyze the initial test video
  • the pros and cons of the quantization step size are obtained by fitting the QP-energy function curve corresponding to the initial quantization step size and the average macroblock energy, that is to say, at least one preset fitting factor in formula (1) is a pass function
  • the value of s 1 may be 13000, the value of s 2 may be 0.3858, and the value of s 3 may be 515000, or it may be calculated by means of function curve fitting according to the actual encoding target Other values are specifically selected according to actual applications, which are not limited in this embodiment of the present application.
  • wanted_bits_window is the preset first frame encoding bit, which is used to represent 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:
  • wanted_bits_window bitrate/fps (2)
  • bitrate represents the encoded bitrate
  • bitrate of the first frame is the default value
  • bitrate of the non-first frame is the bitrate corresponding to the previous frame after encoding , so the wanted_bits_window of the first frame is also the default value.
  • the encoder calculates the complexity cumulative value of the current frame based on the estimated coding complexity, which may include:
  • the encoder may perform an update calculation on the cumulative value of the estimated coding complexity according to the macroblock data of at least one macroblock and a preset compression parameter, so as to obtain the complexity update value of the current frame.
  • the encoder may obtain the number of macroblocks of at least one macroblock obtained by dividing the macroblock by the macroblock calculation module, and calculate the preset compression parameter power and the preset coefficient to estimate the coding complexity, and The product of the one-half power of the number of macroblocks is the cumulative value of the complexity of the current frame.
  • 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.
  • cplxr_sum is the accumulated complexity value of the current frame.
  • the code implementation for the encoder to calculate the complexity cumulative value cplxr_sum of the current frame through S1021-S1022 may be as follows:
  • rc->cplxr_sum .01*pow(rc->cplxr_sum,rc->qcompress)*pow(h->mb.i_mb_count,0.5);//The code instruction corresponding to formula (3), through the preset compression parameter rc ->qcompress and the number of macroblocks h->mb.i_mb_count of at least one macroblock, execute the code instruction corresponding to the process of formula (3), update the initial value corresponding to the variable rc->cplxr_sum, and obtain the complexity accumulation of the current frame value;
  • rc->cplxr_sum .01*pow(7.0e5,rc->qcompress)*pow(h->mb.i_mb_count,0.5);//Calculate the first frame by the fixed value 7.0e5 set manually, that is, 7 ⁇ 10 5 The cumulative value of the complexity;
  • the current inter-frame-level rate control process initializes the complexity cumulative value cplxr_sum of the first frame with a fixed value, such as 7 ⁇ 10 5 , so it cannot be initialized according to the actual complexity of the first frame.
  • Adaptive adjustment of the value which affects the accuracy of the complexity cumulative value calculated based on the initial value, and then affects the initial quantization step size of the first frame calculated by the inter-frame-level rate control process, reducing the encoded video. quality.
  • the estimated coding complexity of the first frame can be obtained by calculating the average macroblock energy of the first frame of video, and then the cumulative complexity value cplxr_sum of the first frame can be obtained by calculating the estimated coding complexity of the first frame, and further
  • the initial quantization step size of the first frame is calculated according to the accumulated complexity value cplxr_sum, which realizes that the initial quantization step size of the first frame calculated by the inter-frame rate control can be adaptively adjusted following the complexity of the first frame, thereby improving the initial quantization of the first frame.
  • the rationality of the step size setting saves the encoding bit rate and improves the encoded video quality.
  • the encoder when the current frame is a non-first frame in the video to be encoded, the encoder may, based on the number of encoded bits of the previous frame corresponding to the current frame, differ from the The quantization parameter is used to accumulate the complexity to obtain the accumulated complexity value of the current frame. That is to say, when the current frame is not the first frame, the encoder can calculate the cumulative complexity value of the current frame according to the encoding result of the previous frame.
  • the above process can be as shown in formula (5). Show:
  • bits(i-1) is the actual number of bits obtained from the encoding of the previous frame
  • qscale_raw(i-1) is the quantized weight value corresponding to the previous frame without adjustment of the bit rate factor
  • qscale_adj(i- 1) is the initial quantization level corresponding to the previous frame adjusted by the bit rate factor
  • cplxr_sum(i-1) is the accumulated complexity value corresponding to the previous frame
  • cplxr_sum(i) is the accumulated complexity value of the current frame.
  • the accumulated complexity value of the current frame is an iterative amount, which is gradually accumulated during the encoding process. Therefore, the setting of the accumulated complexity value of the first frame will affect the encoding quality of the entire video.
  • the method in the embodiment of the present application calculates the cumulative complexity value of the first frame by averaging the macroblock energy, so that the cumulative value of the complexity of the first frame can be adaptively adjusted according to the complexity of the first frame, so that the cumulative value of the complexity of the first frame can be adjusted adaptively.
  • the settings are more accurate, thereby improving the quality of the entire video encoding.
  • the encoder in S103 performs encoding and quantization estimation on the current frame based on the complexity cumulative value of the current frame, and obtaining the initial quantization step size of the current frame can be achieved through S1031-S1034, As shown in Figure 9:
  • the encoder performs sampling filtering on the current frame to obtain a small image with half the original resolution, makes half-pixel precision prediction on the small image, subtracts it from the original image to obtain a residual, and then performs a halves on the residual.
  • Deman transform and absolute sum to obtain SATD then the fuzzy complexity of the current frame can be obtained according to the weighted average of the SATD values of the current frame and the previous adjacent frames.
  • the estimation of the fuzzy complexity of the current frame by the encoder may be as shown in formula (6) and formula (7), as follows:
  • BlurCplx represents blur complexity
  • the encoder can obtain BlurCplx by weighting the complexity of adjacent coded frames according to formula (6).
  • Cplxsum represents the weighted sum of coding complexity
  • Cplxcount represents the weighted sum of coding frame numbers. The calculation methods of Cplxsum and Cplxcount are shown in formula (7).
  • i is the serial number of the frame to be encoded
  • satd is the sum of absolute values of residuals of the current frame after motion compensation, SATD
  • the satd of the first frame is a preset value
  • the satd of the non-first frame can be calculated according to the time-frequency transformation, which is used to reflect the size of the generated code stream.
  • the perceptual coding optimization method performs nonlinear compression on the fuzzy complexity of the current frame to reduce the code rate, as shown in formula (8):
  • S1032 Calculate the ratio between the total bit value of the encoded frames in the to-be-encoded video and the accumulated complexity value to obtain the bit rate factor of the current frame.
  • the encoder calculates the ratio between the total bit value of the encoded frames in the to-be-encoded video and the accumulated complexity value as the bit rate factor of the current frame, as shown in formula (9) and formula (10) :
  • ratefactor is the rate factor of the current frame generated by the rate factor calculation module according to the bitrate of the encoded frame.
  • 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.
  • the encoder can calculate the ratio of the quantization ratio rceq to the code rate factor ratefactor by formula (10), to obtain the initial quantization level of the current frame:
  • qscale is the initial quantization level of the current frame.
  • the encoder may adjust the initial quantization level based on the preset target number of bits to obtain the quantization level of the current frame.
  • the encoder can obtain the quantization of the current frame by calculating the difference between the preset target number of bits and the total bit value generated after the actual encoding of the current frame, and then adjusting the initial quantization level according to the difference. level, so that the size of the generated code stream can be stabilized.
  • the preset target number of bits may be the size of the buffer at the receiving end corresponding to the encoded video, and the encoder may adjust the initial quantization level based on the preset target number of bits through the buffer control module to obtain the current frame's Quantization level.
  • mapping relationship between the preset quantization level and the initial quantization step size may be as shown in formula (11):
  • a, b, and c are empirical value coefficients. In some embodiments, a can take a value of 12, b can take a value of 6, c can take a value of 0.85, qscale is a quantization level, and QP is The quantization step size converted from the quantization level.
  • 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.
  • the complexity cumulative value calculated according to the estimated coding complexity in formula (3) is then used to calculate the bit rate factor in formula (9), and then In formula (10), the initial quantization level is calculated based on the code rate factor, and finally the initial quantization level is converted into an initial quantization step size. That is to say, the accumulated complexity value can play the role of a compression coefficient when calculating the initial quantization step size, that is, the QP value.
  • the estimated coding complexity of the first frame can be adaptively adjusted according to the average macroblock energy of the first frame, thereby realizing the adaptive adjustment of the accumulated complexity value of the first frame and the initial quantization step size, thereby Improved the quality of the encoded video.
  • the encoder in S104 encodes the current frame based on the initial quantization step size of the current frame, and obtaining the encoding result of the current frame can be achieved through S1041-S1044, as shown in the figure 10 shows:
  • the encoder divides the current frame into macroblocks, and after obtaining at least one macroblock, it calculates the average macroblock energy of the at least one macroblock.
  • the encoder needs to first calculate the macroblock energy of each macroblock, and then calculate the average macroblock energy of at least one macroblock.
  • the encoder can acquire the complexity data generated in the process of calculating the energy of the macroblock, that is, in the process of calculating the energy of each macroblock, as the content complexity of each macroblock.
  • the encoder first sets a preset complexity threshold.
  • the preset complexity threshold may be determined according to prior knowledge.
  • the preset complexity threshold may be between [80000, 85000]. value, preferably, the preset complexity threshold can be 82400.
  • the encoder compares the content complexity of each macroblock with a preset complexity threshold, divides the current frame into regions in units of macroblocks, and divides macroblocks whose complexity is higher than the preset complexity threshold. Blocks and macroblocks whose complexity is lower than a preset complexity threshold are divided into different regions, thereby obtaining at least one region. Wherein, the complexity of each region in at least one region is different.
  • the encoder can divide the current frame into a high-complexity region and a low-complexity region by presetting a complexity threshold.
  • S1043. Determine a preset quantization intensity factor of each area in the at least one area, and adjust the initial quantization step size according to the preset quantization intensity factor corresponding to each area to obtain a quantization step size corresponding to each area.
  • the encoder first determines the area complexity of each area according to the content complexity of the macroblocks included in each area.
  • the encoder may calculate the mean value of the content complexity of each macroblock included in each area as the area complexity of each area, or may also calculate the mean value according to other measurement methods, such as variance, etc. The selection is made according to the actual situation, which is not limited in the embodiments of the present application.
  • the encoder determines the preset quantization intensity factor for each region according to the preset correspondence between the region complexity and the preset quantization intensity factor.
  • the size of the preset quantization intensity factor is inversely proportional to its corresponding area complexity.
  • the preset quantization strength factor aq_strength may be used to adjust the block effect in the flat area and the blurring effect in the texture area.
  • the higher the aq_strength the more high-frequency information in the complex area is reduced, but the improved definition of the flat area also means that the texture is more blurred, conversely, the lower the aq_strength, the more high-frequency information in the complex area is retained, while the The sharpness is reduced, which means that the textured areas are sharper.
  • 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 of the low-complexity region to be 0.5
  • the factor aq_strength is 1.0, so that for high-complexity areas with more complex scenes, a lower aq_strength can be used to reduce the blurring phenomenon and improve the overall quality of the encoded video.
  • the above process can be implemented by the following code:
  • h->param.rc.f_aq_strength_cplx 0.5, indicating that the value of the preset quantization strength factor aq_strength of the high-complexity region is set to 0.5, and frame->s_cplx is the content complexity of each macroblock in the region
  • the encoder can use the preset quantization strength factor aq_strength corresponding to the high complexity area, such as 0.5, to set the high complexity area
  • the initial quantization step long to reduce blurring in highly complex areas.
  • the encoder uses the same method to determine the preset quantization intensity factor set in each region according to the regional complexity of the region, and according to the preset quantization intensity factor respectively set in each region, pair the The initial quantization step size is adjusted to obtain the corresponding quantization step size for each region. That is to say, the quantization step size for quantizing the current frame finally calculated in the embodiment of the present application is at least one quantization step size corresponding to at least one area divided with different complexity in the current frame, so it can be calculated according to the current frame The area complexity of the content scene in the quantization step size is adaptively adjusted.
  • each region of the current frame is encoded to obtain the encoding result of the current frame.
  • the encoder encodes each area of the current frame according to the quantization step size corresponding to each area, and obtains an encoding result of the current frame.
  • the encoder divides the current frame according to the complexity of the macroblock, so that when adjusting the quantization step size in the process of the macroblock-level rate control, the quantization step size can be adjusted according to the complexity of the current frame.
  • the adaptive adjustment of sub-regions improves the accuracy of the quantization step size, thereby improving the accuracy of the encoded video.
  • the encoding method of the embodiment of the present application can ensure the ability of the encoder to control the code rate, and will not cause the failure of the code rate control due to the introduction of the algorithm, At the same time, the coding method according to the embodiment of the present application improves the objective quality of PSNR by about 0.145dB on average. From this, 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.
  • FIG. 11 is a schematic structural diagram 1 of an encoder provided by an embodiment of the present application.
  • the encoder 11 includes: an acquisition part 1101 , a calculation part 1102 , and a quantization part part 1103 and encoding part 1104, where,
  • the acquisition part 1101 is configured to acquire image information of the current frame in the inter-frame-level code rate control process when the current frame is the first frame in the video to be encoded;
  • the calculating part 1102 is configured to calculate the complexity cumulative value of the current frame based on the image information of the current frame;
  • the quantization part 1103 is configured to perform coding and quantization estimation on the current frame based on the cumulative complexity value of the current frame to obtain the initial quantization step size of the current frame;
  • the encoding part 1104 is configured 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.
  • 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.
  • the image information is the average macroblock energy of the first frame
  • the calculating part 1102 is further configured to calculate the average macroblock energy according to the average macroblock energy, a preset first frame coding bit and at least one preset
  • the fitting factor evaluates the complexity of the current frame to obtain the estimated coding complexity of the current frame; the at least one preset fitting factor is used to fit the difference between the average macroblock energy and the initial quantization step size The relationship curve between; based on the estimated coding complexity, calculate the complexity cumulative value of the current frame.
  • the calculating part 1102 is further configured to multiply the average macroblock energy by a first fitting factor to obtain a first product result; multiply the preset first frame coded bits by a second Fitting factors 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 code complexity; wherein, the at least one preset fitting factor includes the first fitting factor, the second fitting factor, and the third fitting factor.
  • the obtaining part 1101 is further configured to perform macroblock division on the current frame during the macroblock-level rate control process to obtain at least one macroblock; calculate the at least one macroblock The average macroblock energy is used as the image information of the current frame.
  • the calculating part 1102 is further configured to obtain the number of macroblocks of the at least one macroblock; according to the estimated coding complexity, the number of macroblocks of the at least one macroblock and a preset compression parameter , to obtain the cumulative complexity value of the current frame.
  • the calculating part 1102 is further configured to calculate the preset compression parameter as the power of the estimated coding complexity, and compare the calculation result with the preset coefficient and the macro The multiplication of the one-half power of the number of blocks is performed to obtain the cumulative complexity value of the current frame.
  • the acquiring part 1101 is further configured to calculate the gradient value, edge information or histogram information of the current frame according to the pixel information contained in the current frame.
  • the encoding part 1104 is further configured to obtain the content complexity of each macroblock after dividing the current frame into macroblocks in the macroblock-level rate control; the content complexity of the macroblocks and the preset complexity threshold, the current frame is divided into regions to obtain at least one region; the preset quantization intensity factor of each region in the at least one region is determined, and according to the According to the preset quantization intensity factor corresponding to each area, the initial quantization step size is adjusted to obtain the quantization step size corresponding to each area; according to the quantization step size corresponding to each area, the current frame to encode each region of the current frame to obtain the encoding result of the current frame.
  • the encoding part 1104 is further configured to determine the area complexity of each area according to the content complexity of the macroblocks contained in each area; according to the area complexity and the preset The preset corresponding relationship of the quantization intensity factors determines the preset quantization intensity factor of each area; the size of the preset quantization intensity factor is inversely proportional to the complexity of the area.
  • the quantization part 1103 is further configured to perform fuzzy complexity estimation on the current frame, and perform compression processing on the estimated fuzzy complexity, so as 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 cumulative value of the complexity to obtain the code rate factor of the current frame; Based on the complexity and the code 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 size, the quantization level of the current frame is converted into the initial quantization step size.
  • the quantization part 1103 is further configured to use the ratio of the complexity to the code rate factor as the initial quantization level of the current frame; The initial quantization level is adjusted to obtain the quantization level of the current frame.
  • the calculating part 1102 is configured to perform coding and quantization estimation on the current frame based on the accumulated complexity value of the current frame to obtain the initial quantization step size of the current frame , when the current frame is a non-first frame in the video to be encoded, the complexity is accumulated based on the encoded bits of the previous frame corresponding to the current frame and the quantization parameter of the previous frame processing to obtain the cumulative complexity value of the current frame.
  • the quantization part 1103 is further configured to calculate the difference between the preset target number of bits and the total bit value generated after encoding the current frame, and according to the difference The initial quantization level is adjusted to obtain the quantization level of the current frame.
  • the encoding part 1104 is further configured to calculate the average value of the content complexity of each macroblock included in each region as the region complexity of each region.
  • the encoding part 1104 is further configured to obtain the complexity data generated by the macroblock energy calculation process as the content complexity of each macroblock; the macroblock energy calculation process is used to calculate the macroblock energy of each macroblock to obtain the average macroblock energy of at least one macroblock.
  • 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 may also be stored in a computer-readable storage medium.
  • the technical solutions of the embodiments of the present application can be embodied in the form of software products in essence or in the parts that make contributions to the prior art.
  • the computer software products are stored in a storage medium and include several instructions for A computer device (which may be a terminal, a server, etc.) is caused to execute all or part of the methods described in the various embodiments of the present application.
  • the aforementioned storage medium includes: a U disk, a mobile hard disk, a read only memory (Read Only Memory, ROM), a magnetic disk or an optical disk and other media that can store program codes.
  • ROM Read Only Memory
  • the aforementioned storage medium includes: a U disk, a mobile hard disk, a read only memory (Read Only Memory, ROM), a magnetic disk or an optical disk and other media that can store program codes.
  • the embodiments of the present application are not limited to any specific combination of hardware and software.
  • the embodiments of the present application further provide a computer program product, where the computer program product includes computer-readable codes, and when the computer-readable codes run in an encoder, a processor in the encoder Execution is used to implement the encoding method provided by the embodiment of the present application.
  • the embodiments of the present application further provide a computer-readable storage medium, where computer-executable instructions are stored on the computer-readable storage medium, and the computer-executable instructions are configured to cause the processor to execute the above-mentioned embodiments.
  • FIG. 12 is a second schematic diagram of the composition and structure of an encoder provided by an embodiment of the present application.
  • the encoder 1200 includes: a memory 1201 configured to store Computer program;
  • the processor 1202 is configured to implement the steps of the encoding method provided by the above embodiment when executing the computer program stored in the memory 1201;
  • the encoder 1200 also includes a communication bus 1203; it is configured to connect the memory 1201 and the processor 1202, and realize the connection and communication between the memory 1201 and the processor 1202.
  • the memory 1201 is configured to store computer programs and applications by the processor 1202, and can also cache data to be processed or processed by the processor 1202 and modules in the encoder (eg, image data, audio data, voice communication data, and video communication data). data), which can be implemented through flash memory (FLASH) or random access memory (Random Access Memory, RAM).
  • the above-mentioned processor 1202 may be an Application Specific Integrated Circuit (ASIC), a Digital Signal Processor (DSP), a Digital Signal Processing Device (DSPD), a Programmable Logic Device (Programmable Logic Device) At least one of a Logic Device (PLD), a Field Programmable Gate Array (FPGA), a Central Processing Unit (CPU), a controller, a microcontroller, and a microprocessor.
  • ASIC Application Specific Integrated Circuit
  • DSP Digital Signal Processor
  • DSPD Digital Signal Processing Device
  • PROM Programmable Logic Device
  • PLD Logic Device
  • FPGA Field Programmable Gate Array
  • CPU Central Processing Unit
  • controller a controller
  • microcontroller a microcontroller
  • the above-mentioned computer-readable storage medium/memory can be a read-only memory (Read Only Memory, ROM), a programmable read-only memory (Programmable Read-Only Memory, PROM), an erasable programmable read-only memory (Erasable Programmable Read-Only Memory) Memory, EPROM), Electrically Erasable Programmable Read-Only Memory (EEPROM), Magnetic Random Access Memory (FRAM), Flash Memory (Flash Memory), Magnetic Surface Memory, optical disk, or memory such as Compact Disc Read-Only Memory (CD-ROM); it can also be various terminals including one or any combination of the above memories, such as mobile phones, computers, tablet devices, personal digital Assistant etc.
  • the disclosed apparatus and method may be implemented in other manners.
  • the device embodiments described above are only illustrative.
  • the division of the units is only a logical function division. In actual implementation, there may be other division methods.
  • multiple units or components may be combined, or Can be integrated into another system, or some features can be ignored, or not implemented.
  • the coupling, or direct coupling, or communication connection between the various components shown or discussed may be through some interfaces, and the indirect coupling or communication connection of devices or units may be electrical, mechanical or other forms. of.
  • the unit described above as a separate component may or may not be physically separated, and the component displayed as a unit may or may not be a physical unit; it may be located in one place or distributed to multiple network units; Some or all of the units may be selected according to actual needs to achieve the purpose of the solutions of the embodiments of the present application.
  • each functional unit in each embodiment of the present application may all be integrated into one processing unit, or each unit may be separately used as a unit, or two or more units may be integrated into one unit; the above integration
  • the unit can be implemented either in the form of hardware or in the form of hardware plus software functional units.
  • the above-mentioned integrated units of the present application are implemented in the form of software function modules and sold or used as independent products, they may also be stored in a computer-readable storage medium.
  • the technical solutions of the embodiments of the present application may be embodied in the form of software products in essence or the parts that contribute to related technologies.
  • the computer software products are stored in a storage medium and include several instructions to make The automatic test line of the device performs all or part of the methods described in the various embodiments of the present application.
  • the aforementioned storage medium includes various media that can store program codes, such as a removable storage device, a ROM, a magnetic disk, or an optical disk.
  • the accumulated complexity value of the first frame can be evaluated by using the image information of the first frame, and the initial quantization step size, that is, the QP value, is reasonably set based on the accumulated complexity value of the first frame, so that the QP value can be reasonably set.
  • Adaptive adjustment is performed according to the image information of the first frame, so that the video encoding based on the QP value can obtain a more accurate encoding result, and finally the video quality of the encoded video is improved.
  • the current frame is divided into regions by the complexity of the macroblock, so that when the quantization step size is adjusted in the macroblock-level rate control process, the adaptive adjustment of the subregions can be performed according to the complexity of the current frame, which improves the quantization step. long precision, thus improving the precision of the encoded video. According to the experimental comparison data, it can be concluded that the encoding method in the embodiment of the present application can improve the video quality of the encoded video without causing a burden on the compression rate.

Landscapes

  • Engineering & Computer Science (AREA)
  • Multimedia (AREA)
  • Signal Processing (AREA)
  • Compression Or Coding Systems Of Tv Signals (AREA)

Abstract

Disclosed in embodiments of the present application are an encoding method, an encoder and a computer readable storage medium for improving the video quality of an encoded video. The method comprises: when a current frame is a first frame in a video to be encoded, obtaining image information of the current frame in an inter-frame level code rate control process; calculating a complexity accumulation value of the current frame on the basis of the image information of the current frame; performing coded quantization estimation on the current frame on the basis of the complexity accumulation value of the current frame to obtain an initial quantization step length of the current frame; and encoding the current frame on the basis of the initial quantization step length of the current frame to obtain the encoding result of the current frame.

Description

一种编码方法、编码器及计算机可读存储介质An encoding method, encoder and computer-readable storage medium
相关申请的交叉引用CROSS-REFERENCE TO RELATED APPLICATIONS
本申请基于申请号为202010693484.8、申请日为2020年7月17日的中国专利申请提出,并要求该中国专利申请的优先权,该中国专利申请的全部内容在此引入本申请作为参考。This application is based on the Chinese patent application with the application number of 202010693484.8 and the application date of July 17, 2020, and claims the priority of the Chinese patent application. The entire content of the Chinese patent application is incorporated herein by reference.
技术领域technical field
本申请涉及音视频编码领域,尤其涉及一种编码方法、编码器及计算机可读存储介质。The present application relates to the field of audio and video encoding, and in particular, to an encoding method, an encoder, and a computer-readable storage medium.
背景技术Background technique
视频编码是一种视频压缩技术,是利用视频信息的时域冗余和空域冗余对视频进行压缩的技术,可以达到减小视频占用的存储空间和网络带宽的目的。码率控制是视频编码中的一项关键技术,其目的是在保证视频压缩后所占用比特数一定的情况下使得视频的客观质量最优。量化参数(QuantizationParameter,QP)是视频编码技术中的一个关键参数,直接决定视频编码单元的压缩程度,从而控制视频编码后的码率和视频质量。相关技术中,在对用于计算量化参数的首帧复杂度进行初始值设置时,通常采用人工预设的固定值作为初始值,容易造成对首帧编码时设置的QP不合理,导致即时解码刷新(Instantaneous Decoding Refresh,IDR)帧的码率浪费,从而降低了编码视频的视频质量。Video coding is a video compression technology, which 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 a certain number of bits occupied after video compression. The Quantization Parameter (QP) is a key parameter in the video coding technology, which directly determines the compression degree of the video coding unit, thereby controlling the bit rate and video quality after video coding. In the related art, when setting the initial value of the complexity of the first frame used to calculate the quantization parameter, a fixed value preset manually is usually used as the initial value, which easily causes the QP set when encoding the first frame to be unreasonable, resulting in instant decoding. The bit rate of the Instantaneous Decoding Refresh (IDR) frame is wasted, thereby reducing the video quality of the encoded video.
发明内容SUMMARY OF THE INVENTION
本申请实施例期望提供一种编码方法、编码器及计算机可读存储介质,能够提高编码视频的视频质量。The embodiments of the present application are expected to provide an encoding method, an encoder, and a computer-readable storage medium, which can improve the video quality of the encoded video.
本申请的技术方案是这样实现的:The technical solution of the present application is realized as follows:
第一方面,本申请实施例提供了一种编码方法,应用于编码器,包括:In a first aspect, an embodiment of the present application provides an encoding method, which is applied to an encoder, including:
当当前帧为待编码视频中的首帧时,在帧间级码率控制过程中,获取当前帧的图像信息;When the current frame is the first frame in the video to be encoded, in the inter-frame-level rate control process, the image information of the current frame is acquired;
基于所述当前帧的图像信息,计算当前帧的复杂度累积值;Calculate the complexity cumulative value of the current frame based on the image information of the current frame;
基于所述当前帧的复杂度累积值,对所述当前帧进行编码量化估计,得到所述当前帧的初始量化步长;Based on the cumulative complexity value of the current frame, perform coding and quantization estimation on the current frame to obtain an initial quantization step size of the current frame;
基于所述当前帧的初始量化步长,对所述当前帧进行编码,得到所述当前帧的编码结果。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.
第二方面,本申请实施例提供了一种编码器,包括:获取部分、计算部分、量化部分与编码部分,其中,In a second aspect, an embodiment of the present application provides an encoder, including: an acquisition part, a calculation part, a quantization part, and an encoding part, wherein,
所述获取部分,被配置为当当前帧为待编码视频中的首帧时,在帧间级码率控制过程中,获取当前帧的图像信息;The acquisition part is configured to acquire image information of the current frame in the inter-frame-level code rate control process when the current frame is the first frame in the video to be encoded;
所述计算部分,被配置为基于所述当前帧的图像信息,计算当前帧的复杂度累积值;The calculation part is configured to calculate the complexity cumulative value of the current frame based on the image information of the current frame;
所述量化部分,被配置为基于所述当前帧的复杂度累积值,对所述当前帧进行编码量化估计,得到所述当前帧的初始量化步长;The quantization part is configured to perform coding and quantization estimation on the current frame based on the cumulative complexity value of the current frame to obtain an initial quantization step size of the current frame;
所述编码部分,被配置为基于所述当前帧的初始量化步长,对所述当前帧进行编码,得到所述当前帧的编码结果。The encoding part is configured 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.
第三方面,本申请实施例提供了一种编码器,包括:In a third aspect, an embodiment of the present application provides an encoder, including:
存储器,被配置为存储可执行数据指令;a memory configured to store executable data instructions;
处理器,被配置为执行所述存储器中存储的可执行指令时,实现如上述任一种所述的编码方法。The processor, when configured to execute the executable instructions stored in the memory, implements any of the encoding methods described above.
第四方面,本申请实施例提供了一种计算机可读存储介质,存储有可执行指令,被配置为引起处理器执行时,实现如上述任一种所述的编码方法。In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium storing executable instructions configured to cause a processor to execute any of the encoding methods described above.
第五方面,本申请实施例提供了一种计算机程序产品,所述计算机程序产品包括计算机可读代码,在所述计算机可读代码在编码器中运行的情况下,所述编码器中的处理器执行用于实现如上述任一种所述的编码方法。In a fifth aspect, embodiments of the present application provide a computer program product, where the computer program product includes computer-readable codes, and when the computer-readable codes run in an encoder, processing in the encoder The processor implements the encoding method as described in any of the above.
本申请实施例提供了一种编码方法、编码器及计算机可读存储介质,方法包括:当当前帧为待编码视频中的首帧时,在帧间级码率控制过程中,获取当前帧的图像信息;基于当前帧的图像信息,计算当前帧的复杂度累积值;基于当前帧的复杂度累积值,对当前帧进行编码量化估计,得到当前帧的初始量化步长;基于当前帧的初始量化步长,对当前帧进行编码,得到当前帧的编码结果。通过本申请实施例中的方法,可以通过首帧的图像信息来评估首帧的复杂度累积值,并基于首帧的复杂度累积值对初始量化步长,即QP值进行合理设置,实现了QP值可以根据首帧的图像信息进行自适应调整,使得基于QP值进行的视频编码能够得到更准确的编码结果,最终提高了编码视频的视频质量。Embodiments of the present application provide an encoding method, an encoder, and a computer-readable storage medium. The method includes: when the current frame is the first frame in the video to be encoded, in an inter-frame-level rate control process, obtaining the current frame's Image information; based on the image information of the current frame, calculate the cumulative complexity value of the current frame; based on the cumulative complexity value of the current frame, perform coding and quantization estimation on the current frame to obtain the initial quantization step size of the current frame; based on the initial quantization step size of the current frame The quantization step size is used to encode the current frame to obtain the encoding result of the current frame. Through the method in the embodiment of the present application, the complexity accumulation value of the first frame can be evaluated by using the image information of the first frame, and the initial quantization step size, that is, the QP value, is reasonably set based on the complexity accumulation value of the first frame, thereby realizing The QP value can be adaptively adjusted according to the image information of the first frame, so that the video encoding based on the QP value can obtain more accurate encoding results, and finally improve the video quality of the encoded video.
附图说明Description of drawings
此处的附图被并入说明书中并构成本说明书的一部分,这些附图示出了符合本申请的实施例,并于说明书一起用于说明本申请实施例的技术方案。The accompanying drawings herein are incorporated into the specification and constitute a part of the specification. These drawings illustrate the embodiments in accordance with the present application, and together with the specification, are used to explain the technical solutions of the embodiments of the present application.
图1为目前的X.264编码系统的编码流程图;Fig. 1 is the coding flow chart of the current X.264 coding system;
图2为本申请实施例提供的一种编码方法的流程图一;2 is a flowchart 1 of an encoding method provided by an embodiment of the present application;
图3为本申请实施例提供的一种编码流程图一;FIG. 3 provides a coding flow chart 1 of an embodiment of the present application;
图4为本申请实施例提供的一种编码流程图二;Fig. 4 is a kind of coding flow chart 2 provided by the embodiment of this application;
图5为本申请实施例提供的宏块级码率控制过程的一种实现方式;FIG. 5 is an implementation manner of a macroblock-level rate control process provided by an embodiment of the present application;
图6为本申请实施例提供的宏块级码率控制过程的另一种实现方式;FIG. 6 is another implementation manner of a macroblock-level rate control process provided by an embodiment of the present application;
图7为本申请实施例提供的一种编码方法的流程图二;7 is a second flowchart of an encoding method provided by an embodiment of the present application;
图8为本申请实施例提供的一种编码方法的流程图三;8 is a third flowchart of an encoding method provided by an embodiment of the present application;
图9为本申请实施例提供的一种编码方法的流程图四;FIG. 9 is a fourth flowchart of an encoding method provided by an embodiment of the present application;
图10为本申请实施例提供的一种编码方法的流程图五;10 is a flowchart 5 of an encoding method provided by an embodiment of the present application;
图11为本申请实施例提供的一种编码器的组成结构示意图一FIG. 11 is a schematic diagram 1 of the composition and structure of an encoder according to an embodiment of the application
图12为本申请实施例提供的一种编码器的组成结构示意图二。FIG. 12 is a second schematic diagram of the composition and structure of an encoder according to an embodiment of the present application.
具体实施方式detailed description
下面将结合本申请实施例中的附图,对本申请实施例中的技术方案进行清楚、完整地描述。The technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present application.
对本申请实施例进行进一步详细说明之前,对本申请实施例中涉及的名词和术语进行说明,本申请实施例中涉及的名词和术语适用于如下的解释。Before further describing the embodiments of the present application in detail, the terms and terms involved in the embodiments of the present application are described, and the terms and terms involved in the embodiments of the present application are suitable for the following explanations.
1)H.264:高度压缩数字视频编解码器标准。1) H.264: A highly compressed digital video codec standard.
2)X.264:开源H.264视频编码函数库。2) X.264: Open source H.264 video encoding function library.
3)SATD:Sum of Absolute Transformed Difference,残差经哈德曼变换的4×4块的预测残差绝对值总和,是一种简单的时频变换,用来反映生成码流的大小。3) SATD: Sum of Absolute Transformed Difference, the sum of the absolute values of the prediction residuals of the 4×4 blocks of which the residuals are Hardman transformed, is a simple time-frequency transform used to reflect the size of the generated code stream.
4)QP:量化参数,即量化步长。QP的值越小,量化步长越小,量化的精度就越高,意味着同样画质的情况下,产生的数据量可能会更大。4) QP: quantization parameter, that is, the quantization step size. The smaller the value of QP, 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.
5)VBV:Video Buffering Verifier,视频缓存检验器,用于确保输出的编码码流在接收端不会发生缓冲区下溢。5) VBV: Video Buffering Verifier, a video buffering verifier, used to ensure that the output encoded stream does not underflow the buffer at the receiving end.
6)AQ:Adaptive Quantization,自适应量化。6) AQ: Adaptive Quantization, adaptive quantization.
7)MB:Macro Block,宏块。7) MB: Macro Block, macro block.
8)RCEQ:Rate-Control Equation,速率控制公式,RCEQ建立了一种运动复杂度到量化步长的映射模型。8) RCEQ: Rate-Control Equation, rate control formula, RCEQ establishes a mapping model from motion complexity to quantization step size.
9)PSNR:Peak Signal to Noise Ratio,峰值信噪比,用于评价图像画质的客观量测法。9) PSNR: Peak Signal to Noise Ratio, an objective measurement method for evaluating image quality.
H.264采用拉格朗日代价函数来控制编码,这也是H.264编码复杂度较高的主要原因之一,X.264作为H.264的应用版本,采用半精度帧的SATD作为QP选择的主要依据。X.264码率控制过程分为帧间级码率控制过程和宏块级码率控制过程,其中,每一帧QP值的分配由帧间级码率控制来实现,而每一帧帧内的QP值的分配由宏块级码率控制来实现。X.264码率控制过程主要取决于两个变量,其一为视频帧的复杂度,其二是码率的预算。通常视频帧的复杂度越高,编码所需要的比特越多。如图1所示,图1为目前的X.264编码系统的编码流程图。待编码视频进入编码系统后,会同步进入帧间级码率控制过程与宏块级码率控制过程中,帧间级码率控制过程中,lookahead模块100,被配置为对待编码视频提供视频帧缓冲队列,辅助完成更稳定的码率控制,复杂度估计模块101,被配置为估计出待编码视频中当前帧的复杂度,示例性的,当前帧的复杂度可以是模糊复杂度;量化级别计算模块103,被配置为根据复杂度估计模块101输出的当前帧的复杂度进行量化级别的计算,得到当前帧对应的量化比重,并根据码率因子计算模块102提供的码率因子(ratefactor)对量化比重进行调整,得到初始量化级别;码率因子计算模块102,被配置为根据反馈的已编码帧的码率,计算出当前帧的复杂度累积值,再根据复杂度累积值计算出码率因子并提供给量化级别计算模块103;缓存控制(VBV)模块104,被配置为基于接收端缓冲区域的大小,对量化级别计算模块103输出的初始量化级别进行调整,得到量化级别;量化级别转换模块105,被配置为将量化级别转为初始量化步长提供给宏块级量化步长调整模块106。与此同时,宏块级的码率控制过程与帧间级码率控制过程同步进行,其中,宏块计算模块108,被配置为根据当前帧的图像内容,计算出当前帧的宏块结构(MBTree);自适应量化模块107,被配置为根据当前帧的宏块结构和图像内容计算出当前帧的平均宏块能量,并确定出与平均宏块能量对应的预设量化强度因子;宏块级量化步长调整106,被配置为根据预设量化强度因子对当前帧的初始量化步长进行调整,得到当前帧对应的量化步长;编码模块109,被配置为根据当前帧对应的量化步长对当前帧进行编码,持续上述过程直至待编码视频中的所有帧编码完毕后,输出编码完成的码流。H.264 uses the Lagrangian cost function to control the encoding, which is one of the main reasons for the high coding complexity of H.264. As the application version of H.264, X.264 uses the SATD of the half-precision frame as the QP selection. main basis. The X.264 rate control process is divided into an inter-frame-level rate control process and a macroblock-level rate control process. The allocation of the QP value of each frame is realized by the inter-frame-level rate control, and the The assignment of QP values is implemented by macroblock-level rate control. The X.264 bit rate control process mainly depends on two variables, one is the complexity of the video frame, and the other is the budget of the bit rate. Generally, the higher the complexity of the video frame, the more bits are required for encoding. As shown in FIG. 1 , FIG. 1 is an encoding flow chart of the current X.264 encoding system. After the to-be-encoded video enters the encoding system, it will synchronously enter the inter-frame-level rate control process and the macro-block-level rate control process. During the inter-frame-level rate control process, the lookahead module 100 is configured to provide video frames for the to-be-encoded video. The buffer queue assists in completing more stable bit rate control. The complexity estimation module 101 is configured to estimate the complexity of the current frame in the video to be encoded. Exemplarily, the complexity of the current frame may be the fuzzy complexity; the quantization level The calculation module 103 is configured to calculate the quantization level according to the complexity of the current frame output by the complexity estimation module 101, obtain the quantization proportion corresponding to the current frame, and calculate the code rate factor (ratefactor) provided by the code rate factor calculation module 102. The quantization weight is adjusted to obtain the initial quantization level; the code rate factor calculation module 102 is configured to calculate the complexity accumulation value of the current frame according to the feedback code rate of the coded frame, and then calculate the code according to the complexity accumulation value. The rate factor is provided to the quantization level calculation module 103; the buffer control (VBV) module 104 is configured to adjust the initial quantization level output by the quantization level calculation module 103 based on the size of the buffer area at the receiving end to obtain the quantization level; the quantization level The conversion module 105 is configured to convert the quantization level into an initial quantization step size and provide it to the macroblock-level quantization step size adjustment module 106 . At the same time, the rate control process at the macroblock level is performed synchronously with the rate control process at the inter-frame level, wherein the macroblock calculation module 108 is configured to calculate the macroblock structure of the current frame according to the image content of the current frame ( MBTree); the adaptive quantization module 107 is configured to calculate the average macroblock energy of the current frame according to the macroblock structure and the image content of the current frame, and determine the preset quantization intensity factor corresponding to the average macroblock energy; the macroblock The level quantization step size adjustment 106 is configured to adjust the initial quantization step size of the current frame according to the preset quantization intensity factor to obtain the quantization step size corresponding to the current frame; the encoding module 109 is configured to be configured according to the current frame. The corresponding quantization step size The current frame is long encoded, and the above process continues until all frames in the to-be-encoded video are encoded, and the encoded code stream is output.
从图1所示的编码方法中可以看出,目前,在帧间级码率控制过程中,量化级别计算模块103需要获取码率因子计算模块102根据上一帧编码结果的反馈计算出的码率因子,来对自身计算出的量化比重进行调整,得到初始量化级别。但对于首帧如IDR帧来说,其所在的首帧位置上无法得到上一帧编码结果的反馈,因此目前主要通过人工设定一个固定数值作为码率因子的初始值,进而根据该固定初始值的码率因子计算出首帧的初始量化级别,进而基于初始量化级别计算得到初始量化步长,即QP值。这样会导致首帧的QP值无法根据复杂度进行自适应调整,造成了码率浪费,降低了整体视频的质量。进一步的,目前,在宏块级码率控制过程中,自适应量化模块107中计算出的量化强度因子在整个视频的编码过程中处于固定不变的状态,但在实际编码中,待编码视频的视频内容是不断变化的,如果在复杂区域使用较大的量化强度因子,会使得根据较大量化强度因子调整得到的量化步长明显增加,进而导致在码率较低的条件下复杂区域严重的模糊现象,从而进一步降低了整体视频的质量。It can be seen from the coding method shown in FIG. 1 that at present, in the inter-frame-level code rate control process, the quantization level calculation module 103 needs to obtain the code calculated by the code rate factor calculation module 102 according to the feedback of the coding result of the previous frame. The rate factor is used to adjust the quantization weight calculated by itself to obtain the initial quantization level. However, for the first frame such as IDR frame, the feedback of the encoding result of the previous frame cannot be obtained at the position of the first frame. Therefore, at present, a fixed value is manually set as the initial value of the bit rate factor, and then according to the fixed initial value The initial quantization level of the first frame is calculated by the code rate factor of the value, and then the initial quantization step size, that is, the QP value, is calculated based on the initial quantization level. In this way, the QP value of the first frame cannot be adaptively adjusted according to the complexity, resulting in a waste of bit rate and reducing the quality of the overall video. Further, at present, in the macroblock-level rate control process, the quantization intensity factor calculated in the adaptive quantization module 107 is in a fixed state during the entire video encoding process, but in actual encoding, the video to be encoded is in a fixed state. The video content is constantly changing. If a larger quantization intensity factor is used in the complex area, the quantization step size adjusted according to the larger quantization intensity factor will increase significantly, which will lead to serious problems in the complex area under the condition of low bit rate. blurring, which further degrades the overall video quality.
本申请实施例的提供一种编码方法,应用于编码器,如图2所示:An embodiment of the present application provides an encoding method, which is applied to an encoder, as shown in Figure 2:
S101、当当前帧为待编码视频中的首帧时,在帧间级码率控制过程中,获取当前帧的图像信息。S101. When the current frame is the first frame in the video to be encoded, in the process of inter-frame-level bit rate control, obtain image information of the current frame.
本申请实施例中,对于待编码视频中的首帧,编码器首先获取首帧的图像信息。In this 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.
本申请实施例中,图像信息包括首帧的平均宏块能量、首帧的梯度值、首帧的边缘信息及首帧的直方图信息中的任一种。In the 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.
在本申请的一些实施例中,基于图1所示的码率控制流程,由于在宏级码率控制过程中,宏块计算模块108的执行过程在逻辑上优先于帧间级码率控制过程,考虑在图1的流程中,不增加计算量的基础上,编码器可以将宏块计算模块108执行过程中生成的平均宏块能量作为当前帧的图像信息,以通过平均宏块能量来评估待编码视频中首帧的复杂度累积值,如图3所示。In some embodiments of the present application, based on the rate control flow shown in FIG. 1 , in the macro-level rate control process, the execution process of the macroblock calculation module 108 is logically prior to the inter-frame-level rate control process , considering that in the process of FIG. 1, 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 to evaluate the average macroblock energy. The accumulated complexity value of the first frame in the video to be encoded is shown in FIG. 3 .
本申请实施例中,图3中的宏块计算模块108会将计算得到的首帧的平均宏块能量反馈至帧间级码率控制过程中的码率因子计算模块102,以使码率因子计算模块102能够根据首帧的平均宏块能量进行码率因子的计算,进而根据码率因子调整首帧对应的初始量化步长。In the embodiment of the present application, the macroblock calculation module 108 in FIG. 3 feeds back the calculated average macroblock energy of the first frame to the rate factor calculation module 102 in the inter-frame-level rate control process, so that the rate factor The calculation module 102 can calculate the code 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 code rate factor.
在本申请的另一些实施例中,当当前帧的图像信息为梯度值、边缘信息或直方图信息时,编码器可以如图4所示,通过图像处理模块110,根据当前帧中包含的像素信息,计算出当前帧的梯度值、边缘信息或直方图信息,并将当前帧的梯度值、边缘信息或直方图信息反馈至码率因子计算模块102,以使码率因子计算模块102能够根据首帧的梯度值、边缘信息或直方图信息进行码率因子的计算,进而根据码率因子调整首帧对应的初始量化步长。示例性的,编码器可以根据像素信息中的灰度信息,计算当前帧中每个像素邻域内的灰度变化,进而计算出可以反映当前帧的细节反差程度和纹理变化特征的梯度值,将梯度值作为当前帧的图像信息;在另一些实施例中,编码器可以根据梯度值进一步得到当前帧的边缘信息,将边缘信息作为当前帧的图像信息,以根据边缘信息对当前帧中的内容进行识别和分析;或者,编码器也可以根据像素信息中的灰度信息,计算出可以反映当前帧明暗程度及亮度、色阶分布的直方图信息,将直方图信息作为当前帧的图像信息。In other embodiments of the present application, when the image information of the current frame is gradient value, edge information or histogram information, the encoder may, as shown in FIG. information, calculate the gradient value, edge information or histogram information of the current frame, and feed 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 The gradient value, edge information or histogram information of the first frame is used to calculate the bit rate factor, and then the initial quantization step size corresponding to the first frame is adjusted according to the bit 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 is used 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 determine the content of the current frame according to the edge information. Identify and analyze; or, the encoder can also calculate the histogram information that can reflect the brightness, brightness, and gradation distribution of the current frame according to the grayscale information in the pixel information, and use the histogram information as the image information of the current frame.
S102、基于当前帧的图像信息,计算当前帧的复杂度累积值。S102. Calculate a complexity cumulative value of the current frame based on the image information of the current frame.
本申请实施例中,编码器基于当前帧的图像信息,计算当前帧的复杂度累积值,从而可以根据首帧复杂度累积值对码率因子进行合理的初始化,以通过码率因子对首帧的量化比重进行调整。In the embodiment of the present application, the encoder calculates the complexity cumulative 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 first frame complexity cumulative value, so that the first frame The quantitative proportions are adjusted.
本申请实施例中,对于不同类型的图像信息,可以预先建立对应的目标函数模型,将首帧的图像信息作为目标函数模型的输入值,将初始量化步长作为目标函数模型输出值,以输出的初始量化步长满足低码率、高质量视频应用为目标,通过多次仿真实验分析输出的初始量化步长的数值的优劣,通过函数拟合的方式,拟合初始量化步长与图像信息的曲线,得到初始量化步长的最优值所对应的初始量化步长与图像信息之间的函数关系,进而根据初始量化步长与图像信息之间的函数关系,以及初始量化步长与复杂度累积值之间的预设函数关系,推导出当前帧的图像信息与复杂度累积值之间的关系公式,基于关系公式计算出当前帧的复杂度累积值。In the embodiment of the present application, for different types of image information, a corresponding objective function model may be established in advance, 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 to output The initial quantization step size meets the goal of low bit rate, high-quality video applications, and analyzes the pros and cons of the output initial quantization step size through multiple simulation experiments, and fits the initial quantization step size and the image through function fitting information curve, 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, and then according to the functional relationship between the initial quantization step size and the image information, and the initial quantization step size and the image information. Based on the preset functional relationship between the accumulated complexity values, a relationship formula between the image information of the current frame and the accumulated complexity value is derived, and the accumulated complexity value of the current frame is calculated based on the relationship formula.
可以看出,由于当前帧的图像信息与复杂度累积值之间的关系公式是通过多次仿真实验,将初始量化步长与图像信息进行曲线拟合得到的,因此可以通过当前帧的图像信息所计算出的复杂度累积值更能适应当前帧的真实图像内容,从而保证根据复杂度累积值计算得到的码率因子,以及根据码率因子调整得到的初始量化步长更加准确。It can be seen that since the relationship formula between the image information of the current frame and the accumulated complexity value is obtained by curve fitting the initial quantization step size and image information through multiple simulation experiments, the image information of the current frame can be obtained by curve fitting. The calculated cumulative complexity value can better adapt to the real image content of the current frame, thereby ensuring that the bit rate factor calculated according to the cumulative complexity value and the initial quantization step size adjusted according to the bit rate factor are more accurate.
S103、基于当前帧的复杂度累积值,对当前帧进行编码量化估计,得到当前帧的初始量化步长。S103. Based on the cumulative complexity value of the current frame, perform coding and quantization estimation on the current frame to obtain an initial quantization step size of the current frame.
本申请实施例中,当当前帧为首帧时,编码器可以基于首帧的图像信息计算出首帧的复杂度累积值。In this embodiment of the present application, when the current frame is the first frame, the encoder may calculate the cumulative complexity value of the first frame based on the image information of the first frame.
本申请实施例中,当当前帧为非首帧时,编码器可以结合非首帧的上一帧的编码结果,计算出非首帧的复杂度累积值。In this embodiment of the present application, when the current frame is not the first frame, the encoder may calculate the cumulative complexity value of the non-first frame in combination with the encoding result of the previous frame that is not the first frame.
本申请实施例中,编码器可以先通过复杂度估计模块估计出当前帧的复杂度,并根据 复杂度计算出当前帧的初始量化步长,再根据当前帧的复杂度累积值计算出首帧对应的码率因子,根据码率因子对量化比重进行一次调整得到初始量化级别,再通过缓存控制模块对初始量化级别进行进一步调整,得到当前帧的量化级别,再根据量化级别与量化步长的预设映射关系,将量化级别转化为初始量化步长。In this embodiment of the present application, the encoder may first estimate the complexity of the current frame through the complexity estimation module, calculate the initial quantization step size of the current frame according to the complexity, and then calculate the first frame according to the accumulated complexity value of the current frame For the corresponding bit rate factor, adjust the quantization weight 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. The preset mapping relationship converts the quantization level into the initial quantization step size.
S104、基于当前帧的初始量化步长,对当前帧进行编码,得到当前帧的编码结果。S104 , encoding the current frame based on the initial quantization step size of the current frame to obtain an encoding result of the current frame.
本申请实施例中,编码器得到当前帧的初始量化步长即QP值之后,即完成了当前帧对应的帧间级的码率控制流程,编码器可以继续通过宏块级码率控制过程,对当前帧的初始量化步长进行调整,得到当前帧的量化步长。In the embodiment of the present application, after the encoder obtains the initial quantization step size of the current frame, that is, the QP value, the code rate control process at the inter-frame level corresponding to the current frame is completed, and the encoder can continue to go through the macroblock-level code rate control process. The initial quantization step size of the current frame is adjusted to obtain the quantization step size of the current frame.
在本申请的一些实施例中,宏块级码率控制过程的一种实现方式可以如图5所示,在宏块级码率控制过程1中,编码器可以进行宏块能量计算过程,将当前帧中根据图像内容划分为多个不同的宏块,并根据每个宏块内像素的像素值与平方误差和,计算出每个宏块的宏块能量,进而得到当前帧的平均宏块能量。宏块能量计算过程中得到的平均宏块能量会在自适应量化调节过程中,根据平均宏块能量与预设量化强度因子的对应关系,得到平均宏块能量对应的预设量化强度因子,最后在量化步长调整过程中,通过预设量化强度因子得到初始量化步长的偏移值,再通过初始量化步长的偏移值对初始量化步长进行调整,得到当前帧的量化步长。In some embodiments of the present application, an implementation manner of the macroblock-level rate control process may be as shown in FIG. 5 . In the macroblock-level rate control process 1, the encoder may perform a macroblock energy calculation process, The current frame is divided into a number of different macroblocks according to the image content, and the macroblock energy of each macroblock is calculated according to the pixel value and the square error sum of the pixels in each macroblock, and then the average macroblock of the current frame is obtained. energy. The average macroblock energy obtained in the process of calculating the macroblock energy will, in the adaptive quantization adjustment process, obtain a preset quantization intensity factor corresponding to the average macroblock energy according to the correspondence between the average macroblock energy and the preset quantization intensity factor, and finally In the quantization step size adjustment process, the offset value of the initial quantization step size is obtained by the preset quantization intensity factor, and then the initial quantization step size is adjusted by the offset value of the initial quantization step size to obtain the quantization step size of the current frame.
通常情况下,如果当前帧画面动态情况较多,则其对应的平均宏块能量较高,编码器可以选择较低的预设量化强度因子aq_strength值,示例性的,选择取值在0.6-0.8之间的aq_strength,以保留更多的高频细节,提高整体视频质量;而如果当前帧静态画面较多,则其对应的平均宏块能量较低,编码器可选取较高的aq_strength值,示例性的,编码器可选取大于等于1的aq_strength,以防止暗部因比特不够产生色带。在一些实施例中,上述方法过程可以通过如下代码实现:Under normal circumstances, if the current frame has a lot of dynamics, the corresponding average macroblock energy is higher, and the encoder can select a lower preset quantization strength factor aq_strength value, exemplarily, the selection value is 0.6-0.8 aq_strength in between, in order to retain more high-frequency details and improve the overall video quality; and if there are many static pictures in the current frame, the corresponding average macroblock energy is low, and the encoder can choose a higher aq_strength value, for example Optionally, 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 and process can be implemented by the following code:
Figure PCTCN2021096491-appb-000001
Figure PCTCN2021096491-appb-000001
本申请实施例中,对于上述代码,如果qp_adj-avg_adj大于0,宏块能量energy大的宏块的QP会被调整得更大,从而使得最终计算的qp_offset越大,复杂区域更模糊;如果qp_adj-avg_adj小于0,strength越大,qp_offset越小,最终QP也越小,平坦区域更清晰,由于h->param.rc.f_aq_strength是人工设定的固定aq_strength值,因此难以适应待编码视频中出现的复杂度变化。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 larger the final calculated qp_offset, the more blurred the complex area; 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 video to be encoded. changes in complexity.
在本申请的另一些实施例中,宏块级码率控制过程的另一种实现方式可以如图6所示, 在宏块级码率控制过程2中,编码器利用宏块能量计算过程中计算出的每个宏块的宏块能量,通过复杂度信息计算过程得到每个宏块的内容复杂度,并根据预设的复杂度基准,在复杂度基准调整过程中将当前帧基于每个宏块的内容复杂度划分为不同的区域,并通过自适应量化过程在不同区域设定不同的预设量化强度因子aq_strength,最后通过量化步长调整过程,根据每个区域不同的预设量化强度因子aq_strength对初始量化步长进行偏移量调整,得到该区域对应的量化步长,从而实现预设量化强度因子aq_strength随图像复杂度的变动,能够降低复杂区域的预设量化强度因子,减轻复杂区域的模糊现象,改善预设量化强度因子对视频内容的适应能力。In other embodiments of the present application, another implementation manner of the macroblock-level rate control process may be as shown in FIG. 6 . In the macroblock-level rate control process 2, the encoder uses the macroblock energy calculation process The calculated macroblock energy of each macroblock obtains the content complexity of each macroblock through the complexity information calculation process, and according to the preset complexity benchmark, in the complexity benchmark adjustment process, the current frame is based on each macroblock. The content complexity of the macroblock is divided into different regions, and different preset quantization strength factors aq_strength are set in different regions through the adaptive quantization process. Finally, through the quantization step size adjustment process, according to the different preset quantization strengths of each region The factor aq_strength adjusts the offset of the initial quantization step size to obtain the quantization step size corresponding to the area, so as to realize the change of the preset quantization strength factor aq_strength with the complexity of the image, which can reduce the preset quantization strength factor of complex areas and reduce the complexity of The blurring phenomenon of the area is improved, and the adaptability of the preset quantization intensity factor to the video content is improved.
本申请实施例中,编码器根据宏级量化步长调整模块得到当前帧中每个宏块对应的量化步长之后,即可基于量化步长对当前帧进行编码,得到当前帧的编码结果。编码器基于当前帧的编码结果,以同样的码率控制流程进行下一帧的编码,直至待编码视频编码完成。In the embodiment of the present application, after the encoder obtains the quantization step size corresponding to each macroblock in the current frame according to the macro-level quantization step size adjustment module, the encoder can encode the current frame based on the quantization step size to obtain the encoding result of the current frame. Based on the encoding result of the current frame, the encoder performs the encoding of the next frame with the same rate control process until the encoding of the to-be-encoded video is completed.
可以理解的是,本申请实施例中,对于待编码视频的首帧,编码器可以基于首帧的图像信息得到首帧对应的复杂度累积值,进而根据复杂度累积值进行进一步计算得到首帧的初始量化步长,从而实现了首帧的初始量化步长设置可以根据首帧的复杂度进行自适应设置,避免人工设置了不合理的首帧初始量化步长造成的码率浪费,提高了编码后视频的质量。进一步的,编码器在宏块级码率控制过程中,可以根据宏块复杂度对当前帧进行分区域分场景的预设量化强度因子设置,从而可以根据不同的预设量化强度因子对当前帧的不同复杂度区域分别计算出适合的量化步长,实现了预设量化强度因子随图像复杂度的自适应,提高了图像的清晰度,进一步改善了编码后的视频质量。It can be understood that, in the embodiment of the present application, for the first frame of the video to be encoded, the encoder can obtain the accumulated complexity value corresponding to the first frame based on the image information of the first frame, and then further calculates according to the accumulated complexity value to obtain the first frame. The initial quantization step size of the first frame can be set adaptively according to the complexity of the first frame, so as to avoid the waste of bit rate caused by manually setting the unreasonable initial quantization step size of the first frame, and improve the The quality of the encoded video. Further, in the macroblock-level code rate control process, the encoder can perform preset quantization intensity factor settings for the current frame according to the complexity of the macroblock, so that the current frame can be set according to different preset quantization intensity factors. Appropriate quantization step sizes are calculated respectively for different complexity regions of the image, realizing the self-adaptation of the preset quantization intensity factor with the complexity of the image, improving the clarity of the image, and further improving the quality of the encoded video.
下面,以图像信息为首帧的平均宏块能量为例,进一步说明本申请实施例中的编码方法。In the following, the encoding method in the embodiment of the present application is further described by taking the average macroblock energy of the first frame as the image information as an example.
在本申请的一些实施例中,基于图2,当当前帧为待编码视频中的首帧时,在帧间级码率控制过程中,S101中编码器获取当前视频的图像信息可以通过S1011-S1012实现,如图7所示:In some embodiments of the present application, based on FIG. 2, when the current frame is the first frame in the video to be encoded, in the inter-frame-level rate control process, the encoder in S101 obtains the image information of the current video through S1011- S1012 implementation, as shown in Figure 7:
S1011、在宏块级码率控制过程中,对当前帧进行宏块划分,得到至少一个宏块。S1011. In the macroblock-level rate control process, perform macroblock division on the current frame to obtain at least one macroblock.
本申请实施例中,编码器通过宏块计算模块,基于当前帧的图像内容对当前帧进行宏块划分,得到至少一个宏块。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 the macroblock calculation module to obtain at least one macroblock.
在一些实施例中,至少一个宏块可以是MB tree的形式。In some embodiments, at least one macroblock may be in the form of an MB tree.
S1012、计算至少一个宏块的平均宏块能量,作为当前帧的图像信息。S1012. Calculate the average macroblock energy of at least one macroblock as image information of the current frame.
本申请实施例中,编码器可以在至少一个宏块的每个宏块中,通过像素值与平方误差和,计算出每个宏块的宏块能量,再根据每个宏块的宏块能量得到至少一个宏块的平均宏块能量,将至少一个宏块的平均宏块能力作为当前帧的图像信息。In this embodiment of the present application, the encoder may calculate the macroblock energy of each macroblock by using the pixel value and the sum of squared errors in each macroblock of at least one macroblock, and then calculate the macroblock energy of each macroblock according to the macroblock energy of each macroblock. The average macroblock energy of the at least one macroblock is obtained, and the average macroblock energy of the at least one macroblock is used as the image information of the current frame.
可以理解的是,本申请实施例中使用平均宏块能量作为首帧的图像信息,可以直接利用宏块级码率控制过程中计算得到的平均宏块能量,不需要额外进行图像处理工作,减少了编码器的计算量。It can be understood that, in the embodiment of the present application, the average macroblock energy is used as the image information of the first frame, and the average macroblock energy calculated in the macroblock-level rate control process can be directly used, and additional image processing work is not required. the computational complexity of the encoder.
在本申请的一些实施例中,基于图2或图7,当当前帧为待编码视频中的首帧时,在帧间级码率控制过程中,S102中编码器基于当前帧的图像信息,计算当前帧的复杂度累积值可以通过S1021-S1022实现,如图8所示:In some embodiments of the present application, based on FIG. 2 or FIG. 7 , when the current frame is the first frame in the video to be encoded, in the inter-frame-level rate control process, the encoder in S102 is based on the image information of the current frame, Calculating the complexity cumulative value of the current frame can be achieved through S1021-S1022, as shown in Figure 8:
S1021、根据平均宏块能量、预设首帧编码比特与至少一个预设拟合因子对当前帧进行复杂度评估,得到当前帧的预估编码复杂度;至少一个预设拟合因子用于拟合平均宏块能量与初始量化步长之间的关系曲线。S1021. Perform complexity evaluation on the current frame according to the average macroblock energy, the preset coding bits of the first frame, and at least one preset fitting factor, to obtain the estimated coding complexity of the current frame; at least one preset fitting factor is used for fitting The relationship between the combined average macroblock energy and the initial quantization step size.
本申请实施例中,编码器根据平均宏块能量、预设首帧编码比特与至少一个预设拟合因子对当前帧进行复杂度评估,得到当前帧的预估编码复杂度的过程可以包括:将平均宏块能量乘以第一拟合因子,得到第一乘积结果;将预设首帧编码比特乘以第二拟合因子,得到第二乘积结果;计算第一乘积结果减去第二乘积结果的差值,并将差值与第三拟合因 子相加,得到预估编码复杂度;其中,至少一个预设拟合因子包含第一拟合因子、第二拟合因子与第三拟合因子。如公式(1)所示: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 process of obtaining the estimated coding complexity of the current frame may include: Multiply the average macroblock energy by the first fitting factor to obtain the first product result; multiply the preset first frame coded bits by the second fitting factor to obtain the second product result; calculate the first product result minus the second product The difference value of the results, and the difference value and the third fitting factor are added to obtain the estimated coding complexity; wherein, at least one preset fitting factor includes the first fitting factor, the second fitting factor and the third fitting factor. combination factor. As shown in formula (1):
cplxr_zero=s 1×avg_energy-s 2×wanted_bits_window+s 3      (1) cplxr_zero=s 1 ×avg_energy-s 2 ×wanted_bits_window+s 3 (1)
上述公式(1)中,avg_energy为当前帧即首帧的平均宏块能量,cplxr_zero为根据平均宏块能量计算出的当前帧的预估复杂度,s 1、s 2与s 3分别为至少一个预设拟合因子中的第一拟合因子、第二拟合因子与第三拟合因子。其中,本申请实施例中的至少一个预设拟合因子是通过大量仿真实验,调整初始量化步长与avg_energy之间的关系,以满足低码率、高质量视频应用为目标,分析测试视频初始量化步长的优劣,进而拟合初始量化步长与平均宏块能量对应的QP-energy函数关系曲线得到的,也就是说,公式(1)中的至少一个预设拟合因子为通过函数曲线拟合的方式所获得的最优值。在一些实施例中,s 1的取值可以是13000,s 2的取值可以是0.3858,s 3的取值可以是515000,也可以根据实际的编码目标,通过函数曲线拟合的方式计算出其他取值,具体的根据实际应用进行选择,本申请实施例不做限定。 In the above formula (1), avg_energy is the average macroblock energy of the current frame, that is, the first frame, cplxr_zero is the estimated complexity of the current frame calculated according to the average macroblock energy, s 1 , s 2 and s 3 are at least one The first fitting factor, the second fitting factor and the third fitting factor in the preset fitting factors. Among them, at least one preset fitting factor in the embodiment of the present application is to adjust the relationship between the initial quantization step size and avg_energy through a large number of simulation experiments, so as to meet the low bit rate and high quality video application as the goal, analyze the initial test video The pros and cons of the quantization step size are obtained by fitting the QP-energy function curve corresponding to the initial quantization step size and the average macroblock energy, that is to say, at least one preset fitting factor in formula (1) is a pass function The optimal value obtained by the way of curve fitting. In some embodiments, the value of s 1 may be 13000, the value of s 2 may be 0.3858, and the value of s 3 may be 515000, or it may be calculated by means of function curve fitting according to the actual encoding target Other values are specifically selected according to actual applications, which are not limited in this embodiment of the present application.
公式(1)中,wanted_bits_window为预设首帧编码比特,用于表示已编码帧的目标文件大小,即已编码帧的总比特值,wanted_bits_window可以通过公式(2)求得,如下:In formula (1), wanted_bits_window is the preset first frame encoding bit, which is used to represent 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:
wanted_bits_window=bitrate/fps      (2)wanted_bits_window=bitrate/fps (2)
公式(2)中的fps为待编码视频的预设帧率,bitrate表示编码后的码率,首帧的bitrate为预设值,非首帧的bitrate为其上一帧编码后对应的码率,因此,首帧的wanted_bits_window也为预设值。fps in formula (2) is the preset frame rate of the video to be encoded, bitrate represents the encoded bitrate, the bitrate of the first frame is the default value, and the bitrate of the non-first frame is the bitrate corresponding to the previous frame after encoding , so the wanted_bits_window of the first frame is also the default value.
S1022、基于预估编码复杂度,计算当前帧的复杂度累积值。S1022. Calculate the cumulative complexity value of the current frame based on the estimated coding complexity.
本申请实施例中,编码器基于预估编码复杂度,计算当前帧的复杂度累积值可以包括:In the embodiment of the present application, the encoder calculates the complexity cumulative value of the current frame based on the estimated coding complexity, which may include:
S10221、获取至少一个宏块的宏块数量。S10221. Acquire the number of macroblocks of at least one macroblock.
S10222、根据预估编码复杂度、至少一个宏块的宏块数量与预设压缩参数,得到当前帧的复杂度累积值。S10222. Obtain a complexity cumulative value of the current frame according to the estimated coding complexity, the number of macroblocks of at least one macroblock, and a preset compression parameter.
本申请实施例中,编码器可以根据至少一个宏块的宏块数据与预设压缩参数,对预估编码复杂度进行累积值更新计算,得到当前帧的复杂度更新值。In the embodiment of the present application, the encoder may perform an update calculation on the cumulative value of the estimated coding complexity according to the macroblock data of at least one macroblock and a preset compression parameter, so as to obtain the complexity update value of the current frame.
在一些实施例中,编码器可以获取宏块计算模块进行宏块划分所得到的至少一个宏块的宏块数量,并计算预估编码复杂度的预设压缩参数次幂与预设系数、以及宏块数量的二分之一次幂的乘积,得到当前帧的复杂度累积值。In some embodiments, the encoder may obtain the number of macroblocks of at least one macroblock obtained by dividing the macroblock by the macroblock calculation module, and calculate the preset compression parameter power and the preset coefficient to estimate the coding complexity, and The product of the one-half power of the number of macroblocks is the cumulative value of the complexity of the current frame.
示例性的,上述计算过程可以如公式(3)所示:Exemplarily, the above calculation process can be shown in formula (3):
cplxr_sum=0.01×cplxr_zero qcom×(mbcount) 1/2      (3) cplxr_sum=0.01×cplxr_zero qcom ×(mbcount) 1/2 (3)
公式(3)中,qcomp为预设压缩参数。该参数外部可调,可以在0和1之间取值。mbcount为至少一个宏块的宏块数量。cplxr_sum为当前帧的复杂度累积值。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. cplxr_sum is the accumulated complexity value of the current frame.
在一些实施例中,当当前帧为首帧时,编码器通过S1021-S1022计算出当前帧的复杂度累积值cplxr_sum的代码实现可以如下所示:In some embodiments, when the current frame is the first frame, the code implementation for the encoder to calculate the complexity cumulative value cplxr_sum of the current frame through S1021-S1022 may be as follows:
……...
if(rc->b_abr){//采用ABR编码算法if(rc->b_abr){//ABR encoding algorithm is used
............
rc->cplxr_sumrc->cplxr_sum
=13000*h->param.avg_energy-0.3858*rcc->wanted_bits_window+515000;//公式(1)对应的代码指令,其中h->param.avg_energy为平均宏块能量,rcc->wanted_bits_window为预设首帧编码比特,这里,变量rc->cplxr_sum首次计算得到的初值为当前帧的预估编码复杂度,即cplxr_zero;=13000*h->param.avg_energy-0.3858*rcc->wanted_bits_window+515000;//code instruction corresponding to formula (1), where h->param.avg_energy is the average macroblock energy, rcc->wanted_bits_window is the default The first frame coding bit, here, the initial value calculated by the variable rc->cplxr_sum for the first time is the estimated coding complexity of the current frame, that is, cplxr_zero;
rc->cplxr_sum=.01*pow(rc->cplxr_sum,rc->qcompress)* pow(h->mb.i_mb_count,0.5);//公式(3)对应的代码指令,通过预设压缩参数rc->qcompress与至少一个宏块的宏块数量h->mb.i_mb_count,执行公式(3)过程对应的代码指令,对变量rc->cplxr_sum对应的初值进行更新,得到当前帧的复杂度累积值;rc->cplxr_sum=.01*pow(rc->cplxr_sum,rc->qcompress)*pow(h->mb.i_mb_count,0.5);//The code instruction corresponding to formula (3), through the preset compression parameter rc ->qcompress and the number of macroblocks h->mb.i_mb_count of at least one macroblock, execute the code instruction corresponding to the process of formula (3), update the initial value corresponding to the variable rc->cplxr_sum, and obtain the complexity accumulation of the current frame value;
............
}}
……...
而在目前的帧间级码率控制过程中,对于首帧的复杂度累积值cplxr_sum的计算方法如公式(4)所示:In the current inter-frame-level rate control process, the calculation method of the complexity cumulative value cplxr_sum of the first frame is shown in formula (4):
cplxr_sum=0.01×(7×10 5) qcompress×(mbcount) 1/2      (4) cplxr_sum=0.01×(7×10 5 ) qcompress ×(mbcount) 1/2 (4)
公式(4)对应的代码实现如下所示:The code implementation corresponding to formula (4) is as follows:
……...
if(rc->b_abr){if(rc->b_abr){
............
rc->cplxr_sum=.01*pow(7.0e5,rc->qcompress)*pow(h->mb.i_mb_count,0.5);//通过人工设置的固定值7.0e5,即7×10 5计算首帧的复杂度累积值; rc->cplxr_sum=.01*pow(7.0e5,rc->qcompress)*pow(h->mb.i_mb_count,0.5);//Calculate the first frame by the fixed value 7.0e5 set manually, that is, 7×10 5 The cumulative value of the complexity;
............
}}
……...
可以理解的是,目前的帧间级码率控制过程是通过一个固定值,如7×10 5来对首帧的复杂度累积值cplxr_sum进行初始化的,因此不能根据首帧的实际复杂度进行初始值的自适应调整,从而影响了基于初始值计算得到的复杂度累积值的准确性,进而影响了帧间级码率控制过程计算出的首帧的初始量化步长,降低了编码后的视频质量。而本申请实施例中,可以通过首帧视频的平均宏块能量计算得到首帧的预估编码复杂度,进而通过首帧的预估编码复杂度计算得到首帧的复杂度累积值cplxr_sum,进一步根据复杂度累积值cplxr_sum计算得到首帧的初始量化步长,实现了帧间级码率控制计算的首帧的初始量化步长可以跟随首帧复杂度自适应调整,从而提高了首帧初始量化步长设置的合理性,节约了编码码率,提高了编码后的视频质量。 It can be understood that the current inter-frame-level rate control process initializes the complexity cumulative value cplxr_sum of the first frame with a fixed value, such as 7×10 5 , so it cannot be initialized according to the actual complexity of the first frame. Adaptive adjustment of the value, which affects the accuracy of the complexity cumulative value calculated based on the initial value, and then affects the initial quantization step size of the first frame calculated by the inter-frame-level rate control process, reducing the encoded video. quality. In the embodiment of the present application, the estimated coding complexity of the first frame can be obtained by calculating the average macroblock energy of the first frame of video, and then the cumulative complexity value cplxr_sum of the first frame can be obtained by calculating the estimated coding complexity of the first frame, and further The initial quantization step size of the first frame is calculated according to the accumulated complexity value cplxr_sum, which realizes that the initial quantization step size of the first frame calculated by the inter-frame rate control can be adaptively adjusted following the complexity of the first frame, thereby improving the initial quantization of the first frame. The rationality of the step size setting saves the encoding bit rate and improves the encoded video quality.
需要说明的是,在本申请的一些实施例中,当当前帧为待编码视频中的非首帧时,编码器可以基于当前帧对应的上一帧编码后的比特数,与上一帧的量化参数,对复杂度进行累积处理,得到当前帧的复杂度累积值。也就是说,当当前帧为非首帧时,编码器可以根据上一帧的编码结果,来计算当前帧的复杂度累积值的,在一些实施例中,上述过程可以如公式(5)所示:It should be noted that, in some embodiments of the present application, when the current frame is a non-first frame in the video to be encoded, the encoder may, based on the number of encoded bits of the previous frame corresponding to the current frame, differ from the The quantization parameter is used to accumulate the complexity to obtain the accumulated complexity value of the current frame. That is to say, when the current frame is not the first frame, the encoder can calculate the cumulative complexity value of the current frame according to the encoding result of the previous frame. In some embodiments, the above process can be as shown in formula (5). Show:
Figure PCTCN2021096491-appb-000002
Figure PCTCN2021096491-appb-000002
公式(5)中,bits(i-1)为上一帧编码得到的实际比特数,qscale_raw(i-1)为上一帧对应的未经码率因子调整的量化比重值,qscale_adj(i-1)为上一帧对应的经码率因子调整后的初始量化级别,cplxr_sum(i-1)为上一帧对应的复杂度累积值,cplxr_sum(i)为当前帧的复杂度累积值。In formula (5), bits(i-1) is the actual number of bits obtained from the encoding of the previous frame, qscale_raw(i-1) is the quantized weight value corresponding to the previous frame without adjustment of the bit rate factor, qscale_adj(i- 1) is the initial quantization level corresponding to the previous frame adjusted by the bit rate factor, cplxr_sum(i-1) is the accumulated complexity value corresponding to the previous frame, and cplxr_sum(i) is the accumulated complexity value of the current frame.
可以理解的是,当前帧的复杂度累积值是一个迭代量,在编码过程中逐渐累积,因此首帧的复杂度累积值设置会影响到对整个视频的编码质量。本申请实施例中的方法通过平均宏块能量计算出首帧的复杂度累积值,能够实现首帧的复杂度累积值根据首帧的复杂度进行自适应调整,使得首帧的复杂度累积值的设定更加准确,从而提高了整个视频编码的质量。It can be understood that the accumulated complexity value of the current frame is an iterative amount, which is gradually accumulated during the encoding process. Therefore, the setting of the accumulated complexity value of the first frame will affect the encoding quality of the entire video. The method in the embodiment of the present application calculates the cumulative complexity value of the first frame by averaging the macroblock energy, so that the cumulative value of the complexity of the first frame can be adaptively adjusted according to the complexity of the first frame, so that the cumulative value of the complexity of the first frame can be adjusted adaptively. The settings are more accurate, thereby improving the quality of the entire video encoding.
在本申请的一些实施例中,基于图8,S103中编码器基于当前帧的复杂度累积值,对 当前帧进行编码量化估计,得到当前帧的初始量化步长可以通过S1031-S1034来实现,如图9所示:In some embodiments of the present application, based on FIG. 8 , the encoder in S103 performs encoding and quantization estimation on the current frame based on the complexity cumulative value of the current frame, and obtaining the initial quantization step size of the current frame can be achieved through S1031-S1034, As shown in Figure 9:
S1031、对当前帧进行模糊复杂度估计,并对估计得出的模糊复杂度进行压缩处理,计算得到当前帧的复杂度。S1031 , estimating the fuzzy complexity of the current frame, and compressing the estimated fuzzy complexity to obtain the complexity of the current frame.
本申请实施例中,编码器对当前帧做抽样滤波,得到分辨率是原来一半的小图,在小图上做半像素精度预测,与原图相减得到残差,再对残差做哈德曼变换并求绝对和得到SATD,即可根据当前帧SATD与之前相邻帧的SATD值的加权平均得到当前帧的模糊复杂度。In the 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 half-pixel precision prediction on the small image, subtracts it from the original image to obtain a residual, and then performs a halves on the residual. Deman transform and absolute sum to obtain SATD, then the fuzzy complexity of the current frame can be obtained according to the weighted average of the SATD values of the current frame and the previous adjacent frames.
本申请实施例中,编码器对当前帧进行模糊复杂度估计可以如公式(6)和公式(7)所示,如下:In this embodiment of the present application, the estimation of the fuzzy complexity of the current frame by the encoder may be as shown in formula (6) and formula (7), as follows:
BlurCplx=Cplxsum/Cplxcount        (6)BlurCplx=Cplxsum/Cplxcount (6)
Figure PCTCN2021096491-appb-000003
Figure PCTCN2021096491-appb-000003
公式(6)中,BlurCplx代表模糊复杂度,编码器可以根据公式(6),通过对邻近已编码帧的复杂度加权来得到BlurCplx。公式(6)中,Cplxsum表示编码复杂度加权和,Cplxcount表示编码帧数加权和,Cplxsum与Cplxcount的计算方法如公式(7)所示,公式(7)中,i为待编码帧的序号,satd为当前帧经过运动补偿后的残差绝对值总和SATD,首帧的satd为预设值,非首帧的satd可以根据时频变换的方式计算得到,用于反映生成码流的大小。In formula (6), BlurCplx represents blur complexity, and the encoder can obtain BlurCplx by weighting the complexity of adjacent coded frames according to formula (6). In formula (6), Cplxsum represents the weighted sum of coding complexity, and Cplxcount represents the weighted sum of coding frame numbers. The calculation methods of Cplxsum and Cplxcount are shown in formula (7). In formula (7), i is the serial number of the frame to be encoded, satd is the sum of absolute values of residuals of the current frame after motion compensation, SATD, 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 transformation, which is used to reflect the size of the generated code stream.
本申请实施例中,由于视频帧恒定的质量并不意味着要使用恒定的QP值,根据人眼视觉特性,对于高复杂度的场景,人眼主观很难感受到细节的丢失,因此可以通过感知编码优化的方法,对当前帧的模糊复杂度进行非线性压缩来降低码率,如公式(8)所示:In the embodiment of the present application, since the constant quality of the video frame does not mean the use of a constant QP value, according to the visual characteristics of the human eye, it is difficult for the human eye to perceive the loss of details subjectively in a high-complexity scene. The perceptual coding optimization method performs nonlinear compression on the fuzzy complexity of the current frame to reduce the code rate, as shown in formula (8):
rceq=BlurCplx (1-qcomp),qcomp∈[0,1]      (8) rceq=BlurCplx (1-qcomp) ,qcomp∈[0,1] (8)
公式(8)中,rceq表示经感知编码优化后的复杂度,可以作为量化比重,用于评估当前帧的可量化程度;qcomp的含义为,当qcomp等于1时,各帧的量化比重,即rceq都一样,分配给平缓的帧和复杂的帧的比特相同;当qcomp=0时,各帧的量化比重和其模糊复杂度成正比,最终得到各帧的QP值相等,相当于关闭了此项感知编码优化。In formula (8), rceq represents the complexity after perceptual coding optimization, which can be used as the quantization weight to evaluate the quantization degree of the current frame; the meaning of qcomp is, when qcomp is equal to 1, the quantization weight of each frame, namely The rceq is the same, and the bits allocated to the flat frame and the complex frame are the same; when qcomp=0, the quantization weight of each frame is proportional to its fuzzy complexity, and finally the QP value of each frame is equal, which is equivalent to turning off this function. Item-aware encoding optimizations.
S1032、计算待编码视频中已编码帧的总比特值与复杂度累积值之间的比值,得到当前帧的码率因子。S1032: Calculate the ratio between the total bit value of the encoded frames in the to-be-encoded video and the accumulated complexity value to obtain the bit rate factor of the current frame.
本申请实施例中,编码器计算待编码视频中已编码帧的总比特值与复杂度累积值之间的比值,作为当前帧的码率因子,如公式(9)与公式(10)所示:In the embodiment of the present application, the encoder calculates the ratio between the total bit value of the encoded frames in the to-be-encoded video and the accumulated complexity value as the bit rate factor of the current frame, as shown in formula (9) and formula (10) :
ratefactor=wanted_bits_window/cplxr_sum      (9)ratefactor=wanted_bits_window/cplxr_sum (9)
公式(9)中,ratefactor为码率因子计算模块根据已编码帧bitrate生成的当前帧的码率因子。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.
S1033、基于复杂度与码率因子,得到当前帧的量化级别。S1033. Obtain the quantization level of the current frame based on the complexity and the code rate factor.
本申请实施例中,编码器可以首先将量化比重与码率因子的比值,作为当前帧的初始量化级别。In this 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.
本申请实施例中,编码器可以通过公式(10),计算量化比重rceq与码率因子ratefactor的比值,得到当前帧的初始量化级别:In the embodiment of the present application, the encoder can calculate the ratio of the quantization ratio rceq to the code rate factor ratefactor by formula (10), to obtain the initial quantization level of the current frame:
qscale=rceq/ratefactor      (10)qscale=rceq/ratefactor (10)
公式(10)中,qscale为当前帧的初始量化级别。In formula (10), qscale is the initial quantization level of the current frame.
本申请实施例中,编码器得到当前帧的初始量化级别之后,可以基于预设目标比特数,对初始量化级别进行调整,得到当前帧的量化级别。In this embodiment of the present application, after obtaining the initial quantization level of the current frame, the encoder may adjust the initial quantization level based on the preset target number of bits to obtain the quantization level of the current frame.
本申请实施例中,编码器可以通过计算预设目标比特数与当前帧实际编码后产生的总 比特值之间的差值,进而根据差值对初始量化级别进行调整,来得到当前帧的量化级别,从而可以使得生成的码流大小稳定。In the embodiment of the present application, the encoder can obtain the quantization of the current frame by calculating the difference between the preset target number of bits and the total bit value generated after the actual encoding of the current frame, and then adjusting the initial quantization level according to the difference. level, so that the size of the generated code stream can be stabilized.
在一些实施例中,预设目标比特数可以为编码视频对应的接收端缓冲区的大小,编码器可以通过缓存控制模块,基于预设目标比特数,对初始量化级别进行调整,得到当前帧的量化级别。In some embodiments, the preset target number of bits may be the size of the buffer at the receiving end corresponding to the encoded video, and the encoder may adjust the initial quantization level based on the preset target number of bits through the buffer control module to obtain the current frame's Quantization level.
S1034、基于预设量化级别与初始量化步长的映射关系,将当前帧的量化级别转化为初始量化步长。S1034. Convert the quantization level of the current frame into an initial quantization step size based on the mapping relationship between the preset quantization level and the initial quantization step size.
本申请实施例中,预设量化级别与初始量化步长的映射关系可以如公式(11)所示:In this embodiment of the present application, the mapping relationship between the preset quantization level and the initial quantization step size may be as shown in formula (11):
Figure PCTCN2021096491-appb-000004
Figure PCTCN2021096491-appb-000004
公式(11)中,a、b、c为经验值系数,在一些实施例中,a可以取值为12,b可以取值为6,c可以取值为0.85,qscale为量化级别,QP为由量化级别转化得到的量化步长。In formula (11), a, b, and c are empirical value coefficients. In some embodiments, a can take a value of 12, b can take a value of 6, c can take a value of 0.85, qscale is a quantization level, and QP is The quantization step size converted from the quantization level.
因此,编码器计算出量化级别之后,即可基于预设量化级别与初始量化步长的映射关系,将当前帧的量化级别转化为初始量化步长。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.
可以理解的是,对于待编码视频的首帧,公式(3)中根据预估编码复杂度所计算得到的复杂度累积值,之后在公式(9)中被用于计算得到码率因子,进而在公式(10)中基于码率因子计算出初始量化级别,最终将初始量化级别转化为初始量化步长。也就是说,复杂度累积值在计算初始量化步长,即QP值时,可以起到压缩系数的作用。由于本申请实施例中,首帧的预估编码复杂度可以根据首帧的平均宏块能量进行自适应调整,进而实现了首帧的复杂度累积值以及初始量化步长的自适应调整,从而提高了编码后视频的质量。It can be understood that, for the first frame of the video to be encoded, the complexity cumulative value calculated according to the estimated coding complexity in formula (3) is then used to calculate the bit rate factor in formula (9), and then In formula (10), the initial quantization level is calculated based on the code rate factor, and finally the initial quantization level is converted into an initial quantization step size. That is to say, the accumulated complexity value can play the role of a compression coefficient when calculating the initial quantization step size, that is, the QP value. Because in the embodiment of the present application, the estimated coding complexity of the first frame can be adaptively adjusted according to the average macroblock energy of the first frame, thereby realizing the adaptive adjustment of the accumulated complexity value of the first frame and the initial quantization step size, thereby Improved the quality of the encoded video.
在本申请的一些实施例中,基于图2或图7,S104中编码器基于当前帧的初始量化步长,对当前帧进行编码,得到当前帧的编码结果可以通过S1041-S1044实现,如图10所示:In some embodiments of the present application, based on FIG. 2 or FIG. 7, the encoder in S104 encodes the current frame based on the initial quantization step size of the current frame, and obtaining the encoding result of the current frame can be achieved through S1041-S1044, as shown in the figure 10 shows:
S1041、在宏块级码率控制中,对当前帧进行宏块划分后,获取每个宏块的内容复杂度。S1041. In the macroblock-level rate control, after dividing the current frame into macroblocks, obtain the content complexity of each macroblock.
本申请实施例中,基于上述S1011-S1012,在宏块级码率控制中,编码器对当前帧进行宏块划分,得到至少一个宏块后,会计算至少一个宏块的平均宏块能量。这里,在计算平均宏块能量时,编码器需要先计算出每个宏块的宏块能量,进而计算出至少一个宏块的平均宏块能量。编码器可以获取宏块能量计算过程中,即计算每个宏块能量的过程中所生成的复杂度数据,作为每个宏块的内容复杂度。In the embodiments of the present application, based on the above S1011-S1012, in the macroblock-level rate control, the encoder divides the current frame into macroblocks, and after obtaining at least one macroblock, it calculates the average macroblock energy of the at least one macroblock. Here, when calculating the average macroblock energy, the encoder needs to first calculate the macroblock energy of each macroblock, and then calculate the average macroblock energy of at least one macroblock. The encoder can acquire the complexity data generated in the process of calculating the energy of the macroblock, that is, in the process of calculating the energy of each macroblock, as the content complexity of each macroblock.
S1042、根据每个宏块的内容复杂度和预设复杂度阈值,对当前帧进行区域划分,得到至少一个区域。S1042. According to the content complexity of each macroblock and a preset complexity threshold, perform region division on the current frame to obtain at least one region.
本申请实施例中,编码器首先设定预设复杂度阈值,通常预设复杂度阈值可以是根据先验知识确定,示例性的,预设复杂度阈值可以在[80000,85000]之间取值,优选的,预设复杂度阈值可以为82400。In this embodiment of the present application, the encoder first sets a preset complexity threshold. Usually, the preset complexity threshold may be determined according to prior knowledge. Exemplarily, the preset complexity threshold may be between [80000, 85000]. value, preferably, the preset complexity threshold can be 82400.
本申请实施例中,编码器将每个宏块的内容复杂度与预设复杂度阈值进行对比,以宏块为单位对当前帧进行区域划分,将复杂度高于预设复杂度阈值的宏块和复杂度低于预设复杂度阈值的宏块划分到不同的区域,从而得到至少一个区域。其中,至少一个区域中每个区域的复杂度不同。In this embodiment of the present application, the encoder compares the content complexity of each macroblock with a preset complexity threshold, divides the current frame into regions in units of macroblocks, and divides macroblocks whose complexity is higher than the preset complexity threshold. Blocks and macroblocks whose complexity is lower than a preset complexity threshold are divided into different regions, thereby obtaining at least one region. Wherein, the complexity of each region in at least one region is different.
在一些实施例中,通过预设复杂度阈值,编码器可以将当前帧划分为高复杂度区域与低复杂度区域。In some embodiments, the encoder can divide the current frame into a high-complexity region and a low-complexity region by presetting a complexity threshold.
S1043、确定至少一个区域中的每个区域的预设量化强度因子,并根据每个区域对应的预设量化强度因子,对初始量化步长进行调整,得到每个区域对应的量化步长。S1043. Determine a preset quantization intensity factor of each area in the at least one area, and adjust the initial quantization step size according to the preset quantization intensity factor corresponding to each area to obtain a quantization step size corresponding to each area.
本申请实施例中,编码器首先根据每个区域包含的宏块的内容复杂度,确定每个区域的区域复杂度。In this embodiment of the present application, the encoder first determines the area complexity of each area according to the content complexity of the macroblocks included in each area.
在一些实施例中,编码器可以计算每个区域包含的各个宏块的内容复杂度的均值,作为每个区域的区域复杂度,或者也可以根据其他衡量计算的方法,如方差等,具体的根据实际情况进行选择,本申请实施例不做限定。In some embodiments, the encoder may calculate the mean value of the content complexity of each macroblock included in each area as the area complexity of each area, or may also calculate the mean value according to other measurement methods, such as variance, etc. The selection is made according to the actual situation, which is not limited in the embodiments of the present application.
本申请实施例中,编码器根据区域复杂度与预设量化强度因子的预设对应关系,确定出每个区域的预设量化强度因子。其中,预设量化强度因子的大小与其对应的区域复杂度成反比。In this embodiment of the present application, the encoder determines the preset quantization intensity factor for each region according to the preset correspondence between the region complexity and the preset quantization intensity factor. Wherein, the size of the preset quantization intensity factor is inversely proportional to its corresponding area complexity.
本申请实施例中,预设量化强度因子aq_strength可用于调整平坦区域块效应和纹理区域模糊效应。其中,aq_strength越高,复杂区域的高频信息消减越多,但平坦区域清晰度提升,也意味着纹理越模糊,反之,aq_strength越低,复杂区域的高频信息保留越多,而平坦区域的清晰度降低,也就是说纹理区域更清晰。In this embodiment of the present application, the preset quantization strength factor aq_strength may be used to adjust the block effect in the flat area and the blurring effect in the texture area. Among them, the higher the aq_strength, the more high-frequency information in the complex area is reduced, but the improved definition of the flat area also means that the texture is more blurred, conversely, the lower the aq_strength, the more high-frequency information in the complex area is retained, while the The sharpness is reduced, which means that the textured areas are sharper.
在一些实施例中,编码器可以将当前帧划分为高复杂度区域与低复杂度区域,并设定高复杂度区域的预设量化强度因子aq_strength为0.5,低复杂度区域的预设量化强度因子aq_strength为1.0,从而实现对于场景较为复杂的高复杂度区域,通过较低的aq_strength来降低模糊现象,提升编码后视频的整体质量。在一些实施例中,上述过程可以通过如下代码来实现: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 of the low-complexity region to be 0.5 The factor aq_strength is 1.0, so that for high-complexity areas with more complex scenes, a lower aq_strength can be used to reduce the blurring phenomenon and improve the overall quality of the encoded video. In some embodiments, the above process can be implemented by the following code:
Figure PCTCN2021096491-appb-000005
Figure PCTCN2021096491-appb-000005
上述代码中,h->param.rc.f_aq_strength_cplx=0.5,表示将高复杂度区域的预设量化强度因子aq_strength的值设置为0.5,frame->s_cplx为该区域中根据各个宏块的内容复杂度得到的区域复杂度,当区域复杂度大于预设复杂度阈值82400时,编码器可以使用高复杂度区域对应的预设量化强度因子aq_strength,如0.5,来设置该高复杂度区域的初始量化步长,以降低高复杂区域模糊现象。In the above code, h->param.rc.f_aq_strength_cplx=0.5, indicating that the value of the preset quantization strength factor aq_strength of the high-complexity region is set to 0.5, and frame->s_cplx is the content complexity of each macroblock in the region The obtained area complexity, when the area complexity is greater than the preset complexity threshold of 82400, the encoder can use the preset quantization strength factor aq_strength corresponding to the high complexity area, such as 0.5, to set the high complexity area The initial quantization step long to reduce blurring in highly complex areas.
本申请实施例中,编码器通过同样的方法,根据每个区域的区域复杂度确定该区域上设定的预设量化强度因子,并根据每个区域上各自设定的预设量化强度因子对初始量化步长进行调整,对应得到每个区域对应的量化步长。也就是说,本申请实施例中最终计算得到的对当前帧进行量化的量化步长是与当前帧中以不同复杂度划分出的至少一个区域相对应至少一个量化步长,因此能够根据当前帧中的内容场景的区域复杂度进行量化步长的自适应调整。In the embodiment of the present application, the encoder uses the same method to determine the preset quantization intensity factor set in each region according to the regional complexity of the region, and according to the preset quantization intensity factor respectively set in each region, pair the The initial quantization step size is adjusted to obtain the corresponding quantization step size for each region. That is to say, the quantization step size for quantizing the current frame finally calculated in the embodiment of the present application is at least one quantization step size corresponding to at least one area divided with different complexity in the current frame, so it can be calculated according to the current frame The area complexity of the content scene in the quantization step size is adaptively adjusted.
S1044、根据每个区域对应的量化步长,对当前帧的各个区域进行编码,得到当前帧 的编码结果。S1044. According to the quantization step size corresponding to each region, each region of the current frame is encoded to obtain the encoding result of the current frame.
本申请实施例中,编码器根据每个区域对应的量化步长,对当前帧的各个区域进行编码,得到当前帧的编码结果。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, and obtains an encoding result of the current frame.
可以理解的是,本申请实施例中,编码器通过宏块复杂度对当前帧进行区域划分,实现了在宏块级码率控制过程中调整量化步长时,可以根据当前帧的复杂度进行分区域的自适应调整,提高了量化步长的精确度,从而提高了编码后视频的精度。It can be understood that, in the embodiment of the present application, the encoder divides the current frame according to the complexity of the macroblock, so that when adjusting the quantization step size in the process of the macroblock-level rate control, the quantization step size can be adjusted according to the complexity of the current frame. The adaptive adjustment of sub-regions improves the accuracy of the quantization step size, thereby improving the accuracy of the encoded video.
在一些实施例中,基于本申请实施例提供的编码方法,在X.264软件编码平台上,采用常见标准视频数据作为测试序列,对视频分辨率固定设置为960*540,编码算法采用ABR模式,并将码率设置在相对较低的1.2Mb/s,以此为基础,分别测试通过目前的编码方法得到的编码视频,以及通过本申请实施例中的编码方法得到的编码视频的客观PSNR数值以及对应的码率控制情况,实验结果如表1所示。表1为目前的编码方法与本申请实施例的编码方法得到的编码视频的码率与PSNR的对比情况,如下所示:In some embodiments, based on the encoding method provided by the embodiments of the present application, on the X.264 software encoding platform, common standard video data is used as the test sequence, the video resolution is fixedly set to 960*540, and the encoding algorithm adopts the ABR mode , and set the bit rate at a relatively low 1.2Mb/s, and based on this, test the objective PSNR 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. The numerical value and the corresponding rate control situation, the experimental results are shown in Table 1. Table 1 is a comparison of the code rate and PSNR of the encoded video obtained by the encoding method of the current encoding method and the encoding method of the embodiment of the present application, as follows:
Figure PCTCN2021096491-appb-000006
Figure PCTCN2021096491-appb-000006
表1Table 1
从表1的对比数据中可以看出,相比于目前的编码方法,本申请实施例的编码方法能够保证编码器对码率控制的能力,不会因为算法的引入造成码率控制的失效,同时,本申请实施例的编码方法在PSNR客观质量上总体平均提升了约0.145dB。由此可以得出结论,本申请实施例提供的编码方法能够提升编码视频的视频质量,同时不会造成压缩率负担。It can be seen from the comparison data in Table 1 that, compared with the current encoding method, the encoding method of the embodiment of the present application can ensure the ability of the encoder to control the code rate, and will not cause the failure of the code rate control due to the introduction of the algorithm, At the same time, the coding method according to the embodiment of the present application improves the objective quality of PSNR by about 0.145dB on average. From this, 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.
本申请实施例提供一种编码器,图11为本申请实施例提供的一种编码器的组成结构示意图一,如图11所示,该编码器11包括:获取部分1101、计算部分1102、量化部分1103与编码部分1104,其中,An embodiment of the present application provides an encoder, and FIG. 11 is a schematic structural diagram 1 of an encoder provided by an embodiment of the present application. As shown in FIG. 11 , the encoder 11 includes: an acquisition part 1101 , a calculation part 1102 , and a quantization part part 1103 and encoding part 1104, where,
所述获取部分1101,被配置为当当前帧为待编码视频中的首帧时,在帧间级码率控制过程中,获取当前帧的图像信息;The acquisition part 1101 is configured to acquire image information of the current frame in the inter-frame-level code rate control process when the current frame is the first frame in the video to be encoded;
所述计算部分1102,被配置为基于所述当前帧的图像信息,计算当前帧的复杂度累积值;The calculating part 1102 is configured to calculate the complexity cumulative value of the current frame based on the image information of the current frame;
所述量化部分1103,被配置为基于所述当前帧的复杂度累积值,对所述当前帧进行编码量化估计,得到所述当前帧的初始量化步长;The quantization part 1103 is configured to perform coding and quantization estimation on the current frame based on the cumulative complexity value of the current frame to obtain the initial quantization step size of the current frame;
所述编码部分1104,被配置为基于所述当前帧的初始量化步长,对所述当前帧进行编码,得到所述当前帧的编码结果。The encoding part 1104 is configured 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.
在一些实施例中,所述图像信息包括首帧的平均宏块能量、首帧的梯度值、首帧的边缘信息及首帧的直方图信息中的任一种。In some embodiments, 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.
在一些实施例中,所述图像信息为所述首帧的平均宏块能量,所述计算部分1102,还被配置为根据所述平均宏块能量、预设首帧编码比特与至少一个预设拟合因子对所述当前帧进行复杂度评估,得到所述当前帧的预估编码复杂度;所述至少一个预设拟合因子用于拟合所述平均宏块能量与初始量化步长之间的关系曲线;基于所述预估编码复杂度,计算所述当前帧的复杂度累积值。In some embodiments, the image information is the average macroblock energy of the first frame, and the calculating part 1102 is further configured to calculate the average macroblock energy according to the average macroblock energy, a preset first frame coding bit and at least one preset The fitting factor evaluates the complexity of the current frame to obtain the estimated coding complexity of the current frame; the at least one preset fitting factor is used to fit the difference between the average macroblock energy and the initial quantization step size The relationship curve between; based on the estimated coding complexity, calculate the complexity cumulative value of the current frame.
在一些实施例中,所述计算部分1102,还被配置为将所述平均宏块能量乘以第一拟合因子,得到第一乘积结果;将所述预设首帧编码比特乘以第二拟合因子,得到第二乘积结果;计算所述第一乘积结果减去所述第二乘积结果的差值,并将所述差值与第三拟合因子相加,得到所述预估编码复杂度;其中,所述至少一个预设拟合因子包含所述第一拟合因子、所述第二拟合因子与所述第三拟合因子。In some embodiments, the calculating part 1102 is further configured to multiply the average macroblock energy by a first fitting factor to obtain a first product result; multiply the preset first frame coded bits by a second Fitting factors 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 code complexity; wherein, the at least one preset fitting factor includes the first fitting factor, the second fitting factor, and the third fitting factor.
在一些实施例中,所述获取部分1101,还被配置为在宏块级码率控制过程中,对所述当前帧进行宏块划分,得到至少一个宏块;计算所述至少一个宏块的平均宏块能量,作为所述当前帧的图像信息。In some embodiments, the obtaining part 1101 is further configured to perform macroblock division on the current frame during the macroblock-level rate control process to obtain at least one macroblock; calculate the at least one macroblock The average macroblock energy is used as the image information of the current frame.
在一些实施例中,所述计算部分1102,还被配置为获取所述至少一个宏块的宏块数量;根据预估编码复杂度、所述至少一个宏块的宏块数量与预设压缩参数,得到所述当前帧的复杂度累积值。In some embodiments, the calculating part 1102 is further configured to obtain the number of macroblocks of the at least one macroblock; according to the estimated coding complexity, the number of macroblocks of the at least one macroblock and a preset compression parameter , to obtain the cumulative complexity value of the current frame.
在一些实施例中,所述计算部分1102,还被配置为将所述预设压缩参数作为所述预估编码复杂度的次幂进行运算,并将运算结果与预设系数、以及所述宏块数量的二分之一次幂的相乘,得到所述当前帧的复杂度累积值。In some embodiments, the calculating part 1102 is further configured to calculate the preset compression parameter as the power of the estimated coding complexity, and compare the calculation result with the preset coefficient and the macro The multiplication of the one-half power of the number of blocks is performed to obtain the cumulative complexity value of the current frame.
在一些实施例中,所述获取部分1101,还被配置为根据所述当前帧中包含的像素信息,计算出所述当前帧的梯度值、边缘信息或直方图信息。In some embodiments, the acquiring part 1101 is further configured to calculate the gradient value, edge information or histogram information of the current frame according to the pixel information contained in the current frame.
在一些实施例中,所述编码部分1104,还被配置为在宏块级码率控制中,对所述当前帧进行宏块划分后,获取每个宏块的内容复杂度;根据所述每个宏块的内容复杂度和预设复杂度阈值,对所述当前帧进行区域划分,得到至少一个区域;确定所述至少一个区域中的每个区域的预设量化强度因子,并根据所述每个区域对应的预设量化强度因子,对所述初始量化步长进行调整,得到所述每个区域对应的量化步长;根据所述每个区域对应的量化步长,对所述当前帧的各个区域进行编码,得到所述当前帧的编码结果。In some embodiments, the encoding part 1104 is further configured to obtain the content complexity of each macroblock after dividing the current frame into macroblocks in the macroblock-level rate control; the content complexity of the macroblocks and the preset complexity threshold, the current frame is divided into regions to obtain at least one region; the preset quantization intensity factor of each region in the at least one region is determined, and according to the According to the preset quantization intensity factor corresponding to each area, the initial quantization step size is adjusted to obtain the quantization step size corresponding to each area; according to the quantization step size corresponding to each area, the current frame to encode each region of the current frame to obtain the encoding result of the current frame.
在一些实施例中,所述编码部分1104,还被配置为在根据所述每个区域包含的宏块的内容复杂度,确定所述每个区域的区域复杂度;根据区域复杂度与预设量化强度因子的预设对应关系,确定出所述每个区域的预设量化强度因子;所述预设量化强度因子的大小与区域复杂度成反比。In some embodiments, the encoding part 1104 is further configured to determine the area complexity of each area according to the content complexity of the macroblocks contained in each area; according to the area complexity and the preset The preset corresponding relationship of the quantization intensity factors determines the preset quantization intensity factor of each area; the size of the preset quantization intensity factor is inversely proportional to the complexity of the area.
在一些实施例中,所述量化部分1103,还被配置为在对所述当前帧进行模糊复杂度估计,并对估计得出的模糊复杂度进行压缩处理,计算得到所述当前帧的复杂度;计算所述待编码视频中已编码帧的总比特值与所述复杂度累积值之间的比值,得到所述当前帧的码率因子;基于所述复杂度与所述码率因子,得到所述当前帧的量化级别;基于预设量化级别与初始量化步长的映射关系,将所述当前帧的量化级别转化为所述初始量化步长。In some embodiments, the quantization part 1103 is further configured to perform fuzzy complexity estimation on the current frame, and perform compression processing on the estimated fuzzy complexity, so as 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 cumulative value of the complexity to obtain the code rate factor of the current frame; Based on the complexity and the code 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 size, the quantization level of the current frame is converted into the initial quantization step size.
在一些实施例中,所述量化部分1103,还被配置为将所述复杂度与所述码率因子的比值,作为所述当前帧的初始量化级别;基于预设目标比特数,对所述初始量化级别进行调整,得到所述当前帧的量化级别。In some embodiments, the quantization part 1103 is further configured to use the ratio of the complexity to the code rate factor as the initial quantization level of the current frame; The initial quantization level is adjusted to obtain the quantization level of the current frame.
在一些实施例中,所述计算部分1102,被配置为在所述基于所述当前帧的复杂度累积值,对所述当前帧进行编码量化估计,得到所述当前帧的初始量化步长之前,当所述当前帧为所述待编码视频中的非首帧时,基于所述当前帧对应的上一帧编码后的比特数,与所述上一帧的量化参数,对复杂度进行累积处理,得到所述当前帧的复杂度累积值。In some embodiments, the calculating part 1102 is configured to perform coding and quantization estimation on the current frame based on the accumulated complexity value of the current frame to obtain the initial quantization step size of the current frame , when the current frame is a non-first frame in the video to be encoded, the complexity is accumulated based on the encoded bits of the previous frame corresponding to the current frame and the quantization parameter of the previous frame processing to obtain the cumulative complexity value of the current frame.
在一些实施例中,所述量化部分1103,还被配置为计算所述预设目标比特数与对所述当前帧进行编码后产生的总比特值之间的差值,根据所述差值对所述初始量化级别进行调 整,得到所述当前帧的量化级别。In some embodiments, the quantization part 1103 is further configured to calculate the difference between the preset target number of bits and the total bit value generated after encoding the current frame, and according to the difference The initial quantization level is adjusted to obtain the quantization level of the current frame.
在一些实施例中,所述编码部分1104,还被配置为计算所述每个区域包含的各个宏块的内容复杂度的均值,作为所述每个区域的区域复杂度。In some embodiments, the encoding part 1104 is further configured to calculate the average value of the content complexity of each macroblock included in each region as the region complexity of each region.
在一些实施例中,所述编码部分1104,还被配置为获取宏块能量计算过程生成的复杂度数据,作为所述每个宏块的内容复杂度;所述宏块能量计算过程用于计算所述每个宏块的宏块能量,以得到至少一个宏块的平均宏块能量。In some embodiments, the encoding part 1104 is further configured to obtain the complexity data generated by the macroblock energy calculation process as the content complexity of each macroblock; the macroblock energy calculation process is used to calculate the macroblock energy of each macroblock to obtain the average macroblock energy of at least one macroblock.
需要说明的是,以上装置实施例的描述,与上述方法实施例的描述是类似的,具有同方法实施例相似的有益效果。对于本申请装置实施例中未披露的技术细节,请参照本申请方法实施例的描述而理解。It should be noted that the descriptions of the above apparatus embodiments are similar to the descriptions of the above method embodiments, and have similar beneficial effects to the method embodiments. For technical details not disclosed in the device embodiments of the present application, please refer to the descriptions of the method embodiments of the present application for understanding.
需要说明的是,本申请实施例中,如果以软件功能模块的形式实现上述的信息显示方法,并作为独立的产品销售或使用时,也可以存储在一个计算机可读取存储介质中。基于这样的理解,本申请实施例的技术方案本质上或者说对现有技术做出贡献的部分可以以软件产品的形式体现出来,该计算机软件产品存储在一个存储介质中,包括若干指令用以使得一台计算机设备(可以是终端、服务器等)执行本申请各个实施例所述方法的全部或部分。而前述的存储介质包括:U盘、移动硬盘、只读存储器(Read Only Memory,ROM)、磁碟或者光盘等各种可以存储程序代码的介质。这样,本申请实施例不限制于任何特定的硬件和软件结合。It should be noted that, in the embodiments 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 may also be stored in a computer-readable storage medium. Based on such understanding, the technical solutions of the embodiments of the present application can be embodied in the form of software products in essence or in the parts that make contributions to the prior art. The computer software products are stored in a storage medium and include several instructions for A computer device (which may be a terminal, a server, etc.) is caused to execute all or part of the methods described in the various embodiments of the present application. The aforementioned storage medium includes: a U disk, a mobile hard disk, a read only memory (Read Only Memory, ROM), a magnetic disk or an optical disk and other media that can store program codes. As such, the embodiments of the present application are not limited to any specific combination of hardware and software.
对应地,本申请实施例再提供一种计算机程序产品,所述计算机程序产品包括计算机可读代码,在所述计算机可读代码在编码器中运行的情况下,所述编码器中的处理器执行用于实现本申请实施例提供的编码方法。Correspondingly, the embodiments of the present application further provide a computer program product, where the computer program product includes computer-readable codes, and when the computer-readable codes run in an encoder, a processor in the encoder Execution is used to implement the encoding method provided by the embodiment of the present application.
相应的,本申请实施例再提供一种计算机可读存储介质,所述计算机可读存储介质上存储有计算机可执行指令,该计算机可执行指令被配置为引起处理器执行时,实现上述实施例提供的编码方法的步骤。Correspondingly, the embodiments of the present application further provide a computer-readable storage medium, where computer-executable instructions are stored on the computer-readable storage medium, and the computer-executable instructions are configured to cause the processor to execute the above-mentioned embodiments. Provides the steps of the encoding method.
本申请实施例还提供一种编码器,图12为本申请实施例提供的一种编码器的组成结构示意图二,如图12所示,所述编码器1200包括:存储器1201,被配置为存储计算机程序;An embodiment of the present application further provides an encoder. FIG. 12 is a second schematic diagram of the composition and structure of an encoder provided by an embodiment of the present application. As shown in FIG. 12 , the encoder 1200 includes: a memory 1201 configured to store Computer program;
处理器1202,被配置为执行所述存储器1201中存储的计算机程序时,实现上述实施例提供的编码方法的步骤;The processor 1202 is configured to implement the steps of the encoding method provided by the above embodiment when executing the computer program stored in the memory 1201;
编码器1200还包括通信总线1203;被配置为连接存储器1201与处理器1202,实现存储器1201与处理器1202之间的连接通信。The encoder 1200 also includes a communication bus 1203; it is configured to connect the memory 1201 and the processor 1202, and realize the connection and communication between the memory 1201 and the processor 1202.
存储器1201被配置为存储由处理器1202计算机程序和应用,还可以缓存待处理器1202以及编码器中各模块待处理或已经处理的数据(例如,图像数据、音频数据、语音通信数据和视频通信数据),可以通过闪存(FLASH)或随机访问存储器(Random Access Memory,RAM)实现。The memory 1201 is configured to store computer programs and applications by the processor 1202, and can also cache data to be processed or processed by the processor 1202 and modules in the encoder (eg, image data, audio data, voice communication data, and video communication data). data), which can be implemented through flash memory (FLASH) or random access memory (Random Access Memory, RAM).
处理器1202执行程序时实现上述任一项编码方法的步骤。When the processor 1202 executes the program, the steps of any one of the above encoding methods are implemented.
上述处理器1202可以为特定用途集成电路(Application Specific Integrated Circuit,ASIC)、数字信号处理器(Digital Signal Processor,DSP)、数字信号处理装置(Digital Signal Processing Device,DSPD)、可编程逻辑装置(Programmable Logic Device,PLD)、现场可编程门阵列(Field Programmable Gate Array,FPGA)、中央处理器(Central Processing Unit,CPU)、控制器、微控制器、微处理器中的至少一种。可以理解地,实现上述处理器功能的电子器件还可以为其它,本申请实施例不作限制。The above-mentioned processor 1202 may be an Application Specific Integrated Circuit (ASIC), a Digital Signal Processor (DSP), a Digital Signal Processing Device (DSPD), a Programmable Logic Device (Programmable Logic Device) At least one of a Logic Device (PLD), a Field Programmable Gate Array (FPGA), a Central Processing Unit (CPU), a controller, a microcontroller, and a microprocessor. It can be understood that the electronic device that implements the function of the above processor may also be other, which is not limited in the embodiment of the present application.
上述计算机可读存储介质/存储器可以是只读存储器(Read Only Memory,ROM)、可编程只读存储器(Programmable Read-Only Memory,PROM)、可擦除可编程只读存储器(Erasable Programmable Read-Only Memory,EPROM)、电可擦除可编程只读存储器(Electrically Erasable Programmable Read-Only Memory,EEPROM)、磁性随机存取存储器 (Ferromagnetic Random Access Memory,FRAM)、快闪存储器(Flash Memory)、磁表面存储器、光盘、或只读光盘(Compact Disc Read-Only Memory,CD-ROM)等存储器;也可以是包括上述存储器之一或任意组合的各种终端,如移动电话、计算机、平板设备、个人数字助理等。The above-mentioned computer-readable storage medium/memory can be a read-only memory (Read Only Memory, ROM), a programmable read-only memory (Programmable Read-Only Memory, PROM), an erasable programmable read-only memory (Erasable Programmable Read-Only Memory) Memory, EPROM), Electrically Erasable Programmable Read-Only Memory (EEPROM), Magnetic Random Access Memory (FRAM), Flash Memory (Flash Memory), Magnetic Surface Memory, optical disk, or memory such as Compact Disc Read-Only Memory (CD-ROM); it can also be various terminals including one or any combination of the above memories, such as mobile phones, computers, tablet devices, personal digital Assistant etc.
这里需要指出的是:以上存储介质和设备实施例的描述,与上述方法实施例的描述是类似的,具有同方法实施例相似的有益效果。对于本申请存储介质和设备实施例中未披露的技术细节,请参照本申请方法实施例的描述而理解。It should be pointed out here that the descriptions of the above storage medium and device embodiments are similar to the descriptions of the above method embodiments, and have similar beneficial effects to the method embodiments. For technical details not disclosed in the embodiments of the storage medium and device of the present application, please refer to the description of the method embodiments of the present application to understand.
在本申请所提供的几个实施例中,应该理解到,所揭露的设备和方法,可以通过其它的方式实现。以上所描述的设备实施例仅仅是示意性的,例如,所述单元的划分,仅仅为一种逻辑功能划分,实际实现时可以有另外的划分方式,如:多个单元或组件可以结合,或可以集成到另一个系统,或一些特征可以忽略,或不执行。另外,所显示或讨论的各组成部分相互之间的耦合、或直接耦合、或通信连接可以是通过一些接口,设备或单元的间接耦合或通信连接,可以是电性的、机械的或其它形式的。In the several embodiments provided in this application, it should be understood that the disclosed apparatus and method may be implemented in other manners. The device embodiments described above are only illustrative. For example, the division of the units is only a logical function division. In actual implementation, there may be other division methods. For example, multiple units or components may be combined, or Can be integrated into another system, or some features can be ignored, or not implemented. In addition, the coupling, or direct coupling, or communication connection between the various components shown or discussed may be through some interfaces, and the indirect coupling or communication connection of devices or units may be electrical, mechanical or other forms. of.
上述作为分离部件说明的单元可以是、或也可以不是物理上分开的,作为单元显示的部件可以是、或也可以不是物理单元;既可以位于一个地方,也可以分布到多个网络单元上;可以根据实际的需要选择其中的部分或全部单元来实现本申请实施例方案的目的。The unit described above as a separate component may or may not be physically separated, and the component displayed as a unit may or may not be a physical unit; it may be located in one place or distributed to multiple network units; Some or all of the units may be selected according to actual needs to achieve the purpose of the solutions of the embodiments of the present application.
另外,在本申请各实施例中的各功能单元可以全部集成在一个处理单元中,也可以是各单元分别单独作为一个单元,也可以两个或两个以上单元集成在一个单元中;上述集成的单元既可以采用硬件的形式实现,也可以采用硬件加软件功能单元的形式实现。In addition, each functional unit in each embodiment of the present application may all be integrated into one processing unit, or each unit may be separately used as a unit, or two or more units may be integrated into one unit; the above integration The unit can be implemented either in the form of hardware or in the form of hardware plus software functional units.
或者,本申请上述集成的单元如果以软件功能模块的形式实现并作为独立的产品销售或使用时,也可以存储在一个计算机可读取存储介质中。基于这样的理解,本申请实施例的技术方案本质上或者说对相关技术做出贡献的部分可以以软件产品的形式体现出来,该计算机软件产品存储在一个存储介质中,包括若干指令用以使得设备自动测试线执行本申请各个实施例所述方法的全部或部分。而前述的存储介质包括:移动存储设备、ROM、磁碟或者光盘等各种可以存储程序代码的介质。Alternatively, if the above-mentioned integrated units of the present application are implemented in the form of software function modules and sold or used as independent products, they may also be stored in a computer-readable storage medium. Based on such understanding, the technical solutions of the embodiments of the present application may be embodied in the form of software products in essence or the parts that contribute to related technologies. The computer software products are stored in a storage medium and include several instructions to make The automatic test line of the device performs all or part of the methods described in the various embodiments of the present application. The aforementioned storage medium includes various media that can store program codes, such as a removable storage device, a ROM, a magnetic disk, or an optical disk.
以上所述,仅为本申请的实施方式,但本申请的保护范围并不局限于此,任何熟悉本技术领域的技术人员在本申请揭露的技术范围内,可轻易想到变化或替换,都应涵盖在本申请的保护范围之内。因此,本申请的保护范围应以所述权利要求的保护范围为准。The above is only the embodiment of the present application, but the protection scope of the present application is not limited to this. Covered within the scope of protection of this application. Therefore, the protection scope of the present application should be subject to the protection scope of the claims.
工业实用性Industrial Applicability
本申请实施例中,可以通过首帧的图像信息来评估首帧的复杂度累积值,并基于首帧的复杂度累积值对初始量化步长,即QP值进行合理设置,实现了QP值可以根据首帧的图像信息进行自适应调整,使得基于QP值进行的视频编码能够得到更准确的编码结果,最终提高了编码视频的视频质量。并且,通过宏块复杂度对当前帧进行区域划分,实现了在宏块级码率控制过程中调整量化步长时,可以根据当前帧的复杂度进行分区域的自适应调整,提高了量化步长的精确度,从而提高了编码后视频的精度。根据实验对比数据可以得出,本申请实施例中的编码方法可以提升编码视频的视频质量,同时不会造成压缩率负担。In this embodiment of the present application, the accumulated complexity value of the first frame can be evaluated by using the image information of the first frame, and the initial quantization step size, that is, the QP value, is reasonably set based on the accumulated complexity value of the first frame, so that the QP value can be reasonably set. Adaptive adjustment is performed according to the image information of the first frame, so that the video encoding based on the QP value can obtain a more accurate encoding result, and finally the video quality of the encoded video is improved. In addition, the current frame is divided into regions by the complexity of the macroblock, so that when the quantization step size is adjusted in the macroblock-level rate control process, the adaptive adjustment of the subregions can be performed according to the complexity of the current frame, which improves the quantization step. long precision, thus improving the precision of the encoded video. According to the experimental comparison data, it can be concluded that the encoding method in the embodiment of the present application can improve the video quality of the encoded video without causing a burden on the compression rate.

Claims (20)

  1. 一种编码方法,应用于编码器,包括:An encoding method, applied to an encoder, comprising:
    当当前帧为待编码视频中的首帧时,在帧间级码率控制过程中,获取当前帧的图像信息;When the current frame is the first frame in the video to be encoded, in the inter-frame-level rate control process, the image information of the current frame is acquired;
    基于所述当前帧的图像信息,计算当前帧的复杂度累积值;Calculate the complexity cumulative value of the current frame based on the image information of the current frame;
    基于所述当前帧的复杂度累积值,对所述当前帧进行编码量化估计,得到所述当前帧的初始量化步长;Based on the cumulative complexity value of the current frame, perform coding and quantization estimation on the current frame to obtain an initial quantization step size of the current frame;
    基于所述当前帧的初始量化步长,对所述当前帧进行编码,得到所述当前帧的编码结果。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.
  2. 根据权利要求1所述的方法,其中,所述图像信息包括首帧的平均宏块能量、首帧的梯度值、首帧的边缘信息及首帧的直方图信息中的任一种。The method of claim 1, wherein 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.
  3. 根据权利要求2所述的方法,其中,所述图像信息为所述首帧的平均宏块能量,所述基于所述当前帧的图像信息,计算当前帧的复杂度累积值,包括:The method according to claim 2, wherein the image information is the average macroblock energy of the first frame, and the calculation of the complexity cumulative value of the current frame based on the image information of the current frame, comprising:
    根据所述平均宏块能量、预设首帧编码比特与至少一个预设拟合因子对所述当前帧进行复杂度评估,得到所述当前帧的预估编码复杂度;所述至少一个预设拟合因子用于拟合所述平均宏块能量与初始量化步长之间的关系曲线;The complexity evaluation of the current frame is performed according to the average macroblock energy, the preset coding bits of the first frame and at least one preset fitting factor, so as to obtain the estimated coding complexity of the current frame; the at least one preset coding complexity is obtained. The 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, a cumulative complexity value of the current frame is calculated.
  4. 根据权利要求3所述的方法,其中,所述根据所述平均宏块能量、预设首帧编码比特与至少一个预设拟合因子对所述当前帧进行复杂度评估,得到所述当前帧的预估编码复杂度,包括:The method according to claim 3, wherein the current frame is obtained by performing complexity evaluation on the current frame according to the average macroblock energy, preset first frame coding bits and at least one preset fitting factor The estimated coding complexity of , including:
    将所述平均宏块能量乘以第一拟合因子,得到第一乘积结果;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;
    计算所述第一乘积结果减去所述第二乘积结果的差值,并将所述差值与第三拟合因子相加,得到所述预估编码复杂度;其中,所述至少一个预设拟合因子包含所述第一拟合因子、所述第二拟合因子与所述第三拟合因子。Calculate the difference value of the first product result minus the second product result, and add the difference value to the third fitting factor to obtain the estimated coding complexity; wherein, the at least one predictor It is assumed that the fitting factor includes the first fitting factor, the second fitting factor and the third fitting factor.
  5. 根据权利要求3所述的方法,其中,所述获取当前帧的图像信息,包括:The method according to claim 3, wherein the acquiring the image information of the current frame comprises:
    在宏块级码率控制过程中,对所述当前帧进行宏块划分,得到至少一个宏块;In the macroblock-level rate control process, the current frame is divided into macroblocks to obtain at least one macroblock;
    计算所述至少一个宏块的平均宏块能量,作为所述当前帧的图像信息。Calculate the average macroblock energy of the at least one macroblock as image information of the current frame.
  6. 根据权利要求5所述的方法,其中,所述基于所述预估编码复杂度,计算所述当前帧的复杂度累积值,包括:The method according to claim 5, wherein the calculating a complexity cumulative value of the current frame based on the estimated coding complexity comprises:
    获取所述至少一个宏块的宏块数量;obtaining the number of macroblocks of the at least one macroblock;
    根据预估编码复杂度、所述至少一个宏块的宏块数量与预设压缩参数,得到所述当前帧的复杂度累积值。The cumulative complexity value of the current frame is obtained according to the estimated coding complexity, the number of macroblocks of the at least one macroblock, and a preset compression parameter.
  7. 根据权利要求6所述的方法,其中,所述根据预估编码复杂度、所述至少一个宏块的宏块数量与预设压缩参数,得到所述当前帧的复杂度累积值,包括:The method according to claim 6, wherein obtaining the cumulative complexity value of the current frame according to the estimated coding complexity, the number of macroblocks of the at least one macroblock and a preset compression parameter, comprising:
    将所述预设压缩参数作为所述预估编码复杂度的次幂进行运算,并将运算结果与预设系数、以及所述宏块数量的二分之一次幂的相乘,得到所述当前帧的复杂度累积值。Calculate the preset compression parameter as the power of the estimated coding complexity, and multiply the calculation result with the preset coefficient and the first power of the number of macroblocks to obtain the The accumulated complexity value of the current frame.
  8. 根据权利要求2所述的方法,其中,所述获取当前帧的图像信息,包括:The method according to claim 2, wherein the acquiring the image information of the current frame comprises:
    根据所述当前帧中包含的像素信息,计算出所述当前帧的梯度值、边缘信息或直方图信息。According to the pixel information contained in the current frame, the gradient value, edge information or histogram information of the current frame is calculated.
  9. 根据权利要求1-8任一项所述的方法,其中,所述基于所述当前帧的初始量化步长,对所述当前帧进行编码,得到所述当前帧的编码结果,包括:The method according to any one of claims 1-8, wherein the encoding the current frame based on the initial quantization step size of the current frame to obtain an encoding result of the current frame, comprising:
    在宏块级码率控制中,对所述当前帧进行宏块划分后,获取每个宏块的内容复杂度;In the macroblock-level code rate control, after the current frame is divided into macroblocks, the content complexity of each macroblock is obtained;
    根据所述每个宏块的内容复杂度和预设复杂度阈值,对所述当前帧进行区域划分,得 到至少一个区域;According to the content complexity of each macroblock and the preset complexity threshold, the current frame is divided into regions to obtain at least one region;
    确定所述至少一个区域中的每个区域的预设量化强度因子,并根据所述每个区域对应的预设量化强度因子,对所述初始量化步长进行调整,得到所述每个区域对应的量化步长;Determine a preset quantization intensity factor of each area in the at least one area, and adjust the initial quantization step size according to the preset quantization intensity factor corresponding to each area to obtain the corresponding quantization step size;
    根据所述每个区域对应的量化步长,对所述当前帧的各个区域进行编码,得到所述当前帧的编码结果。According to the quantization step size corresponding to each area, each area of the current frame is encoded to obtain an encoding result of the current frame.
  10. 根据权利要求9所述的方法,其中,所述确定所述至少一个区域中的每个区域的预设量化强度因子,包括:The method of claim 9, wherein the determining a preset quantized intensity factor for each of the at least one region comprises:
    根据所述每个区域包含的宏块的内容复杂度,确定所述每个区域的区域复杂度;Determine the area complexity of each area according to the content complexity of the macroblocks contained in each area;
    根据区域复杂度与预设量化强度因子的预设对应关系,确定出所述每个区域的预设量化强度因子;所述预设量化强度因子的大小与区域复杂度成反比。The preset quantization intensity factor of each area is determined according to the preset correspondence between the area complexity and the preset quantization intensity factor; the size of the preset quantization intensity factor is inversely proportional to the area complexity.
  11. 根据权利要求1-8任一项所述的方法,其中,所述基于所述当前帧的复杂度累积值,对所述当前帧进行编码量化估计,得到所述当前帧的初始量化步长,包括:The method according to any one of claims 1-8, wherein the current frame is subjected to coding and quantization estimation based on a complexity cumulative value of the current frame to obtain an initial quantization step size of the current frame, include:
    对所述当前帧进行模糊复杂度估计,并对估计得出的模糊复杂度进行压缩处理,计算得到所述当前帧的复杂度;Performing fuzzy complexity estimation on the current frame, and compressing the estimated fuzzy complexity, and calculating the complexity of the current frame;
    计算所述待编码视频中已编码帧的总比特值与所述复杂度累积值之间的比值,得到所述当前帧的码率因子;Calculate the ratio between the total bit value of the encoded frame in the to-be-encoded video and the cumulative complexity value to obtain the bit rate factor of the current frame;
    基于所述复杂度与所述码率因子,得到所述当前帧的量化级别;obtaining the quantization level of the current frame based on the complexity and the code rate factor;
    基于预设量化级别与初始量化步长的映射关系,将所述当前帧的量化级别转化为所述初始量化步长。Based on the mapping relationship between the preset quantization level and the initial quantization step size, the quantization level of the current frame is converted into the initial quantization step size.
  12. 根据权利要求11所述的方法,其中,所述基于所述复杂度与所述码率因子,得到所述当前帧的量化级别,包括:The method according to claim 11, wherein the obtaining the quantization level of the current frame based on the complexity and the code rate factor comprises:
    将所述复杂度与所述码率因子的比值,作为所述当前帧的初始量化级别;Taking the ratio of the complexity to the code rate factor as the initial quantization level of the current frame;
    基于预设目标比特数,对所述初始量化级别进行调整,得到所述当前帧的量化级别。Based on the preset target number of bits, the initial quantization level is adjusted to obtain the quantization level of the current frame.
  13. 根据权利要求1-8任一项所述的方法,其中,所述基于所述当前帧的复杂度累积值,对所述当前帧进行编码量化估计,得到所述当前帧的初始量化步长之前,所述方法还包括:The method according to any one of claims 1-8, wherein the coding and quantization estimation is performed on the current frame based on the accumulated complexity value of the current frame, and before the initial quantization step size of the current frame is obtained , the method also includes:
    当所述当前帧为所述待编码视频中的非首帧时,基于所述当前帧对应的上一帧编码后的比特数,与所述上一帧的量化参数,对复杂度进行累积处理,得到所述当前帧的复杂度累积值。When the current frame is not the first frame in the to-be-encoded video, the complexity is accumulated based on the encoded bits of the previous frame corresponding to the current frame and the quantization parameter of the previous frame , to obtain the cumulative complexity value of the current frame.
  14. 根据权利要求12所述的方法,其中,所述基于预设目标比特数,对所述初始量化级别进行调整,得到所述当前帧的量化级别,包括:The method according to claim 12, wherein adjusting the initial quantization level based on a preset target number of bits to obtain the quantization level of the current frame, comprising:
    计算所述预设目标比特数与对所述当前帧进行编码后产生的总比特值之间的差值,根据所述差值对所述初始量化级别进行调整,得到所述当前帧的量化级别。Calculate the difference between the preset target number of bits and the total bit value generated after encoding the current frame, adjust the initial quantization level according to the difference, and obtain the quantization level of the current frame .
  15. 根据权利要求10所述的方法,其中,所述根据所述每个区域包含的宏块的内容复杂度,确定所述每个区域的区域复杂度,包括:The method according to claim 10, wherein the determining the area complexity of each area according to the content complexity of the macroblock included in each area comprises:
    计算所述每个区域包含的各个宏块的内容复杂度的均值,作为所述每个区域的区域复杂度。Calculate the mean value of the content complexity of each macroblock included in each area as the area complexity of each area.
  16. 根据权利要求9所述的方法,其中,所述获取每个宏块的内容复杂度,包括:The method according to claim 9, wherein the obtaining the content complexity of each macroblock comprises:
    获取宏块能量计算过程生成的复杂度数据,作为所述每个宏块的内容复杂度;所述宏块能量计算过程用于计算所述每个宏块的宏块能量,以得到至少一个宏块的平均宏块能量。Obtain the complexity data generated by the macroblock energy calculation process as the content complexity of each macroblock; the macroblock energy calculation process is used to calculate the macroblock energy of each macroblock to obtain at least one macroblock The average macroblock energy of the block.
  17. 一种编码器,包括:获取部分、计算部分、量化部分与编码部分,其中,An encoder, comprising: an acquisition part, a calculation part, a quantization part and an encoding part, wherein,
    所述获取部分,被配置为当当前帧为待编码视频中的首帧时,在帧间级码率控制过程中,获取当前帧的图像信息;The acquisition part is configured to acquire image information of the current frame in the inter-frame-level code rate control process when the current frame is the first frame in the video to be encoded;
    所述计算部分,被配置为基于所述当前帧的图像信息,计算当前帧的复杂度累积值;The calculation part is configured to calculate the complexity cumulative value of the current frame based on the image information of the current frame;
    所述量化部分,被配置为基于所述当前帧的复杂度累积值,对所述当前帧进行编码量 化估计,得到所述当前帧的初始量化步长;Described quantization part, is configured to be based on the complexity accumulation value of described current frame, carry out coding quantization estimation to described current frame, obtain the initial quantization step size of described current frame;
    所述编码部分,被配置为基于所述当前帧的初始量化步长,对所述当前帧进行编码,得到所述当前帧的编码结果。The encoding part is configured 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.
  18. 一种编码器,包括:An encoder comprising:
    存储器,被配置为存储可执行数据指令;a memory configured to store executable data instructions;
    处理器,被配置为执行所述存储器中存储的可执行指令时,实现权利要求1至16任一项所述的方法。A processor, configured to execute the executable instructions stored in the memory, implements the method of any one of claims 1 to 16.
  19. 一种计算机可读存储介质,存储有可执行指令,被配置为引起处理器执行时,实现权利要求1至16任一项所述的方法。A computer-readable storage medium storing executable instructions configured to cause a processor, when executed, to implement the method of any one of claims 1 to 16.
  20. 一种计算机程序产品,所述计算机程序产品包括计算机可读代码,在所述计算机可读代码在编码器中运行的情况下,所述编码器中的处理器执行用于实现权利要求1至16任一项所述的方法。A computer program product comprising computer readable code which, when the computer readable code is run in an encoder, executed by a processor in the encoder for implementing claims 1 to 16 The method of any one.
PCT/CN2021/096491 2020-07-17 2021-05-27 Encoding method, encoder and computer readable storage medium WO2022012183A1 (en)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN202010693484.8 2020-07-17
CN202010693484.8A CN111866504B (en) 2020-07-17 2020-07-17 Encoding method, encoder and computer readable storage medium

Publications (1)

Publication Number Publication Date
WO2022012183A1 true WO2022012183A1 (en) 2022-01-20

Family

ID=73001604

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2021/096491 WO2022012183A1 (en) 2020-07-17 2021-05-27 Encoding method, encoder and computer readable storage medium

Country Status (2)

Country Link
CN (2) CN111866504B (en)
WO (1) WO2022012183A1 (en)

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115002512A (en) * 2022-05-23 2022-09-02 北京市商汤科技开发有限公司 Video transcoding method and device, electronic equipment and storage medium
CN116896641A (en) * 2023-09-11 2023-10-17 禹创半导体(深圳)有限公司 Image compression method, device, equipment and storage medium
CN118055234A (en) * 2024-04-16 2024-05-17 腾讯科技(深圳)有限公司 Video frame encoding method, apparatus, device, medium and computer program product

Families Citing this family (10)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111866504B (en) * 2020-07-17 2022-06-21 Oppo广东移动通信有限公司 Encoding method, encoder and computer readable storage medium
CN113573070A (en) * 2021-06-03 2021-10-29 浙江大华技术股份有限公司 Image coding method and device and computer storage medium
CN113438488B (en) * 2021-06-18 2023-01-31 北京锐马视讯科技有限公司 Low-bit-rate video optimization coding method, device, equipment and storage medium
CN113612999B (en) * 2021-08-20 2024-03-22 北京市商汤科技开发有限公司 Video processing method and device, electronic equipment and storage medium
CN113784126A (en) * 2021-09-17 2021-12-10 Oppo广东移动通信有限公司 Image encoding method, apparatus, device and storage medium
CN116205277A (en) * 2021-11-30 2023-06-02 北京灵汐科技有限公司 Event processing method and device, electronic equipment and computer readable medium
CN114245127B (en) * 2021-12-13 2024-03-19 北京百度网讯科技有限公司 Parameter adjustment method, device, equipment and medium of cloud desktop encoder
CN114584834B (en) * 2022-01-27 2024-02-13 百果园技术(新加坡)有限公司 Video quality optimization method, device, equipment and storage medium
CN116366847A (en) * 2022-07-26 2023-06-30 杭州海康威视数字技术股份有限公司 Video image decoding method, device and storage medium
CN116567286B (en) * 2023-07-10 2023-09-22 武汉幻忆信息科技有限公司 Online live video processing method and system based on artificial intelligence

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101882316A (en) * 2010-06-07 2010-11-10 深圳市融创天下科技发展有限公司 Method, device and system for regional division/coding of image
CN102036074A (en) * 2010-12-21 2011-04-27 汉王科技股份有限公司 Embedded equipment-based code rate control method and device
US20150215621A1 (en) * 2014-01-30 2015-07-30 Qualcomm Incorporated Rate control using complexity in video coding
CN109076212A (en) * 2017-12-27 2018-12-21 深圳市大疆创新科技有限公司 The method and code device of code rate control
CN111866504A (en) * 2020-07-17 2020-10-30 Oppo广东移动通信有限公司 Encoding method, encoder and computer readable storage medium

Family Cites Families (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102036062B (en) * 2009-09-29 2012-12-19 华为技术有限公司 Video coding method and device and electronic equipment
CN104219522B (en) * 2013-06-04 2018-02-16 北京大学 Bit rate control method and device in a kind of encoding video pictures
CN104796725B (en) * 2014-01-21 2019-10-01 Vixs系统公司 With method intra prediction pretreated video encoder and be used therewith
CN105049850B (en) * 2015-03-24 2018-03-06 上海大学 HEVC bit rate control methods based on area-of-interest
US20180324439A1 (en) * 2017-05-08 2018-11-08 Mediatek Inc. Method and apparatus for adaptive video encoding
CN109168030B (en) * 2018-10-12 2021-03-26 中南大学 Video transcoding method, device and storage medium thereof

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101882316A (en) * 2010-06-07 2010-11-10 深圳市融创天下科技发展有限公司 Method, device and system for regional division/coding of image
CN102036074A (en) * 2010-12-21 2011-04-27 汉王科技股份有限公司 Embedded equipment-based code rate control method and device
US20150215621A1 (en) * 2014-01-30 2015-07-30 Qualcomm Incorporated Rate control using complexity in video coding
CN109076212A (en) * 2017-12-27 2018-12-21 深圳市大疆创新科技有限公司 The method and code device of code rate control
CN111866504A (en) * 2020-07-17 2020-10-30 Oppo广东移动通信有限公司 Encoding method, encoder and computer readable storage medium

Cited By (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115002512A (en) * 2022-05-23 2022-09-02 北京市商汤科技开发有限公司 Video transcoding method and device, electronic equipment and storage medium
CN115002512B (en) * 2022-05-23 2023-11-28 北京市商汤科技开发有限公司 Video transcoding method and device, electronic equipment and storage medium
CN116896641A (en) * 2023-09-11 2023-10-17 禹创半导体(深圳)有限公司 Image compression method, device, equipment and storage medium
CN116896641B (en) * 2023-09-11 2023-12-12 禹创半导体(深圳)有限公司 Image compression method, device, equipment and storage medium
CN118055234A (en) * 2024-04-16 2024-05-17 腾讯科技(深圳)有限公司 Video frame encoding method, apparatus, device, medium and computer program product

Also Published As

Publication number Publication date
CN111866504B (en) 2022-06-21
CN111866504A (en) 2020-10-30
CN114979640A (en) 2022-08-30

Similar Documents

Publication Publication Date Title
WO2022012183A1 (en) Encoding method, encoder and computer readable storage medium
CN109068137B (en) Region of interest aware video coding
JP4847521B2 (en) Block noise removal filtering technology for video encoding according to multiple video standards
EP2430836B1 (en) Methods and apparatus for improved quantization rounding offset adjustment for video encoding
US8189933B2 (en) Classifying and controlling encoding quality for textured, dark smooth and smooth video content
CN108574841B (en) Coding method and device based on self-adaptive quantization parameter
WO2014139396A1 (en) Video coding method using at least evaluated visual quality and related video coding apparatus
US10873763B2 (en) Video compression techniques for high dynamic range data
JP2001512651A (en) Calculation method of quantization matrix for each frame
WO2002096118A2 (en) Decoding compressed image data
CN111193931B (en) Video data coding processing method and computer storage medium
EP2232879A1 (en) Method and apparatus for rate control accuracy in video encoding
EP3545677A1 (en) Methods and apparatuses for encoding and decoding video based on perceptual metric classification
KR20100058679A (en) Method and apparatus for rate control accuracy in video encoding and decoding
EP3092797A1 (en) Method and apparatus for encoding image data and method and apparatus for decoding image data
Wang et al. SSIM-inspired divisive normalization for perceptual video coding
CN113784126A (en) Image encoding method, apparatus, device and storage medium
WO2022021422A1 (en) Video coding method and system, coder, and computer storage medium
KR100823145B1 (en) Improvement device and quantization for the quality of image with ROI and the method for operating
WO2008027250A2 (en) Method and apparatus for analytical and empirical hybrid encoding distortion modeling
CN112243129B (en) Video data processing method and device, computer equipment and storage medium
CN112866696A (en) 4K, 8K and 16K ultra-high-definition video coding optimization control method and device
JP2002204449A (en) Quantization unit setting device, quantization unit setting method, coder and coding method, and information recording medium
Jung et al. HEVC encoder optimization for HDR video coding based on perceptual block merging
CN102271247B (en) Method and device for adjusting coding code rate

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 21842598

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 21842598

Country of ref document: EP

Kind code of ref document: A1