Methods for rate control in an MB (macroblock) layer and apparatuses using the same
10375404 ยท 2019-08-06
Assignee
Inventors
Cpc classification
H04N19/42
ELECTRICITY
H04N19/126
ELECTRICITY
H04N19/149
ELECTRICITY
H04N19/137
ELECTRICITY
International classification
H04N7/12
ELECTRICITY
H04N19/42
ELECTRICITY
H04N19/25
ELECTRICITY
Abstract
The invention introduces a method for rate control in an MB (macroblock) layer, including: calculating a prediction MAD (Mean Absolute Difference) of a current MB of a current frame according to a real MAD of a previous MB of a previous frame; calculating a real MAD of the current MB of the current frame; performing an adjustment procedure to adjust the prediction MAD of the current MB of the current frame according to the real MAD of the current MB of the current frame to obtain a final MAD of the current MB of the current frame; calculating a quantization parameter of the current MB of the current frame according to the final MAD of the current MB of the current frame; and outputting the quantization parameter of the current MB of the current frame to a quantizer.
Claims
1. A method for rate control in an MB (macroblock) layer, comprising: calculating a prediction MAD (Mean Absolute Difference) of a current MB of a current frame according to a real MAD of a previous MB of a previous frame, wherein the current MB and the previous MB are located at the same two-dimensional coordinates of the current frame and the previous frame, respectively, and the real MAD of the previous MB of the previous frame reflects the variances between raw data and reconstructed data of the previous MB; calculating a real MAD of the current MB of the current frame, wherein the real MAD of the current MB of the current frame reflects the variances between raw data and reconstructed data of the current MB; performing an adjustment procedure to adjust the prediction MAD of the current MB of the current frame according to the real MAD of the current MB of the current frame to obtain a final MAD of the current MB of the current frame; calculating a quantization parameter of the current MB of the current frame according to the final MAD of the current MB of the current frame; and outputting the quantization parameter of the current MB of the current frame to a quantizer, thereby enabling the quantizer to generate a compressed video stream under a rate corresponding to the current MB of the current frame.
2. The method of claim 1, wherein the prediction MAD of the current MB of the current frame is calculated using a linear prediction model.
3. The method of claim 2, wherein the prediction MAD of the current MB of the current frame is calculated using an Equation:
PredMAD.sub.i,j=a.sub.1RealMAD.sub.i-1,j+a.sub.2; PredMAD.sub.i,j represents the prediction MAD of the current MB of the current frame, RealMAD.sub.i-1,j represents the real MAD of the previous MB of the previous frame, and a.sub.1 and a.sub.2 are parameters of the linear prediction model.
4. The method of claim 3 wherein the parameters a.sub.1 and a.sub.2 are fit by generalized least squares according to historical data.
5. The method of claim 1, wherein the real MAD of the current MB of the current frame is calculated using an Equation:
6. The method of claim 1, wherein the adjustment procedure comprises: calculating an adjustment coefficient of the current MB of the current frame according to the prediction and real MADs of the current MB of the current frame and accumulated deltas of all MBs before the current MB of the current frame; calculating an increment of the current MB of the current frame according to the prediction and real MADs and the adjustment coefficient of the current MB of the current frame; and calculating the final MAD of the current MB of the current frame according to the prediction MAD and the increment of the current MB of the current frame.
7. The method of claim 6, wherein the adjustment coefficient is greater than 0 and is smaller than or equal to 1.
8. The method of claim 6, wherein the adjustment coefficient of the current MB of the current frame is calculated using an Equation:
9. The method of claim 6, wherein the increment of the current MB of the current frame is calculated using an Equation:
Delta.sub.i,j=.sub.i,j(RealMAD.sub.i,jPredMAD.sub.i,j); Delta.sub.i,j represents the increment of the current MB of the current frame, .sub.i,j represents the adjustment coefficient of the current MB of the current frame, RealMAD.sub.i,j represents the real MAD of the current MB of the current frame, and PredMAD.sub.i,j represents the prediction MAD of the current MB of the current frame.
10. The method of claim 6, wherein the final MAD of the current MB of the current frame is calculated using an Equation:
FinMAD.sub.i,j=PredMAD.sub.i,j+Delta.sub.i,j; FinMAD.sub.i,j represents the final MAD of the current MB of the current frame, PredMAD.sub.i,j represents the prediction MAD of the current MB of the current frame, and Delta.sub.i,j represents the increment of the current MB of the current frame.
11. An apparatus for rate control in an MB (macroblock) layer, comprising: a quantizer; and a quantization parameter calculator, coupled to the quantizer, calculating a prediction MAD (Mean Absolute Difference) of a current MB of a current frame according to a real MAD of a previous MB of a previous frame, wherein the current MB and the previous MB are located at the same two-dimensional coordinates of the current frame and the previous frame, respectively, and the real MAD of the previous MB of the previous frame reflects the variances between raw data and reconstructed data of the previous MB; calculating a real MAD of the current MB of the current frame, wherein the real MAD of the current MB of the current frame reflects the variances between raw data and reconstructed data of the current MB; performing an adjustment procedure to adjust the prediction MAD of the current MB of the current frame according to the real MAD of the current MB of the current frame to obtain a final MAD of the current MB of the current frame; calculating a quantization parameter of the current MB of the current frame according to the final MAD of the current MB of the current frame; and outputting the quantization parameter of the current MB of the current frame to a quantizer, thereby enabling the quantizer to generate a compressed video stream under a rate corresponding to the current MB of the current frame.
12. The apparatus of claim 11, wherein the prediction MAD of the current MB of the current frame is calculated using a linear prediction model.
13. The apparatus of claim 12, wherein the prediction MAD of the current MB of the current frame is calculated using an Equation:
PredMAD.sub.i,j=a.sub.1RealMAD.sub.i-1,j+a.sub.2; PredMAD.sub.i,j represents the prediction MAD of the current MB of the current frame, RealMAD.sub.i,j represents the real MAD of the previous MB of the previous frame, and a.sub.1 and a.sub.2 are parameters of the linear prediction model.
14. The apparatus of claim 13, wherein the parameters a.sub.1 and a.sub.2 are fit by generalized least squares according to historical data.
15. The apparatus of claim 11, wherein the real MAD of the current MB of the current frame is calculated using an Equation:
16. The apparatus of claim 11, wherein the adjustment procedure comprises: calculating an adjustment coefficient of the current MB of the current frame according to the prediction and real MADs of the current MB of the current frame and accumulated deltas of all MBs before the current MB of the current frame; calculating an increment of the current MB of the current frame according to the prediction and real MADs and the adjustment coefficient of the current MB of the current frame; and calculating the final MAD of the current MB of the current frame according to the prediction MAD and the increment of the current MB of the current frame.
17. The apparatus of claim 16, wherein the adjustment coefficient is greater than 0 and is smaller than or equal to 1.
18. The apparatus of claim 16, wherein the adjustment coefficient of the current MB of the current frame is calculated using an Equation:
19. The apparatus of claim 16, wherein the increment of the current MB of the current frame is calculated using an Equation:
Delta.sub.i,j=.sub.i,j(RealMAD.sub.i,jPredMAD.sub.i,j); Delta.sub.i,j represents the increment of the current MB of the current frame, .sub.i,j represents the adjustment coefficient of the current MB of the current frame, RealMAD.sub.i,j represents the real MAD of the current MB of the current frame, and PredMAD.sub.i,j represents the prediction MAD of the current MB of the current frame.
20. The apparatus of claim 16, wherein the final MAD of the current MB of the current frame is calculated using an Equation:
FinMAD.sub.i,j=PredMAD.sub.i,j+Delta.sub.i,j; FinMAD.sub.i,j represents the final MAD of the current MB of the current frame, PredMAD.sub.i,j represents the prediction MAD of the current MB of the current frame, and Delta.sub.i,j represents the increment of the current MB of the current frame.
Description
BRIEF DESCRIPTION OF THE DRAWINGS
(1) The present invention can be fully understood by reading the subsequent detailed description and examples with references made to the accompanying drawings, wherein:
(2)
(3)
(4)
(5)
(6)
(7)
(8)
(9)
(10)
(11)
DETAILED DESCRIPTION
(12) The following description is of the best-contemplated mode of carrying out the invention. This description is made for the purpose of illustrating the general principles of the invention and should not be taken in a limiting sense. The scope of the invention is best determined by reference to the appended claims.
(13) The present invention will be described with respect to particular embodiments and with reference to certain drawings, but the invention is not limited thereto and is only limited by the claims. It will be further understood that the terms comprises, comprising, includes and/or including, when used herein, specify the presence of stated features, integers, steps, operations, elements, and/or components, but do not preclude the presence or addition of one or more other features, integers, steps, operations, elements, components, and/or groups thereof.
(14) Use of ordinal terms such as first, second, third, etc., in the claims to modify a claim element does not by itself connote any priority, precedence, or order of one claim element over another or the temporal order in which acts of a method are performed, but are used merely as labels to distinguish one claim element having a certain name from another element having the same name (but for use of the ordinal term) to distinguish the claim elements.
(15)
(16)
(17)
(18) First, a real MAD of an MB (referred to as the current MB hereinafter) of the current frame is calculated, which reflects the variances between raw data and reconstructed data of the current MB (step S410). Specifically, in step S410, the real MAD of the current MB of the current frame may be calculated using Equation (1):
(19)
where RealMAD.sub.i,j represents the real MAD of the j.sup.th MB (the current MB) of the i.sup.th frame (the current frame), M represents the total number of rows of the current MB of the current frame, N represents the total number of columns of the current MB of the current frame, PredPixel.sub.m,n represents the prediction pixel of the n.sup.th column of the m.sup.th row of the j.sup.th MB of the i.sup.th frame obtained from the inverse transformer 283 or 383, and OriPixel.sub.m,n represents the raw pixel of the n.sup.th column of the m.sup.th row of the j.sup.th MB of the i.sup.th frame obtained from the video sequence V.sub.IN. RealMAD.sub.i,j may be stored in a volatile memory, so that it can be used to calculate a quantization parameter for the next frame by the quantization parameter calculator 250 or 350. It should be noted that the conventional calculation of the quantization parameter does not take the factor of the real MAD into account. Therefore, the rate control algorithm is affected by the inaccuracy and latency of the prediction MAD when complexity variances within a video sequence are high. In some embodiments, Equation (1) may be implemented in instructions, macrocode or microcode, and calculated when a processor loads and executes the instructions, macrocode or microcode. In alternative embodiments, Equation (1) may be implemented in dedicated hardware circuits.
(20) Next, a prediction MAD of the current MB of the current frame is calculated according to the real MAD of corresponding MB (referred to as the previous MB) of the previous frame, where the current MB and the previous MB are located at the same two-dimensional coordinates of the current frame and the previous frame, respectively, and the real MAD of the previous MB of the previous frame reflects the variances between raw data and reconstructed data of the previous MB (step S420).
PredMAD.sub.i,j=a.sub.1RealMAD.sub.i-1,j+a.sub.2;
where PredMAD.sub.i,j represents the prediction MAD of the j.sup.th MB (the current MB) of the i.sup.th frame (the current frame), RealMAD.sub.i-1,j represents the real MAD of the j.sup.th MB (the previous MB) of the i1.sup.th frame (the previous frame), and a.sub.1 and a.sub.2 are parameters of the linear prediction model. The parameters a.sub.1 and a.sub.2 are fit by generalized least squares according to historical data, represent a slop and an intercept of the linear prediction model and may be stored in volatile or nonvolatile memory. In some embodiments, Equation (2) may be implemented in instructions, macrocode or microcode, and calculated when a processor loads and executes the instructions, macrocode or microcode. In alternative embodiments, Equation (2) may be implemented in dedicated hardware circuits.
(21) Next, an adjustment coefficient of the current MB of the current frame is calculated according to the prediction and real MADs of the current MB of the current frame and the accumulated deltas of all MBs before the current MB of the current frame (step S430). In step S430, the adjustment coefficient of the current MB of the current frame may be calculated using Equation (3):
(22)
where .sub.i,j represents the adjustment coefficient of the j.sup.th MB (the current MB) of the i.sup.th frame (the current frame),
(23)
represents the accumulated deltas from the 0.sup.th MB to the j1.sup.th MB of the i.sup.th frame (the current frame), PredMAD.sub.i,j represents the prediction MAD of the j.sup.th MB (the current MB) of the i.sup.th frame (the current frame) calculated in step S420, RealMAD.sub.i,j represents the real MAD of the j.sup.th MB (the current MB) of the i.sup.th frame (the current frame) calculated in step S410, and 0<.sub.i,j1. In some embodiments, Equation (3) may be implemented in instructions, macrocode or microcode, and calculated when a processor loads and executes the instructions, macrocode or microcode.
(24) Next, an increment of the current MB of the current frame is calculated according to the prediction MAD, the real MAD and the adjustment coefficient of the current MB of the current frame (step S440). In step S440, the increment of the current MB of the current frame may be calculated using Equation (4):
Delta.sub.i,j=.sub.i,j(RealMAD.sub.i,jPredMAD.sub.i,j);
where Delta.sub.i,j represents the increment of the j.sup.th MB (the current MB) of the i.sup.th frame (the current frame), .sub.i,j represents the adjustment coefficient of the j.sup.th MB of the i.sup.th frame, RealMAD.sub.i,j represents the real MAD of the j.sup.th MB of the i.sup.th frame, and PredMAD.sub.i,j represents the prediction MAD of the j.sup.th MB of the i.sup.th frame. Delta.sub.i,j may be stored in a volatile memory, so that it can be used to calculate an adjustment coefficient for the next MB of the i.sup.th frame (current frame) by the quantization parameter calculator 250 or 350 (as shown in step S430). In some embodiments, Equation (4) may be implemented in instructions, macrocode or microcode, and calculated when a processor loads and executes the instructions, macrocode or microcode. In alternative embodiments, Equation (4) may be implemented in dedicated hardware circuits.
(25) Next, a final MAD of the current MB of the current frame is calculated according to the prediction MAD and the increment of the current MB of the current frame (step S450). In step S450, the final MAD of the current MB of the current frame may be calculated using Equation (5):
FinMAD.sub.i,j=PredMAD.sub.i,j+Delta.sub.i,j;
where FinMAD.sub.i,j represents the final MAD of the j.sup.th MB (the current MB) of the ith frame (the current frame), PredMAD.sub.i,j represents the prediction MAD of the j.sup.th MB of the ith frame, and Delta.sub.i,j represents the increment of the j.sup.th MB of the i.sup.th frame. In some embodiments, Equation (5) may be implemented in instructions, macrocode or microcode, and calculated when a processor loads and executes the instructions, macrocode or microcode. In alternative embodiments, Equation (5) may be implemented in dedicated hardware circuits.
(26) Next, a quantization parameter of the current MB of the current frame is calculated at least according to the final MAD (step S460). In step S460, the quantization parameter of the current MB of the current frame may be calculated using Equation (6):
(27)
where Q.sub.i,j represents a quantization parameter of the j.sup.th MB (the current MB) of the i.sup.th frame (the current frame), f(i,j) represents a stream budget of the j.sup.th MB of the i.sup.th frame, m.sub.h(i,j) represents a syntax element length of the j.sup.th MB of the i.sup.th frame, c.sub.1 and c.sub.2 represent parameters (default constants) of a quantization parameter prediction model and represents the final MAD FinalMAD.sub.i,j of the j.sup.th MB of the i.sup.th frame. In some embodiments, Equation (6) may be implemented in instructions, macrocode or microcode, and calculated when a processor loads and executes the instructions, macrocode or microcode.
(28) Finally, the quantization parameter Q.sub.i,j of the current MB of the current frame is output to the quantizer 270, thereby enabling the quantizer 270 to quantize the current transformed MB of the current frame output from the transformer 230 accordingly (step S470).
(29) In an aspect of embodiments of the invention, a method for rate control in an MB layer includes an adjustment procedure to adjust a prediction MAD according to a real MAD for each MB of the current frame to make a final MAD closer to the reality. Therefore, the quantization parameter calculator 250 can improve the inaccuracy and latency of the prediction MAD under the linear prediction model when complexity variances within a video sequence are high.
(30) The adjustment coefficient .sub.i,j of the j.sup.th MB (the current MB) of the i.sup.th frame (the current frame) recited in step S430 represents the adjustment strength of the prediction MAD of the adjustment mechanism. When .sub.i,j is greater, the rate control needs to take more real MAD into account. Since a stream budget of a frame is determined in the beginning of the encoding, to make the sum of stream budgets of all MBs of the frame achieve the stream budget of the frame, .sub.i,j is used to suppress the trend of the adjustment strength departing from 0.
(31) Although the embodiment has been described as having specific elements in
(32) While the invention has been described by way of example and in terms of the preferred embodiments, it should be understood that the invention is not limited to the disclosed embodiments. On the contrary, it is intended to cover various modifications and similar arrangements (as would be apparent to those skilled in the art). Therefore, the scope of the appended claims should be accorded the broadest interpretation so as to encompass all such modifications and similar arrangements.