CN109862359B - Code rate control method and device based on layered B frame and electronic equipment - Google Patents

Code rate control method and device based on layered B frame and electronic equipment Download PDF

Info

Publication number
CN109862359B
CN109862359B CN201811653605.5A CN201811653605A CN109862359B CN 109862359 B CN109862359 B CN 109862359B CN 201811653605 A CN201811653605 A CN 201811653605A CN 109862359 B CN109862359 B CN 109862359B
Authority
CN
China
Prior art keywords
frame
image
code rate
current
target code
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201811653605.5A
Other languages
Chinese (zh)
Other versions
CN109862359A (en
Inventor
耿晨晖
包佳晶
石小明
张刚
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Sumavision Technologies Co Ltd
Original Assignee
Sumavision Technologies Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Sumavision Technologies Co Ltd filed Critical Sumavision Technologies Co Ltd
Priority to CN201811653605.5A priority Critical patent/CN109862359B/en
Publication of CN109862359A publication Critical patent/CN109862359A/en
Application granted granted Critical
Publication of CN109862359B publication Critical patent/CN109862359B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Landscapes

  • Compression Or Coding Systems Of Tv Signals (AREA)

Abstract

The invention provides a code rate control method, a device and electronic equipment based on layered B frames, wherein the method comprises the steps of obtaining an original video signal; resampling the video signal, wherein the resampled video signal comprises a plurality of frames of images; pre-coding each frame image to obtain a corresponding SATD value; dividing a multi-frame image into a plurality of GOPs, and obtaining the target code rate of each GOP according to preset coding parameters; obtaining the target code rate of each frame of image according to the target code rate of the GOP and the SATD value of each frame of image; obtaining a quantization parameter of the current frame image by using a preset linear model according to the target code rate of the current frame image; and adjusting the quantization parameter according to a preset condition, and then updating the linear model to obtain the quantization parameter of the next frame of image. The invention can adaptively distribute the code rate of each frame according to the video content of the image, stabilize the coding code rate and improve the coding quality on the premise of limited bandwidth and no increase of complexity.

Description

Code rate control method and device based on layered B frame and electronic equipment
Technical Field
The invention relates to the technical field of video image processing, in particular to a code rate control method and device based on a layered B frame and electronic equipment.
Background
With the rapid development of multimedia, network transmission and other technologies, the demand for video definition is also increasing. In practical scenes such as television broadcasting, live conference, telemedicine and the like, low-delay ultrahigh-definition has huge application requirements. In order to transmit effective data under the condition of limited channel bandwidth and transmission delay to ensure the playing quality of a video, code rate control is generally required to be performed on a coding process, namely, the code rate control is performed by selecting a series of coding parameters and adjusting output bits of a video coder in real time, so that the bit rate after coding meets the required code rate limit, and coding distortion is as small as possible.
Disclosure of Invention
In view of the above, an object of the present invention is to provide a method, an apparatus and an electronic device for controlling a code rate based on a layered B frame, so as to stabilize a coding rate and improve a coding quality under the premise of limited bandwidth and without increasing complexity.
In a first aspect, an embodiment of the present invention provides a method for controlling a code rate based on a layered B frame, where the method includes: acquiring an original video signal; resampling the original video signal to obtain a resampled video signal; the resampled video signal comprises a plurality of frames of images; pre-coding each frame image of the multi-frame image to obtain a transformation absolute error and an SATD value of each frame image; dividing a multi-frame image into a plurality of group of pictures (GOPs), and obtaining the target code rate of each GOP according to preset coding parameters; obtaining the target code rate of each frame image in each GOP according to the target code rate of each GOP and the SATD value of each frame image in the GOP corresponding to the target code rate; obtaining a quantization parameter of the image of the current frame by using a preset linear model according to the target code rate of the image of the current frame; and adjusting the quantization parameter according to a preset condition, updating the linear model according to the adjusted quantization parameter, and obtaining the quantization parameter of the next frame of image by using the updated linear model.
With reference to the first aspect, an embodiment of the present invention provides a first possible implementation manner of the first aspect, where the multi-frame image includes an I frame, a P frame, and a B frame; pre-coding each frame image of the multi-frame images to obtain a transformation absolute error and an SATD value of each frame image, and the method comprises the following steps: dividing each frame image into a plurality of coding units (CTUs); calculating the SATD value of each CTU of the I frame in a plurality of preset intra-frame angle prediction modes respectively, and determining the minimum SATD value as the SATD value of the current CTU; calculating the SATD value of each CTU of the P frame in an intra mode, an inter _2N × 2N mode and a skip mode respectively, and determining the minimum SATD value as the SATD value of the current CTU; calculating the SATD value of each CTU of the B frame in an intra mode, an inter _2N × 2N mode and a skip mode respectively, and determining the minimum SATD value as the SATD value of the current CTU; and superposing the SATD values of all the CTUs of each frame image to obtain the SATD value of each frame image.
With reference to the first aspect, an embodiment of the present invention provides a second possible implementation manner of the first aspect, where the preset coding parameters include a video frame rate and a coding target bitrate.
With reference to the first possible implementation manner of the first aspect, an embodiment of the present invention provides a third possible implementation manner of the first aspect, where the obtaining a target code rate of each frame image in each GOP according to the target code rate of each GOP and a SATD value of each frame image in the GOP corresponding to the target code rate includes: obtaining the SATD value of the current GOP according to the SATD value of the P frame included by the current GOP, the SATD value of the B frame included by the current GOP and the weight of the preset P frame and the layered B frame; obtaining the target code rate of the P frame according to the target code rate of the current GOP, the SATD value and the weight of the current GOP and the transformation absolute error sum of the P frame included by the current GOP; obtaining the target code rate of the B frame according to the target code rate of the P frame, the SATD value corresponding to the target code rate of the P frame and the SATD value of the B frame included by the current GOP; and obtaining the target code rate of the I frame according to the interval length and the coding parameters between the current I frame and the last I frame.
With reference to the first aspect, an embodiment of the present invention provides a fourth possible implementation manner of the first aspect, where the preset linear model is:
QP=α·SATD/R;
wherein QP represents a quantization parameter of an image of the current frame; α represents a model parameter of the linear model; SATD denotes the SATD value of the picture of the current frame; and R represents the target code rate of the image of the current frame.
With reference to the first aspect, an embodiment of the present invention provides a fifth possible implementation manner of the first aspect, where adjusting the quantization parameter according to a preset condition includes: obtaining a check value VBV of the current frame according to a preset video cache checker and the target code rate of the current frame; and comparing the VBV with a preset safety zone, and adjusting the quantization parameter according to the comparison result until the VBV corresponding to the adjusted quantization parameter is positioned in the safety zone.
With reference to the fourth possible implementation manner of the first aspect, an embodiment of the present invention provides a sixth possible implementation manner of the first aspect, where the updating the linear model according to the adjusted quantization parameter includes: the model parameters are updated using the following formula:
α′=SATD/(QP·R)
αcurrent=0.2·α′+0.8·αlast
wherein alpha iscurrentRepresenting the updated model parameters; alpha is alphalastRepresenting model parameters before updating.
With reference to the first aspect, an embodiment of the present invention provides a seventh possible implementation manner of the first aspect, where the method further includes: calculating the short-time average SATD value of the forward sequence of each frame; comparing the SATD value of the current frame with the short-time average SATD value of the forward sequence of the current frame, and judging whether the current frame is a scene switching frame according to the comparison result; if so, initializing the linear model, and determining the quantization parameter of the current frame according to the initialized linear model.
In a second aspect, an embodiment of the present invention further provides a rate control device based on a layered B frame, where the rate control device includes: the resampling module is used for acquiring an original video signal; resampling the original video signal to obtain a resampled video signal; the resampled video signal comprises a plurality of frames of images; the pre-coding module is used for pre-coding each frame of image of the multi-frame image to obtain the transformation absolute error and the SATD value of each frame of image; the first calculation module is used for dividing a multi-frame image into a plurality of group of pictures (GOPs), and obtaining the target code rate of each GOP according to preset encoding parameters; the second calculation module is used for obtaining the target code rate of each frame image in each GOP according to the target code rate of each GOP and the SATD value of each frame image in the GOP corresponding to the target code rate; the quantization parameter calculation module is used for obtaining the quantization parameter of the image of the current frame by utilizing a preset linear model according to the target code rate of the image of the current frame; and the adjustment updating module is used for adjusting the quantization parameter according to a preset condition, updating the linear model according to the adjusted quantization parameter and obtaining the quantization parameter of the next frame of image by using the updated linear model.
In a third aspect, an embodiment of the present invention further provides an electronic device, including a memory and a processor, where the memory stores a computer program that is executable on the processor, and when the processor executes the computer program, the steps of the method in the first aspect are implemented.
The embodiment of the invention has the following beneficial effects:
the embodiment of the invention provides a code rate control method, a device and electronic equipment based on a layered B frame, wherein the method comprises the following steps: acquiring an original video signal; resampling the original video signal to obtain a resampled video signal; the resampled video signal comprises a plurality of frames of images; pre-coding each frame image of the multi-frame image to obtain a transformation absolute error and an SATD value of each frame image; dividing a multi-frame image into a plurality of group of pictures (GOPs), and obtaining the target code rate of each GOP according to preset coding parameters; obtaining the target code rate of each frame image in each GOP according to the target code rate of each GOP and the SATD value of each frame image in the GOP corresponding to the target code rate; obtaining a quantization parameter of the image of the current frame by using a preset linear model according to the target code rate of the image of the current frame; and adjusting the quantization parameter according to a preset condition, updating the linear model according to the adjusted quantization parameter, and obtaining the quantization parameter of the next frame of image by using the updated linear model. The embodiment of the invention can adaptively distribute the code rate of each frame according to the video content of the image, stabilize the coding code rate and improve the coding quality on the premise of limited bandwidth and no increase of complexity.
Additional features and advantages of the invention will be set forth in the description which follows, and in part will be obvious from the description, or may be learned by the practice of the invention as set forth above.
In order to make the aforementioned and other objects, features and advantages of the present invention comprehensible, preferred embodiments accompanied with figures are described in detail below.
Drawings
In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the embodiments or the prior art will be briefly described below, and it is obvious that the drawings in the following description are some embodiments of the present invention, and other drawings can be obtained by those skilled in the art without creative efforts.
Fig. 1 is a flowchart of a code rate control method based on a layered B frame according to an embodiment of the present invention;
fig. 2 is a flowchart for processing a GOP to obtain a QP value of each frame of image in the GOP according to an embodiment of the present invention;
fig. 3 is a schematic structural diagram of a GOP according to an embodiment of the present invention;
fig. 4 is a schematic structural diagram of a code rate control apparatus based on a layered B frame according to an embodiment of the present invention;
fig. 5 is a schematic structural diagram of an electronic device according to an embodiment of the present invention.
Detailed Description
To make the objects, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings, and it is apparent that the described embodiments are some, but not all embodiments of the present invention. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
Currently, the key point Of the Rate control algorithm is to determine a Quantization Parameter (QP) related to a Rate, and generally, the Rate control technique includes two modes, namely, a Variable Bit Rate (VBR) mode and a fixed Bit Rate (CBR) mode, where the CBR mode can fully utilize a bandwidth under a condition Of limited channel bandwidth, and thus is widely used in the field Of television broadcasting, a video image is composed Of a plurality Of temporally continuous images, and when encoding, the video image is generally divided into a plurality Of small Group Of Pictures (GOP), and the video image is divided into a plurality Of temporal layers according to a temporal level based on a GOP structure Of a layered B frame to be encoded, including a base layer and a plurality Of enhancement layers. When encoding, the image of the base layer does not depend on other image layers, the image of the enhancement layer must depend on other image layers, and the image of the low temporal level is referred to by the image of the high temporal level image layer as a reference frame, however, the existing code rate control method based on the layered B frame allocates the target bit number of each temporal layer of the current GOP according to the information after the previous GOP encoding, or controls the target code rate of different layers of the B frame by using the preset weight coefficient, and does not consider the influence caused by the change of the video content, or uses the complexity of the predicted MAD metric image frame, when the image content is complicated, the target code rate control of each frame is inaccurate, the encoding quality is influenced, and the method cannot be well applied to the low-delay and ultra-high-definition video processing, based on this, the code rate control method based on the layered B frame provided by the embodiments of the present invention, The device and the electronic equipment can be applied to scenes for carrying out low-delay ultrahigh-definition processing on video images.
To facilitate understanding of the present embodiment, first, a detailed description is given to a code rate control method based on a layered B frame disclosed in the present embodiment.
Referring to fig. 1, a flow chart of a code rate control method based on a layered B frame is shown, wherein the method comprises the following steps:
step S102, acquiring an original video signal;
step S104, resampling the original video signal to obtain a resampled video signal; the resampled video signal comprises a plurality of frames of images;
after the original video signal is obtained, the original video signal is resampled, and the video signal with relatively low resolution is obtained after the video signal with high resolution is resampled.
Specifically, a bilinear inner resampling may be performed on a high-definition video signal with a resolution of W × H to obtain a relatively low-resolution video signal (W/2 × H/2), where W, H represents the number of pixels in the width direction and the height direction of the video signal, respectively.
Then, the video signal with relatively low resolution is subjected to coding analysis processing, and when the video signal is processed, the video signal is divided into images of one frame and one frame, and the coding analysis processing is performed on each frame of image.
Step S106, carrying out pre-coding processing on each frame of image of the multi-frame image to obtain the transformation absolute error and the SATD value of each frame of image;
the video signal comprises a plurality of frames of images, the types of the image frames comprise I frames, P frames and B frames, and each frame of image is respectively pre-coded to obtain the Sum of Absolute errors (SATD) of each frame of image.
The core of rate control for low latency is to build a model between the complexity of the video frame and the coded bits. Common ways to measure the complexity of a video frame are: sum of Absolute differences (Sum of Absolute Difference, SAD for short), Sum of transformed Absolute differences (Sum of Absolute Transform, SATD for short), Sum of squared errors (Sum of Square Difference, SSD for short), Mean Absolute differences (MAD for short), and the like. The SATD is the sum of absolute values of prediction residuals of the residuals subjected to Hadamard Transform (Hadamard Transform), and the Hadamard Transform can be regarded as simple time-frequency Transform, and the value of the time-frequency Transform can reflect the size of a generated code stream to a certain extent, so that the SATD value of each frame image needs to be calculated when pre-coding is carried out, and the SATD value obtained by calculation is used as the measurement of the complexity of an original video frame.
When calculating the SATD value of each frame image, it is necessary to divide each frame image into a plurality of Coding units (CTUs), in order to better perform Coding processing and improve Coding quality, the CTUs are preferably 16 × 16 in size, then each CTU is processed to obtain the SATD value of each CTU, and then the SATD values of all CTUs of each frame image are superimposed to obtain the SATD value of each frame image.
The methods employed to calculate the SATD value of the CTU for different kinds of image frames are different due to the different kinds of image frames.
For each CTU of an I frame, calculating the SATD value of each CTU in a plurality of preset intra-frame angle prediction modes respectively, selecting the prediction mode corresponding to the minimum SATD value as the optimal angle direction of the current CTU, and taking the minimum SATD value as the SATD value of the current CTU, so that the SATD value of each CTU in the I frame can be obtained, and the SATD value of the current I frame can be obtained; for the AVS2 standard, pattern 0, pattern 6, pattern 12, pattern 18, pattern 24, and pattern 30 in the standard angle pattern are employed.
And for the B frame and the P frame, processing each CTU by adopting the same method, respectively calculating the SATD value of each CTU in an intra mode, an inter _2N × 2N mode and a skip mode, selecting the mode corresponding to the minimum SATD value as the optimal prediction mode of the current CTU, and taking the minimum SATD value as the SATD value of the current CTU, thus obtaining the SATD value of the B frame or the P frame.
Step S108, dividing a multi-frame image into a plurality of group of pictures (GOPs), and obtaining the target code rate of each GOP according to preset coding parameters;
dividing a multi-frame image into a plurality of group of pictures (GOPs) according to the type of the frame, wherein the dividing rule can be realized by using the prior art, and is not repeated herein.
Step S110, obtaining the target code rate of each frame image in each GOP according to the target code rate of each GOP and the SATD value of each frame image in the GOP corresponding to the target code rate;
and for each GOP, obtaining the target code rate of each frame of image in the current GOP according to the target code rate of the current GOP and the SATD value of each frame of image in the current GOP, and carrying out the treatment on each GOP to obtain the target code rate of each frame of image in the video signal.
Step S112, obtaining a quantization parameter of the image of the current frame by using a preset linear model according to the target code rate of the image of the current frame;
and pre-establishing a first-order linear model of the target code rate and the quantization parameter QP of the image frames, and inputting the target code rate of each frame of image into the linear model to obtain the quantization parameter of each frame of image.
And step S114, adjusting the quantization parameter according to a preset condition, updating the linear model according to the adjusted quantization parameter, and obtaining the quantization parameter of the next frame of image by using the updated linear model.
After the quantization parameter of each frame of image is obtained through calculation, the quantization parameter needs to be judged, whether the quantization parameter meets the expected assumption or not is judged, the quantization parameter is judged by using the preset condition, if the quantization parameter does not meet the preset condition, the quantization parameter is considered not to meet the expected assumption, the quantization parameter needs to be adjusted, the adjusted quantization parameter is continuously judged until the adjusted quantization parameter meets the preset condition, then the linear model is updated according to the adjusted quantization parameter, and the quantization parameter of the next frame of image is obtained through calculation by using the updated novel model.
The embodiment of the invention provides a code rate control method based on a layered B frame, which comprises the steps of obtaining an original video signal; resampling the original video signal to obtain a resampled video signal; the resampled video signal comprises a plurality of frames of images; pre-coding each frame image of the multi-frame image to obtain a transformation absolute error and an SATD value of each frame image; dividing a multi-frame image into a plurality of group of pictures (GOPs), and obtaining the target code rate of each GOP according to preset coding parameters; obtaining the target code rate of each frame image in each GOP according to the target code rate of each GOP and the SATD value of each frame image in the GOP corresponding to the target code rate; obtaining a quantization parameter of the image of the current frame by using a preset linear model according to the target code rate of the image of the current frame; and adjusting the quantization parameter according to a preset condition, updating the linear model according to the adjusted quantization parameter, and obtaining the quantization parameter of the next frame of image by using the updated linear model. The embodiment of the invention can adaptively distribute the code rate of each frame according to the video content of the image, stabilize the coding code rate and improve the coding quality on the premise of limited bandwidth and no increase of complexity.
Corresponding to the above embodiment of the present invention, the embodiment of the present invention uses one GOP as an example to describe the above processing in detail, as shown in fig. 2, the specific processing steps are as follows:
step S202, obtaining a target code rate of the current GOP according to preset coding parameters;
the preset coding parameters comprise a video frame rate and a coding target code rate, and the target code rate of the current GOP is calculated by using the following formula according to the preset coding parameters and the length of the current GOP:
RGOP=lengthGOP/FPS×BitRate;
wherein R isGOPRepresenting a target code rate of a current GOP; lengthGOPIndicates the length of the current GOP; FPS represents the video frame rate; BitRate denotes an encoding target code rate.
Step S204, obtaining the target code rate of each frame image in the current GOP according to the target code rate of the current GOP and the SATD value of each frame image in the current GOP;
referring to FIG. 3, a diagram of a GOP structure is shown, wherein the image layers of the GOP include a base layer and three enhancement layers B0、B1And B2The base layer includes 1 frame and P frame, the enhancement layer includes B frame, when coding, the image of the base layer does not need to depend on other image layers, and the enhancement layer B0The image of (2) needs to realize coding by taking the coding result of the base layer as a reference; enhancement layer B1The image of (2) requires a base layer and an enhancement layer B0The encoding result of (2) as a reference to achieve encoding; enhancement layer B2The image of (2) requires a base layer and an enhancement layer B0And enhancement layer B1The encoding result of (2) is used as a reference to realize encoding.
Before calculating the target code rate of each frame image in the current GOP, the SATD value of the current GOP needs to be calculated, the SATD value of the current GOP is only related to the B frame and the P frame, and the SATD value of the current GOP is calculated by using the following formula according to the SATD value of the P frame, the SATD value of the B frame and the preset weights of the P frame and the layered B frame:
Figure BDA0001929616160000111
wherein, SATDGOPA SATD value representing a current GOP; i represents the type of frame, including B frame and P frame; w is aiRepresenting the weight value corresponding to the i frame; SATDiIndicating the SATD value of the i-frame.
The weighting values of the B frame and the P frame are preset as follows:
Figure BDA0001929616160000112
because the types of the image frames in the GOP are different, different methods are adopted to process the different types of image frames to obtain the target code rate of each frame of image.
For the P frame, because the P frame is a base layer, the target code rate of the P frame can be obtained by using the following formula according to the target code rate of the current GOP, the SATD value of the current GOP, the weight value of the P frame and the SATD value of the P frame:
RP=RGOP·wP·SATDP/SATDGOP
wherein R isPRepresenting a target code rate of the P frame; rGOPRepresenting a target code rate for the GOP; w is aPRepresents a weight value of the P frame; SATDPRepresenting P framesThe SATD value of (a); SATDGOPIndicating the SATD value of the GOP.
For the B frame, because the B frame is an enhancement layer, the target code rate of the B frame per se needs to be calculated by means of the target code rate of the P frame of the base layer, and the target code rate of the B frame of each enhancement layer is calculated by using the following formula according to the target code rate of the P frame, the SATD value of the P frame and the SATD value of the B frame:
Ri=RP·SATDi/SATDP
wherein R isiRepresenting the target code rate of the i frame, the i frame representing the B frame of the enhancement layer; rPRepresenting a target code rate of the P frame; SATDiA SATD value representing the i-frame; SATDPIndicating the SATD value of the P frame.
By using the above formula, the enhancement layer B can be calculated0、B1And B2And the target code rate of the B frame of each layer.
For the I frame, because the I frame is a key frame, for the processing of the key frame, the target code rate of the current I frame needs to be calculated by using the following formula according to the interval length between the current I frame and the previous I frame and the preset coding parameters:
RI=lengthgap_I/lengthGOP×BitRate;
wherein R isIRepresenting the target code rate of the current I frame; lengthgap-IRepresenting the interval length between the current I frame and the last I frame; lengthGOPIndicates the length of the current GOP; BitRate denotes an encoding target code rate.
And step S206, obtaining the quantization parameter of each frame of image by using a preset linear model according to the target code rate of each frame of image.
The preset linear model is:
QP=α·SATD/R;
wherein QP represents a quantization parameter of an image of the current frame; α represents a model parameter of the linear model; SATD denotes the SATD value of the picture of the current frame; and R represents the target code rate of the image of the current frame.
When calculating the B frame and the P frame, the SATD value of the B frame, the target code rate of the B frame, the SATD value of the P frame and the target code rate of the P frame are respectively brought into a linear model to calculate the QP value of the B frame and the P frame.
When each frame image is coded, scene detection is needed, namely whether the video image content has strong correlation in time is judged, the judging method is to calculate the short-time average SATD value of the forward sequence of each frame image, compare the SATD value of the current frame with the short-time average SATD value of the forward sequence of the current frame, judge whether the current frame is a scene switching frame according to the comparison result, if so, initialize the linear model, and determine the quantization parameter of the current frame according to the initialized linear model.
The short-time average SATD value of the forward sequence of the current frame is calculated by utilizing an exponential reinforced averaging idea, and the calculation is specifically carried out by utilizing the following formula:
SATDaverage(n)=β·SATDaverage(n-1)+(1-β)·SATDcurrent
wherein, SATDaverage(n) a short-time average SATD value representing the forward sequence of the current frame; beta represents an attenuation factor, and the value of beta is 0.5; SATDaverage(n-1) a short-time average SATD value representing a forward sequence of a frame preceding the current frame; SATDcurrentRepresenting the SATD value of the current frame.
SATD of the current framecurrentAnd the calculated SATDaverage(n) comparing if SATDcurrent>SATDaverage1.5 or SATDcurrent<SATDaverageAnd 1.5, judging that the image content of the current frame is irrelevant to the forward frame, judging the current frame as a scene switching frame, initializing a linear model at the moment, and determining a quantization parameter QP value of the current frame by using the initialized linear model.
By processing each GOP through the steps, the QP value of each frame of image can be obtained.
The embodiment of the invention aims to improve the existing code rate control algorithm based on a layered B frame structure, introduce a code rate control strategy based on a layered B frame of a time level layer, control the B frame of the same time level layer as a whole, realize the corresponding code rate control operation of the time level layer, introduce a weight coefficient to process the B frames of different time level layers, distribute corresponding target bit numbers, introduce a self-adaptive bit number distribution scheme aiming at a low-delay ultra-high definition application scene, and realize effective code rate control of a layered B frame coding structure. The embodiment of the invention can adaptively distribute the code rate of each frame according to the video content of the image, stabilize the coding code rate and improve the coding quality on the premise of limited bandwidth and no increase of complexity.
Corresponding to the embodiment of the present invention, the embodiment of the present invention further provides a method for updating a linear model, and the specific processing procedures are as follows:
because the model parameter of the linear model is a prior value, iterative updating is required after each real encoding, and when the number of threads is large, the updating hysteresis brings serious code rate fluctuation, so that the code rate fluctuation needs to be restricted.
Obtaining a check value VBV of the current frame according to a preset video cache checker and the target code rate of the current frame;
the VBV is compared with a predetermined safety zone (VBV)low,VBVhigh) And comparing, judging whether the quantization parameter needs to be adjusted or not according to a comparison result, if the VBV of the current frame is smaller than the minimum value of the safety zone, turning down the QP value, if the VBV of the current frame is larger than the maximum value of the safety zone, turning up the QP value, and if the VBV of the current frame is positioned in the safety zone, not adjusting.
The adjustment of the QP value is a continuous iterative process, each adjustment increases or decreases a preset value on the basis of the original QP value, the preferable scheme is that 1 is increased or decreased each time, a new target code rate is obtained according to the adjusted QP value, the new target code rate is used for predicting the VBV value, if the predicted VBV value is located in a preset safety zone, the iterative process is stopped, otherwise, the process is repeated until the VBV corresponding to the adjusted QP value is located in the safety zone.
Calculating a new target code rate by using the following formula:
R=α·SATD/QP;
wherein, R represents a new target code rate; α represents a model parameter; SATD denotes the SATD value of the current frame; QP represents the adjusted QP value.
After each frame of image is encoded, the VBV value needs to be updated by using the following formula:
VBVcurrent=VBVlast+BitRate/FPS-bitcurrent
wherein, VBVcurrentRepresents the updated VBV value; VBVlastRepresents the VBV value before update; bitrate represents a coding target code rate; FPS represents the video frame rate; bitcurrentRepresenting the number of bits of the current frame.
The model parameters also need to be updated using the following formula:
α′=SATD/(QP·R)
αcurrent=0.2·α′+0.8·αlast
wherein alpha iscurrentRepresenting the updated model parameters; alpha is alphalastRepresenting model parameters before updating; SATD denotes the SATD value of the current frame; QP represents the QP value for the current frame; r represents a target code rate of the current frame.
The embodiment of the invention can well meet the requirement of low-delay ultrahigh-definition coding, and can improve the coding quality on the premise of fixing the channel width and not increasing the complexity.
Corresponding to the foregoing embodiment of the present invention, an embodiment of the present invention further provides a rate control apparatus based on a layered B frame, as shown in fig. 4, where the apparatus includes:
a resampling module 40, configured to obtain an original video signal; resampling the original video signal to obtain a resampled video signal; the resampled video signal comprises a plurality of frames of images;
a pre-coding module 41, configured to perform pre-coding processing on each frame of image of the multiple frames of images to obtain a transformation absolute error and an SATD value of each frame of image;
the first calculation module 42 is configured to divide a multi-frame image into a plurality of group of pictures (GOPs), and obtain a target code rate of each GOP according to preset coding parameters;
a second calculating module 43, configured to obtain a target code rate of each frame image in each GOP according to the target code rate of each GOP and the SATD value of each frame image in the GOP corresponding to the target code rate;
the quantization parameter calculation module 44 is configured to obtain a quantization parameter of the image of the current frame by using a preset linear model according to the target code rate of the image of the current frame;
and an adjusting and updating module 45, configured to adjust the quantization parameter according to a preset condition, update the linear model according to the adjusted quantization parameter, and obtain the quantization parameter of the next frame of image by using the updated linear model.
The code rate control device based on the layered B frame provided by the embodiment of the invention has the same technical characteristics as the code rate control method based on the layered B frame provided by the embodiment, so that the same technical problems can be solved, and the same technical effect can be achieved.
As shown in fig. 5, the electronic device 5 includes a memory 51 and a processor 52, where the memory 51 stores a computer program that can be executed on the processor 52, and the processor executes the computer program to implement the steps of the method provided in the embodiment of the present invention.
Referring to fig. 5, the electronic device further includes: a bus 53 and a communication interface 54, the processor 52, the communication interface 54 and the memory 51 being connected by the bus 53; the processor 52 is for executing executable modules, e.g. computer programs, stored in the memory 51.
The Memory 51 may include a high-speed Random Access Memory (RAM) and may also include a non-volatile Memory (non-volatile Memory), such as at least one disk Memory. The communication connection between the network element of the system and at least one other network element is realized through at least one communication interface 54 (which may be wired or wireless), and the internet, a wide area network, a local network, a metropolitan area network, and the like can be used.
The bus 53 may be an ISA bus, a PCI bus, an EISA bus, or the like. The bus may be divided into an address bus, a data bus, a control bus, etc. For ease of illustration, only one double-headed arrow is shown in FIG. 5, but this does not indicate only one bus or one type of bus.
The memory 51 is used for storing a program, and the processor 52 executes the program after receiving an execution instruction, and the method performed by any of the foregoing embodiments of the present invention may be applied to the processor 52, or implemented by the processor 52.
Processor 52 may be an integrated circuit chip having signal processing capabilities. In implementation, the steps of the above method may be performed by integrated logic circuits of hardware or instructions in the form of software in the processor 52. The Processor 52 may be a general-purpose Processor, and includes a Central Processing Unit (CPU), a Network Processor (NP), and the like; the device can also be a Digital Signal Processor (DSP), an Application Specific Integrated Circuit (ASIC), a Field-Programmable Gate Array (FPGA), or other Programmable logic devices, discrete Gate or transistor logic devices, discrete hardware components. The various methods, steps and logic blocks disclosed in the embodiments of the present invention may be implemented or performed. A general purpose processor may be a microprocessor or the processor may be any conventional processor or the like. The steps of the method disclosed in connection with the embodiments of the present invention may be directly implemented by a hardware decoding processor, or implemented by a combination of hardware and software modules in the decoding processor. The software module may be located in ram, flash memory, rom, prom, or eprom, registers, etc. storage media as is well known in the art. The storage medium is located in the memory 51, and the processor 52 reads the information in the memory 51 and completes the steps of the method in combination with the hardware thereof.
Embodiments of the present invention also provide a computer readable medium having non-volatile program code executable by a processor, where the program code causes the processor to execute the method according to the embodiments of the present invention.
The computer-readable medium having the processor-executable nonvolatile program code according to the embodiments of the present invention has the same technical features as those of the embodiments of the present invention according to the above embodiments, so that the same technical problems can be solved, and the same technical effects can be achieved.
The computer program product provided in the embodiment of the present invention includes a computer-readable storage medium storing a nonvolatile program code executable by a processor, where instructions included in the program code may be used to execute the method described in the foregoing method embodiment, and specific implementation may refer to the method embodiment, and is not described herein again.
The functions, if implemented in the form of software functional units and sold or used as a stand-alone product, may be stored in a computer readable storage medium. Based on such understanding, the technical solution of the present invention may be embodied in the form of a software product, which is stored in a storage medium and includes instructions for causing a computer device (which may be a personal computer, a server, or a network device) to execute all or part of the steps of the method according to the embodiments of the present invention. And the aforementioned storage medium includes: a U-disk, a removable hard disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a magnetic disk or an optical disk, and other various media capable of storing program codes.
Finally, it should be noted that: the above-mentioned embodiments are only specific embodiments of the present invention, which are used for illustrating the technical solutions of the present invention and not for limiting the same, and the protection scope of the present invention is not limited thereto, although the present invention is described in detail with reference to the foregoing embodiments, those skilled in the art should understand that: any person skilled in the art can modify or easily conceive the technical solutions described in the foregoing embodiments or equivalent substitutes for some technical features within the technical scope of the present disclosure; such modifications, changes or substitutions do not depart from the spirit and scope of the embodiments of the present invention, and they should be construed as being included therein. Therefore, the protection scope of the present invention shall be subject to the protection scope of the appended claims.

Claims (8)

1. A code rate control method based on layered B frames is characterized by comprising the following steps:
acquiring an original video signal;
resampling the original video signal to obtain a resampled video signal; the resampled video signal comprises a plurality of frames of images;
pre-coding each frame image of the multi-frame image to obtain a transformation absolute error and an SATD value of each frame image;
dividing the multi-frame image into a plurality of group of pictures (GOPs), and obtaining the target code rate of each GOP according to preset coding parameters;
obtaining the target code rate of each frame image in each GOP according to the target code rate of each GOP and the SATD value of each frame image in the GOP corresponding to the target code rate;
obtaining a quantization parameter of the image of the current frame by using a preset linear model according to the target code rate of the image of the current frame;
adjusting the quantization parameter according to a preset condition, updating the linear model according to the adjusted quantization parameter, and obtaining the quantization parameter of the next frame of image by using the updated linear model;
the preset linear model is as follows:
QP=α·SATD/R;
wherein QP represents a quantization parameter for an image of the current frame; a represents a model parameter of the linear model; SATD represents the SATD value of the picture of the current frame; r represents the target code rate of the image of the current frame;
the updating the linear model according to the adjusted quantization parameter includes:
updating the model parameters using the following formula:
α′=SATD/(QP·R)
αcurrent=0.2·α′+0.8·αlast
wherein alpha iscurrentRepresenting the updated model parameters; alpha is alphalastRepresenting model parameters before updating.
2. The method of claim 1, wherein the multi-frame image comprises an I-frame, a P-frame, and a B-frame;
the pre-coding processing of each frame image of the multi-frame images to obtain the transformation absolute error and the SATD value of each frame image comprises:
dividing each frame of image into a plurality of coding units (CTUs);
calculating the SATD value of each CTU of the I frame in a plurality of preset intra-frame angle prediction modes respectively, and determining the minimum SATD value as the SATD value of the current CTU;
calculating the SATD value of each CTU of the P frame in an intra mode, an inter _2N × 2N mode and a skip mode respectively, and determining the minimum SATD value as the SATD value of the current CTU;
calculating the SATD value of each CTU of the B frame in an intra mode, an inter _2N x 2N mode and a skip mode respectively, and determining the minimum SATD value as the SATD value of the current CTU;
and superposing the SATD values of all the CTUs of each frame image to obtain the SATD value of each frame image.
3. The method of claim 1, wherein the preset encoding parameters comprise a video frame rate and an encoding target bitrate.
4. The method of claim 2, wherein obtaining the target code rate of each frame image in each GOP according to the target code rate of each GOP and the SATD value of each frame image in the GOP corresponding to the target code rate comprises:
obtaining the SATD value of the current GOP according to the SATD value of the P frame included by the current GOP, the SATD value of the B frame included by the current GOP and the weight of a preset P frame and a preset layered B frame;
obtaining the target code rate of the P frame according to the target code rate of the current GOP, the SATD value of the current GOP, the weight and the SATD value of the P frame included by the current GOP;
obtaining the target code rate of the B frame according to the target code rate of the P frame, the SATD value corresponding to the target code rate of the P frame and the SATD value of the B frame included in the current GOP;
and obtaining the target code rate of the I frame according to the interval length between the current I frame and the last I frame and the coding parameters.
5. The method according to claim 1, wherein the adjusting the quantization parameter according to a preset condition comprises:
obtaining a check value VBV of the current frame according to a preset video cache checker and the target code rate of the current frame;
and comparing the VBV with a preset safety zone, and adjusting the quantization parameter according to a comparison result until the VBV corresponding to the adjusted quantization parameter is positioned in the safety zone.
6. The method of claim 1, further comprising:
calculating the short-time average SATD value of the forward sequence of each frame;
comparing the SATD value of the current frame with the short-time average SATD value of the forward sequence of the current frame, and judging whether the current frame is a scene switching frame according to the comparison result;
if so, initializing the linear model, and determining the quantization parameter of the current frame according to the initialized linear model.
7. A rate control apparatus based on layered B frames, comprising:
the resampling module is used for acquiring an original video signal; resampling the original video signal to obtain a resampled video signal; the resampled video signal comprises a plurality of frames of images;
the pre-coding module is used for pre-coding each frame of image of the multi-frame of image to obtain the transformation absolute error and the SATD value of each frame of image;
the first calculation module is used for dividing the multi-frame image into a plurality of group of pictures (GOPs), and obtaining the target code rate of each GOP according to preset coding parameters;
the second calculation module is used for obtaining the target code rate of each frame image in each GOP according to the target code rate of each GOP and the SATD value of each frame image in the GOP corresponding to the target code rate;
the quantization parameter calculation module is used for obtaining the quantization parameter of the image of the current frame by utilizing a preset linear model according to the target code rate of the image of the current frame;
the adjustment updating module is used for adjusting the quantization parameters according to preset conditions, updating the linear model according to the adjusted quantization parameters, and obtaining the quantization parameters of the next frame of image by using the updated linear model; the preset linear model is as follows:
QP=α·SATD/R;
wherein QP represents a quantization parameter for an image of the current frame; a represents a model parameter of the linear model; SATD represents the SATD value of the picture of the current frame; r represents the target code rate of the image of the current frame;
the adjustment update module is specifically configured to:
updating the model parameters using the following formula:
α′=SATD/(QP·R)
αcurrent=0.2·α′+0.8·αlast
wherein alpha iscurrentRepresenting the updated model parameters; alpha is alphalastRepresenting model parameters before updating.
8. An electronic device comprising a memory and a processor, wherein the memory stores a computer program operable on the processor, and wherein the processor implements the steps of the method of any of claims 1 to 6 when executing the computer program.
CN201811653605.5A 2018-12-29 2018-12-29 Code rate control method and device based on layered B frame and electronic equipment Active CN109862359B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201811653605.5A CN109862359B (en) 2018-12-29 2018-12-29 Code rate control method and device based on layered B frame and electronic equipment

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201811653605.5A CN109862359B (en) 2018-12-29 2018-12-29 Code rate control method and device based on layered B frame and electronic equipment

Publications (2)

Publication Number Publication Date
CN109862359A CN109862359A (en) 2019-06-07
CN109862359B true CN109862359B (en) 2021-01-08

Family

ID=66893755

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201811653605.5A Active CN109862359B (en) 2018-12-29 2018-12-29 Code rate control method and device based on layered B frame and electronic equipment

Country Status (1)

Country Link
CN (1) CN109862359B (en)

Families Citing this family (15)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112312231B (en) * 2019-07-31 2022-09-02 北京金山云网络技术有限公司 Video image coding method and device, electronic equipment and medium
CN112752103B (en) * 2019-10-31 2023-01-31 Oppo广东移动通信有限公司 Method and device for controlling code rate
CN110971900A (en) * 2019-11-14 2020-04-07 杭州当虹科技股份有限公司 Code rate control method suitable for 4K and 8K ultrahigh-definition motion flat video
CN111416978B (en) * 2020-04-29 2022-06-07 随锐科技集团股份有限公司 Video encoding and decoding method and system, and computer readable storage medium
CN111726656B (en) * 2020-07-20 2022-07-26 有半岛(北京)信息科技有限公司 Transcoding method, device, server and storage medium of live video
CN113301340A (en) * 2020-09-29 2021-08-24 阿里巴巴集团控股有限公司 Encoding parameter determination method, video transmission method and device
CN112243129B (en) * 2020-10-15 2022-10-11 北京达佳互联信息技术有限公司 Video data processing method and device, computer equipment and storage medium
CN112351276B (en) * 2020-11-04 2024-05-31 北京金山云网络技术有限公司 Video encoding method and device and video decoding method and device
CN112351277B (en) * 2020-11-04 2024-04-05 北京金山云网络技术有限公司 Video encoding method and device and video decoding method and device
CN112422965B (en) * 2020-11-16 2022-08-30 深圳市嬴圳科技有限公司 Video code rate control method and device, computer equipment and storage medium
CN113382242B (en) * 2021-05-20 2023-01-24 北京大学深圳研究生院 Code rate control method, device, equipment and computer readable storage medium
CN113473125B (en) * 2021-06-25 2023-08-15 咪咕互动娱乐有限公司 Code rate control method, equipment, storage medium and product
CN114554204A (en) * 2022-01-20 2022-05-27 珠海全志科技股份有限公司 Method and device for adjusting image quality of coded image
CN116567228A (en) * 2022-01-27 2023-08-08 腾讯科技(深圳)有限公司 Encoding method, real-time communication method, apparatus, device and storage medium
CN118632000A (en) * 2023-03-07 2024-09-10 华为技术有限公司 Image coding and decoding method, device and system

Family Cites Families (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US8897359B2 (en) * 2008-06-03 2014-11-25 Microsoft Corporation Adaptive quantization for enhancement layer video coding
CN101325711A (en) * 2008-07-16 2008-12-17 上海大学 Method for controlling self-adaption code rate based on space-time shielding effect
CN101917614B (en) * 2010-06-03 2012-07-04 北京邮电大学 Bit rate control method based on H.264 hierarchical B-frame coding structure
CN102420987A (en) * 2011-12-01 2012-04-18 上海大学 Self-adaption bit distribution method based on code rate control of hierarchical B frame structure
CN102724502B (en) * 2012-06-11 2015-08-19 华为技术有限公司 The control method of code check and device in a kind of Video coding
CN103957410B (en) * 2013-12-30 2017-04-19 南京邮电大学 I-frame code rate control method based on residual frequency domain complexity

Also Published As

Publication number Publication date
CN109862359A (en) 2019-06-07

Similar Documents

Publication Publication Date Title
CN109862359B (en) Code rate control method and device based on layered B frame and electronic equipment
US11451787B2 (en) Method and apparatus for video encoding and decoding
JP6862633B2 (en) Rate control method and rate control device
CN1910934B (en) Encoder with adaptive rate control
JP4529919B2 (en) Adaptive quantization apparatus and adaptive quantization program
JP3840020B2 (en) Video encoding device
CN102932641B (en) A kind of constant-quality bit rate control method
JP5770476B2 (en) Method and apparatus for accurate rate control in video coding
JP2006140758A (en) Method, apparatus and program for encoding moving image
JP5133290B2 (en) Video encoding apparatus and decoding apparatus
WO2016082529A1 (en) Video coding method and device
US20100111180A1 (en) Scene change detection
CN108012149B (en) Code rate control method in video coding
JP2007525063A (en) How to control multipath video rate to match sliding window channel limit
CN109803146B (en) Method, apparatus, medium, and device for secondary compression of video
CN104113761B (en) Bit rate control method and encoder in a kind of Video coding
TWI734865B (en) Method and encoder system for encoding video
TW201906412A (en) Method and apparatus for performing fixed size slice coding with slice boundary prediction
US6389073B1 (en) Coding control method, coding control apparatus and storage medium containing coding control program
US20120195364A1 (en) Dynamic mode search order control for a video encoder
CN115118976A (en) Image coding method, readable medium and electronic device thereof
KR101868270B1 (en) Content-aware video encoding method, controller and system based on single-pass consistent quality control
WO2018109455A1 (en) Motion compensation techniques for video
KR20130032807A (en) Method and apparatus for encoding a moving picture
JP4718736B2 (en) Video encoding device

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant