A method and device for controlling I frame rate suitable for hardware implementation
By performing intra-coding mode filtering and intra-coding complexity calculation of I frames in the hardware video encoder, and using the information of the encoded video frames to calculate the frame-level Lagrangian multiplier, the problem of I frame code rate control accuracy is solved, and more accurate code rate control and higher robustness are achieved.
Patent Information
- Application Number
- CN202211134183.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-09-18
- Publication Date
- 2025-03-14
- Estimated Expiration
- 2042-09-18
AI Technical Summary
In hardware video encoder, it is difficult for the prior art to accurately calculate the frame-level Lagrangian multiplier of I frame, resulting in a large gap between the actual number of coded bits of I frame and the target bit number, causing instantaneous code rate fluctuations.
By using multiple intra-coding modes for the image block to be encoded for preliminary screening, the prediction cost of each intra-coding mode is calculated, the smallest intra-coding mode prediction cost is filtered out to characterize the intra-coding complexity, and the frame-level Lagrangian multiplier of the to-code I-frame is calculated using the information of the encoded video frame.
The accuracy of I-frame code rate control is improved, the actual number of coded bits is closer to the target bit number, the errors in the code rate control process are reduced, and the changes in the video stream content are adapted to the changes in the video stream content are improved.
Smart Images

Figure CN115550656B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to a video encoding technology, and in particular to a code rate control method. Background Art
[0002] Video coding technology compresses redundant components in video images and uses as little data as possible to represent video information. Common video coding standards include AVC (Advanced Video Coding, also known as H.264) and HEVC (High Efficiency Video Coding, also known as H.265). Video coding technology uses image blocks as the most basic coding units. For example, in HEVC, the basic unit of coding is CU (Coding Unit). CU can be an image block of 64 pixels × 64 pixels, 32 pixels × 32 pixels, 16 pixels × 16 pixels, or 8 pixels × 8 pixels.
[0003] In order to remove information redundancy in the spatial and temporal domains, the input video frames are encoded using intra-frame coding and inter-frame coding techniques. The encoded video frames can generally be divided into I-frames that only use intra-frame coding techniques, and P-frames and B-frames that use a mixture of intra-frame coding and inter-frame coding techniques. When encoding an I-frame, only intra-frame coding techniques are used, and only the information of the current video frame is used for encoding, without reference to the information of other encoded video frames. All image blocks in an I-frame are encoded as intra-frame coding blocks. When encoding a P-frame and a B-frame, intra-frame coding and inter-frame coding techniques are mixed, and not only the information of the current video frame is used for encoding, but also the information of one or more other encoded video frames is referenced. Image blocks in a P-frame and a B-frame can be encoded as intra-frame coding blocks or as inter-frame coding blocks. For each image block in a P-frame and a B-frame, if the rate-distortion cost of using intra-frame coding techniques is lower, then this image block will be encoded as an intra-frame coding block; if the rate-distortion cost of using inter-frame coding techniques is lower, then this image block will be encoded as an inter-frame coding block. For each input video frame, the type of encoded frame is determined by the picture group (GOP) parameter set by the user. Figure 1 A common GOP structure is shown, which contains I-frames, P-frames or B-frames.
[0004] In order to maximize the video compression rate, common video coding algorithms are often lossy compression algorithms, such as AVC and HEVC. This causes the difference between the encoded and reconstructed video and the original video, that is, the encoded and reconstructed video will be distorted. For lossy compression algorithms, their coding performance needs to be measured by the coding bit rate (Rate) and the distortion (Distortion) introduced by the coding. In the process of video coding, the coding bit rate and coding distortion are mutually restricted and contradictory. For example, reducing the coding bit rate often increases the coding distortion, while reducing the coding distortion often increases the coding bit rate. Rate Distortion Optimization (RDO) is to reduce the coding distortion as much as possible under a certain coding bit rate, or to reduce the coding bit rate as much as possible under a certain coding distortion. In common video coding algorithms, the rate distortion optimization method based on the Lagrange multiplier λ is currently used. Assume that D is the coding distortion, R is the coding bit rate, and J is the coding rate distortion cost (Rate Distortion Cost, RD Cost), J = D + λ × R. The rate-distortion optimization method based on the Lagrange multiplier λ can be expressed as min(J), where min() means taking the minimum value. In video encoding, each coding mode has its corresponding coding distortion D and coding bit rate R, so the coding rate-distortion cost J corresponding to each coding mode can be calculated. Selecting the coding mode with the smallest rate-distortion cost J for video encoding can obtain the best coding performance. The process of the encoder selecting the optimal coding mode for each image block to be encoded by the rate-distortion optimization method is called the mode selection (Mode Decision) of the image block to be encoded.
[0005] See also Figure 2 The existing mode selection system for the image block to be encoded includes a video frame encoding type selection module 11, an intra-frame encoding mode prediction module 12, an inter-frame encoding mode prediction module 13, an intra-frame encoding mode rate-distortion optimization module 14, an inter-frame encoding mode rate-distortion optimization module 15, and a coding mode selection module 16.
[0006] The video frame encoding type selection module 11 determines the type of the current video frame to be encoded according to the group of pictures (GOP) parameters set by the user, that is, determines whether the current video frame to be encoded needs to be encoded as an I frame, a P frame or a B frame.
[0007] The intra-frame coding mode prediction module 12 will perform a preliminary screening of a large number of intra-frame coding modes, and screen out one or more intra-frame coding mode candidates with the lowest prediction cost by calculating the prediction cost corresponding to each intra-frame coding mode. Similarly, the inter-frame coding mode prediction module 13 will perform a preliminary screening of a large number of inter-frame coding modes, and screen out one or more inter-frame coding mode candidates with the lowest prediction cost by calculating the prediction cost corresponding to each inter-frame coding mode.
[0008] The intra-frame coding mode rate-distortion optimization module 14 calculates the accurate rate-distortion cost for all intra-frame coding mode candidates, and takes the intra-frame coding mode with the minimum rate-distortion cost as the optimal intra-frame coding mode. Similarly, the inter-frame coding mode rate-distortion optimization module 15 calculates the accurate rate-distortion cost for all inter-frame coding mode candidates, and takes the inter-frame coding mode with the minimum rate-distortion cost as the optimal inter-frame coding mode.
[0009] The coding mode selection module 16 uses the optimal intra-frame coding mode as the optimal coding mode for the image block in the I frame, and uses the optimal intra-frame coding mode and the optimal inter-frame coding mode with the smaller rate-distortion cost as the optimal coding mode for the image block in the P frame or B frame.
[0010] If the current video frame to be encoded is an I frame, since the I frame only uses intra-frame coding technology, the image blocks inside it are processed by the intra-frame coding mode prediction module 12, the intra-frame coding mode rate-distortion optimization module 14 and the coding mode selection module 16 to obtain the optimal coding mode of the image blocks. If the current video frame to be encoded is a P frame or a B frame, since the P frame and the B frame use a mixture of intra-frame coding technology and inter-frame coding technology, the image blocks inside it are processed by the intra-frame coding mode prediction module 12, the inter-frame coding mode prediction module 13, the intra-frame coding mode rate-distortion optimization module 14, the inter-frame coding mode rate-distortion optimization module 15 and the coding mode selection module 16 to obtain the optimal coding mode of the image blocks. It can be seen that no matter it is an I frame, a P frame or a B frame, the image blocks inside it need to pass through the intra-frame coding mode prediction module 12 to calculate the prediction cost corresponding to the intra-frame coding mode.
[0011] In essence, the coding mode prediction modules 12, 13 and the coding mode rate-distortion optimization modules 14, 15 all use rate-distortion optimization methods to screen the coding modes of the image blocks. The difference between the two modules mainly lies in the different precisions of the cost calculation methods used. In the coding mode prediction modules 12, 13, a cost calculation method with less computational effort and lower precision is generally adopted. The SAD (Sum of Absolute Difference) algorithm or the SATD (Sum of Absolute Transformed Difference) algorithm is generally used to calculate the distortion cost. The simplified bit rate estimation algorithm, such as the exponential-Golomb coding algorithm, is generally used to calculate the coding bit rate cost, and the transformation and quantization operations are generally not introduced in the coding mode prediction stage. In the rate-distortion optimization module of the coding mode, a cost calculation method with large computational complexity and high precision is generally adopted. The SSD (Sum of Squared Differences) algorithm is generally used to calculate the distortion cost, and the CABAC (Context-based Adaptive Binary Arithmatic Coding) algorithm or CAVLC (Context-based Adaptive Variable Length Coding) algorithm is generally used to calculate the coding bit rate cost, and the coding mode rate-distortion optimization stage generally introduces transformation and quantization operations. Conventionally, the rate-distortion cost calculated by the coding mode prediction modules 12 and 13 is called the prediction cost of the coding mode.
[0012] In real life, the channel bandwidth (channel capacity) used to transmit compressed video is limited. If the encoding bit rate of the compressed video is too high and exceeds the capacity of the channel bandwidth, it will cause video transmission congestion or even packet loss. If the encoding bit rate of the compressed video is too low, the channel bandwidth will not be fully utilized and higher video quality cannot be obtained. Therefore, it is necessary to use rate control technology to control the output bit rate of the video encoder to match it with the channel bandwidth.
[0013] The rate control technology adjusts the encoding parameters of the video encoder so that the output bit rate of the video encoder is equal to the preset target bit rate, while minimizing the encoding distortion to improve the video encoding quality. Currently, the rate control algorithm used in the HEVC reference encoder HM (High Efficiency Video Coding Test Model) is based on the JCTVC-K0103 proposal. The JCTVC-K0103 proposal established a mathematical relationship model between the encoding bit rate R and the Lagrange multiplier λ (i.e., the R-λ model), and achieved the rate control task through two links: target bit allocation and target bit control.
[0014] In the JCTVC-K0103 proposal, target bit allocation is performed at three levels, namely, the GOP (Group Of Pictures, i.e., a set of temporally continuous video frames) level, the video frame level, and the basic coding unit level. After the target bit allocation at the video frame level, the target number of coding bits for the current video frame to be encoded is determined. The next step is to calculate the value of the Lagrange multiplier (frame-level Lagrange multiplier) λ of the current video frame to be encoded based on the R-λ model proposed in the JCTVC-K0103 proposal: λ = α·bpp β . Among them, λ is the Lagrange multiplier of the current video frame to be encoded; α and β are R-λ model parameters, whose values are determined by the video content and encoder configuration parameters, and are continuously updated as the encoding process proceeds; bpp is the number of bits per pixel (bit per pixel), which represents the average target number of coding bits allocated to each pixel point, and its value is the quotient of the target number of coding bits of the video frame to be encoded and the number of pixels in the video frame. After calculating the Lagrange multiplier λ of the current video frame to be encoded, λ can be used for rate-distortion optimization in the encoding process.
[0015] Since the computational complexity of video encoding algorithms is very high, in order to increase the speed of video encoding and achieve real-time encoding and transmission, it has become a common practice in the industry to use application-specific integrated circuits (ASICs) to perform hardware acceleration on the video encoding process. This type of application-specific integrated circuit that performs hardware acceleration on the video encoding process is generally called a hardware video encoder.
[0016] In hardware video encoders, rate control of I frames has always been a difficult problem. This is because in the existing JCTVC-K0103 proposal, the rate control parameters (α and β) of I frames are empirical values, which have no direct relationship with the content complexity of I frames. This will lead to a large error in the calculated frame-level Lagrangian multiplier λ, which ultimately leads to a large gap between the actual number of bits encoded by the I frame and the target number of bits, causing drastic instantaneous rate fluctuations. If the frame-level Lagrangian multiplier λ of the I frame is to be calculated more accurately, it is necessary to add a special image preprocessing stage before the I frame encoding to evaluate and calculate the content complexity of the I frame. Then, the parameters of the rate control algorithm are adjusted according to the content complexity of the I frame, and the adjusted rate control parameters are used to encode the I frame. The frame-level Lagrangian multiplier λ of the I frame calculated by this type of scheme is generally more accurate, and the rate control effect is better. However, in hardware video encoders, adding a special preprocessing stage is not only costly, but also increases the delay of video encoding, so it is not suitable for hardware video encoder implementation. Summary of the invention
[0017] The technical problem to be solved by the present invention is: to design a rate control method for I frame suitable for hardware video encoder implementation, and to accurately calculate the frame-level Lagrange multiplier λ of the I frame without adding a special image preprocessing stage, so that the actual number of encoded bits of the I frame is closer to the target number of encoded bits, making the rate control process more accurate.
[0018] In order to solve the above technical problems, the present invention proposes an I frame rate control method suitable for hardware implementation, comprising the following steps. Step S21: Use multiple intra-frame coding modes to perform preliminary screening on each image block to be encoded, that is, calculate the prediction cost corresponding to each intra-frame coding mode, and screen out one or more intra-frame coding modes with the lowest prediction cost as intra-frame coding mode candidates, as well as the intra-frame coding mode prediction cost corresponding to each intra-frame coding mode candidate. Step S22: Screen the intra-frame coding mode prediction cost corresponding to each intra-frame coding mode candidate of the image block to be encoded, and select the minimum intra-frame coding mode prediction cost to characterize the intra-frame coding complexity of the image block to be encoded; then take the sum of the intra-frame coding complexities of all image blocks in the video frame as the intra-frame coding complexity of the video frame. Step S23: Calculate the frame-level Lagrange multiplier of the I frame to be encoded based on the actual number of coding bits, frame-level Lagrange multipliers and intra-frame coding complexity of the previous encoded I frame, combined with the target number of coding bits and intra-frame coding complexity of the I frame to be encoded; wherein the intra-frame coding complexity of the I frame to be encoded is obtained by replacing the intra-frame coding complexity of the previous encoded video frame of the I frame to be encoded.
[0019] Furthermore, in step S22, only the intra-frame coding complexity of each I frame and the video frame preceding each I frame is calculated.
[0020] Furthermore, in step S23, the frame-level Lagrange multiplier λ of the I frame to be encoded is new From formula 5: Find; where f -1 It is the inverse function of the first function f that characterizes the relationship between the ratio of different frame-level Lagrange multipliers and the ratio of different actual coding bit numbers when encoding I frames; I(n) new Indicates the target number of encoding bits for the I frame to be encoded; I(m) old represents the actual number of coded bits of the previous coded I frame; g is the second function that represents the relationship between the ratio of different intra-frame coding complexities and the ratio of different actual number of coded bits when encoding an I frame; ω n-1 Indicates the intra-frame coding complexity of the previous coded video frame of the I frame to be coded, which is used to replace the intra-frame coding complexity ω of the I frame to be coded n ;ω m represents the intra-frame coding complexity of the previous coded I frame; old Represents the frame-level Lagrange multiplier of the previous coded I frame.
[0021] Furthermore, the first function f is given by Formula 1: Obtaining: The specific expression of the first function f is obtained by calculating and fitting the actual parameters of the I frame in the video after encoding.
[0022] Furthermore, the second function g is given by Formula 2: Obtaining; The specific expression of the second function g is obtained by calculating and fitting the actual parameters of the I frame in the video after encoding.
[0023] Furthermore, I frame encoding experiments are conducted on a large number of different video streams in advance, and expressions of the first function f and the second function g are obtained by function fitting and stored in the video encoder.
[0024] Furthermore, in step S23, after the frame-level Lagrange multiplier of the I frame to be encoded is calculated, the I frame to be encoded is encoded, and its actual number of encoding bits and intra-frame encoding complexity are obtained.
[0025] Further, step S24 is added after step S23. Step S24: after the current I frame is encoded, the first function f and the second function g used in the process of calculating the frame-level Lagrangian multiplier of the I frame to be encoded are corrected according to the actual number of encoded bits, frame-level Lagrangian multipliers and intra-frame coding complexity of the currently encoded I frame and the previous encoded I frame.
[0026] The present invention also proposes an I frame rate control device suitable for hardware implementation, including an intra-frame coding mode prediction module, an intra-frame coding complexity calculation module, and an I frame Lagrangian constant calculation module. The intra-frame coding mode prediction module is used to preliminarily screen multiple intra-frame coding modes for the image block to be coded, that is, to calculate the prediction cost corresponding to each intra-frame coding mode, and screen out one or more intra-frame coding modes with the lowest prediction cost as intra-frame coding mode candidates, and the intra-frame coding mode prediction cost corresponding to each intra-frame coding mode candidate. The intra-frame coding complexity calculation module is used to screen the intra-frame coding mode prediction cost corresponding to each intra-frame coding mode candidate of the image block to be coded, and select the minimum intra-frame coding mode prediction cost to characterize the intra-frame coding complexity of the image block to be coded; then the sum of the intra-frame coding complexities of all image blocks in the video frame is used as the intra-frame coding complexity of the video frame. The I-frame Lagrangian constant calculation module is used to calculate the frame-level Lagrangian multiplier of the I-frame to be encoded based on the actual number of coding bits, frame-level Lagrangian multipliers and intra-frame coding complexity of the previous encoded I-frame, combined with the target number of coding bits and intra-frame coding complexity of the I-frame to be encoded; wherein the intra-frame coding complexity of the I-frame to be encoded is obtained by replacing the intra-frame coding complexity of the previous encoded video frame of the I-frame to be encoded.
[0027] Furthermore, an I-frame Lagrangian constant calculation correction module is added after the I-frame Lagrangian constant calculation module. The I-frame Lagrangian constant calculation correction module is used to correct the first function f and the second function g used in the process of calculating the frame-level Lagrangian multiplier of the I frame to be encoded according to the actual number of coded bits, frame-level Lagrangian multipliers and intra-frame coding complexity of the currently encoded I frame and the previous encoded I frame after the current I frame is encoded.
[0028] The technical effect achieved by the present invention is: the frame-level Lagrange multiplier of the I frame to be encoded is calculated by using the information of the encoded video frame, the calculation accuracy is high, and the accuracy of the I frame rate control is effectively improved. In addition, the present invention does not need to increase the image preprocessing level, the hardware overhead is small, and the implementation cost is low; the optional correction step can eliminate the accumulated error, so that the I frame rate control process can adapt to the changes in the video stream content, and improve the robustness of the I frame rate control. BRIEF DESCRIPTION OF THE DRAWINGS
[0029] Figure 1 This is a schematic diagram of a common image group structure.
[0030] Figure 2 It is a structural diagram of an existing mode selection system for an image block to be encoded.
[0031] Figure 3It is a flow chart of Embodiment 1 of the I frame rate control method suitable for hardware implementation proposed by the present invention.
[0032] Figure 4 It is a flow chart of Embodiment 2 of the I frame bit rate control method suitable for hardware implementation proposed by the present invention.
[0033] Figure 5 It is a structural diagram of Embodiment 1 of an I frame bit rate control device suitable for hardware implementation proposed by the present invention.
[0034] Figure 6 It is a structural diagram of a second embodiment of an I frame bit rate control device suitable for hardware implementation proposed by the present invention.
[0035] Explanation of the reference numerals in the figure: 11 is a video frame coding type selection module, 12 is an intra-frame coding mode prediction module, 13 is an inter-frame coding mode prediction module, 14 is an intra-frame coding mode rate-distortion optimization module, 15 is an inter-frame coding mode rate-distortion optimization module, 16 is a coding mode selection module, 21 is an intra-frame coding mode prediction module, 22 is an intra-frame coding complexity calculation module, 23 is an I-frame Lagrangian constant calculation module, and 24 is an I-frame Lagrangian constant calculation correction module. DETAILED DESCRIPTION
[0036] See also Figure 3 , Embodiment 1 of the I frame bit rate control method suitable for hardware implementation proposed by the present invention includes the following steps.
[0037] Step S21: For each image block to be encoded, multiple intra-frame coding modes are used for preliminary screening, that is, the prediction cost corresponding to each intra-frame coding mode is calculated, and one or more intra-frame coding modes with the lowest prediction cost of the image block to be encoded are screened out as intra-frame coding mode candidates, as well as the intra-frame coding mode prediction cost corresponding to each intra-frame coding mode candidate. The prediction cost refers to a coding rate distortion cost J with small computational complexity and low precision, J=D+λ×R. Among them, D is the coding distortion, and the SAD algorithm or SATD algorithm is generally used; R is the coding bit rate, and a simplified bit rate estimation algorithm is generally used. And transformation and quantization operations are generally not introduced in the calculation process. This step is a step in the existing video encoding process. Intra-frame coding mode prediction will be performed for all image blocks of I frames, P frames and B frames.
[0038] Step S22: Screen the intra-coding mode prediction cost corresponding to each intra-coding mode candidate of the image block to be encoded, and select the minimum intra-coding mode prediction cost to characterize the intra-coding complexity of the image block to be encoded; then take the sum of the intra-coding complexities of all image blocks in the video frame as the intra-coding complexity of the video frame. Preferably, this step only calculates the intra-coding complexity of each I frame and the video frame preceding each I frame, and does not calculate the intra-coding complexity of other video frames. This step reuses the calculation results of intra-coding mode prediction in the existing video encoding process, specifically, reuses the calculation results of intra-coding mode prediction of all image blocks in each I frame and all image blocks in the video frame preceding each I frame (intra-coding mode candidates and their corresponding intra-coding mode prediction costs), without introducing additional image preprocessing stages, which is an innovation of the present invention.
[0039] Step S23: Based on the actual number of coded bits of the previous coded I frame and the frame-level Lagrange multiplier λ old The frame-level Lagrange multiplier λ of the I frame to be encoded is calculated by combining the target number of encoding bits and the intra-frame coding complexity of the I frame to be encoded. new The intra-frame coding complexity of the I frame to be coded is replaced by the intra-frame coding complexity of the previous coded video frame of the I frame to be coded. new Afterwards, the I frame to be encoded can be encoded, and its actual encoding bit number and intra-frame encoding complexity can be obtained.
[0040] The frame-level Lagrange multiplier λ of the I frame to be encoded new From formula 5: This is an example. -1 It is the inverse function of the first function f that characterizes the relationship between the ratio of different frame-level Lagrange multipliers and the ratio of different actual coding bit numbers when encoding I frames. I(n) new Indicates the target number of bits for encoding the I frame to be encoded. I(m) old Indicates the actual number of coded bits of the previous coded I frame. g is the second function that characterizes the relationship between the ratio of different intra-frame coding complexities and the ratio of different actual number of coded bits when encoding an I frame. ω n-1 Indicates the intra-frame coding complexity of the previous coded video frame of the I frame to be coded, which is used to replace the intra-frame coding complexity ω of the I frame to be coded n ω m Indicates the intra-frame coding complexity of the previous coded I frame. old represents the frame-level Lagrangian multiplier of the previous coded I frame. In this step, the frame-level Lagrangian multiplier λ of the I frame to be coded is derived using the information of the coded I frame.new The process of replacing the intra-frame coding complexity of the I frame to be coded by utilizing the correlation of consecutive video frames in the time domain belongs to the innovation of the present invention.
[0041] See also Figure 1 , the mth frame and the nth frame are two adjacent I frames, and there may be zero or more P frames or B frames between them. Let I(m) old Indicates that the mth frame adopts λ old The actual number of coded bits after encoding, let I(m) new Indicates that the mth frame adopts λ new The actual number of coded bits after encoding, let I(n) old Indicates that the nth frame adopts λ old The actual number of coded bits after encoding, let I(n) new Indicates that the nth frame adopts λ new The actual number of coded bits after encoding, let ω m Denotes the intra-frame coding complexity of the mth frame, let ω n Indicates the intra-frame coding complexity of the nth frame.
[0042] The first function f is given by formula 1: Get. The physical meaning of formula 1 is: when different frame-level Lagrange multipliers are used to encode the same video frame as an I frame, the ratio of the actual number of encoded bits obtained after encoding is related to the ratio of the frame-level Lagrange multipliers, and this relationship can be expressed by the first function f. The specific expression of the first function f can be obtained by calculating and fitting the actual parameters of the I frame in the video after encoding, which will not be repeated here.
[0043] The second function g is given by formula 2: Get. The physical meaning of formula 2 is that when the same frame-level Lagrange multiplier is used to encode different video frames for I frame, the ratio of the actual number of encoded bits obtained after encoding is related to the ratio of the intra-frame encoding complexity of the video frame, and this relationship can be expressed by the second function g. The specific expression of the second function g can be obtained by calculating and fitting the actual parameters of the I frame in the video after encoding, which will not be repeated here.
[0044] When the present invention is implemented specifically, a large number of experiments are conducted in advance to find that the first function f and the second function g maintain similar rules in different videos. The present invention conducts I frame encoding experiments on a large number of different video streams in advance, and obtains the expression of the first function f and the expression of the second function g by function fitting, and saves them in the video encoder. Since they are obtained after I frame encoding of a large number of different video streams, the expression of the first function f and the expression of the second function g are adapted to the vast majority of video streams and are not limited to a certain video stream. Therefore, the first function f and the second function g in the above formulas 1 and 2 belong to a known functional relationship. When using the preset first function f and the second function g to encode a new video stream for I frame, there is a small probability that the content of the new video stream will not be well adapted. At this time, it is necessary to correct the first function f and the second function g according to the actual encoding parameters after I frame encoding in this video stream, such as the optional correction step S24 described later.
[0045] Based on the deduction of formula 1 and formula 2, we can get formula 3: Further deduction can get formula 4: In formula 4, the mth frame is an encoded I frame, and its encoding process has been completed. The corresponding actual number of encoded bits is I(m) old , the frame-level Lagrange multiplier λ used in encoding old and intra-frame coding complexity ω m are all known quantities. The nth frame is the I frame to be encoded, so I(n) new Represents the expected target number of coded bits, which is a known quantity; ω n represents the intra-frame coding complexity of the nth frame. Since the nth frame has not been encoded yet, it is an unknown quantity; λ new Represents when the actual number of coded bits of the nth frame is the expected target number of coded bits I(n) new When , the frame-level Lagrangian multiplier to be used is an unknown quantity and is also a quantity that needs to be calculated. In order to use formula 4 to calculate the frame-level Lagrangian multiplier λ of the I frame to be encoded new The present invention utilizes the correlation of consecutive video frames in the time domain (consecutive video frames are similar in content) and uses the intra-frame coding complexity ω of the encoded n-1th frame adjacent to the nth frame. n-1 To replace the intra-frame coding complexity ω of the nth frame to be encoded n Since the sampling time of the n-1th frame is very close to that of the nth frame, the contents of the two video frames are very similar, and the error of the replacement operation of the intra-frame coding complexity is very small, and the frame-level Lagrange multiplier λ of the coded I frame will not be affected. new Thus, since the encoding of the n-1th frame has been completed, its intra-frame encoding complexity ωn-1 is a known quantity. In formula 4, let ω n-1 Replace ω n , we can get Formula 5.
[0046] See also Figure 4 The second embodiment of the I frame bit rate control method suitable for hardware implementation proposed by the present invention adds step S24 after step S23 of the first embodiment.
[0047] Step S24: After the current I frame is encoded, the frame-level Lagrangian multiplier λ of the I frame to be encoded is calculated according to the actual number of coded bits of the current I frame that has just been encoded and the previous I frame that has been encoded, the frame-level Lagrangian multiplier and the intra-frame coding complexity. new This step is used to suppress the error introduced by the intra-frame coding complexity replacement operation so that it does not accumulate due to the increase in the number of coded frames, making the first function f and the second function g more suitable for the content characteristics of the current video stream, thereby making the calculation of the frame-level Lagrange multiplier of the subsequent I frame more accurate.
[0048] Still Figure 1 For example, the nth frame is the I frame that has just been encoded, and the mth frame is the previous I frame that has been encoded. Formula 1 is used to fit the function for the correction of the first function f. The parameters in Formula 1 use the actual number of encoded bits and frame-level Lagrange multipliers obtained after encoding the mth and nth frames. Formula 2 is used to fit the function for the correction of the second function g. The parameters in Formula 2 use the actual number of encoded bits and intra-frame coding complexity obtained after encoding the mth and nth frames.
[0049] See also Figure 5 The first embodiment of the I frame rate control device suitable for hardware implementation proposed by the present invention includes an intra-frame coding mode prediction module 21, an intra-frame coding complexity calculation module 22, and an I frame Lagrangian constant calculation module 23. Figure 5 The device shown corresponds to Figure 3 The method shown.
[0050] The intra-frame coding mode prediction module 21 is used to preliminarily screen multiple intra-frame coding modes for the image block to be coded, that is, to calculate the prediction cost corresponding to each intra-frame coding mode, and screen out one or more intra-frame coding modes with the lowest prediction cost as intra-frame coding mode candidates, and the intra-frame coding mode prediction cost corresponding to each intra-frame coding mode candidate. It should be particularly noted that Figure 5 The intra-frame coding mode prediction module 21 and Figure 2 The intra-frame coding mode prediction module 12 in the figure is only different in the figure mark, and is essentially the same module.
[0051] The intra-frame coding complexity calculation module 22 is used to screen the intra-frame coding mode prediction cost corresponding to each intra-frame coding mode candidate of the image block to be encoded, and select the minimum intra-frame coding mode prediction cost to characterize the intra-frame coding complexity of the image block to be encoded; and then take the sum of the intra-frame coding complexities of all image blocks in the video frame as the intra-frame coding complexity of the video frame.
[0052] The I frame Lagrangian constant calculation module 23 is used to calculate the actual number of coded bits of the previous coded I frame, the frame-level Lagrangian multiplier λ old The frame-level Lagrange multiplier λ of the I frame to be encoded is calculated by combining the target number of encoding bits and the intra-frame coding complexity of the I frame to be encoded. new The intra-frame coding complexity of the I frame to be coded is replaced by the intra-frame coding complexity of the previous coded video frame of the I frame to be coded.
[0053] See also Figure 6 The second embodiment of the I frame rate control device suitable for hardware implementation proposed by the present invention adds an I frame Lagrangian constant calculation correction module 24 after the I frame Lagrangian constant calculation module 23 of the first embodiment. Figure 6 The device shown corresponds to Figure 4 The method shown.
[0054] The I-frame Lagrangian constant calculation and correction module 24 is used to calculate the frame-level Lagrangian multiplier λ of the I-frame to be encoded according to the actual number of coded bits of the currently encoded I-frame and the previous encoded I-frame, the frame-level Lagrangian multiplier and the intra-frame coding complexity after the current I-frame is encoded. new The first function f and the second function g are used in the process for correction.
[0055] The present invention proposes an I-frame rate control method suitable for a hardware video encoder, which uses the intra-frame coding mode prediction cost generated during the video frame coding process to characterize the intra-frame coding complexity of the video frame, does not need to increase the image preprocessing level, has low hardware overhead, and has low implementation cost. The rate control method proposed by the present invention also uses the information of the encoded video frame to calculate the frame-level Lagrangian multiplier of the I frame to be encoded, with high calculation accuracy, which effectively improves the accuracy of the I-frame rate control. The rate control method proposed by the present invention also uses the actual coding information after the I-frame coding is completed to correct the calculation method of the frame-level Lagrangian multiplier λ of the I-frame, which can effectively eliminate the accumulated error, so that the rate control process of the I-frame can adapt to the changes in the video frame content, and improve the robustness of the I-frame rate control.
[0056] The above are only preferred embodiments of the present invention and are not intended to limit the present invention. For those skilled in the art, the present invention may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.
Claims
1. A method for controlling an I frame rate suitable for hardware implementation, characterized in that: The method comprises the following steps: Step S21: performing preliminary screening using multiple intra-coding modes for each image block to be encoded, that is, calculating the prediction costs corresponding to each intra-coding mode, screening out one or more intra-coding modes with the lowest prediction costs as intra-coding mode candidates, and the intra-coding mode prediction costs corresponding to each intra-coding mode candidate; Step S22: screening the intra-frame coding mode prediction cost corresponding to each intra-frame coding mode candidate of the image block to be coded, selecting the minimum intra-frame coding mode prediction cost to represent the intra-frame coding complexity of the image block to be coded; then taking the sum of the intra-frame coding complexities of all image blocks in the video frame as the intra-frame coding complexity of the video frame; Step S23: Calculate the frame-level Lagrange multiplier of the I frame to be encoded according to the actual number of coding bits, frame-level Lagrange multipliers and intra-frame coding complexity of the previous encoded I frame, combined with the target number of coding bits and intra-frame coding complexity of the I frame to be encoded; wherein the intra-frame coding complexity of the I frame to be encoded is obtained by replacing the intra-frame coding complexity of the previous encoded video frame of the I frame to be encoded; In step S23, the frame-level Lagrange multiplier λ of the I frame to be encoded new From formula 5: Find; where f -1 It is the inverse function of the first function f that represents the relationship between "using different frame-level Lagrange multipliers to encode the same video frame for I frame, and the ratio of the actual number of encoded bits obtained after encoding to the ratio of the frame-level Lagrange multipliers"; I(n) new Indicates the target number of bits for encoding the I frame to be encoded; I(m) old represents the actual number of coded bits of the previous coded I frame; g is the second function representing the relationship between "the ratio of the actual number of coded bits obtained after encoding different video frames using the same frame-level Lagrange multiplier to the ratio of the intra-frame coding complexity of the video frame"; ω n-1 Indicates the intra-frame coding complexity of the previous coded video frame of the I frame to be coded, which is used to replace the intra-frame coding complexity ω of the I frame to be coded n ;ω m represents the intra-frame coding complexity of the previous coded I frame; old Represents the frame-level Lagrange multiplier of the previous coded I frame.
2. The I frame rate control method suitable for hardware implementation according to claim 1, characterized in that: In step S22, only the intra-frame coding complexity of each I frame and the video frame preceding each I frame is calculated.
3. The I frame rate control method suitable for hardware implementation according to claim 1, characterized in that: The first function f is given by formula 1: Get; I(m) new Indicates that the mth frame adopts λ new The actual number of encoding bits after encoding; the specific expression of the first function f is obtained by calculating and fitting the actual parameters of the I frame in the video after encoding.
4. The I frame rate control method suitable for hardware implementation according to claim 1, characterized in that: The second function g is given by formula 2: Obtaining; The specific expression of the second function g is obtained by calculating and fitting the actual parameters of the I frame in the video after encoding.
5. The I frame rate control method suitable for hardware implementation according to claim 3 or 4, characterized in that: I frame encoding experiments are conducted on a large number of different video streams in advance, and expressions of the first function f and the second function g are obtained by function fitting and stored in the video encoder.
6. The I frame rate control method suitable for hardware implementation according to claim 1, characterized in that: In the step S23, after the frame-level Lagrange multiplier of the I frame to be encoded is calculated, the I frame to be encoded is encoded, and its actual encoding bit number and intra-frame encoding complexity are obtained.
7. The I frame rate control method suitable for hardware implementation according to claim 6, characterized in that Add step S24 after step S23; Step S24: After the current I frame is encoded, the first function f and the second function g used in the process of calculating the frame-level Lagrangian multipliers of the I frame to be encoded are corrected according to the actual number of encoded bits of the currently encoded I frame and the previous encoded I frame, the frame-level Lagrangian multipliers and the intra-frame coding complexity.
8. An I frame rate control device suitable for hardware implementation, characterized in that: It includes intra-frame coding mode prediction module, intra-frame coding complexity calculation module, and I-frame Lagrangian constant calculation module; The intra-frame coding mode prediction module is used to preliminarily screen multiple intra-frame coding modes for the image block to be coded, that is, to calculate the prediction cost corresponding to each intra-frame coding mode, and screen out one or more intra-frame coding modes with the lowest prediction cost as intra-frame coding mode candidates, and the intra-frame coding mode prediction cost corresponding to each intra-frame coding mode candidate; The intra-frame coding complexity calculation module is used to screen the intra-frame coding mode prediction cost corresponding to each intra-frame coding mode candidate of the image block to be coded, select the minimum intra-frame coding mode prediction cost to represent the intra-frame coding complexity of the image block to be coded; and then take the sum of the intra-frame coding complexities of all image blocks in the video frame as the intra-frame coding complexity of the video frame; The I-frame Lagrangian constant calculation module is used to calculate the frame-level Lagrangian multiplier of the I-frame to be encoded according to the actual number of coding bits, frame-level Lagrangian multipliers and intra-frame coding complexity of the previous encoded I-frame, combined with the target number of coding bits and intra-frame coding complexity of the I-frame to be encoded; wherein the intra-frame coding complexity of the I-frame to be encoded is obtained by replacing the intra-frame coding complexity of the previous encoded video frame of the I-frame to be encoded; The frame-level Lagrange multiplier λ of the I frame to be encoded new From formula 5: Find; where f -1 It is the inverse function of the first function f that represents the relationship between "using different frame-level Lagrange multipliers to encode the same video frame for I frame, and the ratio of the actual number of encoded bits obtained after encoding to the ratio of the frame-level Lagrange multipliers"; I(n) new Indicates the target number of bits for encoding the I frame to be encoded; I(m) old represents the actual number of coded bits of the previous coded I frame; g is the second function representing the relationship between "the ratio of the actual number of coded bits obtained after encoding different video frames using the same frame-level Lagrange multiplier to the ratio of the intra-frame coding complexity of the video frame"; ω n-1 Indicates the intra-frame coding complexity of the previous coded video frame of the I frame to be coded, which is used to replace the intra-frame coding complexity ω of the I frame to be coded n ;ω m represents the intra-frame coding complexity of the previous coded I frame; old Represents the frame-level Lagrange multiplier of the previous coded I frame.
9. The I frame rate control device suitable for hardware implementation according to claim 8, characterized in that An I-frame Lagrangian constant calculation correction module is added after the I-frame Lagrangian constant calculation module; The I-frame Lagrangian constant calculation and correction module is used to correct the first function f and the second function g used in the process of calculating the frame-level Lagrangian multipliers of the I frame to be encoded after the current I frame encoding is completed, according to the actual number of encoded bits, frame-level Lagrangian multipliers and intra-frame coding complexity of the currently encoded I frame and the previous encoded I frame.
Citation Information
Patent Citations
Code rate control method of video code
CN101094411A
Video coding mode selection method and system based on SSIM evaluation
CN103634600A