Method for improving two-pass bitrate control by using average peak signal-to-noise ratio
By using the average peak signal-to-noise ratio to adjust the target number of bits and quantization parameters of each frame in the two pass rate control method, the problem of uneven quality of video frames caused by the existing methods is solved, and the video quality is stable improvement.
Patent Information
- Application Number
- CN202211330231.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-10-27
- Publication Date
- 2025-06-27
- Estimated Expiration
- 2042-10-27
AI Technical Summary
While improving the quality of video in complex scenes, the existing two pass rate control methods will reduce the quality of simple scenes, resulting in uneven quality of video frames, especially when flat frames are easy to have block effects.
In the two pass rate control method, the average peak signal-to-noise ratio (PSNR) is used to adjust the target number of each frame and the quantization parameter (QP) is adjusted to achieve the goal of less fluctuation of PSNR in each frame.
It effectively improves the stability of video quality, reduces PSNR fluctuations between each frame, and improves the overall quality of video.
Smart Images

Figure CN115802042B_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of video coding, and particularly relates to a method for improving two-pass bitrate control by using the average peak signal-to-noise ratio. Background Art
[0002] Video technology has been widely applied in fields such as mobile terminals, webcasting, home theaters, and remote monitoring. The video resolution has gradually shifted from standard definition (SD) to high definition (HD) and ultra-high definition (UHD). Currently, internationally common video coding and decoding standards include H.264, H.265 / HEVC, and domestic standards such as AVS, AVS+, and AVS2.
[0003] Bitrate control is an important part of video coding. Refer to Figure 1 , which calculates the number of bits that should be allocated to each frame image and each region in the image in the video by obtaining video source characteristics (such as the degree of motion intensity, image texture complexity, etc.) and the available network bandwidth, calculates the QP (Quantitative parameters) using the RQ model, and performs encoding to make the output bitstream conform to the transmission of the channel while making the output video quality as good as possible. The way the RQ model calculates the quantization parameter is as follows:
[0004]
[0005] Where Bits is the number of available bits for the current frame; SATD is the sum of the absolute values of the residual transforms of the current frame, used to measure the complexity of the current frame; a, b, and c are model parameters; if the available bits for a certain frame are larger, its QP value is smaller, the quantization distortion is smaller, and the encoding quality of this frame is better.
[0006] Usually, the video coding method only encodes once. However, since the complexity of each frame in the video is different, the number of bits required for each frame is different, and the encoding distortion degree is also different. To improve the video quality, refer to Figure 2, the two-pass bitrate control method is applied to offline video coding. This method encodes twice. In the first encoding, all frames of the video are encoded once, and the complexity, SATD, QP, and bit count of each frame are statistically calculated. Based on the information of each frame from the first encoding, more bitrate is allocated to frames with higher complexity, and less bitrate is allocated to frames with lower complexity. Then, the QP of each frame is calculated, and the second encoding is performed. Although the existing two-pass bitrate control method can improve the quality of complex scenes in the video, it reduces the quality of simple scenes, and the reduction amplitude may be large, which will affect the visual perception of the human eye. Especially for flat frames, if the allocated bitrate is not high enough, block effects are likely to occur, ultimately resulting in uneven quality of each frame in the video. Summary of the Invention
[0007] In view of the above problems, the present invention provides a method for improving two-pass bitrate control using the average peak signal-to-noise ratio, which makes the PSNR fluctuation between frames smaller and improves the stability of video quality.
[0008] To solve the above technical problems, the present invention adopts the following technical solutions:
[0009] A method for improving two-pass bitrate control using the average peak signal-to-noise ratio, comprising the following steps:
[0010] Set the target total bit count TB, start the first encoding of two-pass, obtain the bitstream. After the encoding ends, count the total number of frames N in the video, the PSNR, QP, and Bits of each frame, and mark the PSNR of each frame as psnr(1), psnr(2),......, psnr(N) respectively, and calculate their average value denoted as psnr_avg. Mark the QP of each frame as qp(1), qp(2),......, qp(N) respectively, and mark the Bits of each frame as bits(1), bits(2),......, bits(N);
[0011] Start the second encoding of two-pass. According to the target total bit count TB and the information collected in the first encoding, calculate the actual QP value of each frame, and encode each frame to obtain the final bitstream.
[0012] Preferably, calculating the actual QP value of each frame includes:
[0013] Taking psnr_avg as the target PSNR for each frame, calculate the QP adjustment amplitude required for each frame according to the difference between the PSNR of each frame and the target PSNR. Define the first target QP of the i-th frame as:
[0014] qp_tg1(i) = qp(i) + A × (psnr(i) - psnr_avg)
[0015] Where A is an adjustment coefficient,
[0016] Mark the first target QP of each frame as qp_tg1(1), qp_tg1(2),......, qp_tg1(N);
[0017] Define the adjustment factor corresponding to the first target QP as t, where t is an integer within the range of (-51 to 51). Define the second target QP of each frame as qp_tg1(1) + t, qp_tg1(2) + t,......, qp_tg1(N) + t. At this time, the calculation formula for the corresponding total number of bits bitsc(t) is:
[0018]
[0019] Successively calculate bitsc(1), bitsc(2),......, bitsc(M), and select the value closest to the target total number of bits TB among them. The t corresponding to this value is the optimal QP adjustment factor. Let k be equal to this optimal QP adjustment factor, and calculate the actual QP of each frame as qp_tg1(1) + k, qp_tg1(2) + k,......, qp_tg1(N) + k.
[0020] Preferably, the calculation method of the adjustment coefficient A is as follows:
[0021]
[0022] Where avg_qp_h1 is the average QP value of the 1st, 2nd,......, frames in the first encoding; avg_qp_h2 is the average QP value of the ......, Nth frames in the first encoding; avg_psnr_h1 is the average PSNR value of the 1st, 2nd,......, frames in the first encoding; avg_psnr_h2 is the average PSNR value of the Nth frames in the first encoding.
[0023] Preferably, the calculation method of avg_qp_h1 is as follows:
[0024]
[0025] Preferably, the calculation method of avg_qp_h2 is as follows:
[0026]
[0027] Preferably, the calculation method of avg_psnr_h1 is as follows:
[0028]
[0029] Preferably, the calculation method of avg_psnr_h2 is as follows:
[0030]
[0031] The present invention has the following beneficial effects: Aiming at the problems existing in the existing two-pass bitrate control, the PSNR result of the first encoding is used to adjust the target bit number of each frame in the second encoding. The method of the present invention first calculates the PSNR of all frames in the first encoding, obtains its average PSNR, and uses the average PSNR as the target PSNR in the second encoding, and adjusts the QP of each frame accordingly, so that the PSNR fluctuation between frames in the second encoding is smaller, and the stability of the video quality is improved. Description of the Drawings
[0032] Figure 1 is the flowchart of the bitrate control;
[0033] Figure 2 is the flowchart of the two-pass bitrate control algorithm.
[0034] Figure 3 is the flowchart of the steps of the method for improving two-pass bitrate control by using the average peak signal-to-noise ratio in the embodiment of the present invention. Detailed Embodiment
[0035] Next, the technical solutions in the embodiments of the present invention will be clearly and completely described in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, rather than all of the embodiments. All other embodiments obtained by those of ordinary skill in the art based on the embodiments of the present invention without creative efforts shall fall within the protection scope of the present invention.
[0036] Refer to Figure 3 , which shows the flowchart of the steps of the method for improving two-pass bitrate control by using the average peak signal-to-noise ratio in the embodiment of the present invention, and includes the following steps:
[0037] Set the target total bit count TB, start the first pass of the two-pass encoding, obtain the bitstream. After the encoding is completed, count the total number of video frames N, the PSNR, QP, and Bits of each frame, and label the PSNR of each frame as psnr(1), psnr(2),......, psnr(N) respectively, and calculate their average value denoted as psnr_avg. Label the QP of each frame as qp(1), qp(2),......, qp(N) respectively, and label the Bits of each frame as bits(1), bits(2),......, bits(N).
[0038] Start the second pass of the two-pass encoding. According to the target total bit count TB and the information collected in the first pass, calculate the actual QP value of each frame, and encode each frame to obtain the final bitstream.
[0039] Further, in an embodiment of the present invention, calculating the actual QP value of each frame includes:
[0040] Taking psnr_avg as the target PSNR for each frame, calculate the QP adjustment amplitude required for each frame according to the difference between the PSNR of each frame and the target PSNR. Define the first target QP of the i-th frame as:
[0041] qp_tg1(i) = qp(i) + A × (psnr(i) - psnr_avg)
[0042] where A is the adjustment coefficient.
[0043] Label the first target QP of each frame as qp_tg1(1), qp_tg1(2),......, qp_tg1(N) respectively.
[0044] Define the adjustment factor corresponding to the first target QP as t, where t is an integer within the range of (-51 to 51). Define the second target QP of each frame as qp_tg1(1) + t, qp_tg1(2) + t,......, qp_tg1(N) + t respectively. At this time, the calculation formula for the corresponding total bit count bitsc(t) is:
[0045]
[0046] Successively calculate bitsc(1), bitsc(2),......, bitsc(M), and select the value closest to the target total bit count TB among them. The t corresponding to this value is the optimal QP adjustment factor. Let k be equal to this optimal QP adjustment factor, and calculate the actual QP of each frame as qp_tg1(1) + k, qp_tg1(2) + k,......, qp_tg1(N) + k respectively.
[0047] Further, in an embodiment of the present invention, the calculation method of the adjustment coefficient A is as follows:
[0048]
[0049] where avg_qp_h1 is the average QP value of the 1st, 2nd,..., frames in the first encoding; avg_qp_h2 is the average QP value of the Nth frame in the first encoding; avg_psnr_h1 is the average PSNR value of the 1st, 2nd,..., frames in the first encoding; avg_psnr_h2 is the average PSNR value of the Nth frame in the first encoding.
[0050] The calculation method of avg_qp_h1 is as follows:
[0051]
[0052] The calculation method of avg_qp_h2 is as follows:
[0053]
[0054] The calculation method of avg_psnr_h1 is as follows:
[0055]
[0056] The calculation method of avg_psnr_h2 is as follows:
[0057]
[0058] Through the above settings, a method for improving two-pass bitrate control by using the average peak signal-to-noise ratio adjusts the target bit numbers of each frame in the second encoding based on the PSNR result of the first encoding. The method of the present invention first calculates the PSNR of all frames in the first encoding, obtains its average PSNR, uses the average PSNR as the target PSNR in the second encoding, and adjusts the QP of each frame accordingly, so that the PSNR fluctuation between frames in the second encoding is smaller, and the stability of the video quality is improved. The method for improving two-pass bitrate control by using the peak signal-to-noise ratio set above can be applied to various encoders, such as HEVC, H264, MPEG4, AVS, AVS2, AVS3, etc.
[0059] It should be understood that the exemplary embodiments described herein are illustrative and not restrictive. Although one or more embodiments of the present invention have been described in conjunction with the accompanying drawings, those of ordinary skill in the art should understand that various changes in form and detail may be made without departing from the spirit and scope of the present invention as defined by the appended claims.
Claims
1. A method for improving two-pass bitrate control using the average peak signal-to-noise ratio, characterized in that, It includes the following steps: Set the target total bit number TB, start the first encoding of two - pass, obtain the bitstream. After the encoding ends, count the total number of video frames N, the PSNR, QP, and Bits of each frame, mark the PSNR of each frame as psnr(1), psnr(2),......, psnr(N) respectively, calculate their average value and denote it as psnr_avg, mark the QP of each frame as qp(1), qp(2),......, qp(N) respectively, and mark the Bits of each frame as bits(1), bits(2),......, bits(N); Start the second encoding of two - pass. According to the target total bit number TB and the information collected in the first encoding, calculate the actual QP value of each frame, and encode each frame to obtain the final bitstream; Among them, calculating the actual QP value of each frame includes: Taking psnr_avg as the target PSNR of each frame, calculate the QP adjustment amplitude required for each frame according to the gap between the PSNR of each frame and the target PSNR. Define the first target QP of the i - th frame as: qp_tg1(i) = qp(i)+A×(psnr(i)-psnr_avg) where A is the adjustment coefficient, Mark the first target QP of each frame as qp_tg1(1), qp_tg1(2),......, qp_tg1(N); Define the adjustment factor corresponding to the first target QP as t, t is an integer within the range of (- 51~51). Define the second target QP of each frame as qp_tg1(1)+t, qp_tg1(2)+t,......, qp_tg1(N)+t. At this time, the calculation formula for the corresponding total bit number bitsc(t) is: Successively calculate bitsc(1), bitsc(2),......, bitsc(M), and select the value closest to the target total bit number TB among them. The t corresponding to this value is the optimal QP adjustment factor. Let k be equal to this optimal QP adjustment factor, and calculate the actual QP of each frame as qp_tg1(1)+k, qp_tg1(2)+k,......, qp_tg1(N)+k; The calculation method of the adjustment coefficient A is as follows: where avg_qp_h1 is the average QP value of the 1st, 2nd,......, frames in the first encoding; avg_qp_h2 is the average QP value of the ......, N frames in the first encoding; avg_psnr_h1 is the average PSNR value of the 1st, 2nd,......, frames in the first encoding; avg_psnr_h2 is the average PSNR value of the ......, N frames in the first encoding.
2. The method for improving two-pass bitrate control by using the average peak signal-to-noise ratio as claimed in claim 1, wherein The calculation method of avg_qp_h1 is as follows:
3. The method for improving two-pass bitrate control by using the average peak signal-to-noise ratio as claimed in claim 1, wherein The calculation method of avg_qp_h2 is as follows:
4. The method for improving two-pass bitrate control by using the average peak signal-to-noise ratio as claimed in claim 1, wherein The calculation method of avg_psnr_h1 is as follows:
5. The method for improving two-pass bitrate control by using the average peak signal-to-noise ratio as claimed in claim 1, wherein The calculation method of avg_psnr_h2 is as follows:
Citation Information
Patent Citations
Method for controlling balanced code rate and picture quality code rate
CN101202912A
Two pass rate control techniques for video coding using rate-distortion characteristics
CN101331773A