two pass fixed qp rate control method

By using a two-pass fixed QP bitrate control method, the QP value of the frame is adjusted through two encoding processes, which solves the problem of poor video quality in existing technologies, achieves stable bitrate and quality, and improves video encoding performance.

CN115802043BActive Publication Date: 2026-03-27HANGZHOU ARCVIDEO TECHNOLOGY CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-10-27
Publication Date
2026-03-27

AI Technical Summary

Technical Problem

Existing two-pass bitrate control methods cannot effectively optimize overall video quality in video encoding, resulting in poor video quality in some complex scenes, especially under dynamic bitrate and average bitrate control, where video quality fluctuates significantly.

Method used

The two-pass fixed QP bitrate control method is adopted. Through two encoding processes, the frame type, QP and bit count information are statistically analyzed, and the QP value of each frame is calculated and adjusted to make the actual bitrate close to the target bitrate and ensure the stable quality of each frame. The QP values ​​of I-frames, P-frames and B-frames are calculated using a specific QP value adjustment formula.

Benefits of technology

It achieved an actual bitrate close to the target bitrate, while maintaining relatively stable frame quality, avoiding the occurrence of extremely poor quality frames, and improving the overall video quality.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115802043B_ABST
    Figure CN115802043B_ABST
Patent Text Reader

Abstract

The application discloses a two pass fixed QP code rate control method, comprising the following steps: setting a target total bit number TB, starting a first encoding of the two pass, obtaining a code stream, after the encoding is finished, counting a total frame number N of the video, a frame type of each frame, a QP of each frame, a texture bit number of each frame, a motion vector bit number of each frame, marking the frame type of each frame as FT(1), FT(2),..., FT(N) respectively, marking the QP of each frame as qp(1), qp(2),..., qp(N) respectively, marking the texture bit number of each frame as tex_bits(1), tex_bits(2),..., tex_bits(N) respectively, and marking the motion vector bit number of each frame as mv_bits(1), mv_bits(2),..., mv_bits(N) respectively; starting a second encoding of the two pass, calculating actual QP values of each frame according to the target total bit number TB and the information collected in the first encoding, and encoding each frame to obtain a final code stream.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The application belongs to the technical field of video coding, and particularly relates to a two-pass fixed QP rate control method. BACKGROUND

[0002] Video technology has been widely applied in mobile terminals, network live broadcast, home theaters and remote monitoring fields, and video resolution gradually changes from standard definition (SD) to high definition (HD) and ultra high-definition (UHD), and current international commonly used video coding standards include H.264, H.265 / HEVC and domestic AVS, AVS+ and AVS2.

[0003] Video image data has strong correlation, and many adjacent pixel data in a frame of image is similar or identical, and data between adjacent frames also has many similarities or repetitions, and coding compression is to remove these redundant information in data. In order to improve coding compression efficiency, the encoder sets different frame types for each frame, and the frame types usually include I frame, P frame and B frame, wherein the I frame adopts intra-frame coding, the P frame adopts forward reference inter-frame coding, and the B frame is bidirectional reference inter-frame coding.

[0004] Rate control is an important part of video coding, and refers to Figure 1 , which calculates the number of bits that should be allocated to each frame of video and each region in the frame by acquiring video source characteristics (such as motion intensity, image texture complexity, etc.) and available network bandwidth, calculates QP (quantitative parameters) by using an RQ model, and performs coding to make the output code stream meet the transmission of the channel and make the output video quality as good as possible. The RQ model calculates the quantitative parameters in the following manner:

[0005]

[0006] wherein Bits is the available number of bits of the current frame; SATD is the sum of residual transform absolute values of the current frame, and is used to measure the complexity of the current frame; a, b and c are model parameters; if the available number of bits of a frame is larger, the QP value is smaller, the quantization distortion is smaller, and the coding quality of the frame is better.

[0007] Generally, a video coding method is only coded once, but since the complexity of each frame of video is different, the number of bits required by each frame is different, and the coding distortion degree is also different. In order to improve the video quality, refer to Figure 2, two pass code rate control method is applied to offline video encoding, the method encodes twice, the first encoding encodes all frames of the video once, and the complexity, SATD, QP and bit number of each frame are counted, based on the information of each frame of the first encoding, more code rate is allocated to the frame with large complexity, and less code rate is allocated to the frame with small complexity, and the QP of each frame is calculated, and the second encoding is performed. In order to make the actual code rate and the target bandwidth match as much as possible, the existing two pass code rate control method adopts a dynamic bit rate (Variable Bit Rate, VBR) or average bit rate (Average Bitrate, ABR) to calculate the QP of each frame, but VBR and ABR cannot optimize the overall quality, because the code rate fluctuation of VBR and ABR is limited, and some complex scenes adopt a larger QP value, resulting in poor output video quality. SUMMARY

[0008] In view of the above problems, the present application provides a two pass fixed QP code rate control method, which makes the actual code rate close to the target code rate, and can also make the quality between frames relatively stable, and there is no frame with extremely poor quality.

[0009] To solve the above technical problems, the technical scheme adopted by the present application is as follows:

[0010] The embodiment of the present application provides a two pass fixed QP code rate control method, comprising the following steps:

[0011] Setting a target total bit number TB, starting the first encoding of two pass, obtaining a code stream, after the encoding is completed, counting the total frame number N of the video, the frame type of each frame, the QP of each frame, the texture bit number of each frame, and the motion vector bit number of each frame, marking the frame type of each frame as FT(1), FT(2),..., FT(N) respectively, marking the QP of each frame as qp(1), qp(2),..., qp(N) respectively, marking the texture bit number of each frame as tex_bits(1), tex_bits(2),..., tex_bits(N) respectively, and marking the motion vector bit number of each frame as mv_bits(1), mv_bits(2),..., mv_bits(N) respectively;

[0012] Starting the second encoding of two pass, calculating the actual QP value of each frame according to the target total bit number TB and the information collected in the first encoding, and encoding each frame to obtain a final code stream.

[0013] Preferably, calculating the actual QP value of each frame further comprises:

[0014] Step 1, define the first baseline QP value as:

[0015]

[0016] The round() function is used to round down the data, and L1 is defined as the list of the first baseline QP values ​​obtained from the calculation.

[0017] Step 2: Calculate the encoded QP value of each frame based on the qp_base1 value and the frame type of each frame, and label them as qp_c(1), qp_c(2), ..., qp_c(N). Calculate their estimated bit counts, and label them as bits_c(1), bits_c(2), ..., bits_c(N). Their sum is the estimated total bit count bits_c. If bits_c is greater than the target total bit count TB, increment qp_base1 by 1 and execute Step 3; if bits_c is less than the target total bit count TB, decrement qp_base1 by 1 and execute Step 3; if bits_c is equal to the target total bit count TB, execute Step 4.

[0018] Step 3: Determine if qp_base1 is in QP list L1. If it is, proceed to step 4. Otherwise, add the value of qp_base1 to QP list L1 and proceed to step 2.

[0019] Step 4: Define the current qp_base1 value as the second baseline QP, and mark it as qp_base2. Calculate the actual QP of each frame based on qp_base2 and the frame type of each frame.

[0020] Preferably, in step 2, the encoded QP value of each frame is calculated based on the qp_base1 value and the frame type of each frame. The calculation of qp_c is as follows:

[0021] If it is an I-frame, qp_c = qp_base1-3;

[0022] If it is a P-frame, qp_c = qp_base1;

[0023] If it is a B-frame, qp_c = qp_base1 + 3.

[0024] Preferably, in step 2, the encoded QP value of each frame is calculated based on the qp_base1 value and the frame type of each frame, and labeled as qp_c(1), qp_c(2), ..., qp_c(N), and their estimated number of bits is calculated and labeled as bits_c(1), bits_c(2), ..., bits_c(N), respectively. The calculation method is as follows:

[0025]

[0026] wherein a is in the range of (1, 1.5), β is in the range of (0.5, 1.2), tex_bits(i) is the texture bit number of the i-th frame in the first encoding, and mv_bits(i) is the motion vector bit number of the i-th frame in the first encoding.

[0027] Preferably, the actual QP value of each frame is calculated according to qp_base2 and the frame type of each frame in the fourth step as follows:

[0028] If it is an I frame, the actual QP value is qp_base2-3;

[0029] If it is a P frame, the actual QP value is qp_base2;

[0030] If it is a B frame, the actual QP value is qp_base2+3.

[0031] The present application has the following beneficial effects: in the second encoding of two pass, a set of QP values, including I frame QP, P frame QP and B frame QP, is calculated by traversing each available QP value, so that the actual code rate is close to the target code rate, and the video frames are encoded by using the set of QP values, which can make the actual code rate close to the target code rate, and can also make the quality of each frame relatively stable, and there is no frame with extremely poor quality. BRIEF DESCRIPTION OF DRAWINGS

[0032] Figure 1 is a code rate control flowchart;

[0033] Figure 2 is a two pass code rate control algorithm flowchart.

[0034] Figure 3 is a step flowchart of the two pass constant QP code rate control method of the embodiment of the present application. DETAILED DESCRIPTION

[0035] The technical solutions in the embodiments of the present application will be described clearly and completely below with reference to the drawings in the embodiments of the present application. Obviously, the described embodiments are only some of the embodiments of the present application, but not all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without creative work fall within the protection scope of the present application.

[0036] Referring to Figure 3 , a step flowchart of a two pass constant QP code rate control method of an embodiment of the present application is shown, including the following steps:

[0037] Setting a target total bit number TB, starting a first encoding of two passes, obtaining a code stream, after the encoding is finished, counting a total frame number N of the video, a frame type of each frame, a QP of each frame, a texture bit number of each frame, a motion vector bit number of each frame, marking the frame type of each frame as FT(1), FT(2),..., FT(N) respectively, marking the QP of each frame as qp(1), qp(2),..., qp(N) respectively, marking the texture bit number of each frame as tex_bits(1), tex_bits(2),..., tex_bits(N) respectively, and marking the motion vector bit number of each frame as mv_bits(1), mv_bits(2),..., mv_bits(N) respectively;

[0038] Starting a second encoding of two passes, according to the target total bit number TB and the information collected in the first encoding, calculating actual QP values of each frame, and encoding each frame to obtain a final code stream.

[0039] In an embodiment of the present application, calculating the actual QP values of each frame further comprises:

[0040] Step 1, defining a first reference QP value as:

[0041]

[0042] wherein round() is an integer function, and defining a list of the first reference QP values calculated as L1;

[0043] Step 2, calculating encoding QP values of each frame according to the qp_base1 value and the frame type of each frame, marking as qp_c(1), qp_c(2),..., qp_c(N), and calculating their estimated bit numbers, marking as bits_c(1), bits_c(2),..., bits_c(N) respectively, and their cumulative sum is an estimated total bit number bits_c, if bits_c is greater than the target total bit number TB, then qp_base1 is added by 1, and Step 3 is executed; if bits_c is less than the target total bit number TB, then qp_base1 is subtracted by 1, and Step 3 is executed; if bits_c is equal to the target total bit number TB, then Step 4 is executed;

[0044] Step 3, judging whether qp_base1 is in the QP list L1, if yes, then Step 4 is executed, otherwise, adding the qp_base1 value to the QP list L1, and Step 2 is executed;

[0045] Step 4: Define the current qp_base1 value as the second baseline QP, and mark it as qp_base2. Calculate the actual QP of each frame based on qp_base2 and the frame type of each frame.

[0046] Furthermore, in one embodiment of the present invention, in step 2, the encoded QP value of each frame is calculated based on the qp_base1 value and the frame type of each frame. The calculation of qp_c is as follows:

[0047] If it is an I-frame, qp_c = qp_base1-3;

[0048] If it is a P-frame, qp_c = qp_base1;

[0049] If it is a B-frame, qp_c = qp_base1 + 3.

[0050] Further, in one embodiment of the present invention, in step 2, the encoded QP value of each frame is calculated based on the qp_base1 value and the frame type of each frame, and labeled as qp_c(1), qp_c(2), ..., qp_c(N), and their estimated number of bits is calculated, labeled as bits_c(1), bits_c(2), ..., bits_c(N), respectively. The calculation method of these values ​​is as follows:

[0051]

[0052] The values ​​of α range from (1, 1.5), the values ​​of β range from (0.5, 1.2), tex_bits(i) is the number of texture bits in the i-th frame in the first encoding, and mv_bits(i) is the number of motion vector bits in the i-th frame in the first encoding.

[0053] Furthermore, in one embodiment of the present invention, the actual QP value of each frame calculated in step 4 based on qp_base2 and the frame type of each frame is as follows:

[0054] If it is an I-frame, the actual QP value is qp_base2-3;

[0055] If it is a P-frame, the actual QP value is qp_base2;

[0056] If it is a B-frame, the actual QP value is qp_base2+3.

[0057] Through the above setting, a two pass fixed QP rate control method, in the second encoding of two pass, by traversing each available QP value, a set of QP values is calculated to make the actual code rate close to the target code rate, including I frame QP, P frame QP, B frame QP, and the video frame is encoded with the set of QP values, the method can make the actual code rate close to the target code rate, and the quality between each frame is relatively stable, and there is no extremely poor quality frame, and the subjective quality is obviously better than the traditional two pass VBR and two pass ABR method. The two pass fixed QP rate control method set above can be applied to various encoders, such as HEVC, H264, MPEG4, AVS, AVS2, AVS3, etc.

[0058] It should be understood that the example embodiments described herein are illustrative and non-limiting. Although one or more embodiments of the application are described in conjunction with the attached figures, it should be understood that various changes, modifications, and substitutions can be made by one of ordinary skill in the art without departing from the spirit and scope of the application as defined by the following claims.

Claims

1. A two-pass fixed QP rate control method, 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, the frame type of each frame, the QP of each frame, the number of texture bits of each frame, and the number of motion vector bits of each frame. Mark the frame type of each frame as FT(1), FT(2), ..., FT(N), mark the QP of each frame as qp(1), qp(2), ..., qp(N), mark the number of texture bits of each frame as tex_bits(1), tex_bits(2), ..., tex_bits(N), and mark the number of motion vector bits of each frame as mv_bits(1), mv_bits(2), ..., mv_bits(N). The second encoding of the two-pass process begins. Based on the target total number of bits (TB) and the information collected in the first encoding, the actual QP value of each frame is calculated, and each frame is encoded to obtain the final bitstream. Calculating the actual QP value for each frame further includes: Step 1, define the first baseline QP value as: ; in () is the floor function, and the list of the first baseline QP values ​​calculated is defined as L1; Step 2, according to The QP value of each frame is calculated based on the frame type and the QP value of each frame, labeled as qp_c(1), qp_c(2), ..., qp_c(N). Their estimated bit counts are also calculated and labeled as bits_c(1), bits_c(2), ..., bits_c(N). Their sum is the estimated total bit count bits_c. If bits_c is greater than the target total bit count TB, then... Increment by 1 and proceed to step 3; if bits_c is less than the target total number of bits TB, then let... Decrease by 1 and proceed to step 3; if bits_c equals the target total number of bits TB, proceed to step 4; Step 3, make a judgment Is it in QP list L1? If yes, proceed to step 4; otherwise, ... Add the value to QP list L1 and perform step 2; Step 4, at this time The value is defined as the second baseline QP, and is tagged as ,according to The actual QP for each frame is calculated based on the frame type of each frame.

2. The two-pass fixed QP rate control method as described in claim 1, characterized in that, According to the second step The QP value of each frame is calculated based on the frame type and the value of each frame. The calculation of qp_c is as follows: If it is an I-frame ; If it's a P-frame ; If it is a B-frame, .

3. The two-pass fixed QP rate control method as described in claim 1, characterized in that, In step 2, according to The QP values ​​of each frame are calculated based on the frame type and the frame value, and are labeled as qp_c(1), qp_c(2), ..., qp_c(N). Their estimated bit counts are also calculated and labeled as bits_c(1), bits_c(2), ..., bits_c(N). The calculation method for bits_c(N) is as follows: ; in The value range is (1, 1.5). The value range is (0.5, 1.2), tex_bits(i) is the number of texture bits in the i-th frame in the first encoding, and mv_bits(i) is the number of motion vector bits in the i-th frame in the first encoding.

4. The two-pass fixed QP rate control method as described in claim 1, characterized in that, According to the fourth step The actual QP value for each frame is calculated based on the frame type of each frame as follows: If it is an I-frame, the actual QP value is... ; If it's a P-frame, the actual QP value is... ; If it's a B-frame, the actual QP value is... .

Citation Information

Patent Citations

  • Two pass rate control techniques for video coding using a min-max approach

    CN101523915A

  • Rate control for two-pass encoder using adaptive quantization parameters

    US20110150076A1