A Bitrate Control Method and Device for Constant Video Quality
By calculating the PSNR during the video encoding process and using the R-D model to predict the target encoding bit number, the problems of adjustment period and oscillation in the prior art are solved, and fast and stable constant video quality control is achieved.
Patent Information
- Application Number
- CN202310875692.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-07-17
- Publication Date
- 2025-07-25
- Estimated Expiration
- 2043-07-17
AI Technical Summary
The existing variable bit rate control method for constant video quality has a long adjustment period and is prone to oscillation when adjusting the video encoding quality, and cannot quickly stabilize within the video quality range expected by users.
By calculating its peak signal-to-noise ratio PSNR when the encoding of the previous video frame is completed, and using the time domain similarity of the R-D model and the front and rear video frames, the target encoding bit number of video frames to be encoded is predicted, and the smooth step length is adjusted in combination with the bit rate, and the encoding parameters are quickly adjusted to maintain the video quality within the preset range.
The code rate control is achieved directly and effectively, and the video quality is quickly returned and stabilized within the expected range of users, avoiding oscillation and improving user experience.
Smart Images

Figure CN117014613B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to a video coding technology, and particularly to a bitrate control method with constant video quality and adaptive variable bitrate. Background Art
[0002] Video coding is a technology that compresses redundant components in video images and uses as little data as possible to represent video information. Common video coding standards include HEVC (High Efficiency Video Coding), also known as H.265, and AVC (Advanced Video Coding), also known as H.264.
[0003] Video coding technology uses image blocks as the most basic coding units. For example, in HEVC, the basic unit of video coding is the CU (Coding Unit). The CU can be an image block with a size of 64 pixels × 64 pixels, 32 pixels × 32 pixels, 16 pixels × 16 pixels, or 8 pixels × 8 pixels. Among them, the image block with a size of 64 pixels × 64 pixels is also called the LCU (Largest Coding Unit).
[0004] In order to improve the video compression ratio as much as possible, common video coding algorithms often adopt lossy compression algorithms, resulting in differences (distortion) between the encoded and reconstructed video and the original video. Both HEVC and AVC belong to lossy compression algorithms. The coding performance of lossy compression algorithms is jointly measured by the coding bitrate (Rate) and the distortion (Distortion) introduced by coding. During the video coding process, the coding bitrate R and the coding distortion D restrict and contradict each other. Reducing the coding bitrate R often increases the coding distortion D, and reducing the coding distortion D often increases the coding bitrate R. Rate-Distortion Optimization (RDO) is to minimize the coding distortion D as much as possible under a certain coding bitrate R, or to minimize the coding bitrate R as much as possible under a certain coding distortion D. Common video coding algorithms all adopt a rate-distortion optimization method based on the Lagrange multiplier λ, which is to obtain the minimum coding rate-distortion cost (RD Cost) J, where J = D + λ × R.
[0005] During video encoding, each encoding mode has an encoding distortion D and an encoding bitrate R, and the rate-distortion cost J of each encoding mode can be calculated. During video encoding, selecting the encoding mode with the minimum rate-distortion cost J for encoding can achieve optimal encoding performance. The process by which the encoder selects the optimal encoding mode for each image block to be encoded through rate-distortion optimization is called the mode decision of the image block to be encoded.
[0006] In real life, the channel bandwidth capacity for transmitting video is limited. If the encoding bitrate of the video is too high and exceeds the channel bandwidth capacity, it will cause video transmission congestion or even packet loss. If the encoding bitrate of the video is too low, it will result in the underutilization of the channel bandwidth and the inability to obtain higher video quality. Therefore, it is necessary to use rate control technology to control the output bitrate of the video encoder to match the channel bandwidth capacity.
[0007] Rate control is to adjust the encoding parameters of the video encoder so that the output bitrate of the video encoder is equal to the preset target bitrate, while minimizing the encoding distortion as much as possible to improve the video encoding quality. In common rate control algorithms, the rate control task is generally achieved through two links: target bit allocation and target bit control.
[0008] The target bit allocation link is generally carried out at three levels, namely the GOP (Group of Pictures, that is, a set of temporally consecutive video frames) level, the video frame level, and the image block level. The target bit allocation at the GOP level is to obtain the target encoding bits of the GOP based on the target encoding bitrate of the video. The target bit allocation at the video frame level is to obtain the target encoding bits of each video frame within the GOP based on the target encoding bits of the GOP. The target bit allocation at the image block level is to obtain the target encoding bits of each image block within the video frame based on the target encoding bits of the video frame and the bit allocation weights of each image block within the video frame.
[0009] The target bit control link is generally carried out at the video frame level and the image block level. At the video frame level, the Lagrange multiplier λ and the quantization parameter (QP) at the video frame level are calculated based on the target encoding bits of the video frame. At the image block level, the Lagrange multiplier λ and the quantization parameter QP at the image block level of a certain image block are calculated based on the target encoding bits of the image block, the Lagrange multiplier λ and the quantization parameter QP at the video frame level of the video frame to which the image block belongs, and the Lagrange multiplier λ and the quantization parameter QP at the image block level of the previous encoded image block, and are used for the video encoding process of the image block.
[0010] Both the Lagrange multiplier λ and the quantization parameter QP are divided into video frame level and image block level. In the target bit allocation and target bit control links at the video frame level (i.e., the bit rate control at the video frame level), the Lagrange multiplier λ and the quantization parameter QP at the video frame level are used. In the target bit allocation and target bit control links at the image block level (i.e., the bit rate control at the image block level), the Lagrange multiplier λ and the quantization parameter QP at the image block level are used. The Lagrange multiplier at the video frame level is sometimes simply referred to as the Lagrange multiplier at the video frame level, the Lagrange multiplier at the frame level, or the Lagrange multiplier of the video frame. The Lagrange multiplier at the image block level is sometimes simply referred to as the Lagrange multiplier at the image block level, the Lagrange multiplier at the block level, or the Lagrange multiplier of the image block. The abbreviations of the quantization parameter are similar.
[0011] In the common CBR (Constant Bit Rate) bit rate control method, regardless of how the content of the video frame changes, the encoding bit rate (i.e., the encoding bit rate) of the video frame needs to be maintained at a constant value. The bit rate of the video stream encoded by the CBR bit rate control method is stable and is very suitable for scenarios sensitive to changes in the video encoding bandwidth, such as real-time video calls. However, in the CBR bit rate control method, since the encoding bit rate of the video frame is constant, when the content of the video frame is relatively simple (for example, the video content has simple texture or small motion), the video encoding quality will become very high, even exceeding the user's requirements, resulting in a large amount of bit waste. When the content of the video frame is relatively complex (for example, the video content has complex texture or large motion), due to the constant encoding bit rate of the video frame, more bits cannot be used for encoding, which will cause a significant reduction in the video encoding quality and cannot meet the user's requirements. Therefore, although the CBR bit rate control method can achieve a constant encoding bit rate, when the content of the video frame changes, the video encoding quality will also fluctuate greatly, affecting the user's viewing experience.
[0012] Therefore, it is necessary to develop a variable bit rate control method with constant video quality that can automatically detect changes in the video encoding quality of a video sequence (i.e., an ordered arrangement of multiple video frames) and adjust the encoding bit rate of the video sequence accordingly, so that the video encoding quality of the video sequence is maintained within an acceptable and roughly constant range. When the video encoding quality of the video sequence is too high, the encoding bit rate is reduced to save the number of encoding bits; when the video encoding quality of the video sequence is too low, the encoding bit rate is increased to improve the video encoding quality.
[0013] At present, there are some bit rate control methods with constant video quality and variable bit rate. For example, a negative feedback method is used. When the encoding quality of each video frame is completed, the encoding quality of the video frame is calculated. When the encoding quality of the video frame exceeds the upper threshold, the encoding parameters of the subsequent video frames are adjusted (for example, the quantization parameter QP of the video frame is increased) to reduce the encoding quality of the video sequence. When the encoding quality of the video frame is lower than the lower threshold, the encoding parameters of the subsequent video frames are adjusted (for example, the quantization parameter QP of the video frame is reduced) to improve the encoding quality of the video sequence. This scheme has the following defects: (1) The adjustment cycle is long. When the encoding quality of the video frame exceeds the upper and lower thresholds, adjustments need to be made on more subsequent video frames to restore the video encoding quality to normal. (2) When adjusting the encoding parameters of the video frame, if the adjustment step size is not set reasonably, video encoding quality oscillation is likely to occur. Summary of the invention
[0014] The technical problem to be solved by the present invention is: how to make the bit rate control method of the variable bit rate with constant video quality to achieve rapid adjustment and not easy to generate oscillation.
[0015] To solve the above technical problems, the present invention proposes a bit rate control method for constant video quality, comprising the following steps. Step S1: When the encoding of the previous video frame is completed, use its corresponding original video frame and reconstructed video frame to calculate its peak signal-to-noise ratio (PSNR). Step S2: Determine whether the PSNR of the previous encoded video frame is within the PSNR lower limit threshold (PSNR) preset by the user. min PSNR upper threshold PSNR max within the PSNR threshold range; if not, proceed to step S3; if yes, proceed to step S4. Step S3: Based on the relationship model between the coding distortion and the coding bit rate of the video encoder, namely the RD model, the similarity in the time domain of the previous and subsequent video frames is utilized, and the parameters of the previous encoded video frame are used to replace the corresponding parameters of the video frame to be encoded, and the target coding bit number of the video frame to be encoded that can make the PSNR of the video frame to be encoded return to the PSNR threshold range preset by the user is predicted; then proceed to step S5. Step S4: According to the target bit rate and bit rate adjustment smoothing step size of the video sequence preset by the user, calculate the target coding bit number of the video frame to be encoded that can maintain the coding bit rate of the video sequence at the target bit rate preset by the user; then proceed to step S5. Step S5: According to the target coding bit number of the video frame to be encoded, the target bit control operation is performed on the video frame to be encoded to obtain the Lagrange multiplier and quantization parameter of the video frame to be encoded.
[0016] Furthermore, in step S1, the calculation formula of the PSNR of the encoded video frame is: where bits is the bit width of the pixel points inside the encoded video frame, and MSE is the mean square error of the encoded video frame; where M is the width of the video frame, N is the height of the video frame, and S i,j is the luminance value of the pixel at the coordinate (i, j) inside the original video frame corresponding to the encoded video frame, and R i,j is the luminance value of the pixel at the coordinate (i, j) inside the reconstructed video frame corresponding to the encoded video frame.
[0017] Further, in step S3, if the PSNR of the previous video frame is lower than the lower PSNR threshold PSNR min preset by the user, then PSNR min is used as the target PSNR of the video frame to be encoded; if the PSNR of the previous video frame is higher than the upper PSNR threshold PSNR max preset by the user, then PSNR max is used as the target PSNR of the video frame to be encoded.
[0018] Further, in step S3, each coding mode in the video encoder has its corresponding coding distortion D and coding bit rate R. By performing curve fitting on these coding distortions D and coding bit rates R, the R-D model of the video encoder is obtained: D = f(R); where the function f() represents the relationship between the coding distortion D and the coding bit rate R.
[0019] Exemplarily, in step S3, the R-D model of the HEVC video encoder is: D = c × R -k ; where c and k are model parameters related to the video frame content and are continuously updated as the video sequence is encoded; the coding distortion D is characterized by MSE.
[0020] Further, in step S3, the previous encoded video frame is the (n - 1)-th frame. Let D n-1 represent its coding distortion, R n-1 represent its actual coding bit number, c n-1 and k n-1 be its corresponding c parameter and k parameter respectively, then there is: The current video frame to be encoded is the n-th frame. Let D n represent its coding distortion, R n represent its target coding bit number, c n and k n be its corresponding c parameter and k parameter respectively, then there is: Use c n-1 to approximately replace c n and use k n-1 to approximately replace kn , and then we have: Then we get Formula One: For the previous encoded video frame, use PSNR n-1 to represent its PSNR, then we have: For the current video frame to be encoded, use PSNR n to represent its target PSNR, then we have: We get: Then we get Formula Two: Substitute Formula Two into Formula One to get Formula Three: In Formula Three, R n represents the target encoding bit rate required for the nth frame to be encoded to reach the target PSNR.
[0021] Furthermore, in step S4, if the PSNR of the previous encoded video frame is within the PSNR threshold range preset by the user, and the encoding bit rate of the previous encoded video frame is equal to the target bit rate BitRate of the video sequence preset by the user tgt , then the target encoding bit rate BitRate of the current video frame to be encoded is equal to the target bit rate BitRate of the video sequence preset by the user tgt ; that is: BitRate = BitRate tgt .
[0022] Furthermore, in step S4, if the PSNR of the previous encoded video frame is within the PSNR threshold range preset by the user, but the encoding bit rate of the previous encoded video frame is not equal to the target bit rate BitRate of the video sequence preset by the user tgt , then the target encoding bit rate of the current video frame to be encoded is calculated by the following formula; BitRate m represents the encoding bit rate of the mth video frame after the PSNR of the video frame returns within the PSNR threshold range preset by the user; when 1 ≤ m ≤ BitRateStep, where BitRate rec represents the encoding bit rate of the first encoded video frame during the process of returning from outside the PSNR threshold range preset by the user to within the PSNR threshold range preset by the user, and BitRateStep represents the smooth step length of the bit rate adjustment set by the user; when m > BitRateStep, BitRate m = BitRate tgt ; which video frame among these m video frames the video frame to be encoded belongs to, the corresponding BitRate m is used as the target encoding bit rate BitRate of the video frame to be encoded.
[0023] Further, in step S4, the target coding bit number of the video frame to be coded = the target coding bit rate of the video frame to be coded ÷ the coding frame rate.
[0024] The present invention also provides a bit rate control device for constant video quality, including a video frame PSNR calculation module, a video frame PSNR comparison module, a video frame bit prediction module, a video frame bit calculation module, and a video frame bit control module. The video frame PSNR calculation module is used to calculate the peak signal-to-noise ratio (PSNR) using the corresponding original video frame and reconstructed video frame when the previous video frame is encoded. The video frame PSNR comparison module is used to determine whether the PSNR of the previous encoded video frame is within the PSNR threshold range from the user-defined PSNR lower threshold PSNR min to the PSNR upper threshold PSNR max ; if not, it is subsequently processed by the video frame bit prediction module; if so, it is subsequently processed by the video frame bit calculation module. The video frame bit prediction module is used to predict the target coding bit number of the video frame to be coded that can make the PSNR of the video frame to be coded return to the preset PSNR threshold range by using the relationship model between the coding distortion and coding bit rate of the video encoder, i.e., the R-D model, and substituting with the parameters of the previous and subsequent video frames; it is subsequently processed by the video frame bit control module. The video frame bit calculation module is used to calculate the target coding bit number of the video frame to be coded that can keep the coding bit rate of the video sequence at the user-defined target bit rate according to the user-defined target bit rate of the video sequence and the bit rate adjustment smooth step; it is subsequently processed by the video frame bit control module. The video frame bit control module is used to perform target bit control operations on the video frame to be coded according to the target coding bit number of the video frame to be coded, and obtain the Lagrange multiplier and quantization parameter of the video frame to be coded.
[0025] The technical effects achieved by the present invention are: the bit rate control is directly effective, the video quality returns quickly and without oscillation. Description of the Drawings
[0026] Figure 1 is a schematic flowchart of the bit rate control method for constant video quality proposed by the present invention.
[0027] Figure 2 is a schematic structural diagram of the bit rate control device for constant video quality proposed by the present invention.
[0028] Explanation of the reference numerals in the drawings: 1 is the video frame PSNR calculation module, 2 is the video frame PSNR comparison module, 3 is the video frame bit prediction module, 4 is the video frame bit calculation module, and 5 is the video frame bit control module. Detailed Embodiments
[0029] Please refer to Figure 1 , the bitrate control method for constant video quality proposed by the present invention includes the following steps.
[0030] Step S1: When the encoding of the previous video frame is completed, use the corresponding original video frame and reconstructed video frame to calculate the PSNR (Peak Signal-to-Noise Ratio) of the previous video frame. The original video frame refers to the state of the encoded video frame before encoding. The reconstructed video frame refers to the video frame obtained by decoding the encoded video frame. Since the video encoding process is a lossy compression process, there is distortion introduced by encoding in the reconstructed video frame compared with the original video frame.
[0031] In the field of video encoding, the encoding quality of a video frame is generally represented by PSNR. The formula for the mean square error (MSE) of an encoded video frame is:[[]] where M is the width of the video frame (in pixels), N is the height of the video frame (in pixels), S i,j is the luminance value of the pixel at coordinates (i, j) inside the original video frame corresponding to the encoded video frame, and R i,j is the luminance value of the pixel at coordinates (i, j) inside the reconstructed video frame corresponding to the encoded video frame. The formula for the PSNR of an encoded video frame is:[[]] where bits is the bit width of the pixels inside the encoded video frame.
[0032] Step S2: Compare the PSNR of the previous encoded video frame with the user-predefined PSNR upper threshold PSNR max and PSNR lower threshold PSNR min to determine whether the PSNR of the previous encoded video frame is within the user-predefined PSNR threshold range from PSNR min to PSNR max . If not, go to step S3. If so, go to step S4.
[0033] Step S3: When the PSNR of the previous encoded video frame exceeds the user-predefined PSNR threshold range, i.e., < PSNR min or > PSNR max, according to the R-D model of the video encoder (the relationship model between the encoding distortion D and the encoding bit rate R), by utilizing the similarity in the time domain between the previous and the current video frames, the parameters of the previous encoded video frame are used to replace the corresponding parameters of the video frame to be encoded, and the target encoding bit rate of the video frame to be encoded that can make the PSNR of the video frame to be encoded return to the range of the user-preset PSNR threshold is predicted. Subsequently, it proceeds to step S5.
[0034] In a video encoder, each encoding mode has its corresponding encoding distortion D and encoding bit rate R. By performing curve fitting on these encoding distortions D and encoding bit rates R, the "bit rate-distortion" relationship model of the video encoder, that is, the R-D model: D = f(R), can be obtained. Among them, the function f() represents the relationship between the encoding distortion D and the encoding bit rate R. For example, for the HEVC video encoder, its R-D model is: D = c × R -k . Among them, c and k are model parameters related to the video frame content and are continuously updated as the video sequence is encoded. The encoding distortion D is characterized by MSE.
[0035] In this step, using the R-D model of the video encoder and a series of formula derivation processes, the target encoding bit rate that can make the PSNR of the video frame to be encoded return to the range of the user-preset PSNR threshold is predicted. For the convenience of description, the following takes the HEVC video encoder as an example (that is, using the R-D model of the HEVC video encoder) for derivation.
[0036] Assume that the previous encoded video frame is the (n - 1)-th frame, and use D n-1 to represent its encoding distortion (characterized by MSE), R n-1 to represent its actual encoding bit rate, c n-1 and k n-1 to be its corresponding c parameter and k parameter respectively, then there is: For the current video frame to be encoded (i.e., the n-th frame), use D n to represent its encoding distortion (characterized by MSE), R n to represent its target encoding bit rate, c n and k n to be its corresponding c parameter and k parameter respectively, then there is: For the current video frame to be encoded, since the encoding of it has not started yet, its c n , k nThe parameters are unknown. However, in a video sequence, due to the temporal correlation of consecutive video frames (consecutive video frames are similar in content), it can be approximately considered that the content of the current video frame to be encoded is highly similar to that of the previous encoded video frame. Therefore, the c parameter and the k parameter, which are highly correlated with the video frame content, are also highly similar. Thus, in the present invention, c n-1 is approximately replaced by c n , and k n-1 is approximately replaced by k n . Furthermore, we have: Furthermore, Formula 1 can be obtained: In Formula 1, since the (n - 1)-th frame has been encoded, D n-1 , R n-1 and k n-1 are all known. Since the n-th frame has not started encoding yet, D n and R n are unknown.
[0037] In this step, if the PSNR of the previous video frame is lower than the lower PSNR threshold PSNR min preset by the user, then PSNR min is used as the target PSNR of the video frame to be encoded. If the PSNR of the previous video frame is higher than the upper PSNR threshold PSNR max preset by the user, then PSNR max is used as the target PSNR of the video frame to be encoded. In this way, if the target encoding bit number allocated for the video frame to be encoded can make the PSNR of the video frame to be encoded reach the target PSNR, the PSNR of the video frame to be encoded can be brought back within the PSNR threshold range preset by the user.
[0038] For the previous encoded video frame (the (n - 1)-th frame), let PSNR n-1 represent its PSNR, then we have: For the current video frame to be encoded (the n-th frame), let PSNR n represent its target PSNR, then we have: In this way, we can obtain: Furthermore, Formula 2 can be obtained:
[0039] Substituting Formula 2 into Formula 1, Formula 3 can be obtained: In Formula 3, R n-1 , k n-1 and PSNR n-1 are the parameters of the encoded (n - 1)-th frame and are known quantities. PSNR n represents the target PSNR of the n-th frame to be encoded and is a known quantity. Rn denotes the target coding bit number required for the nth frame to be encoded to reach the target PSNR. It is an unknown quantity and also the quantity to be obtained. In Equation 3, since there is only R n one unknown, so R n can be solved.
[0040] In this step, through the derivation processes of Equation 1, Equation 2, and Equation 3, the target coding bit number R n of the video frame to be encoded predicted is the target coding bit number to be allocated when it is desired that the video frame to be encoded reaches the target PSNR. In this process, the use of the correlation in the time domain of consecutive video frames to simplify the operation process, and the derivation process of using Equation 1, Equation 2, and Equation 3 for the target coding bit number of the video frame to be encoded belong to the innovation of the present invention.
[0041] It should be noted that for different video encoders (such as a video encoder adopting the AVC video coding standard), its R-D model is generally different from that of the HEVC video encoder, that is, the expression form of the function f in D = f(R) is different. Even so, using the idea of the present invention, it is still possible to derive and predict the target coding bit number to be allocated when it is desired that the video frame to be encoded reaches the target PSNR by using its corresponding R-D model. Therefore, the present invention is applicable not only to the HEVC video encoder but also to video encoders adopting other video coding standards.
[0042] Step S4: When the PSNR of the previous encoded video frame is within the PSNR threshold range preset by the user, that is, ≥ PSNR min and ≤ PSNR max , according to the target bit rate (i.e., the target coding bit rate) of the video sequence preset by the user and the code rate adjustment smoothing step size, calculate the target coding bit number of the video frame to be encoded that can keep the coding bit rate of the video sequence at the target bit rate preset by the user. Then enter Step S5.
[0043] This step is processed separately in two cases. For the convenience of description, use BitRate tgt to represent the target bit rate of the video sequence preset by the user, and BitRate to represent the target coding bit rate (i.e., the target coding bit rate) of the current video frame to be encoded.
[0044] Case 1: The PSNR of the previous encoded video frame is within the PSNR threshold range preset by the user, and the coding bit rate of the previous encoded video frame is equal to the target bit rate of the video sequence preset by the user. In this case, directly make the target coding bit rate of the video frame to be encoded equal to the target bit rate of the video sequence preset by the user. That is: BitRate = BitRate tgt .
[0045] Case 2: The PSNR of the previous encoded video frame is within the PSNR threshold range preset by the user, but the encoding bitrate of the previous encoded video frame is not equal to the target bitrate of the video sequence preset by the user. This situation generally occurs when the PSNR of the video frame returns from outside the PSNR threshold range preset by the user to within the PSNR threshold range preset by the user. In this case, the target encoding bitrate of the video frame to be encoded is calculated by the following formula. BitRate m represents the encoding bitrate of the m-th video frame after the PSNR of the video frame returns to within the PSNR threshold range preset by the user. When 1 ≤ m ≤ BitRateStep, BitRate m needs to be jointly calculated by BitRate tgt , BitRate rec , and BitRateStep, where BitRate rec represents the encoding bitrate of the first encoded video frame in the process of returning from outside the PSNR threshold range preset by the user to within the PSNR threshold range preset by the user (that is, the PSNR of the previous frame is outside the PSNR threshold range preset by the user, and the PSNR of this frame returns to within the PSNR threshold range preset by the user). BitRateStep represents the smoothing step size of the bitrate adjustment set by the user. Its physical meaning is that after the PSNR of the video frame returns to within the PSNR threshold range preset by the user, the video encoding bitrates of several consecutive subsequent video frames need to be gradually adjusted from BitRate rec to the target bitrate BitRate tgt preset by the user. The value of BitRateStep is the number of these consecutive video frames used to smooth the video encoding quality. When m > BitRateStep, BitRate m = BitRate tgt . Which of these m video frames the video frame to be encoded belongs to, the corresponding BitRate m is used as the target encoding bitrate BitRate of the video frame to be encoded. For example, when m = 1, it represents the first video frame after the PSNR of the video frame returns to within the PSNR threshold range preset by the user.
[0046] After calculating the target encoding bitrate of the video frame to be encoded in the above two cases, the target encoding number of bits of the video frame to be encoded is calculated according to the following formula: Target encoding number of bits of the video frame to be encoded = Target encoding bitrate of the video frame to be encoded ÷ Encoding frame rate.
[0047] Step S5: Based on the target coding bit number of the video frame to be coded predicted in Step S3 or calculated in Step S4, perform target bit control operation on the video frame to be coded to obtain the Lagrange multiplier and quantization parameter of the video frame to be coded, which are used for the actual coding process of the video frame to be coded. There are various options for the algorithm of the target bit control operation, such as the JCTVC-K0103 proposal, etc., which will not be elaborated here.
[0048] Please refer to Figure 2 , the bit rate control device for constant video quality proposed by the present invention includes a video frame PSNR calculation module 1, a video frame PSNR comparison module 2, a video frame bit prediction module 3, a video frame bit calculation module 4, and a video frame bit control module 5. Figure 2 The device shown corresponds to Figure 1 the method shown.
[0049] The video frame PSNR calculation module 1 is used to calculate the PSNR of the previous video frame using the corresponding original video frame and reconstructed video frame when the previous video frame coding is completed.
[0050] The video frame PSNR comparison module 2 is used to determine whether the PSNR of the previous coded video frame is within the PSNR threshold range preset by the user from PSNR min to PSNR max . If not, it will be handed over to the video frame bit prediction module 3 for processing later. If so, it will be handed over to the video frame bit calculation module 4 for processing later.
[0051] The video frame bit prediction module 3 is used to predict the target coding bit number of the video frame to be coded that can make the PSNR of the video frame to be coded return to the preset PSNR threshold range by using the parameters of the front and rear video frames instead according to the R-D model of the video encoder. It will be handed over to the video frame bit control module 5 for processing later.
[0052] The video frame bit calculation module 4 is used to calculate the target coding bit number of the video frame to be coded that can keep the coding bit rate of the video sequence at the target bit rate preset by the user according to the target bit rate of the video sequence preset by the user and the smooth step size of bit rate adjustment. It will be handed over to the video frame bit control module 5 for processing later.
[0053] The video frame bit control module 5 is used to perform target bit control operation on the video frame to be coded based on the target coding bit number of the video frame to be coded predicted by the video frame bit prediction module 3 or calculated by the video frame bit calculation module 4 to obtain the Lagrange multiplier and quantization parameter of the video frame to be coded, which are used for the actual coding process of the video frame to be coded.
[0054] The present invention proposes a bitrate control method with constant video quality and adaptive variable bitrate. The method proposed by the present invention can automatically detect the PSNR of the encoded video frames, and when the PSNR of the video frames exceeds the PSNR threshold range preset by the user, based on the R-D model of the video encoder and using the similarity in the time domain between the front and rear video frames, predict the target encoding bit number of the video frame to be encoded, so that the PSNR of the video frame to be encoded returns to the PSNR threshold range preset by the user, thereby maintaining the video quality of the video sequence within the video quality range expected by the user.
[0055] Compared with other variable bitrate bitrate control methods with constant video quality, the method proposed by the present invention has the advantages of direct and effective bitrate control, and rapid and oscillation-free video quality regression. In the present invention, by introducing the R-D model of the video encoder and using the similarity in the time domain between the front and rear video frames, directly predict the target encoding bit number of the video frame to be encoded when the target PSNR is expected to be reached, and the adjustment is accurate and rapid. Through experimental verification, in most cases, the PSNR of the video frame can return to the preset range after one frame adjustment cycle. In the existing methods, generally a negative feedback method is used for control. When the encoding quality of the encoded video frame exceeds the preset PSNR range, adjust the encoding parameters of the subsequent video frames to be encoded to make the PSNR return to the preset range. When adjusting the parameters of the encoder, generally empirical values are used for adjustment, and it is necessary to monitor the adjustment effect after each adjustment and adjust the parameters of the next adjustment according to the different adjustment results. Since the encoding configuration parameters and video content of each video encoding may be different, it is easy to make the adjustment strength too large or too small by using the empirical value adjustment method. If the adjustment strength is too large, oscillation is likely to occur; if the adjustment strength is too small, the adjustment cycle is long. In other words, the traditional method is to use the "trial" method for adjustment, and it is impossible to know whether the adjustment strength is appropriate before adjustment, and only after adjustment can it be known; while the method of the present invention has predicted the accurate adjustment strength required based on the R-D model before adjustment, and the adjustment effect is almost in place in one step.
[0056] The above are only the preferred embodiments of the present invention and are not used to limit the present invention. For those skilled in the art, the present invention can have various changes and modifications. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention shall be included within the protection scope of the present invention.
Claims
1. A bitrate control method for constant video quality, characterized in that, It includes the following steps; Step S1: When the encoding of the previous video frame is completed, use its corresponding original video frame and reconstructed video frame to calculate its peak signal-to-noise ratio PSNR; Step S2: Determine whether the PSNR of the previous encoded video frame is within the PSNR threshold range from the user - preset PSNR lower threshold PSNR min to the PSNR upper threshold PSNR max ; if not, proceed to Step S3; if so, proceed to Step S4; Step S3: According to the relationship model between the encoding distortion and encoding bit rate of the video encoder, i.e., the R-D model, utilize the similarity in the time domain between the previous and next video frames, and use the parameters related to the video frame content of the previous encoded video frame in the R-D model to replace the corresponding parameters of the video frame to be encoded in the R-D model, and predict the target encoding bit rate of the video frame to be encoded that can make the PSNR of the video frame to be encoded return to the user-prescribed PSNR threshold range; then proceed to step S5; In step S3, when the video encoder is an HEVC video encoder, the R-D model is: D = c × R -k ; where c and k are model parameters related to the video frame content and are continuously updated as the video sequence is encoded; the encoding distortion D is characterized by MSE; the previous encoded video frame is the (n - 1)-th frame, and D n-1 represents its encoding distortion, and R n-1 represents its actual encoded bit count, and c n-1 and k n-1 are the corresponding c parameter and k parameter respectively, then there is: The current video frame to be encoded is the n-th frame, and D n represents its encoding distortion, and R n represents its target encoded bit count, and c n and k n are the corresponding c parameter and k parameter respectively, then there is: Use c n-1 to approximately replace c n , use k n-1 to approximately replace k n , and then there is: Furthermore, formula one is obtained: For the previous encoded video frame, use PSNR n-1 to represent its PSNR, then we have: PSNR n-1 = 10 × For the current video frame to be encoded, use PSNR n to represent its target PSNR, then we have: PSNR n = 10 × We get: Furthermore, we obtain Equation 2: Substitute Equation 2 into Equation 1 to obtain Equation 3: In Equation 3, R n represents the target coding bit number required for the nth frame to be encoded to achieve the target PSNR; Step S4: According to the target bit rate of the video sequence preset by the user and the smooth step size for bit rate adjustment, calculate the target encoding bit rate of the video frame to be encoded that can keep the encoding bit rate of the video sequence at the target bit rate preset by the user; then proceed to step S5; Step S5: According to the target encoding bit rate of the video frame to be encoded, perform target bit control operations on the video frame to be encoded to obtain the Lagrange multiplier and quantization parameter of the video frame to be encoded.
2. The bitrate control method for constant video quality according to claim 1, characterized in that In the step S1, the calculation formula of the PSNR of the encoded video frame is as follows: where bits is the bit width of the pixel points inside the encoded video frame, and MSE is the mean square error of the encoded video frame; where M is the width of the video frame, N is the height of the video frame, S i,j is the luminance value of the pixel with coordinates (i, j) inside the original video frame corresponding to the encoded video frame, and R i,j is the luminance value of the pixel with coordinates (i, j) inside the reconstructed video frame corresponding to the encoded video frame.
3. The bit rate control method for constant video quality according to claim 1, characterized in that In the step S3, if the PSNR of the previous video frame is lower than the lower PSNR threshold PSNR preset by the user min , then PSNR min is used as the target PSNR of the video frame to be encoded; if the PSNR of the previous video frame is higher than the upper PSNR threshold PSNR preset by the user max , then PSNR max is used as the target PSNR of the video frame to be encoded.
4. The bitrate control method for constant video quality according to claim 3, characterized in that, In the said step S3, each encoding mode in the video encoder has its corresponding encoding distortion D and encoding bit rate R. By performing curve fitting on these encoding distortions D and encoding bit rates R, the R-D model of the video encoder is obtained: D = f(R); where the function f() represents the relationship between the encoding distortion D and the encoding bit rate R.
5. The bit rate control method for constant video quality according to claim 1, characterized in that In the step S4, if the PSNR of the previous encoded video frame is within the PSNR threshold range preset by the user, and the encoding bit rate of the previous encoded video frame is equal to the target bit rate BitRate of the video sequence preset by the user tgt , then the target encoding bit rate BitRate of the current video frame to be encoded is equal to the target bit rate BitRate of the video sequence preset by the user tgt ; that is: BitRate = BitRate tgt .
6. The bitrate control method for constant video quality according to claim 1, characterized in that In step S4, if the PSNR of the previous encoded video frame is within the PSNR threshold range preset by the user, but the encoding bitrate of the previous encoded video frame is not equal to the target bitrate BitRate of the video sequence preset by the user tgt , then the target encoding bitrate of the current video frame to be encoded is calculated by the following formula; BitRate m represents the encoding bitrate of the m-th video frame after the PSNR of the video frame returns to the PSNR threshold range preset by the user; when 1 ≤ m ≤ BitRateStep, where, BitRate rec represents the encoding bitrate of the first encoded video frame during the process of returning from outside the PSNR threshold range preset by the user to within the PSNR threshold range preset by the user, and BitRateStep represents the smoothing step size of the bitrate adjustment set by the user; when m > BitRateStep, BitRate m = BitRate tgt ; which one of these m video frames the video frame to be encoded belongs to, and the corresponding BitRate m is used as the target encoding bitrate BitRate of the video frame to be encoded.
7. The bit rate control method for constant video quality according to claim 5 or 6, characterized in that In the said step S4, the target encoding bit rate of the video frame to be encoded = the target encoding bit rate of the video frame to be encoded ÷ the encoding frame rate.
8. A bit rate control device for constant video quality, characterized in that It includes a video frame PSNR calculation module, a video frame PSNR comparison module, a video frame bit prediction module, a video frame bit calculation module, and a video frame bit control module; The said video frame PSNR calculation module is used to calculate the peak signal-to-noise ratio PSNR by using its corresponding original video frame and reconstructed video frame when the encoding of the previous video frame is completed; The video frame PSNR comparison module is used to determine whether the PSNR of the previous encoded video frame is within the PSNR threshold range from the user-preset PSNR lower threshold PSNR min to the PSNR upper threshold PSNR max ; if not, it is subsequently processed by the video frame bit prediction module; if so, it is subsequently processed by the video frame bit calculation module; The said video frame bit prediction module is used to, according to the relationship model between the encoding distortion and encoding bit rate of the video encoder, i.e., the R-D model, use the parameters related to the video frame content of the previous encoded video frame in the R-D model to replace the corresponding parameters of the video frame to be encoded in the R-D model, and predict the target encoding bit rate of the video frame to be encoded that can make the PSNR of the video frame to be encoded return to the preset PSNR threshold range; then hand it over to the video frame bit control module for processing; When the video encoder is an HEVC video encoder, the R-D model is: D = c × R -k ; where c and k are model parameters related to the video frame content and are continuously updated as the video sequence is encoded; the encoding distortion D is characterized by MSE; the previous encoded video frame is the (n - 1)-th frame, and its encoding distortion is denoted by D n-1 , and its actual encoded bit count is denoted by R n-1 , c n-1 and k n-1 are the corresponding c parameter and k parameter respectively, then there is: The current video frame to be encoded is the n-th frame, and its encoding distortion is denoted by D n , and its target encoded bit count is denoted by R n , c n and k n are the corresponding c parameter and k parameter respectively, then there is: Approximate c n-1 with c n , approximate k n-1 with k n , and then there is: Furthermore, the following formula 1 is obtained: For the previous encoded video frame, use PSNR n-1 to represent its PSNR, then there is: For the current video frame to be encoded, use PSNR n to represent its target PSNR, then there is: Obtain: Furthermore, obtain Formula 2: Substitute Equation 2 into Equation 1 to obtain Equation 3: In Equation 3, R n represents the target coding bit number required for the n-th frame to be coded to achieve the target PSNR; The said video frame bit calculation module is used to calculate the target encoding bit rate of the video frame to be encoded that can keep the encoding bit rate of the video sequence at the target bit rate preset by the user according to the target bit rate of the video sequence preset by the user and the smooth step size for bit rate adjustment; then hand it over to the video frame bit control module for processing; The said video frame bit control module is used to perform target bit control operations on the video frame to be encoded according to the target encoding bit rate of the video frame to be encoded to obtain the Lagrange multiplier and quantization parameter of the video frame to be encoded.
Citation Information
Patent Citations
Method for controlling balanced code rate and picture quality code rate
CN101202912A
HEVC rate control model parameter updating algorithm based on distortion measurement
CN104767999A