A method for rate control of video coding
By extracting the spatiotemporal-texture features of video frames and combining them with a 3D lookup table and a buffer state compensation factor, the accuracy and stability issues of bitrate control in existing video coding standards are solved, achieving precise bitrate allocation and buffer management, and improving video coding quality and efficiency.
Patent Information
- Application Number
- CN202611439361.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-09-16
- Publication Date
- 2026-11-27
AI Technical Summary
Existing video coding standards suffer from insufficient precision, unstable buffer state feedback, and inaccurate quantization parameter adjustment in complex scenarios, leading to unstable coding quality and resource waste.
By extracting the spatiotemporal-texture features of video frames, a set of basic feature maps is generated. A three-dimensional lookup table is used to classify the complexity level. A buffer state compensation factor is generated through proportional and integral operations. A nonlinear transformation is performed using a pre-calibrated bitrate-quantization parameter mapping curve to achieve closed-loop bitrate control.
It achieves precise bitrate allocation, suppresses buffer fluctuations, improves video quality and encoding efficiency, adapts to dynamic changes in video content, and ensures the stability and robustness of the output bitstream.
Smart Images

Figure CN123185356A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of next-generation information technology, and in particular to a method for controlling the bitrate of video encoding. Background Technology
[0002] Early video coding standards primarily employed rate-distortion optimization-based rate control algorithms, such as TM5 (Test Model 5) and VM8. These algorithms typically relied on pixel-domain complexity statistics, using simple statistics like mean absolute error (MAD) or mean to predict macroblock coding complexity and allocate bitrate accordingly. With advancements in coding technology, rate control methods based on the RQ (rate-quantization parameter) model emerged. These methods establish a mathematical relationship between quantization parameters and the generated bitrate, using quadratic or exponential models for bitrate prediction. In recent years, rate control techniques have gradually shifted towards perception and machine learning-based approaches, attempting to utilize visual saliency detection or neural networks to predict the complexity of image regions in order to achieve better subjective visual quality within limited bandwidth.
[0003] Existing bitrate control methods still suffer from significant shortcomings in accuracy and stability under complex scenarios. First, traditional complexity assessment methods often rely solely on single pixel residuals or gradient information, failing to comprehensively characterize the complexity of texture, motion, and spatial details within video frames. This leads to a mismatch between bitrate allocation and actual encoding requirements, resulting in blurred textured areas or wasted bitrate in flat areas. Second, regarding buffer state feedback mechanisms, existing technologies mostly employ simple linear compensation or hysteresis adjustment, lacking dynamic response capabilities to buffer occupancy deviations. This causes severe fluctuations in the buffer during scene transitions or rapid motion, leading to bitrate oscillations or quality jumps. Furthermore, existing bitrate-quantization parameter mapping relationships are largely based on empirical formulas or offline statistics, failing to fully consider the nonlinear characteristics at different complexity levels. This results in low precision in quantization parameter adjustment and slow convergence speed of closed-loop control, making it difficult to meet the stable encoding requirements of high-dynamic-range video sequences. Summary of the Invention
[0004] In order to overcome the above-mentioned defects of the prior art and to achieve the above objectives, the present invention proposes the following technical solution: A video encoding bitrate control method, comprising: S1: Obtain the video frame sequence, perform spatiotemporal-texture feature extraction preprocessing on the video frame sequence, and generate a set of basic feature maps; The basic feature map set includes the temporal activity, spatial detail, and texture energy value of each coding unit; S2: Based on the set of basic feature maps, a three-dimensional lookup table is used to map the complexity level and perform frame type weighted prediction to generate hierarchical bitrate allocation coefficients. The hierarchical code rate allocation coefficient includes the complexity level identifier of each coding unit and the corresponding code rate weight value. S3: Based on the hierarchical bitrate allocation coefficient, the buffer state compensation factor is generated by performing proportional and integral operations on the buffer deviation value, and the bitrate weight value is corrected. Then, the target quantization parameter is generated by performing nonlinear transformation through the precalibrated bitrate-quantization parameter mapping curve. S4: Quantize the transform coefficients based on the target quantization parameters, and update the buffer state according to the number of bits consumed after quantization to achieve closed-loop code rate control.
[0005] The process of generating the basic feature map set is as follows: Obtain the pixel difference between the current coded frame and the previous reference frame, generate a temporal residual map, and use the average absolute difference of each coded unit in the temporal residual map as the temporal activity. The 3×3 Sobel operator is used to perform gradient convolution operation on the current coded frame to generate a spatial gradient magnitude map. The root mean square of the sum of the squares of the vertical gradient components and the horizontal gradient components of each coded unit in the spatial gradient magnitude map is used as the spatial detail. Perform an 8×8 sub-block discrete cosine transform on the current encoded frame, extract the AC coefficient energy of each sub-block, generate a texture complexity map, and use the sum of squares of the 63 AC coefficients of each encoded unit in the texture complexity map as the texture energy value. Temporal activity, spatial detail, and texture energy values are correlated and integrated according to the location of the coding unit to obtain a set of basic feature maps.
[0006] The process of generating a spatial gradient magnitude map by performing gradient convolution on the current coded frame using the 3×3 Sobel operator includes: The horizontal gradient components are obtained by performing horizontal convolution operations on the pixels of the current encoded frame using the 3×3 Sobel operator. The vertical gradient components are obtained by performing vertical convolution operations on the pixels of the current encoded frame using the 3×3 Sobel operator. Calculate the sum of the squared values of the horizontal gradient components and the vertical gradient components to obtain the sum of squared gradients. The gradient magnitude is obtained by taking the square root of the sum of squared gradients. The average gradient magnitude of all pixels within each coding unit is used as the spatial detail to generate a spatial gradient magnitude map.
[0007] The process of generating hierarchical bitrate allocation coefficients is as follows: Extract the temporal activity, spatial detail, and texture energy value of each coding unit in the basic feature map set; Using temporal activity, spatial detail, and texture energy as indexes, a pre-built 3D lookup table is queried to obtain the complexity level corresponding to each coding unit, and a complexity level mapping table is generated. Match the corresponding initial bitrate weight coefficient according to the complexity level in the complexity level mapping table; Obtain the frame type identifier of the current encoded frame, and multiply the initial bitrate weight coefficient by the preset frame type adjustment factor based on the frame type identifier to obtain the hierarchical bitrate allocation coefficient.
[0008] The process of multiplying the initial bitrate weighting coefficient by a preset frame type adjustment factor based on the frame type identifier includes: Read the complexity level from the complexity level mapping table, and find the initial code rate weight coefficient corresponding to each complexity level according to the predefined correspondence between level and weight. Determine whether the frame type of the current coded frame is an intra-coded frame, a forward predictive coded frame, or a bidirectional predictive coded frame. When the frame type is identified as an intra-coded frame, the initial bit rate weight coefficient is multiplied by the first preset adjustment factor; When the frame type is identified as a forward predictive coding frame, the initial bit rate weight coefficient is multiplied by the second preset adjustment factor; When the frame type is identified as a bidirectional predictive coding frame, the initial bit rate weight coefficient is multiplied by the third preset adjustment factor to generate the hierarchical bit rate allocation coefficient.
[0009] The process of generating the target quantization parameters is as follows: Obtain the current actual occupancy rate of the encoding buffer, calculate the difference between the target buffer occupancy rate and the actual occupancy rate, and obtain the buffer deviation value; The buffer deviation value is proportionally calculated to obtain the proportional compensation value, and the buffer deviation value is integrally calculated to obtain the integral compensation value. The proportional compensation value and the integral compensation value are added together to generate the buffer state compensation factor. The corrected rate allocation coefficients are obtained by multiplying the rate weight values in the hierarchical rate allocation coefficients using the buffer state compensation factor. The corrected bitrate allocation coefficients are input into the pre-calibrated bitrate-quantization parameter mapping curve, and non-linear mapping is performed to obtain the target quantization parameters.
[0010] The process of inputting the corrected rate allocation coefficients into the pre-calibrated rate-quantization parameter mapping curve to perform nonlinear mapping includes: Read the pre-stored bitrate-quantization parameter mapping curve, which is obtained through offline training and represents the correspondence between bitrate weights and quantization parameters under different complexity levels; The corrected bitrate allocation coefficient is used as the horizontal axis value. Substitute it into the function relationship corresponding to the bitrate-quantization parameter mapping curve to calculate the corresponding vertical axis value and obtain the initial value of the quantization parameter. The initial value of the quantization parameter is rounded to the nearest integer, and the rounded value is restricted to the range of the preset quantization parameter to obtain the target quantization parameter.
[0011] The process of achieving closed-loop bit rate control is as follows: Substitute the target quantization parameters into the quantizer, perform a division truncation operation on the transform coefficients generated during the video encoding process, and generate quantized coefficients. Entropy encoding is performed on the quantized coefficients, the length of the binary bit stream output by entropy encoding is counted, and the actual number of bits consumed by the current encoding unit is calculated. The actual number of bits consumed is deducted from the remaining allocable bits in the current encoding buffer to obtain the updated remaining allocable bits. Closed-loop rate control is achieved by recalculating the actual occupancy of the current encoding buffer based on the updated remaining allocable bits.
[0012] The present invention has the following beneficial effects: 1. By extracting temporal activity, spatial detail, and texture energy values to construct a multi-dimensional basic feature map set, and combining it with a three-dimensional lookup table for complexity classification, this method can comprehensively and accurately reflect the true coding difficulty of coding units. Compared with traditional single indicators, this method realizes the transformation from "coarse estimation" to "fine classification", making the bitrate allocation more in line with the image content. It effectively avoids the problems of distortion in texture-rich areas due to insufficient bitrate and waste in flat areas due to excessive bitrate.
[0013] 2. By introducing proportional and integral operations to process the buffer deviation value, a buffer state compensation factor is generated, forming a closed-loop feedback control system. This mechanism can quickly respond to changes in buffer occupancy, automatically reducing the bit rate weight when the buffer is full and automatically increasing the bit rate weight when the buffer is idle, effectively suppressing the risk of buffer overflow or underflow and ensuring the stability and continuity of the output bitstream.
[0014] 3. By using a pre-calibrated bitrate-quantization parameter mapping curve for nonlinear mapping, the method overcomes the mapping distortion defects of traditional linear models in low or high bitrate ranges. This method can accurately output the target quantization parameter based on the corrected bitrate allocation coefficient, improving the linearity and accuracy of quantization parameter adjustment. This allows the encoding process to maximize the peak signal-to-noise ratio and subjective visual quality of the video while maintaining the target bitrate.
[0015] 4. By feeding back the actual number of bits consumed in real time to the calculation of the remaining allocable bits in the buffer, and recalculating the actual occupancy rate to participate in the generation of the next round of quantization parameters, a complete closed-loop control loop is formed. This real-time feedback mechanism enables the bitrate control method to dynamically adapt to sudden changes and fluctuations in the complexity of video content, significantly improving the system's robustness and coding efficiency under varying video sequences. Attached Figure Description
[0016] Figure 1 This is a flowchart illustrating the steps of a video encoding rate control method proposed in this invention.
[0017] Figure 2 This is a schematic diagram illustrating a video encoding bitrate control method proposed in this invention. Detailed Implementation
[0018] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0019] Example 1
[0020] like Figure 1-2 As shown, the present invention proposes a video encoding bitrate control method, comprising: S1: Obtain the video frame sequence, perform spatiotemporal-texture feature extraction preprocessing on the video frame sequence, and generate a set of basic feature maps; First, obtain the pixel difference between the current encoded frame and the previous reference frame. Let the brightness value of the pixel located in the i-th row and j-th column of the current encoded frame be... The pixel brightness value at the corresponding position in the previous reference frame is Calculate the absolute difference between the two. ; A temporal residual map D is generated by traversing the entire frame of the image. The temporal residual map is divided into coding units of size 16×16 pixels, and all values within each coding unit are calculated. The arithmetic mean of the values is used as the temporal activity T of the coding unit. Subsequently, a 3×3 Sobel operator is used to perform gradient convolution on the current coded frame: A 3×3 Sobel operator is used to perform horizontal convolution operations on each pixel of the current coded frame. For each pixel within the image, its 3×3 neighborhood is multiplied and accumulated with the horizontal convolution kernel to obtain the horizontal gradient component. ; Subsequently, a 3×3 Sobel operator is used to perform vertical convolution operations on each pixel of the current encoded frame. For each pixel, its 3×3 neighborhood is multiplied and accumulated with the vertical convolution kernel to obtain the vertical gradient component. ; Next, the sum of the squared values of the horizontal and vertical gradient components is calculated to obtain the gradient summation. For each pixel, this is calculated. Generate a gradient sum of squares plot; Then, the square root operation is performed on the sum of squared gradients to obtain the gradient magnitude. The square root of each value in the sum of squared gradient graph is then taken to obtain the gradient magnitude M, thus generating a spatial gradient magnitude graph. Finally, the average gradient magnitude of all pixels in each coding unit is taken as the spatial detail. The spatial gradient magnitude map is divided into coding units of 16×16 pixels, and the average value of all M values in the unit is calculated, which is the spatial detail S. Next, perform an 8×8 sub-block discrete cosine transform on the current coded frame: First, the current encoded frame is divided into non-overlapping 8×8 pixel sub-blocks. The image is then divided into several 8×8 pixel blocks according to the raster scan order. Subsequently, a discrete cosine transform is performed on each 8×8 pixel sub-block. A two-dimensional discrete cosine transform is performed on each sub-block to obtain 64 transform coefficients F(u,v), where u and v are frequency coordinates. Next, the DC coefficients of the 64 transformation coefficients are removed, and the 63 AC coefficients are retained. The coefficient F(0,0) at the frequency coordinate u=0 and v=0 is defined as the DC coefficient and removed, and the remaining 63 AC coefficients are retained. Finally, the sum of squares of the 63 AC coefficients is calculated and used as the texture energy value to generate a texture complexity map. The texture energy value E is obtained by squaring each of the 63 AC coefficients and then summing the results. The calculation formula is as follows:
[0021] Arrange the texture energy values E of all sub-blocks according to their positions to generate a texture complexity map; Finally, the temporal activity, spatial detail, and texture energy values are correlated and integrated according to the coding unit position. These three values are combined into a feature vector, and all feature vectors are arranged in the order of image raster scanning to obtain a set of basic feature maps.
[0022] S2: Based on the set of basic feature maps, a three-dimensional lookup table is used to map the complexity level and perform frame type weighted prediction to generate hierarchical bitrate allocation coefficients. First, extract the temporal activity, spatial detail, and texture energy values corresponding to each coding unit in the basic feature map set. Then, read the basic feature map set generated by the previous steps, which is organized with coding units as the basic unit. Traverse each encoding unit in the set and parse out the three feature parameters corresponding to the unit in turn: temporal activity T, spatial detail S, and texture energy E. These parameters together constitute the feature vector of the coding unit, which is used to characterize the visual complexity of the region. Subsequently, using temporal activity, spatial detail, and texture energy values as indexes, a pre-built 3D lookup table is queried to obtain the complexity level corresponding to each coding unit, generating a complexity level mapping table. The pre-built 3D lookup table is a discretized mapping matrix. Its three input dimensions correspond to the quantization ranges of temporal activity T, spatial detail S, and texture energy E, respectively, and the output dimension is the complexity level L. Specifically, the three extracted feature values are divided by their respective quantization step sizes and rounded to obtain the three-dimensional index address. , , The address is used to perform an address lookup operation in the three-dimensional lookup table, read the complexity level value L stored at the address, traverse all coding units, establish a one-to-one correspondence between the identifier of each coding unit and its corresponding complexity level L, and form a complexity level mapping table. Next, the corresponding initial bitrate weight coefficient is matched according to the complexity level in the complexity level mapping table; A predefined linear correspondence between complexity levels and initial bitrate weight coefficients is established. This correspondence is typically stored as a one-dimensional array or lookup table, where the array index is the complexity level L and the array value is the corresponding initial bitrate weight coefficient. ; Among them, the higher the complexity level L, the more important or more difficult the region is to compress. The larger the value; Traverse the complexity level mapping table, and search within the one-dimensional array above according to the complexity level L of each coding unit to obtain the corresponding initial bitrate weight coefficient. ; Obtain the frame type identifier of the current encoded frame, and multiply the initial bitrate weight coefficient by a preset frame type adjustment factor based on the frame type identifier, specifically: First, read the complexity levels from the complexity level mapping table, and according to the predefined correspondence between levels and weights, find the initial bitrate weight coefficient corresponding to each complexity level. ; Subsequently, the frame type identifier of the current coded frame is determined as an intra-coded frame, a forward predictive coded frame, or a bidirectional predictive coded frame. Next, when the frame type is identified as an intra-coded frame, the initial bitrate weighting coefficient is multiplied by the first preset adjustment factor. ; Then, when the frame type is identified as a forward predictive coded frame, the initial bit rate weight coefficient is multiplied by the second preset adjustment factor. ; Finally, when the frame type is identified as a bidirectional predictive coded frame, the initial bit rate weight coefficient is multiplied by the third preset adjustment factor. ; Among them, the three adjustment factors satisfy the relationship ; Parse the frame header syntax elements of the current coded frame to obtain the frame type identification information, which indicates that the current frame belongs to one of the following: intra-coded frame, forward predictive coded frame, or bidirectional predictive coded frame. Select the corresponding preset adjustment factor based on the frame type identifier; the intra-coded frame corresponds to the first preset adjustment factor. The forward predictive coded frame corresponds to the second preset adjustment factor. The bidirectional predictive coded frame corresponds to the third preset adjustment factor. ; Initial bitrate weighting coefficients Multiplying the selected adjustment factor yields the hierarchical rate allocation coefficient W for that coding unit. Summarizing the hierarchical rate allocation coefficients W for all coding units yields the hierarchical rate allocation coefficient set.
[0023] S3: Based on the hierarchical bitrate allocation coefficient, the buffer state compensation factor is generated by performing proportional and integral operations on the buffer deviation value, and the bitrate weight value is corrected. Then, the target quantization parameter is generated by performing nonlinear transformation through the precalibrated bitrate-quantization parameter mapping curve. First, obtain the current actual occupancy rate of the encoding buffer, calculate the difference between the target buffer occupancy rate and the actual occupancy rate to obtain the buffer deviation value, and read the encoding buffer status register to obtain the number of bits stored in the buffer at the current moment. and the total capacity of the buffer ; Calculate the actual occupancy rate of the current encoding buffer. The calculation formula is: Predefined target buffer occupancy rate This value is usually set between 0.5 and 0.8 to maintain the stable state of the buffer. The difference between the target buffer occupancy rate and the actual occupancy rate is calculated to obtain the buffer deviation value e. This deviation value e reflects the degree of deviation between the current buffer state and the target state. Subsequently, a proportional calculation is performed on the buffer deviation value to obtain the proportional compensation value, and an integral calculation is performed on the buffer deviation value to obtain the integral compensation value. The proportional compensation value and the integral compensation value are added together to generate the buffer state compensation factor, and the proportional coefficient is set. and integral coefficient These two coefficients are determined through system identification or experience; Multiply the current buffer deviation value e by the scaling factor Obtain the proportional compensation value The calculation formula is: ; At the same time, the current deviation value e is added to the total historical deviation, and the result is multiplied by the integral coefficient. Obtain the compensation value for the integral item. The calculation formula is: The proportional compensation value Compensation value with integral term Add them together to generate the buffer state compensation factor. ; The compensation factor is used to dynamically adjust the margin of the code rate allocation to prevent buffer overflow or underflow. Next, the bitrate weight values in the hierarchical bitrate allocation coefficients are multiplied using the buffer state compensation factor to obtain the corrected bitrate allocation coefficients. The hierarchical bitrate allocation coefficient set is read, and the bitrate weight value W of the i-th coding unit is obtained. This bitrate weight value W is then multiplied by the buffer state compensation factor. Multiply the values and dynamically adjust the weights using a compensation factor to obtain the adjusted bitrate allocation coefficients. ; When the buffer is nearly full, If the value is less than 1, the bitrate weight is reduced to slow down the data inflow; when the buffer is idle, If the value is greater than 1, increase the bitrate weight to improve quality; Then the corrected bitrate allocation coefficients Input a pre-calibrated bitrate-quantization parameter mapping curve and perform a non-linear mapping: Read the pre-stored bitrate-quantization parameter mapping curve, which is obtained through offline training and represents the correspondence between bitrate weights and quantization parameters under different complexity levels; Read the pre-calibrated bitrate-quantization parameter mapping curve data from a non-volatile storage medium. The curve data reflects the size of the quantization parameter required to achieve the target bitrate under different coding complexities. During the offline training phase, a large number of video sequences with different texture complexities are pre-encoded, and the bitrate weight values when a specific bitrate is reached under different quantization parameters are statistically analyzed to fit the nonlinear mapping curve. This curve usually exhibits monotonically increasing logarithmic or exponential characteristics to ensure a unique correspondence between input and output. Subsequently, the corrected bitrate allocation coefficients will be... Substitute the horizontal axis value into the function relationship corresponding to the bitrate-quantization parameter mapping curve to calculate the corresponding vertical axis value and obtain the initial value of the quantization parameter. For each coding unit, its corrected rate allocation coefficients are read. If the mapping curve is stored in the form of a mathematical function, then the corrected bitrate allocation coefficients will be... Substituting the values as independent variables into the corresponding functional relationship for calculation, if the mapping curve is stored in the form of a lookup table, then the lookup and correction of the bitrate allocation coefficients are performed. Find the closest x-coordinate value and read its corresponding y-coordinate value; The calculated or table-lookup value is defined as the initial value of the quantization parameter. ; Among them, the initial value of the quantization parameter It is usually a floating-point number, reflecting the theoretically optimal quantization step size; Finally, the initial value of the quantization parameter is rounded to the nearest integer, and the rounded value is limited to the preset quantization parameter range to obtain the target quantization parameter. Because video coding standards (such as H.264 / AVC, H.265 / HEVC, etc.) stipulate that quantization parameters must be integers, therefore, the initial value of the quantization parameter... Perform rounding to the nearest integer to obtain the quantization parameters in integer form. ; The default range for the quantization parameter is 0 to 51. The quantization parameter is then evaluated in integer form. If the value is less than 0, then set the target quantization parameter QP to 0. Determine the quantization parameter in integer form If the value is greater than 51, then set the target quantization parameter QP to 51. Otherwise, use integer quantization parameters. The formula for directly using QP as the target quantization parameter is as follows:
[0024] Here, round() represents the rounding function, and the target quantization parameter QP will be directly used to control the encoder's quantizer to complete the final bit rate control decision.
[0025] S4: Quantize the transform coefficients based on the target quantization parameters, and update the buffer state according to the number of bits consumed after quantization to achieve closed-loop code rate control; First, the target quantization parameters are substituted into the quantizer, and the transform coefficients generated during the video encoding process are truncated by division to generate quantized coefficients. Read the target quantization parameter QP generated by the preceding steps, and map QP to the corresponding quantization step size according to the predefined quantization step size lookup table of the video coding standard (such as H.264 / AVC or H.265 / HEVC). During video encoding, after the current coding unit undergoes intra-frame or inter-frame prediction, a prediction residual signal is generated. This residual signal is then transformed into transform coefficients X by integer transformation (such as discrete cosine transform or its approximate transformation). The quantizer receives the transform coefficients X and the quantization step size. Perform division truncation operation, that is, calculate The calculation result is rounded to zero (decimal part is truncated) to generate the quantized coefficient Xq; This process, which reduces the amount of data by lowering the precision of the coefficients, is the core step in achieving bitrate control. Subsequently, entropy encoding is performed on the quantized coefficients, the length of the binary bitstream output by entropy encoding is counted, the actual number of bits consumed by the current encoding unit is calculated, and the quantized coefficients are then... The input entropy encoder uses context-adaptive binary arithmetic coding or variable-length coding to scan, run-length encoded and binaryize the quantized coefficients to generate a compressed binary bitstream. Then, during the entropy coding process, the length of the output bitstream is counted in real time, and the total number of bits in the binary code stream generated by the current coding unit is recorded. This number of bits is defined as the number of bits actually consumed by the current coding unit. ; This value accurately reflects the actual usage of buffer resources by the current coding unit under the current quantization parameters; Next, the actual number of bits consumed is subtracted from the remaining allocable bits in the current encoding buffer to obtain the updated remaining allocable bits, and the remaining allocable bit counter of the current encoding buffer is read. This counter records the bit budget that has not yet been allocated within the current frame or current picture group, and the number of bits actually consumed by the current coding unit. From the remaining allocatable bits Subtract from the middle, perform a deduction operation, and obtain the updated number of remaining allocable bits. ; Finally, based on the updated remaining allocable bits, the actual occupancy rate of the current encoding buffer is recalculated to achieve closed-loop rate control and obtain the total capacity of the encoding buffer. Total capacity The maximum number of bits that the buffer can hold is defined. Using the updated number of remaining allocatable bits and total capacity Recalculate the actual occupancy rate of the current encoding buffer. The calculation formula is as follows:
[0026] Among them, the calculated actual occupancy rate Ocurr reflects the fullness of the buffer at the current moment; Based on actual occupancy rate The step of generating target quantization parameters is used to calculate the buffer deviation value e of the next coding unit. Through this feedback mechanism, the system can dynamically adjust the quantization parameters of subsequent coding units according to the real-time status of the buffer, thereby forming a closed-loop control system to ensure that the output bit rate is stable at the target level, effectively avoid buffer overflow or underflow, and maintain the smooth transmission of the video bitstream.
[0027] In the application, several formulas are calculated by removing dimensions and taking their numerical values. The formulas are established by collecting a large amount of data and simulating the most recent real situation. Some coefficients or weights in the formulas are set by those skilled in the art according to the actual situation, so they will not be elaborated here.
[0028] The above embodiments can be implemented, in whole or in part, by software, hardware, firmware, or any other combination thereof. When implemented in software, the above embodiments can be implemented, in whole or in part, as a computer program product. Those skilled in the art will recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution.
[0029] Although embodiments of the invention have been shown and described, it will be understood by those skilled in the art that various changes, modifications, substitutions and alterations can be made to these embodiments without departing from the principles and spirit of the invention, the scope of which is defined by the appended claims and their equivalents.
Claims
1. A video encoding bitrate control method, characterized in that, include: S1: Obtain the video frame sequence, perform spatiotemporal-texture feature extraction preprocessing on the video frame sequence, and generate a set of basic feature maps; The basic feature map set includes the temporal activity, spatial detail, and texture energy value of each coding unit; S2: Based on the set of basic feature maps, a three-dimensional lookup table is used to map the complexity level and perform frame type weighted prediction to generate hierarchical bitrate allocation coefficients. The hierarchical code rate allocation coefficient includes the complexity level identifier of each coding unit and the corresponding code rate weight value. S3: Based on the hierarchical bitrate allocation coefficient, the buffer state compensation factor is generated by performing proportional and integral operations on the buffer deviation value, and the bitrate weight value is corrected. Then, the target quantization parameter is generated by performing nonlinear transformation through the precalibrated bitrate-quantization parameter mapping curve. S4: Quantize the transform coefficients based on the target quantization parameters, and update the buffer state according to the number of bits consumed after quantization to achieve closed-loop code rate control.
2. The video encoding bitrate control method as described in claim 1, characterized in that, The process of generating the basic feature map set is as follows: Obtain the pixel difference between the current coded frame and the previous reference frame, generate a temporal residual map, and use the average absolute difference of each coded unit in the temporal residual map as the temporal activity. The 3×3 Sobel operator is used to perform gradient convolution operation on the current coded frame to generate a spatial gradient magnitude map. The root mean square of the sum of the squares of the vertical gradient components and the horizontal gradient components of each coded unit in the spatial gradient magnitude map is used as the spatial detail. Perform an 8×8 sub-block discrete cosine transform on the current encoded frame, extract the AC coefficient energy of each sub-block, generate a texture complexity map, and use the sum of squares of the 63 AC coefficients of each encoded unit in the texture complexity map as the texture energy value. Temporal activity, spatial detail, and texture energy values are correlated and integrated according to the location of the coding unit to obtain a set of basic feature maps.
3. A video encoding bitrate control method as described in claim 2, characterized in that, The process of generating a spatial gradient magnitude map by performing gradient convolution on the current coded frame using the 3×3 Sobel operator includes: The horizontal gradient components are obtained by performing horizontal convolution operations on the pixels of the current encoded frame using the 3×3 Sobel operator. The vertical gradient components are obtained by performing vertical convolution operations on the pixels of the current encoded frame using the 3×3 Sobel operator. Calculate the sum of the squared values of the horizontal gradient components and the vertical gradient components to obtain the sum of squared gradients. The gradient magnitude is obtained by taking the square root of the sum of squared gradients. The average gradient magnitude of all pixels within each coding unit is used as the spatial detail to generate a spatial gradient magnitude map.
4. The video encoding bitrate control method as described in claim 1, characterized in that, The process of generating hierarchical bitrate allocation coefficients is as follows: Extract the temporal activity, spatial detail, and texture energy value of each coding unit in the basic feature map set; Using temporal activity, spatial detail, and texture energy as indexes, a pre-built 3D lookup table is queried to obtain the complexity level corresponding to each coding unit, and a complexity level mapping table is generated. Match the corresponding initial bitrate weight coefficient according to the complexity level in the complexity level mapping table; Obtain the frame type identifier of the current encoded frame, and multiply the initial bit rate weight coefficient by the preset frame type adjustment factor based on the frame type identifier to obtain the hierarchical bit rate allocation coefficient.
5. A video encoding bitrate control method as described in claim 4, characterized in that, The process of multiplying the initial bitrate weighting coefficient by a preset frame type adjustment factor based on the frame type identifier includes: Read the complexity level from the complexity level mapping table, and find the initial code rate weight coefficient corresponding to each complexity level according to the predefined correspondence between level and weight. Determine whether the current coded frame is an intra-coded frame, a forward predictive coded frame, or a bidirectional predictive coded frame. When the frame type is identified as an intra-coded frame, the initial bit rate weight coefficient is multiplied by the first preset adjustment factor; When the frame type is identified as a forward predictive coding frame, the initial bit rate weight coefficient is multiplied by the second preset adjustment factor; When the frame type is identified as a bidirectional predictive coding frame, the initial bit rate weight coefficient is multiplied by the third preset adjustment factor to generate the hierarchical bit rate allocation coefficient.
6. A video encoding bitrate control method as described in claim 1, characterized in that, The process of generating the target quantization parameters is as follows: Obtain the current actual occupancy rate of the encoding buffer, calculate the difference between the target buffer occupancy rate and the actual occupancy rate, and obtain the buffer deviation value; The buffer deviation value is proportionally calculated to obtain the proportional compensation value, and the buffer deviation value is integrally calculated to obtain the integral compensation value. The proportional compensation value and the integral compensation value are added together to generate the buffer state compensation factor. The corrected rate allocation coefficients are obtained by multiplying the rate weight values in the hierarchical rate allocation coefficients using the buffer state compensation factor. The corrected bitrate allocation coefficients are input into the pre-calibrated bitrate-quantization parameter mapping curve, and non-linear mapping is performed to obtain the target quantization parameters.
7. A video encoding bitrate control method as described in claim 6, characterized in that, The process of inputting the corrected rate allocation coefficients into the pre-calibrated rate-quantization parameter mapping curve to perform nonlinear mapping includes: Read the pre-stored bitrate-quantization parameter mapping curve, which is obtained through offline training and represents the correspondence between bitrate weights and quantization parameters under different complexity levels; The corrected bitrate allocation coefficient is used as the horizontal axis value. Substitute it into the function relationship corresponding to the bitrate-quantization parameter mapping curve to calculate the corresponding vertical axis value and obtain the initial value of the quantization parameter. The initial value of the quantization parameter is rounded to the nearest integer, and the rounded value is restricted to the range of the preset quantization parameter to obtain the target quantization parameter.
8. A video encoding bitrate control method as described in claim 1, characterized in that, The process of achieving closed-loop bit rate control is as follows: Substitute the target quantization parameters into the quantizer, perform a division truncation operation on the transform coefficients generated during the video encoding process, and generate quantized coefficients. Entropy encoding is performed on the quantized coefficients, the length of the binary bit stream output by entropy encoding is counted, and the actual number of bits consumed by the current encoding unit is calculated. The actual number of bits consumed is deducted from the remaining allocable bits in the current encoding buffer to obtain the updated remaining allocable bits. Closed-loop rate control is achieved by recalculating the actual occupancy of the current encoding buffer based on the updated remaining allocable bits.
