A method and device for quantizing a B frame, an electronic device, and a storage medium
By dynamically calculating quantization parameters based on the reference frame type and content characteristics of the B-frame, the coding performance loss caused by fixed B-frame quantization parameters in existing technologies is solved, achieving more efficient video coding.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- HANGZHOU MICROFRAME INFORMATION TECH CO LTD
- Filing Date
- 2023-09-20
- Publication Date
- 2026-05-29
AI Technical Summary
In existing video coding standards, the quantization parameters of B-frames use fixed values, ignoring the content characteristics of B-frames at different temporal levels, resulting in a loss of coding performance.
Based on the reference frame type and content characteristics of the B-frame, the quantization parameters are dynamically calculated and the quantization process is optimized by fitting the mapping relationship between intra-frame coding cost and quantization offset.
By dynamically calculating quantization parameters, the encoding performance of video coding is improved, adapting to the video coding needs of different scenarios.
Smart Images

Figure CN117221545B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of video coding, and more specifically to a method, apparatus, electronic device, and storage medium for quantizing B-frames. Background Technology
[0002] In existing video coding standards, the video frames to be encoded are divided into several groups, and each group of video frames is called a GOP (Group of Pictures). The number of video frames in a GOP is generally fixed, and a GOP can include three types of frames: I-frames, P-frames, and B-frames. Among them, I-frames are intra-predictive frames, P-frames are one-way predictive frames, and B-frames are two-way predictive frames.
[0003] During encoding, B-frames are predicted using inter-frame prediction. Unlike I-frames and P-frames, B-frames can be distributed across different temporal levels. Depending on the content characteristics of the B-frame, its reference frame can be of different types of video frames. Generally, the quantization parameters of a video frame are obtained from the initial QP and quantization offset. The initial QP and quantization offset are usually set to constant values based on experience before encoding begins. This singular setting method cannot meet the needs of video encoding in all scenarios and has certain limitations, resulting in a certain degree of performance loss. For B-frames with diverse reference frame types, traditional quantization methods do not consider the content characteristics of B-frames at different temporal levels, choosing fixed quantization parameters. This leads to different levels of B-frames using the same quantization parameters, ignoring the importance of the reference structure of different B-frame levels. Summary of the Invention
[0004] In view of the above-mentioned problems with existing methods, this invention proposes a B-frame quantization method, apparatus, electronic device and storage medium.
[0005] Specifically, the embodiments of the present invention provide the following technical solutions:
[0006] In a first aspect, embodiments of the present invention provide a B-frame quantization method, comprising:
[0007] Determine the reference frame type of the current B frame. The reference frame includes: forward reference frame and backward reference frame.
[0008] The basic frame level QP of the current B-frame is determined based on the reference frame.
[0009] The first quantization offset is obtained by fitting the mapping relationship between the intra-frame coding cost and the quantization offset.
[0010] The actual quantization offset is obtained based on the first quantization offset.
[0011] The quantization parameters of the current B-frame are obtained based on the basic frame-level QP and the actual quantization offset.
[0012] Secondly, embodiments of the present invention provide a B-frame quantization apparatus, comprising:
[0013] The determination module is used to determine the reference frame type of the current B frame, wherein the reference frame includes: a forward reference frame and a backward reference frame.
[0014] The first calculation module is used to determine the basic frame level QP of the current B frame based on the reference frame.
[0015] The fitting module is used to obtain the first quantization offset by fitting the mapping relationship between the intra-frame coding cost and the quantization offset.
[0016] The second calculation module is used to obtain the actual quantization offset based on the first quantization offset.
[0017] The third calculation module is used to obtain the quantization parameters of the current B-frame based on the basic frame level QP and the actual quantization offset.
[0018] Thirdly, embodiments of the present invention provide an electronic device, including: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, the instructions being executed by the at least one processor to enable the at least one processor to perform the method as described in any of the preceding aspects.
[0019] Fourthly, embodiments of the present invention provide a non-transitory computer-readable storage medium storing computer instructions for using a computer to perform the method described in any of the preceding aspects.
[0020] As can be seen from the above technical solutions, the technical solutions provided by the embodiments of the present invention have the following beneficial effects: The embodiments of the present invention utilize the characteristic that B frames at different time domain levels have different reference frame types, calculate and select different quantization parameters according to their different content characteristics, realize the optimization of quantization parameters, and improve coding performance. Attached Figure Description
[0021] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained from these drawings without creative effort.
[0022] Figure 1This is a flowchart of a B-frame quantization method provided in an embodiment of the present invention.
[0023] Figure 2 This is a schematic diagram of the inter-frame reference structure.
[0024] Figure 3 This is a flowchart of a B-frame quantization method provided in another embodiment of the present invention.
[0025] Figure 4 This is a schematic diagram of the structure of a B-frame quantization device provided in an embodiment of the present invention.
[0026] Figure 5 This is a schematic diagram of the structure of a B-frame quantization device provided in another embodiment of the present invention.
[0027] Figure 6 This is a schematic diagram of the structure of an electronic device provided in an embodiment of the present invention. Detailed Implementation
[0028] The specific embodiments of the present invention will be further described below with reference to the accompanying drawings. The following examples are only used to more clearly illustrate the technical solutions of the present invention and should not be construed as limiting the scope of protection of the present invention.
[0029] Figure 1 A flowchart of a B-frame quantization method provided in an embodiment of the present invention is shown, as follows: Figure 1 As shown, the B-frame quantization method provided in this embodiment of the invention specifically includes the following:
[0030] Step 1: Determine the reference frame type of the current B frame. The reference frame includes: forward reference frame and backward reference frame.
[0031] like Figure 2 As shown, it can be understood that a GOP (Group of Pictures) can include three types of frames: I-frames, P-frames, and B-frames. I-frames are intra-predicted frames, P-frames are unidirectional predicted frames, and B-frames are bidirectional predicted frames. Therefore, the reference frames for a B-frame include a forward reference frame and a backward reference frame.
[0032] The reference frame type of the current B frame includes:
[0033] The forward reference frame is an I-frame, and the backward reference frame is not an I-frame; the forward reference frame is not an I-frame, and the backward reference frame is an I-frame; both the forward reference frame and the backward reference frame are I-frames; neither the forward reference frame nor the backward reference frame is an I-frame.
[0034] Step 2: Determine the basic frame level QP of the current B-frame based on the reference frame.
[0035] Furthermore, before determining the basic frame level QP of the current B-frame, the following steps are also included:
[0036] The distances between the current B-frame and the forward reference frame, and between the current B-frame and the backward reference frame, are respectively denoted as D. front and D back .
[0037] The frame-level QPs of the forward reference frame and the backward reference frame are obtained respectively, and denoted as QP. front and QP back .
[0038] The step of determining the basic frame level QP of the current B-frame based on the reference frame includes:
[0039] When the forward reference frame is an I-frame and the backward reference frame is not an I-frame, the basic frame level QP of the current B-frame is denoted as QP. basic, Specifically, QP basic = QP back .
[0040] When the forward reference frame is not an I-frame and the backward reference frame is an I-frame, the basic frame level QP of the current B-frame is denoted as QP. basic Specifically, QP basic = QP front .
[0041] When both the forward reference frame and the backward reference frame are I-frames, the basic frame level QP of the current B-frame is denoted as QP. basic Specifically, QP basic = (QP front + QP back ) / 2 + c.
[0042] Where c is an empirical constant.
[0043] When neither the forward reference frame nor the backward reference frame is an I-frame, the basic frame level QP of the current B-frame is denoted as QP. basic Specifically, QP basic = (QP front * D back + QP back * D front ) / (D front + D back ).
[0044] Step 3: Obtain the first quantization offset by fitting the mapping relationship between the intra-frame coding cost and the quantization offset.
[0045] The methods for calculating the intra-frame coding cost include, but are not limited to: Var (Variance), SAD (Sum of absolute differences), SATD (Sum of absolute transformed difference), and SSE (Sum of squares error).
[0046] Fit the mapping relationship between intra-frame coding cost and quantization offset:
[0047] offset cost = 1 - 1 / pow((1 + pow((cost / a), b)),c)
[0048] Where a, b, and c are all empirical thresholds, cost is the intra-frame coding cost, and pow() is an exponential function.
[0049] Preferably, when the intra-frame coding cost is calculated using the Var (variance) method, a mapping relationship between the intra-frame coding cost and the quantization offset is fitted:
[0050] offset cost = log (max (var, 1)) - c
[0051] Where var is the average pixel variance of the video frame, c is an empirical constant, and max() is the maximum value function.
[0052] The first quantization offset of the current B-frame and the reference frame is obtained based on the mapping relationship, the intra-frame coding cost of the current B-frame and the reference frame.
[0053] Step 4: Obtain the actual quantization offset based on the first quantization offset.
[0054] Δoffset1 = fabs (offset cost_bframe - offset cost_front )
[0055] Δoffset2 = fabs (offset cost_bframe - offset cost_back )
[0056] Wherein, Δoffset1 is the absolute difference between the current B-frame and the first quantization offset of the forward reference frame, Δoffset2 is the absolute difference between the current B-frame and the first quantization offset of the backward reference frame, and offset cost_bframe The first quantization offset of the current B-frame, offsetcost_front The first quantization offset of the forward reference frame, offset cost_back The first quantization offset of the backward reference frame is given by fabs(), which is a floating-point absolute value function.
[0057] Specifically, when the forward reference frame is an I-frame and the backward reference frame is not an I-frame, the actual quantization offset is denoted as offset, where offset = Δoffset2.
[0058] When the forward reference frame is not an I-frame and the backward reference frame is an I-frame, the actual quantization offset is denoted as offset, where offset = Δoffset1.
[0059] When both the forward reference frame and the backward reference frame are I-frames, the actual quantization offset is denoted as offset, where offset = (w1 * Δoffset1 + w2 * Δoffset2) / 2.
[0060] When neither the forward reference frame nor the backward reference frame is an I-frame, the actual quantization offset is denoted as offset = (w3 * Δoffset1 + w4 * Δoffset2) / 2.
[0061] Among them, w1, w2, w3, and w4 are constant coefficients.
[0062] Step 5: Obtain the quantization parameters of the current B-frame based on the basic frame-level QP and the actual quantization offset.
[0063] QP B = QP basic + offset.
[0064] Specifically, when the forward reference frame is an I-frame and the backward reference frame is not an I-frame, the quantization parameter of the current B-frame is QP. B = QP basic + offset = QP back + Δoffset2.
[0065] When the forward reference frame is not an I-frame and the backward reference frame is an I-frame, the quantization parameter of the current B-frame is QP. B = QP basic + offset = QP front + Δoffset1.
[0066] When both the forward reference frame and the backward reference frame are I-frames, the quantization parameter of the current B-frame is QP. B = QPbasic + offset = (QP front + QP back ) / 2 + c+ (w1* Δoffset1+ w2* Δoffset2) / 2.
[0067] When neither the forward reference frame nor the backward reference frame is an I-frame, the quantization parameter of the current B-frame is QP. B = QP basic + offset = (QP front * D back + QP back * D front ) / (D front + D back ) + (w3* Δoffset1+ w4* Δoffset2) / 2.
[0068] Furthermore, in order to calculate the quantization offset of the current B-frame more accurately, such as... Figure 3 As shown, in another embodiment, the actual quantization offset can be corrected before obtaining the quantization parameters of the current B-frame based on the basic frame level QP and the actual quantization offset.
[0069] The correction of the actual quantization offset includes:
[0070] The correction factor for the quantization offset is calculated based on the ratio of the number of SKIP blocks to the number of I blocks in the video frame.
[0071] It is understood that the SKIP block is a block without residuals in the inter-frame coded block, and the I block is an intra-frame coded block. The number of SKIP blocks can characterize the difference between video frames in the time domain; the number of I blocks can characterize the difference between video frames in the spatial domain.
[0072] The step of calculating the correction factor for the quantization offset based on the ratio of the number of SKIP blocks to the number of I blocks in a video frame includes:
[0073] Calculate the proportions of SKIP blocks and I blocks in the reference frame, respectively.
[0074] ratio skip = count skip / count mb
[0075] ratio I = count I / count mb
[0076] Where, count skip count represents the number of SKIP blocks in a video frame. I The number of I-blocks in a video frame, count mb This represents the total number of coded blocks in a single video frame.
[0077] Specifically, when the forward reference frame is an I-frame and the backward reference frame is not an I-frame, the ratio of the number of SKIP blocks to the number of I-blocks in the reference frame is the same as the ratio of the number of SKIP blocks to the number of I-blocks in the backward reference frame.
[0078] ratio skip = count skip_back / count mb
[0079] ratio I = count I_back / count mb
[0080] Where, count skip_back The number of SKIP blocks in the backward reference frame, count I_back The number of I-blocks in the backward reference frame, count mb This represents the total number of coded blocks in the backward reference frame.
[0081] When the forward reference frame is not an I-frame and the backward reference frame is an I-frame, the ratio of the number of SKIP blocks to the number of I-blocks in the reference frame is the same as the ratio of the number of SKIP blocks to the number of I-blocks in the forward reference frame:
[0082] ratio skip = count skip_front / count mb
[0083] ratio I = count I_front / count mb
[0084] Where, count skip_front The number of SKIP blocks in the forward reference frame, count I_front The number of I-blocks in the forward reference frame, count mb This represents the total number of coded blocks in the forward reference frame.
[0085] When both the forward reference frame and the backward reference frame are I-frames, the proportion of SKIP blocks in the reference frame is 0, and the proportion of I-blocks is 1.
[0086] When both the forward reference frame and the backward reference frame are not I frames, the proportion of the number of SKIP blocks in the reference frame is the average of the proportions of the number of SKIP blocks in the forward reference frame and the backward reference frame, and the proportion of the number of I blocks in the reference frame is the average of the proportions of the number of I blocks in the forward reference frame and the backward reference frame:
[0087] ratio skip = (count skip_front + count skip_back ) / (2 * count mb )
[0088] ratio I = (count I_front + count I_back ) / (2 * count mb )
[0089] Where count skip_front is the number of SKIP blocks in the forward reference frame, count I_front is the number of I blocks in the forward reference frame, count skip_back is the number of SKIP blocks in the backward reference frame, count I_back is the number of I blocks in the backward reference frame, and count mb is the total number of coded blocks in the single reference frame.
[0090] Calculating the correction factor of the quantization offset includes:
[0091] If ratio skip > TH1, and ratio I < TH2
[0092] factor = 1 + k1* ratio skip .
[0093] If ratio skip <TH2, and ratio I >TH1
[0094] factor = 1 - k2*ratio I .
[0095] In other cases: factor = 1.0
[0096] Where TH1 and TH2 are both empirical thresholds less than 1; k1 and k2 are both empirical coefficients less than 1.
[0097] The actual quantization offset is corrected according to the correction factor of the quantization offset:
[0098] offset = offset * factor
[0099] Where offset is the actual quantization offset, and factor is the correction factor for the quantization offset.
[0100] Figure 4 A schematic diagram of the structure of a B-frame quantization device provided in an embodiment of the present invention is shown, as follows: Figure 4 As shown, the B-frame quantization device provided in this embodiment of the invention specifically includes the following components:
[0101] The determination module is used to determine the reference frame type of the current B frame, wherein the reference frame includes: a forward reference frame and a backward reference frame.
[0102] The reference frame type of the current B frame includes:
[0103] The forward reference frame is an I-frame, and the backward reference frame is not an I-frame; the forward reference frame is not an I-frame, and the backward reference frame is an I-frame; both the forward reference frame and the backward reference frame are I-frames; neither the forward reference frame nor the backward reference frame is an I-frame.
[0104] The first calculation module is used to determine the basic frame level QP of the current B-frame based on the reference frame.
[0105] Furthermore, before determining the basic frame level QP of the current B-frame, the following steps are also included:
[0106] The distances between the current B-frame and the forward reference frame, and between the current B-frame and the backward reference frame, are respectively denoted as D. front and D back .
[0107] The frame-level QPs of the forward reference frame and the backward reference frame are obtained respectively, and denoted as QP. front and QP back .
[0108] The step of determining the basic frame level QP of the current B-frame based on the reference frame includes:
[0109] When the forward reference frame is an I-frame and the backward reference frame is not an I-frame, the basic frame level QP of the current B-frame is denoted as QP. basic, Specifically, QP basic = QP back .
[0110] When the forward reference frame is not an I-frame and the backward reference frame is an I-frame, the basic frame level QP of the current B-frame is denoted as QP. basic Specifically, QP basic = QP front .
[0111] When both the forward reference frame and the backward reference frame are I-frames, the basic frame level QP of the current B-frame is denoted as QP. basic Specifically, QP basic = (QP front + QP back ) / 2 + c.
[0112] Where c is an empirical constant.
[0113] When neither the forward reference frame nor the backward reference frame is an I-frame, the basic frame level QP of the current B-frame is denoted as QP. basic Specifically, QP basic = (QP front * D back + QP back * D front ) / (D front + D back ).
[0114] The fitting module is used to obtain the first quantization offset by fitting the mapping relationship between the intra-frame coding cost and the quantization offset.
[0115] The methods for calculating the intra-frame coding cost include, but are not limited to: Var (Variance), SAD (Sum of absolute differences), SATD (Sum of absolute transformed difference), and SSE (Sum of squares error).
[0116] Fit the mapping relationship between intra-frame coding cost and quantization offset:
[0117] offset cost = 1 - 1 / pow((1 + pow((cost / a), b)),c)
[0118] Where a, b, and c are all empirical thresholds, cost is the intra-frame coding cost, and pow() is an exponential function.
[0119] Preferably, when the intra-frame coding cost is calculated using the Var (variance) method, a mapping relationship between the intra-frame coding cost and the quantization offset is fitted:
[0120] offset cost = log (max (var, 1)) - c
[0121] Where var is the average pixel variance of the video frame, c is an empirical constant, and max() is the maximum value function.
[0122] The first quantization offset of the current B-frame and the reference frame is obtained based on the mapping relationship, the intra-frame coding cost of the current B-frame and the reference frame.
[0123] The second calculation module is used to obtain the actual quantization offset based on the first quantization offset:
[0124] Δoffset1 = fabs (offset cost_bframe - offset cost_front )
[0125] Δoffset2 = fabs (offset cost_bframe - offset cost_back )
[0126] Wherein, Δoffset1 is the absolute difference between the current B-frame and the first quantization offset of the forward reference frame, Δoffset2 is the absolute difference between the current B-frame and the first quantization offset of the backward reference frame, and offset cost_bframe The first quantization offset of the current B-frame, offset cost_front The first quantization offset of the forward reference frame, offset cost_back The first quantization offset of the backward reference frame is given by fabs(), which is a floating-point absolute value function.
[0127] Specifically, when the forward reference frame is an I-frame and the backward reference frame is not an I-frame, the actual quantization offset is denoted as offset, where offset = Δoffset2.
[0128] When the forward reference frame is not an I-frame and the backward reference frame is an I-frame, the actual quantization offset is denoted as offset, where offset = Δoffset1.
[0129] When both the forward reference frame and the backward reference frame are I-frames, the actual quantization offset is denoted as offset, where offset = (w1 * Δoffset1 + w2 * Δoffset2) / 2.
[0130] When neither the forward reference frame nor the backward reference frame is an I-frame, the actual quantization offset is denoted as offset = (w3 * Δoffset1 + w4 * Δoffset2) / 2.
[0131] Among them, w1, w2, w3, and w4 are constant coefficients.
[0132] The third calculation module is used to obtain the quantization parameters of the current B-frame based on the basic frame-level QP and the actual quantization offset.
[0133] QP B = QP basic + offset.
[0134] Specifically, when the forward reference frame is an I-frame and the backward reference frame is not an I-frame, the quantization parameter of the current B-frame is QP. B = QP basic + offset = QP back + Δoffset2.
[0135] When the forward reference frame is not an I-frame and the backward reference frame is an I-frame, the quantization parameter of the current B-frame is QP. B = QP basic + offset = QP front + Δoffset1.
[0136] When both the forward reference frame and the backward reference frame are I-frames, the quantization parameter of the current B-frame is QP. B = QP basic + offset = (QP front + QP back ) / 2 + c+ (w1* Δoffset1+ w2* Δoffset2) / 2.
[0137] When neither the forward reference frame nor the backward reference frame is an I-frame, the quantization parameter of the current B-frame is QP. B = QP basic + offset = (QP front * D back + QP back * D front ) / (Dfront + D back ) + (w3* Δoffset1+ w4* Δoffset2) / 2.
[0138] Furthermore, in order to calculate the quantization offset of the current B-frame more accurately, such as... Figure 5 As shown, in another embodiment, a correction module may be included before the third calculation module for correcting the actual quantization offset.
[0139] The correction of the actual quantization offset includes:
[0140] The correction factor for the quantization offset is calculated based on the ratio of the number of SKIP blocks to the number of I blocks in the video frame.
[0141] The step of calculating the correction factor for the quantization offset based on the ratio of the number of SKIP blocks to the number of I blocks in a video frame includes:
[0142] Calculate the proportions of SKIP blocks and I blocks in the reference frame, respectively.
[0143] ratio skip = count skip / count mb
[0144] ratio I = count I / count mb
[0145] Where, count skip count represents the number of SKIP blocks in a video frame. I The number of I-blocks in a video frame, count mb This represents the total number of coded blocks in a single video frame.
[0146] Specifically, when the forward reference frame is an I-frame and the backward reference frame is not an I-frame, the ratio of the number of SKIP blocks to the number of I-blocks in the reference frame is the same as the ratio of the number of SKIP blocks to the number of I-blocks in the backward reference frame.
[0147] ratio skip = count skip_back / count mb
[0148] ratio I = count I_back / count mb
[0149] Where, count skip_back The number of SKIP blocks in the backward reference frame, count I_back The number of I-blocks in the backward reference frame, count mb This represents the total number of coded blocks in the backward reference frame.
[0150] When the forward reference frame is not an I-frame and the backward reference frame is an I-frame, the ratio of the number of SKIP blocks to the number of I-blocks in the reference frame is the same as the ratio of the number of SKIP blocks to the number of I-blocks in the forward reference frame:
[0151] ratio skip = count skip_front / count mb
[0152] ratio I = count I_front / count mb
[0153] Where, count skip_front The number of SKIP blocks in the forward reference frame, count I_front The number of I-blocks in the forward reference frame, count mb This represents the total number of coded blocks in the forward reference frame.
[0154] When both the forward reference frame and the backward reference frame are I-frames, the proportion of SKIP blocks in the reference frame is 0, and the proportion of I-blocks is 1.
[0155] When neither the forward reference frame nor the backward reference frame is an I-frame, the proportion of SKIP blocks in the reference frame is the average of the proportions of SKIP blocks in the forward reference frame and the backward reference frame, and the proportion of I-blocks in the reference frame is the average of the proportions of I-blocks in the forward reference frame and the backward reference frame.
[0156] ratio skip = (count skip_front + count skip_back ) / (2 * count mb )
[0157] ratio I = (count I_front + count I_back ) / (2 * count mb )
[0158] Where, count skip_frontis the number of SKIP blocks in the forward reference frame, count I_front is the number of I blocks in the forward reference frame, count skip_back is the number of SKIP blocks in the backward reference frame, count I_back is the number of I blocks in the backward reference frame, count mb is the total number of coded blocks in the single reference frame.
[0159] Calculating the correction factor of the quantization offset includes:
[0160] If ratio skip > TH1, and ratio I < TH2
[0161] factor = 1 + k1 * ratio skip .
[0162] If ratio skip < TH2, and ratio I > TH1
[0163] factor = 1 - k2 * ratio I .
[0164] In other cases: factor = 1.0
[0165] where TH1 and TH2 are both empirical thresholds less than 1; k1 and k2 are both empirical coefficients less than 1.
[0166] According to the correction factor of the quantization offset, correct the actual quantization offset:
[0167] offset = offset * factor
[0168] where offset is the actual quantization offset and factor is the correction factor of the quantization offset.
[0169] Based on the same inventive concept, another embodiment of the present invention provides an electronic device, as Figure 6 shown, the electronic device specifically includes the following: a processor 601, a memory 602, a communication interface 603, and a communication bus 604.
[0170] Among them, the processor 601, the memory 602, and the communication interface 603 complete mutual communication through the communication bus 604; the communication interface 603 is used to implement information transmission between devices.
[0171] The processor 601 is used to call the computer program in the memory 602, and when the processor executes the computer program, it implements all the steps of the quantization method of the B-frame described above.
[0172] Based on the same inventive concept, another embodiment of the present invention provides a non-transitory computer-readable storage medium storing a computer program that, when executed by a processor, implements all the steps of the quantization method for the B-frame described above.
[0173] The logical instructions in the aforementioned memory can be implemented as software functional units and sold or used as independent products, and can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this invention, or the part that contributes to the prior art, or a part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0174] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of the embodiments of the present invention according to actual needs. Those skilled in the art can understand and implement this without any creative effort.
[0175] Furthermore, in embodiments of the present invention, relational terms such as "first" and "second" are used merely to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. In the description of this specification, the term "an embodiment," etc., means that a specific feature, structure, material, or characteristic described in connection with that embodiment or example is included in at least one embodiment or example of the present invention. In this specification, illustrative expressions of the above terms do not necessarily refer to the same embodiment or example. Moreover, the specific features, structures, materials, or characteristics described may be combined in any suitable manner in one or more embodiments or examples. Furthermore, without contradiction, those skilled in the art can combine and integrate the different embodiments or examples described in this specification, as well as the features of different embodiments or examples.
[0176] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, and not to limit them; although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features; and these modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A quantization method for B-frames, characterized in that, include: Determine the reference frame type of the current B frame, wherein the reference frame includes: forward reference frame and backward reference frame; The basic frame level QP of the current B-frame is determined based on the reference frame; The first quantization offset is obtained by fitting the mapping relationship between the intra-frame coding cost and the quantization offset. The actual quantization offset is obtained based on the first quantization offset; The quantization parameters of the current B-frame are obtained based on the basic frame-level QP and the actual quantization offset. The step of determining the basic frame level QP of the current B-frame based on the reference frame includes: Obtain the distance between the current B-frame and the reference frame; Obtain the frame-level QP of the reference frame; When the forward reference frame is an I-frame and the backward reference frame is not an I-frame, then the basic frame level QP of the current B-frame is QP. back ; When the forward reference frame is not an I-frame and the backward reference frame is an I-frame, then the basic frame level QP of the current B-frame is QP. front ; When both the forward reference frame and the backward reference frame are I-frames, the basic frame level QP of the current B-frame is (QP... front + QP back ) / 2 + c; When neither the forward reference frame nor the backward reference frame is an I-frame, the basic frame level QP of the current B-frame is (QP... front * D back + QP back * D front ) / (D front + D back ); Among them, QP back The frame-level QP of the backward reference frame, QP front For the frame-level QP of the forward reference frame, D front D is the distance between the current B-frame and the forward reference frame. back The distance between the current B-frame and the backward reference frame is c, which is an empirical constant. The step of obtaining the actual quantization offset based on the first quantization offset includes: Δoffset1 = fabs (offset cost_bframe - offset cost_front ) ; Δoffset2 = fabs (offset cost_bframe - offset cost_back ); Wherein, Δoffset1 is the absolute difference between the current B-frame and the first quantization offset of the forward reference frame, Δoffset2 is the absolute difference between the current B-frame and the first quantization offset of the backward reference frame, and offset cost_bframe The first quantization offset of the current B-frame, offset cost_front The first quantization offset of the forward reference frame, offset cost_back The first quantization offset of the backward reference frame, where fabs() is a floating-point absolute value function; When the forward reference frame is an I-frame and the backward reference frame is not an I-frame, the actual quantization offset is Δoffset2; When the forward reference frame is not an I-frame and the backward reference frame is an I-frame, the actual quantization offset is Δoffset1; When both the forward reference frame and the backward reference frame are I-frames, the actual quantization offset is (w1 * Δoffset1 + w2 * Δoffset2) / 2. When neither the forward reference frame nor the backward reference frame is an I-frame, the actual quantization offset is (w3 * Δoffset1 + w4 * Δoffset2) / 2. Among them, w1, w2, w3, and w4 are constant coefficients.
2. The quantization method for B-frames according to claim 1, characterized in that, The reference frame type of the current B frame includes: The forward reference frame is an I-frame, and the backward reference frame is not an I-frame; The forward reference frame is an I-frame, and the backward reference frame is an I-frame; Both the forward reference frame and the backward reference frame are I-frames; Neither the forward reference frame nor the backward reference frame is an I-frame.
3. The quantization method for B-frames according to claim 1, characterized in that, The methods for calculating the intra-frame coding cost include: Var, SAD, SATD, and SSE.
4. The quantization method for B-frames according to claim 1, characterized in that, The process of obtaining the first quantization offset by fitting the mapping relationship between intra-frame coding cost and quantization offset includes: Fit the mapping relationship between intra-frame coding cost and quantization offset: offset cost = 1 - 1 / pow((1 + pow((cost / a), b)),c) Where a, b, and c are all empirical thresholds, cost is the intra-frame coding cost, and pow() is an exponential function; The first quantization offset of the current B-frame and the reference frame is obtained based on the mapping relationship, the intra-frame coding cost of the current B-frame and the reference frame.
5. The quantization method for B-frames according to claim 1, characterized in that, The process of obtaining the first quantization offset by fitting the mapping relationship between intra-frame coding cost and quantization offset includes: Fit the mapping relationship between intra-frame coding cost and quantization offset: offset cost = log(max(var,1)) - c Where var is the average pixel variance of the video frame, c is an empirical constant, and max() is the maximum value function; The first quantization offset of the current B-frame and the reference frame is obtained based on the mapping relationship, the intra-frame coding cost of the current B-frame and the reference frame.
6. The quantization method for B-frames according to claim 1, characterized in that, Before obtaining the quantization parameters of the current B-frame based on the basic frame-level QP and the actual quantization offset, the method further includes correcting the actual quantization offset, including: Calculate the proportions of SKIP blocks and I blocks in the reference frame, respectively; ratio skip = count skip / count mb ratio I = count I / count mb Where, count skip count represents the number of SKIP blocks in a video frame. I The number of I-blocks in a video frame, count mb The total number of coded blocks in a single video frame; When the forward reference frame is an I-frame and the backward reference frame is not an I-frame, the ratio of the number of SKIP blocks to the number of I-blocks in the reference frame is the same as the ratio of the number of SKIP blocks to the number of I-blocks in the backward reference frame: ratio skip = count skip_back / count mb_back ratio I = count I_back / count mb_back Where, count skip_back The number of SKIP blocks in the backward reference frame, count I_back The number of I-blocks in the backward reference frame, count mb_back The total number of coded blocks in the backward reference frame; When the forward reference frame is not an I-frame and the backward reference frame is an I-frame, the ratio of the number of SKIP blocks to the number of I-blocks in the reference frame is the same as the ratio of the number of SKIP blocks to the number of I-blocks in the forward reference frame. ratio skip = count skip_front / count mb_front ratio I = count I_front / count mb_front Where, count skip_front The number of SKIP blocks in the forward reference frame, count I_front The number of I-blocks in the forward reference frame, count mb_front The total number of coded blocks in the forward reference frame; When both the forward reference frame and the backward reference frame are I-frames, the proportion of SKIP blocks in the reference frame is 0, and the proportion of I-blocks is 1. When neither the forward reference frame nor the backward reference frame is an I-frame, the proportion of SKIP blocks in the reference frame is the average of the proportions of SKIP blocks in the forward reference frame and the backward reference frame, and the proportion of I-blocks in the reference frame is the average of the proportions of I-blocks in the forward reference frame and the backward reference frame. ratio skip = (count skip_front + count skip_back ) / (count mb_front +count mb_back ) ratio I = (count I_front + count I_back ) / count mb_front +count mb_back ) Where, count skip_front The number of SKIP blocks in the forward reference frame, count I_front The number of I-blocks in the forward reference frame, count skip_back The number of SKIP blocks in the backward reference frame, count I_back The number of I-blocks in the backward reference frame, count mb_front The total number of coded blocks in the forward reference frame, count mb_back The total number of coded blocks in the backward reference frame; Calculate the correction factor for the quantization offset: If ratio skip > TH1, and ratio I < TH2 factor = 1 + k1 * ratio skip If ratio skip < TH2, and ratio I > TH1 factor = 1 - k2*ratio I Other cases: factor = 1.0 Where TH1 and TH2 are both empirical thresholds less than 1; k1 and k2 are both empirical coefficients less than 1; The actual quantization offset is corrected according to the correction factor of the quantization offset: offset = offset * factor Where offset is the actual quantization offset, and factor is the correction factor for the quantization offset.
7. The quantization method for B-frames according to claim 1, characterized in that, The quantization parameters of the current B-frame are obtained based on the basic frame-level QP and the actual quantization offset. QP B = QP basic + offset, Among them, QP B QP is the quantization parameter of the current B-frame. basic The basic frame-level QP is defined as , and offset is defined as the actual quantization offset.
8. A quantization device for B-frames, characterized in that, include: The determination module is used to determine the reference frame type of the current B frame, wherein the reference frame includes: a forward reference frame and a backward reference frame; The first calculation module is used to determine the basic frame level QP of the current B frame based on the reference frame. The step of determining the basic frame level QP of the current B-frame based on the reference frame includes: Obtain the distance between the current B-frame and the reference frame; Obtain the frame-level QP of the reference frame; When the forward reference frame is an I-frame and the backward reference frame is not an I-frame, then the basic frame level QP of the current B-frame is QP. back ; When the forward reference frame is not an I-frame and the backward reference frame is an I-frame, then the basic frame level QP of the current B-frame is QP. front ; When both the forward reference frame and the backward reference frame are I-frames, the basic frame level QP of the current B-frame is (QP... front + QP back ) / 2 + c; When neither the forward reference frame nor the backward reference frame is an I-frame, the basic frame level QP of the current B-frame is (QP... front * D back + QP back * D front ) / (D front + D back ); Among them, QP back The frame-level QP of the backward reference frame, QP front For the frame-level QP of the forward reference frame, D front D is the distance between the current B-frame and the forward reference frame. back The distance between the current B-frame and the backward reference frame is c, where c is an empirical constant. The fitting module is used to obtain the first quantization offset by fitting the mapping relationship between the intra-frame coding cost and the quantization offset; The second calculation module is used to obtain the actual quantization offset based on the first quantization offset. The step of obtaining the actual quantization offset based on the first quantization offset includes: Δoffset1 = fabs (offset cost_bframe - offset cost_front ) ; Δoffset2 = fabs (offset cost_bframe - offset cost_back ); Wherein, Δoffset1 is the absolute difference between the current B-frame and the first quantization offset of the forward reference frame, Δoffset2 is the absolute difference between the current B-frame and the first quantization offset of the backward reference frame, and offset cost_bframe The first quantization offset of the current B-frame, offset cost_front The first quantization offset of the forward reference frame, offset cost_back The first quantization offset of the backward reference frame, where fabs() is a floating-point absolute value function; When the forward reference frame is an I-frame and the backward reference frame is not an I-frame, the actual quantization offset is Δoffset2; When the forward reference frame is not an I-frame and the backward reference frame is an I-frame, the actual quantization offset is Δoffset1; When both the forward reference frame and the backward reference frame are I-frames, the actual quantization offset is (w1 * Δoffset1 + w2 * Δoffset2) / 2. When neither the forward reference frame nor the backward reference frame is an I-frame, the actual quantization offset is (w3 * Δoffset1 + w4 * Δoffset2) / 2. Among them, w1, w2, w3, and w4 are constant coefficients; The third calculation module is used to obtain the quantization parameters of the current B-frame based on the basic frame level QP and the actual quantization offset.
9. The quantization apparatus for B-frames according to claim 8, characterized in that, A correction module is included before the third calculation module to correct the actual quantization offset.
10. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the computer program, it implements the quantization method for B-frames as described in any one of claims 1 to 7.
11. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that, When executed by a processor, the computer program implements the quantization method for B-frames as described in any one of claims 1 to 7.