A method for improving two-pass code rate control using peak signal-to-noise ratio.

By improving the peak signal-to-noise ratio adjustment method, adjusting the number of bits and QP value of video encoding frame by frame, the problem of quality degradation in simple scenes in the existing technology is solved, and a balanced improvement in video quality is achieved.

CN115802041BActive Publication Date: 2026-11-17HANGZHOU ARCVIDEO TECHNOLOGY CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202211328520.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-10-27
Publication Date
2026-11-17
Estimated Expiration
2042-10-27

AI Technical Summary

Technical Problem

Existing two-pass bitrate control methods fail to adequately consider the output quality of the first encoded frame in video encoding, resulting in excessive degradation of video quality in simple scenes when the bit count is transferred to complex scenes.

Method used

A peak signal-to-noise ratio (PSNR) improved two-pass rate control method is adopted. The target number of each frame in the second encoding is adjusted based on the PSNR result of the first encoding. The frames are divided into good quality, poor quality, and balanced frames. The QP value is adjusted according to the PSNR redundancy to ensure that the quality of good quality frames does not drop too much and the quality of poor quality frames is improved.

Benefits of technology

It improved the overall subjective quality of the video, ensuring that the quality of high-quality frames did not degrade and the quality of low-quality frames improved, thus achieving a balanced improvement in video quality.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115802041B_ABST
    Figure CN115802041B_ABST
Patent Text Reader

Abstract

This invention discloses a method for improving two-pass bitrate control using peak signal-to-noise ratio (PSNR), comprising the following steps: setting a target total number of bits (TB), starting the first two-pass encoding, acquiring the bitstream, and after encoding, statistically analyzing the total number of video frames (N), PSNR, QP, SATD, and Bits of each frame, starting the pre-analysis stage of the second two-pass encoding, defining the PSNR redundancy of the i-th frame as psnr_rd(i) = psnr(i) - TH1, where TH1 is a constant with a value range of (30~40). When psnr_rd(i) is greater than 0, the subjective quality is good; when psnr_rd(i) is less than 0, the subjective quality is poor. Calculating the QP values ​​of frames with good quality, frames with poor quality, and frames with balanced quality, respectively. Starting the encoding stage of the second two-pass encoding, determining whether each frame belongs to a frame with good quality, a frame with poor quality, or a frame with balanced quality, and encoding using the calculated QP values ​​to obtain the final bitstream.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the field of video coding technology, specifically relating to a method for improving two-pass bitrate control using peak signal-to-noise ratio. Background Technology

[0002] Video technology has been widely used in mobile terminals, live web streaming, home theaters, and remote monitoring. Video resolution has also gradually shifted from Standard Definition (SD) to High Definition (HD) and Ultra High Definition (UHD). Currently, the internationally used video codec 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 encoding; see [link to relevant documentation]. Figure 1 It calculates the number of bits that should be allocated to each frame and each region of the video by acquiring the characteristics of the video source (such as the intensity of motion, image texture complexity, etc.) and the available network bandwidth. It then uses the RQ model to calculate the QP (Quantitative Parameters) and encodes the data to ensure the output bitstream conforms to the channel's transmission requirements while maximizing the output video quality. The RQ model calculates the quantization parameters as follows:

[0004]

[0005] Bits represents the number of available bits in the current frame; SATD represents 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 number of available bits in a frame is larger, its QP value is smaller, the quantization distortion is smaller, and the encoding quality of the frame is better.

[0006] Typically, video encoding methods only encode once. However, because the complexity of each frame in a video varies, the number of bits required for each frame differs, resulting in varying degrees of encoding distortion. To improve video quality, see... Figure 2 The two-pass bitrate control method is applied to offline video encoding. This method encodes twice. The first encoding encodes all frames of the video and calculates the complexity, SATD, QP, and bit count of each frame. Based on the information from the first encoding, frames with higher complexity are allocated a higher bitrate, while frames with lower complexity are allocated a lower bitrate. The QP of each frame is also calculated before the second encoding. However, the existing two-pass method, in transferring bit counts from simple scenes to complex scenes, does not fully consider the output quality of the first encoded frames. The transferred bit count may be excessive, significantly degrading the quality of simple scenes. Summary of the Invention

[0007] In view of the above problems, the present invention provides a method for improving two-pass bitrate control using peak signal-to-noise ratio (PSNR). The PSNR result of the first encoding is used to adjust the target number of each frame in the second encoding, so that the PSNR in the second encoding is not much lower than that in the first encoding. This ensures that the quality of better frames does not drop too much in the second encoding, and the quality of worse frames can also be improved, thereby improving the overall subjective quality of the video.

[0008] To solve the above-mentioned technical problems, the present invention adopts the following technical solution:

[0009] A method for improving two-pass code rate control using peak signal-to-noise ratio includes the following steps:

[0010] Set the target total number of bits TB, start the first encoding of two passes, obtain the bitstream, and after the encoding is completed, count the total number of video frames N, PSNR, QP, SATD, and Bits of each frame, and mark the PSNR of each frame as psnr(1), psnr(2), ..., psnr(N), the QP of each frame as qp(1), qp(2), ..., qp(N), the SATD of each frame as satd(1), satd(2), ..., satd(N), and the Bits of each frame as bits(1), bits(2), ..., bits(N);

[0011] The pre-analysis phase of the second encoding of the two-pass begins. The PSNR redundancy of the i-th frame is defined as psnr_rd(i) = psnr(i) - TH1, where TH1 is a constant with a value range of (30~40). When psnr_rd(i) is greater than 0, the subjective quality is better, and when psnr_rd(i) is less than 0, the subjective quality is worse.

[0012] Calculate the QP values ​​for high-quality frames, low-quality frames, and balanced quality frames respectively;

[0013] The second encoding stage of the two-pass process begins by determining whether each frame belongs to a high-quality frame, a low-quality frame, or a quality-balanced frame, and then encoding it using the calculated QP value to obtain the final bitstream.

[0014] Preferably, frames with better quality are those where psnr_rd(i) > 0.

[0015] Preferably, the QP value of a high-quality frame is calculated as follows:

[0016] The number of bits in the first encoding of a frame with better quality is denoted as bits_g(1), bits_g(2), ..., bits_g(k), and the PSNR redundancy is denoted as psnr_rd_g(1), psnr_rd_g(2), ..., psnr_rd_g(k). The number of bits saved by a frame with better quality is defined as the bit redundancy. The bit redundancy Sv(i) of the i-th frame with better quality is: Sv(i) = Max(bits_g(i)*(1-0.25*psnr_rd_g(i)), bits_g(i)*0.4 After subtracting the bit redundancy, the available bits of the better quality frames are marked as bits_g(1)-Sv(1), bits_g(2)-Sv(2), ..., bits_g(k)-Sv(k). The SATD of the better quality frames obtained from the results of the first encoding are marked as satd_g(1), satd_g(2), ..., satd_g(k). The QP of the better quality frames is calculated using the RQ model and marked as qp_g(1), qp_g(2), ..., qp_g(k), where k represents the number of better quality frames.

[0017] Preferably, the frames with poor quality are the 20% of all frames with the smallest psnr_rd(i).

[0018] Preferably, the QP value of a frame with poor quality is calculated as follows:

[0019] The number of bits for the poor-quality frames during the first encoding is denoted as bits_b(1), bits_b(2), ..., bits_b(h), where h represents the number of poor-quality frames. The total number of bits saved by the better-quality frames is calculated as Bits_save:

[0020]

[0021] Bits_save is evenly distributed to the poor quality frames. The target number of bits for the poor quality frames in the second encoding is bits_b(1) + Bits_save / h, bits_b(2) + Bits_save / h, ..., bits_b(h) + Bits_save / h. The SATD of the poor quality frames is obtained from the results of the first encoding and labeled as satd_b(1), satd_b(2), ..., satd_b(h). The QP of the poor quality frames is calculated using the RQ model and labeled as qp_b(1), qp_b(2), ..., qp_b(h).

[0022] Preferably, the QP value of the quality-balanced frame is equal to the QP value of the corresponding frame in the first encoding, and the QP values ​​of the quality-balanced frames are marked as qp_m(1), qp_m(2), ..., qp_m(f), where f represents the frame number of the quality-balanced frame.

[0023] The present invention has the following beneficial effects: Addressing the problems of existing two-pass bitrate control, the target bit count for each frame in the second encoding is adjusted based on the PSNR result of the first encoding. First, the PSNR of all frames in the first encoding is calculated, and all frames are divided into high-quality frames, low-quality frames, and balanced-quality frames. During the second encoding, the total number of bits saved by the high-quality frames when the PSNR decreases by a certain amount is calculated, and these bits are allocated to the low-quality frames. This ensures that the quality of high-quality frames does not decrease too much during the second encoding, and the quality of low-quality frames can also be improved, thereby improving the overall subjective quality of the video. Attached Figure Description

[0024] Figure 1 Here is a flowchart of the bitrate control process;

[0025] Figure 2 This is a flowchart of the two-pass rate control algorithm.

[0026] Figure 3 This is a flowchart illustrating the steps of a method for improving two-pass code rate control using peak signal-to-noise ratio according to an embodiment of the present invention. Detailed Implementation

[0027] 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, not all, of the embodiments of the present invention. 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.

[0028] See Figure 3 The diagram shows a flowchart of the method for improving two-pass code rate control using peak signal-to-noise ratio according to an embodiment of the present invention, including the following steps:

[0029] Set the target total number of bits TB, start the first encoding of two passes, obtain the bitstream, and after the encoding is completed, count the total number of video frames N, PSNR, QP, SATD, and Bits of each frame, and mark the PSNR of each frame as psnr(1), psnr(2), ..., psnr(N), the QP of each frame as qp(1), qp(2), ..., qp(N), the SATD of each frame as satd(1), satd(2), ..., satd(N), and the Bits of each frame as bits(1), bits(2), ..., bits(N);

[0030] The pre-analysis phase of the second encoding of the two-pass begins. Since frames with very high PSNR in the first encoding have better subjective quality, if their PSNR drops within a certain range, it will not affect their subjective quality too much. Therefore, they have PSNR redundancy. The PSNR redundancy of the i-th frame is defined as psnr_rd(i) = psnr(i) - TH1, where TH1 is a constant with a value range of (30~40). When psnr_rd(i) is greater than 0, the subjective quality is better, and when psnr_rd(i) is less than 0, the subjective quality is worse.

[0031] Calculate the QP values ​​for high-quality frames, low-quality frames, and balanced quality frames respectively;

[0032] The second encoding stage of the two-pass process begins by determining whether each frame belongs to a high-quality frame, a low-quality frame, or a quality-balanced frame, and then encoding it using the calculated QP value to obtain the final bitstream.

[0033] In one embodiment of the present invention, a frame with better quality is a frame where psnr_rd(i) > 0. The QP value of a frame with better quality is calculated as follows:

[0034] The number of bits in the first encoding of a frame with better quality is denoted as bits_g(1), bits_g(2), ..., bits_g(k), and the PSNR redundancy is denoted as psnr_rd_g(1), psnr_rd_g(2), ..., psnr_rd_g(k). The number of bits saved by a frame with better quality is defined as the bit redundancy. The bit redundancy Sv(i) of the i-th frame with better quality is: Sv(i) = Max(bits_g(i)*(1-0.25*psnr_rd_g(i)), bits_g(i)*0.4 After subtracting the bit redundancy, the available bits of the better quality frames are marked as bits_g(1)-Sv(1), bits_g(2)-Sv(2), ..., bits_g(k)-Sv(k). The SATD of the better quality frames obtained from the results of the first encoding are marked as satd_g(1), satd_g(2), ..., satd_g(k). The QP of the better quality frames is calculated using the RQ model and marked as qp_g(1), qp_g(2), ..., qp_g(k), where k represents the number of better quality frames.

[0035] In one embodiment of the present invention, the poor quality frames are the 20% of frames with the smallest psnr_rd(i) among all frames. The QP value of the poor quality frames is calculated as follows:

[0036] The number of bits for the poor-quality frames during the first encoding is denoted as bits_b(1), bits_b(2), ..., bits_b(h), where h represents the number of poor-quality frames. The total number of bits saved by the better-quality frames is calculated as Bits_save:

[0037]

[0038] Bits_save is evenly distributed to the poor quality frames. The target number of bits for the poor quality frames in the second encoding is bits_b(1) + Bits_save / h, bits_b(2) + Bits_save / h, ..., bits_b(h) + Bits_save / h. The SATD of the poor quality frames is obtained from the results of the first encoding and labeled as satd_b(1), satd_b(2), ..., satd_b(h). The QP of the poor quality frames is calculated using the RQ model and labeled as qp_b(1), qp_b(2), ..., qp_b(h).

[0039] Based on the defined good quality frames and poor quality frames, if a frame is neither a good quality frame nor a poor quality frame, then the frame is defined as a quality-balanced frame. The QP value of a quality-balanced frame is equal to the QP value of the corresponding frame in the first encoding. The QP values ​​of the quality-balanced frames are labeled as qp_m(1), qp_m(2), ..., qp_m(f), where f represents the number of quality-balanced frames.

[0040] The above-described method for improving two-pass bitrate control using peak signal-to-noise ratio (PSNR) first calculates the PSNR of all frames in the first encoding pass and categorizes them into high-quality frames, low-quality frames, and balanced quality frames. In the second encoding pass, it calculates the total number of bits saved by reducing the PSNR of high-quality frames by a certain margin and allocates these bits to the low-quality frames. This ensures that the quality of high-quality frames does not drop too much in the second encoding pass, while the quality of low-quality frames also improves, thereby enhancing the overall subjective quality of the video. This method of improving two-pass bitrate control using PSNR can be applied to various encoders, such as HEVC, H.264, MPEG4, AVS, AVS2, and AVS3.

[0041] It should be understood that the exemplary embodiments described herein are illustrative and not restrictive. Although one or more embodiments of the invention have been described in conjunction with the accompanying drawings, those skilled in the art will understand that various changes in form and detail may be made without departing from the spirit and scope of the invention as defined by the appended claims.

Claims

1. A method for improving two-pass code rate control using peak signal-to-noise ratio, characterized in that, Includes the following steps: Set the target total number of bits TB, start the first encoding of two passes, obtain the bitstream, and after the encoding is completed, count the total number of video frames N, PSNR, QP, SATD, and Bits of each frame, and mark the PSNR of each frame as psnr(1), psnr(2), ..., psnr(N), the QP of each frame as qp(1), qp(2), ..., qp(N), the SATD of each frame as satd(1), satd(2), ..., satd(N), and the Bits of each frame as bits(1), bits(2), ..., bits(N); Calculate the total number of bits saved by the better quality frames. save, will Save the average allocation to the poor-quality frames; The pre-analysis phase of the second encoding of the two-pass begins, and the PSNR redundancy of the i-th frame is defined as psnr_rd(i) = psnr(i) - TH1, where TH1 is a constant with a value range of 30 to 40. Calculate the QP values ​​for high-quality frames, low-quality frames, and balanced quality frames respectively; The QP value of a quality-balanced frame is equal to the QP value of the corresponding frame in the first encoding. The second encoding stage of the two-pass process begins by determining whether each frame belongs to a high-quality frame, a low-quality frame, or a balanced quality frame, and then encoding it using the calculated QP value to obtain the final bitstream. Frames of good quality are those with psnr_rd(i) > 0, frames of poor quality are the 20% of all frames with the smallest psnr_rd(i), and the rest are frames of balanced quality. The QP value of frames of good quality is calculated as follows: The number of bits in the first encoding of a frame with better quality is denoted as bits_g(1), bits_g(2), ..., bits_g(k), and the PSNR redundancy is denoted as psnr_rd_g(1), psnr_rd_g(2), ..., psnr_rd_g(k). The number of bits saved by a frame with better quality is defined as the bit redundancy. The bit redundancy of the i-th frame with better quality is... for: After subtracting the bit redundancy, the available bits of the better quality frames are marked as bits_g(1)-Sv(1), bits_g(2)-Sv(2), ..., bits_g(k)-Sv(k). The SATD of the better quality frames obtained from the results of the first encoding are marked as satd_g(1), satd_g(2), ..., satd_g(k). The QP of the better quality frames is calculated using the RQ model and marked as qp_g(1), qp_g(2), ..., qp_g(k), where k represents the number of better quality frames.

2. The method for improving two-pass code rate control using peak signal-to-noise ratio as described in claim 1, characterized in that, The QP value of a poor-quality frame is calculated as follows: The number of bits for the poor-quality frames during the first encoding is denoted as bits_b(1), bits_b(2), ..., bits_b(h), where h represents the number of poor-quality frames and the total number of bits saved by the better-quality frames. The calculation method for save is as follows: The target number of bits for the poor quality frame during the second encoding is bits_b(1)+ save / h, bits_b(2)+ save / h, ..., bits_b(h) + save / h, obtain the SATD of the poor quality frame from the result of the first encoding, and label them as satd_b(1), satd_b(2), ..., satd_b(h). Calculate the QP of the poor quality frame using the RQ model, and label them as qp_b(1), qp_b(2), ..., qp_b(h).

3. The method for improving two-pass code rate control using peak signal-to-noise ratio as described in claim 1, characterized in that, The QPs of the quality equalization frames are labeled as qp_m(1), qp_m(2), ..., qp_m(f), where f represents the number of quality equalization frames.

Citation Information

Patent Citations

  • Method for controlling code rate of secondary AVS encoding of video signal

    CN101547349A