A kind of bit rate control method
Technical field
The present invention relates to a kind of bit rate control method.
Background technology
In recent years a collection of digital audio/video encoding and decoding standard of Chu Xianing, representative have an international standard MPEG-1, H.263, MPEG-2, MPEG-4, AVC H.264/MPEG-4, the autonomous standard A VS that formulates of China, WM9 that Microsoft releases or the like, these standards all relate to different video code check range of application in actual applications.In order to make different standard application in different range of code rates, we just are necessary for the different rate control algorithm of various standard formulations, picture is at MPEG-1, H.263, MPEG-2, in these standards of MPEG-4, there are a lot of rate control algorithms to obtain practical application, yet at up-to-date video standard, as H.264/MPEG-4AVC and in the AVS standard, owing to adopted a lot of brand-new coding techniquess, a lot of rate control algorithms in the past can not satisfy practical application, so we need a kind of rate control algorithm at these up-to-date standard design.
Summary of the invention
A kind of bit rate control method provided by the invention, the control precision height, subjective picture quality is good, and computation complexity is very low simultaneously, not only is fit to the various software application and the real-time working of suitable hardware.
In order to achieve the above object, the invention provides a kind of bit rate control method, it comprises following steps:
Step 1, in frame level bit-rate control, (GOP) is unit with each image sets, calculates the bit B of each image sets
Gop:
Step 1.1, according to channel target bit rate R and frame per second F, calculate the bit B of each image sets
Gop:
B in following formula
FullnessBe remaining bit number in the buffer memory, S
GopBe the number of image frames among each image sets GOP;
Step 1.2, to remaining bit number B in the buffer memory
FullnessBe initialized as 0.
Step 2, can be I image (I picture) according to the image type of present frame, P image (forward prediction image) or B image (bidirectional predictive picture) calculate the bit B that current image frame is distributed
Cur_frame:
B
cur_frame=P
cur×(B
gop-B
cur_gop_used)/(P
ip×P
pb×F
i+P
pb×F
p+F
b)(2)
F in following formula
i, F
p, F
bBe respectively the frame number of I image, P image and B image, P
IpBe the Bit Allocation in Discrete weight parameter of I image with respect to the P image, P
PbBe the Bit Allocation in Discrete weight parameter of P image with respect to the B image, P
CurWeight parameter for present frame;
Initialization B
Cur_gop_used,, F
i, F
p, F
b, and set P
Ip, P
PbValue;
The target average quantization coefficient Q of step 3, calculating current image frame
Cur_ave:
If the already used bit number of former frame image is B
Prev_frame, the number of former frame image summation about non-zero DCT (discrete cosine transform) coefficient is N
Prev_frame, then the number of summation about non-zero DCT coefficients is in the present frame:
N
cur_frame=B
cur_frame×N
prev_frame/B
prev_frame (3)
If the number of a frame DCT coefficient is N
Total_frame, the average quantization coefficient of former frame image is Q
Prev_ave, then the target average quantization coefficient of current image frame is:
Q
cur_ave=Q
prev_ave+W×(N
prev_frame-N
cur_frame/(N
total_frame-N
prev_frame)(4)
W is a weight coefficient in following formula, and its value can define according to different situations.
Step 4, macro-block level Rate Control:
If the already used bit of coded macroblocks is B in step 4.1 present image
Cur_frame_used, the bit that then remains macro block and distributed is:
B
cur_frame_rest=B
cur_frame-B
cur_frame_used (5)
If the number of the summation about non-zero DCT coefficients in the coded macroblocks is N
Cur_frame_used, then the number of the summation about non-zero DCT coefficients of coded macroblocks is not:
N
cur_frame_rest=B
cur_frame_rest×N
cur_frame_used/B
cur_frame_used (6)
If the number of the DCT coefficient of step 4.2 residue macro block is N
Total_frame_rest, the average of the summation about non-zero DCT coefficients of current macro is:
N
cur_mb_sve=N
cur_frame_rest/N
cotal_frame_rest (7)
The number N of the summation about non-zero DCT coefficients of step 4.3, calculating current macro
Pred_mb:
Because in coded macroblocks, there is correlation between the macro block, therefore we can be according to the number of the summation about non-zero DCT coefficients of coded macroblocks, perhaps according to the sum of current macro DCT coefficient and the prediction number of current macro zero DCT coefficient, dope the number of the summation about non-zero DCT coefficients of current macro, that is:
N
i Prev_mbBe illustrated in the current macro number of the summation about non-zero DCT coefficients of coded macroblocks before;
NZ
i Prev_mbBe illustrated in the current macro number of the zero DCT coefficient of coded macroblocks before, nZ
Pred_mbPrediction number for the zero DCT coefficient of current macro;
N
pred_mb=N
mb-nZ
pred_mb (10)
In following formula, N
MbThe sum of the DCT coefficient of expression current macro, Pred represents Forecasting Methodology, and N represents the needed number of coded macroblocks in the past of this Forecasting Methodology.
If the quantization parameter of the previous macro block of step 4.4 current coding macro block is Q
Prev_mb, then the quantization parameter of current coding macro block is:
Max gets max-operator for both in following formula, and W is a weight coefficient, and its value is defined according to different situations by the user;
With Q
Cur_mbBe limited in [Q
Cur_ave-step, Q
Cur_ave+ step] in the scope, wherein step is the jump coefficient of quantization parameter, is defined as required by the user.
Step 4.5, macroblock coding.
After step 4.6, current macro coding are finished, upgrade the employed bit B of coded macroblocks
Cur_frameAnd the number N of the summation about non-zero DCT coefficients of coded macroblocks
Cur_frame_usedIf all macroblock codings of present image are finished, promptly finish the frame coding of present image, then arrive step 5, otherwise to step 4.1.
Step 5, current image frame coding are finished, upgrade B
Cur_gop_used, B
Prev_frame, N
Prev_frame,Q
Prev_ave, judge whether the frame coding of two field pictures all among the present image group GOP is finished, be, then arrive step 6, otherwise to step 2.
Step 6, with remaining bit number assignment in the current cache to the B parameter of present image group GOP
FullnessIf the coding of all images group is all finished, then finish, otherwise to step 1.
Further, in the step 2 of the present invention, the weight parameter P of present frame
CurBe defined as:
Further, defined the prediction of current macro summation about non-zero DCT coefficients in the formula in the step 4.3 of the present invention (8), Pred represents Forecasting Methodology, and N represents the needed number of coded macroblocks in the past of this Forecasting Methodology.Pred can have a lot of methods, as mean value method and median method.
Mean value method:
Wherein, N
Prev_mbThe predicted value of expression current macro non-zero discrete cosine transform coefficient, N
i Prev_mbThe number of representing the non-zero discrete cosine transform coefficient of encoded macro block i.
Median method:
N
pred_mb=MID(N
A prev_mb,N
B prev_mb,N
C prev_mb) (14)
MID represents to get coded macroblocks N in following formula
A Prev_mb, N
B Prev_mb, N
C Prev_mbMedian;
When the number of coded macroblocks more than or equal to 3 the time, then choose three macro blocks with current coding macro block correlation maximum therein, obtain the number of their non-zero discrete cosine transform coefficient: N respectively
A Prev_mb, N
B Prev_mb, N
C Prev_mb
When the number of coded macroblocks less than 3 the time, then by adding 0 value, make formula (14) guarantee all the time 3 parameters to be got median; If coded macroblocks does not exist, then make 3 parameter N in the formula (14)
A Prev_mb, N
B Prev_mb, N
C Prev_mbValue be 0.
Further, defined current macro zero DCT coefficient prediction in the formula in the step 4.3 of the present invention (9), Pred represents Forecasting Methodology, N represents the needed number of coded macroblocks in the past of this Forecasting Methodology, its Forecasting Methodology is the same with the summation about non-zero DCT coefficients prediction can a lot of methods, as mean value method and median method.
Mean value method:
Wherein, N
Zero_pred_mdThe predicted value of expression current macro zero discrete cosine transform coefficient, N
i Zero_pred_mbThe number of representing the zero discrete cosine transform coefficient of encoded macro block i.
Median method:
N
zero_pred_mb=MID(N
A zero_prev_mb,N
B zero_prev_mb,N
C zero_prev_mb (16)
MID represents the N of coded macroblocks in following formula
A Zero_prev_mb, N
B Zero_prev_mb, N
C Zero_prev_mbGet median;
When the number of coded macroblocks more than or equal to 3 the time, then choose three macro blocks with current coding macro block correlation maximum therein, obtain the number of their zero discrete cosine transform coefficient: N respectively
A Zero_prev_mb, N
B Zerp_prev_mb, N
C Zero_prev_mb
When the number of coded macroblocks less than 3 the time, then by adding 0 value, make formula (16) guarantee all the time 3 parameters to be got median; If coded macroblocks does not exist, then make 3 parameter N in the formula (16)
A Zero_prev_mb, N
B Zero_prev_mb, N
C Zero_prev_mbValue be 0.
A kind of bit rate control method provided by the invention comprises frame level bit-rate control and macro-block level Rate Control, the control precision height, and subjective picture quality is good, and computation complexity is very low simultaneously, not only is fit to the various software application and the real-time working of suitable hardware.
Description of drawings
Fig. 1 is the macro block spatial relation figure of a kind of bit rate control method provided by the invention.
Embodiment
Followingly specify a kind of preferred forms of the present invention according to Fig. 1:
The invention provides a kind of bit rate control method, it comprises following steps:
Step 1.1, according to channel target bit rate R and frame per second F, calculate the bit B of each image sets
Gop:
B in following formula
FullnessBe remaining bit number in the buffer memory, S
GopBe the number of image frames among each image sets GOP;
Step 1.2, to remaining bit number B in the buffer memory
FullnessBe initialized as 0.
Step 2, can be I image (I picture) according to the image type of present frame, P image (forward prediction image) or B image (bidirectional predictive picture) calculate the bit B that current image frame is distributed
Cur_frame:
B
cur_frame=P
cur×(B
gop-B
cur_gop-used)/(P
ip×P
pb×F
i+P
pb×F
p+F
b) (2)
F in following formula
i, F
p, F
bBe respectively the frame number of I image and P image and B image, P
IpBe the Bit Allocation in Discrete weight parameter of I image with respect to the P image, P
PbBe the Bit Allocation in Discrete weight parameter of P image with respect to the B image, P
CurWeight parameter for present frame.
Initialization B
Cur_gop_used,, F
i, F
p, F
b, and set P
Ip, P
PbValue.
The target average quantization coefficient Q of step 3, calculating current image frame
Cur_ave:
If the already used bit number of former frame image is B
Prev_frame, the number of former frame image summation about non-zero DCT (discrete cosine transform) coefficient is N
Prev_frame, then the number of summation about non-zero DCT coefficients is in the present frame:
N
cur_frame=B
cur_frame×N
prev_frame (3)
If the number of a frame DCT coefficient is N
Total_frame, the average quantization coefficient of former frame image is Q
Prev_ave, then the target average quantization coefficient of current image frame is:
Q
cur_ave=Q
prev_ave+W×(N
prev_frame-N
cur_frame)/(N
total_frame-N
prev_frame)(4)
W is a weight coefficient in following formula, and its value is defined according to different situations by the user.
Step 4, macro-block level Rate Control:
If in step 4.1 present image the bit that uses of coded macroblocks be B
Cur_frame_used, the bit that then remains macro block and distributed is:
B
cur_frame_rest=B
cur_frame-B
cur_frame_used (5)
If the number of the summation about non-zero DCT coefficients in the coded macroblocks is N
Cur_frame_used, then the number of the summation about non-zero DCT coefficients of coded macroblocks is not:
N
cur_frame_rest=B
cur_frame_rest×N
cur_frame_used/B
cur_frame_used (6)
If the number of the DCT coefficient of step 4.2 residue macro block is N
Total_frame_rest, the average of the summation about non-zero DCT coefficients of current macro is:
N
cur_mb_ave=N
cur_frame_rest/N
total_frame_rest (7)
The number N of the summation about non-zero DCT coefficients of step 4.3, calculating current macro
Pred_mb:
Because in coded macroblocks, there is correlation between the macro block, therefore we can be according to the number of the summation about non-zero DCT coefficients of coded macroblocks, perhaps according to the sum of current macro DCT coefficient and the prediction number of current macro zero DCT coefficient, dope the number of the summation about non-zero DCT coefficients of current macro, that is:
N
i Prev_mbBe illustrated in the current macro number of the summation about non-zero DCT coefficients of coded macroblocks before;
NZ
i Prev_mbBe illustrated in the current macro number of the zero DCT coefficient of coded macroblocks before, nZ
Pred_mbPrediction number for the zero DCT coefficient of current macro;
N
pred_mb=N
mb-nZ
pred_mb (10)
In following formula, N
MbThe sum of the DCT coefficient of expression current macro, Pred represents Forecasting Methodology, and N represents the needed number of coded macroblocks in the past of this Forecasting Methodology.
If the quantization parameter of the previous macro block of step 4.4 current coding macro block is Q
Prev_mb, then the quantization parameter of current coding macro block is:
Max gets max-operator for both in following formula, and W is a weight coefficient, and its value is defined according to different situations by the user;
With Q
Cur_mbBe limited in [Q
Cur_ave-step, Q
Cur_ave+ step] in the scope, wherein step is the jump coefficient of quantization parameter, can define as required.
Step 4.5, macroblock coding.
After step 4.6, current macro coding are finished, upgrade the employed bit B of coded macroblocks
Cur_frame_usedAnd the number N of the summation about non-zero DCT coefficients of coded macroblocks
Cur_frame_usedIf all macroblock codings of present image are finished, and then arrive step 5, otherwise to step 4.1.
Step 5, current image frame coding are finished, upgrade B
Cur_gop_used, B
Prev_frame, N
Prev_frame, Q
Prev_ave, judge whether the frame coding of two field pictures all among the present image group GOP is finished, be, then arrive step 6, otherwise to step 2.
Step 6, with remaining bit number assignment in the current cache to the B parameter of present image group GOP
FulnessIf the coding of all images group is all finished, then finish, otherwise to step 1.
Further, in the step 2 of the present invention, the weight parameter P of present frame
CurBe defined as:
Further, defined the prediction of current macro summation about non-zero DCT coefficients in the formula in the step 4.3 of the present invention (8), Pred represents Forecasting Methodology, and N represents the needed number of coded macroblocks in the past of this Forecasting Methodology.
If N equals 4, and the position relation as shown in Figure 1, and wherein E is a current coding macro block, and other are encoded macro block, and then Pred can have a lot of methods, simply enumerates following two kinds: mean value method and median method.
Mean value method:
N in following formula
i Prev_mbBe respectively N
A Prev_mb, N
B Prev_mb, N
C Prev_mbAnd N
D Prev_mb, represent encoded macro block A, macro block B, the number of the non-zero discrete cosine transform coefficient of macro block C and macro block D respectively.
Median method:
At first at the macro block A that has encoded, macro block B, among macro block C and the macro block D, 3 macro blocks selecting to obtain with current coding macro block correlation maximum are macro block A, macro block B, macro block C is to the number N of the non-zero discrete cosine transform coefficient of these three macro blocks
A Prev_mb, N
B Rev_mb, N
C Prev_mbGet median, that is:
N
pred_mb=MID(N
A prev_mb,N
B prev_mb,N
C prev_mb) (14)
Above-mentioned, only enumerated this simple adjacent macroblocks situation and two kinds of simple forecast methods, formula among the present invention (8) expression from around this method of prediction summation about non-zero DCT coefficients the coded macroblocks, therefore not only be confined to top exemplary method.
Further, defined current macro zero DCT coefficient prediction in the formula in the step 4.3 of the present invention (9), Pred represents Forecasting Methodology, and N represents the needed number of coded macroblocks in the past of this Forecasting Methodology.Its Forecasting Methodology is the same with the summation about non-zero DCT coefficients prediction:
Mean value method:
N
Zero_pred_mbThe predicted value of expression current macro zero discrete cosine transform coefficient, N
i Zero_pred_mbBe respectively N
A Zero_prde_mb, N
B Zero_pred_mb, N
C Zero_pred_mbAnd N
D Zero_pred_mb, represent encoded macro block A, macro block B, the number of the zero discrete cosine transform coefficient of macro block C and macro block D respectively.
Median method:
At first at the macro block A that has encoded, macro block B, among macro block C and the macro block D, 3 macro blocks selecting to obtain with current coding macro block correlation maximum are macro block A, macro block B, macro block C is to the number N of the zero discrete cosine transform coefficient of these three macro blocks
A Zero_prev_mb, N
B Zero_prev_mb, N
C Zero_prev_mbGet median, that is:
N
zero_pred_mb=MID(N
A zero_prev_mb,N
B zero_prev_mb,N
C zero_prev_mb) (16)
Above-mentioned, only enumerated this simple adjacent macroblocks situation and two kinds of simple forecast methods, formula among the present invention (9) expression from around this method of prediction zero DCT coefficient the coded macroblocks, also not only be confined to top exemplary method.
A kind of bit rate control method provided by the invention comprises frame level bit-rate control and macro-block level Rate Control, the control precision height, and subjective picture quality is good, and computation complexity is very low simultaneously, not only is fit to the various software application and the real-time working of suitable hardware.