CN112188208A - Macro block level code rate control method and related device - Google Patents

Macro block level code rate control method and related device Download PDF

Info

Publication number
CN112188208A
CN112188208A CN202010988369.3A CN202010988369A CN112188208A CN 112188208 A CN112188208 A CN 112188208A CN 202010988369 A CN202010988369 A CN 202010988369A CN 112188208 A CN112188208 A CN 112188208A
Authority
CN
China
Prior art keywords
current frame
frame
macro block
bit number
macroblock
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.)
Granted
Application number
CN202010988369.3A
Other languages
Chinese (zh)
Other versions
CN112188208B (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.)
Zhejiang Dahua Technology Co Ltd
Original Assignee
Zhejiang Dahua Technology 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 Zhejiang Dahua Technology Co Ltd filed Critical Zhejiang Dahua Technology Co Ltd
Priority to CN202010988369.3A priority Critical patent/CN112188208B/en
Publication of CN112188208A publication Critical patent/CN112188208A/en
Application granted granted Critical
Publication of CN112188208B publication Critical patent/CN112188208B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04NPICTORIAL COMMUNICATION, e.g. TELEVISION
    • H04N19/00Methods or arrangements for coding, decoding, compressing or decompressing digital video signals
    • H04N19/10Methods or arrangements for coding, decoding, compressing or decompressing digital video signals using adaptive coding
    • H04N19/169Methods or arrangements for coding, decoding, compressing or decompressing digital video signals using adaptive coding characterised by the coding unit, i.e. the structural portion or semantic portion of the video signal being the object or the subject of the adaptive coding
    • H04N19/17Methods or arrangements for coding, decoding, compressing or decompressing digital video signals using adaptive coding characterised by the coding unit, i.e. the structural portion or semantic portion of the video signal being the object or the subject of the adaptive coding the unit being an image region, e.g. an object
    • H04N19/176Methods or arrangements for coding, decoding, compressing or decompressing digital video signals using adaptive coding characterised by the coding unit, i.e. the structural portion or semantic portion of the video signal being the object or the subject of the adaptive coding the unit being an image region, e.g. an object the region being a block, e.g. a macroblock
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04NPICTORIAL COMMUNICATION, e.g. TELEVISION
    • H04N19/00Methods or arrangements for coding, decoding, compressing or decompressing digital video signals
    • H04N19/10Methods or arrangements for coding, decoding, compressing or decompressing digital video signals using adaptive coding
    • H04N19/102Methods or arrangements for coding, decoding, compressing or decompressing digital video signals using adaptive coding characterised by the element, parameter or selection affected or controlled by the adaptive coding
    • H04N19/124Quantisation
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04NPICTORIAL COMMUNICATION, e.g. TELEVISION
    • H04N19/00Methods or arrangements for coding, decoding, compressing or decompressing digital video signals
    • H04N19/10Methods or arrangements for coding, decoding, compressing or decompressing digital video signals using adaptive coding
    • H04N19/134Methods or arrangements for coding, decoding, compressing or decompressing digital video signals using adaptive coding characterised by the element, parameter or criterion affecting or controlling the adaptive coding
    • H04N19/146Data rate or code amount at the encoder output

Landscapes

  • Engineering & Computer Science (AREA)
  • Multimedia (AREA)
  • Signal Processing (AREA)
  • Compression Or Coding Systems Of Tv Signals (AREA)

Abstract

The invention provides a control method of a macroblock-level code rate and a related device, wherein the control method of the macroblock-level code rate comprises the steps of obtaining a first target coding pixel bit number of a current frame, and distributing the first target coding pixel bit number to each macroblock in the current frame by utilizing a mapping model so that each macroblock of the current frame has a corresponding second target coding pixel bit number; calculating to obtain a block-level quantization parameter corresponding to each macro block in the current frame according to the second target coding pixel bit number by using a mapping model; and coding each macro block of the current frame according to the block-level quantization parameter corresponding to each macro block in the current frame so as to obtain the actual coding pixel bit number corresponding to each macro block of the current frame. The invention accurately controls the code rate and reduces the code rate fluctuation by accurately controlling the quantization parameter of each macro block.

Description

Macro block level code rate control method and related device
Technical Field
The invention relates to the technical field of video coding and decoding, in particular to a macro-block-level code rate control method and a related device.
Background
Video codec techniques aim at compressing the captured video signal into data of a different standard format for transmission or storage. The video coding and decoding standards are H.264/AVC, H.265/HEVC, VP8/VP9/AV1 and the like. The performance of video encoding and decoding mainly uses the quality of video, such as peak Signal-to-Noise ratio (psnr), (peak Signal-to-Noise ratio), structural Similarity (ssim), (structural Similarity index), and compression rate as evaluation indexes. The higher the compression rate, the lower the representative code rate, and the smaller the storage space occupied by the video file output by the encoder. The better the objective quality of the video is, the more clear the video picture feeling of the user in the video watching experience is represented to a certain extent, but the better the code rate is increased.
The code rate control is one of the key technologies of the video coding standard, and the local code rate at each moment can be controlled by adjusting the coding parameters in the coding process. The code rate control method is divided into two types: VBR (Variable Bit Rate) and CBR (Constant Bit Rate). CBR requires tighter code rate control than VBR, because CBR requires that the local code rate be kept constant, while VBR allows the local code rate to float within a certain range. With the development of multimedia technology, the performance requirement on the rate control of the video stream is also improved, and for CBR, an accurate rate can meet the requirement of not wasting bandwidth transmission data to the maximum extent.
The compressed size of a video frame is related to parameters selected by the encoder during the encoding process, including frame class (I/P/B frames), motion information, Quantization Parameter (QP), etc. The choice of different parameters has a very important impact on the coding bit rate of the final video. Among these parameters, the Quantization Parameter (QP) controls the amount of data lost during the lossy quantization process, and has a direct effect on the frame size after encoding. The frame types are classified into an intra-frame prediction (I frame), an inter-frame prediction (P frame) which can be used as a reference frame, and an inter-frame prediction (B frame) which can be used as a non-reference frame, and the size of the frame has an influence on the coding performance, for example, the intra-frame prediction is important in the coding process and may require more bits to be coded. When a coded frame is coded, the coded frame is divided into different basic coding units, which are represented by macroblocks (mb) with the size of 16 × 16 in H264, and represented by Largest Coding Units (LCUs) with the size of 64 × 64 in H265 standard, and each coding unit is subjected to prediction, quantization, entropy coding, filtering and other processes to form a complete video frame coding process. Therefore, there is a need for an encoding method capable of accurately controlling the accuracy of the video encoding size of each frame.
Disclosure of Invention
The invention provides a macro-block-level code rate control method and a related device, which accurately control the code rate and reduce the code rate fluctuation by accurately controlling the quantization parameter of each macro block.
In order to solve the above technical problems, a first technical solution provided by the present invention is: a method for controlling a macroblock-level code rate is provided, which comprises the following steps: acquiring the first target coding pixel bit number of the current frame; distributing a first target coding pixel bit number to each macro block in the current frame by using a mapping model so that each macro block of the current frame has a corresponding second target coding pixel bit number; calculating to obtain a block-level quantization parameter corresponding to each macro block in the current frame according to the second target coding pixel bit number by using a mapping model; and coding each macro block of the current frame according to the block-level quantization parameter corresponding to each macro block of the current frame to obtain the actual coding pixel bit number corresponding to each macro block of the current frame.
Wherein the allocating, by using the mapping model, a first target encoding pixel bit number to each macroblock of the current frame, so that each macroblock of the current frame has a corresponding second target encoding pixel bit number includes: encoding the previous frame of the current frame by adopting a preset quantization parameter to obtain the actual encoding pixel bit number of the previous frame and a block-level quantization parameter corresponding to each macro block in the previous frame; predicting the actual coding pixel bit number corresponding to each macro block in the previous frame by using the actual coding pixel bit number of the previous frame, the preset quantization parameter and the block-level quantization parameter corresponding to each macro block in the previous frame in combination with the gradient texture; calculating parameters of a mapping model according to the actual coding pixel bit number corresponding to each macro block in the previous frame and the block-level quantization parameters corresponding to each macro block in the previous frame, and constructing the mapping model by using the parameters of the mapping model; wherein the gradient texture comprises a gradient texture of an encoded frame and a gradient texture of an encoded macroblock.
Wherein the allocating, by using the mapping model, a first target encoding pixel bit number to each macroblock of the current frame, so that each macroblock of the current frame has a corresponding second target encoding pixel bit number includes: calculating to obtain a weight factor corresponding to each macro block in the current frame by using the parameters of the mapping model and the corresponding frame level quantization parameters in the previous frame; calculating to obtain a second target coding pixel bit number of the current frame by using a weight factor corresponding to each macro block in the current frame, the number of macro blocks in the current frame and the first target coding pixel bit number of the current frame; the weighting factor corresponding to each macro block in the current frame is in direct proportion to the second target coding pixel bit number of the current frame.
Wherein, the obtaining the first target coding pixel bit number of the current frame includes: and calculating to obtain the first target coding pixel bit number of the current frame by adopting a frame-level code rate control method.
Wherein, after encoding each macroblock of the current frame according to the block-level quantization parameter corresponding to each macroblock of the current frame to obtain the actual number of coded pixel bits corresponding to each macroblock of the current frame, the method further includes: and updating the parameters of the mapping model by using the actual coding pixel bit number corresponding to each macro block of the current frame and the block-level quantization parameter corresponding to each macro block of the current frame to obtain an updated mapping model.
Wherein, after encoding each macroblock of the current frame according to the block-level quantization parameter corresponding to each macroblock of the current frame to obtain the actual number of coded pixel bits corresponding to each macroblock of the current frame, the method further includes: acquiring the bit number of a first target coding pixel of a next frame of a current frame; distributing a first target coding pixel bit number to each macro block in the next frame by using the updated mapping model so that each macro block in the next frame has a corresponding second target coding pixel bit number; calculating to obtain a block-level quantization parameter corresponding to each macro block in the next frame according to the second target coding pixel bit number by using the updated mapping model; and encoding each macro block of the next frame by using the block-level quantization parameter corresponding to each macro block in the next frame to obtain the actual encoding pixel bit number corresponding to each macro block of the next frame.
Wherein the allocating a first target encoding pixel bit number to each macroblock in the next frame by using the updated mapping model so that each macroblock in the next frame has a corresponding second target encoding pixel bit number comprises: calculating to obtain a weight factor corresponding to each macro block in the next frame by using the updated mapping model parameters and the block-level quantization parameters corresponding to each macro block in the current frame; calculating to obtain a second target coding pixel bit number of the next frame by using the weight factor corresponding to each macro block in the next frame, the macro block number of the next frame and the first target coding pixel bit number of the next frame; and the weighting factor corresponding to each macro block in the next frame is in direct proportion to the second target coding pixel bit number of the next frame.
In order to solve the above technical problems, a second technical solution provided by the present invention is: provided is a macroblock-level rate control device, including: the encoding information acquisition module is used for acquiring the number of first target encoding pixel bits of the current frame; a bit allocation module, configured to allocate a first target coding pixel bit number to each macroblock in the current frame by using a mapping model, so that each macroblock of the current frame has a corresponding second target coding pixel bit number; the calculation module is used for calculating and obtaining a block-level quantization parameter corresponding to each macro block in the current frame according to the second target coding pixel bit number by using a mapping model; and the coding module is used for coding each macro block of the current frame according to the block-level quantization parameter corresponding to each macro block of the current frame so as to obtain the actual coding pixel bit number corresponding to each macro block of the current frame.
In order to solve the above technical problems, a third technical solution provided by the present invention is: the macro-block level nanofiltration control method comprises the following steps: encoding a current frame by adopting a preset quantization parameter to obtain the actual encoding pixel bit number of the current frame and a block-level quantization parameter corresponding to each macro block in the current frame; predicting the actual coding pixel bit number corresponding to each macro block in the current frame by using the actual coding pixel bit number of the current frame, the preset quantization parameter and the block-level quantization parameter corresponding to each macro block in the current frame in combination with the gradient texture; calculating parameters of a mapping model according to the actual coding pixel bit number corresponding to each macro block in the current frame and the block-level quantization parameters corresponding to each macro block in the current frame, and constructing the mapping model by using the parameters of the mapping model; acquiring the bit number of a first target coding pixel of a next frame of a current frame; distributing a first target coding pixel bit number to each macro block in the next frame by using a mapping model so that each macro block of the next frame has a corresponding second target coding pixel bit number; calculating to obtain a block-level quantization parameter corresponding to each macro block in the next frame according to the second target coding pixel bit number by using a mapping model; and coding each macro block of the next frame of the current frame according to the block-level quantization parameter corresponding to each macro block in the next frame of the current frame so as to obtain the actual coded pixel bit number corresponding to each macro block of the next frame of the current frame.
Wherein the allocating, by using the mapping model, a first target number of coded pixel bits to each macroblock in the next frame, so that each macroblock in the next frame has a corresponding second target number of coded pixel bits includes: calculating to obtain a weight factor corresponding to each macro block in the next frame of the current frame by using the parameters of the mapping model and the corresponding frame-level quantization parameters in the current frame; calculating to obtain a second target coding pixel bit number of the next frame of the current frame by using a weight factor corresponding to each macro block in the next frame of the current frame, the number of macro blocks in the next frame of the current frame and the first target coding pixel bit number of the next frame of the current frame; the weighting factor corresponding to each macro block in the next frame of the current frame is in direct proportion to the second target coding pixel bit number of the next frame of the current frame.
In order to solve the above technical problems, a fourth technical solution provided by the present invention is: provided is a macroblock-level rate control device, including: the first coding module is used for coding a current frame by adopting a preset quantization parameter so as to obtain the actual coding pixel bit number of the current frame and a block-level quantization parameter corresponding to each macro block in the current frame; the prediction module is used for predicting the actual coding pixel bit number corresponding to each macro block in the current frame by using the actual coding pixel bit number of the current frame, the preset quantization parameter and the block-level quantization parameter corresponding to each macro block in the current frame in combination with the gradient texture; a mapping model construction module, configured to calculate parameters of a mapping model according to the actual coded pixel bit number corresponding to each macroblock in the current frame and the block-level quantization parameter corresponding to each macroblock in the current frame, and construct the mapping model using the parameters of the mapping model; the encoding information acquisition module is used for acquiring the number of first target encoding pixel bits of the next frame of the current frame; a bit allocation module, configured to allocate a first target number of coded pixel bits to each macroblock in the next frame by using a mapping model, so that each macroblock in the next frame has a corresponding second target number of coded pixel bits; the calculation module is used for calculating and obtaining a block-level quantization parameter corresponding to each macro block in the next frame according to the second target coding pixel bit number by using a mapping model; and the second coding module is used for coding each macro block of the next frame of the current frame according to the block-level quantization parameter corresponding to each macro block in the next frame of the current frame so as to obtain the actual coding pixel bit number corresponding to each macro block of the next frame of the current frame.
In order to solve the above technical problems, a fifth technical solution provided by the present invention is: provided is an electronic device including: the device comprises a memory and a processor, wherein the memory stores program instructions, and the processor calls the program instructions from the memory to execute any one of the macroblock-level rate control methods.
In order to solve the above technical problems, a sixth technical solution provided by the present invention is: there is provided a computer readable storage medium storing a program file executable to implement the macroblock-level rate control method of any of the above.
The method has the advantages that the method is different from the prior art, and distributes the second target coding pixel bit number for each macro block in the current frame by utilizing the mapping model according to the first target coding pixel bit number of the current frame; calculating a block-level quantization parameter corresponding to each macro block in the current frame by using a mapping model according to the number of second target coding pixel bits allocated to each macro block in the current frame; and coding each macro block of the current frame according to the block-level quantization parameter corresponding to each macro block in the current frame so as to obtain the actual coding pixel bit number corresponding to each macro block of the current frame. The invention accurately controls the code rate and reduces the code rate fluctuation by accurately controlling the quantization parameter of each macro block.
Drawings
In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the drawings needed to be used in the description of the embodiments are briefly introduced below, it is obvious that the drawings in the following description are only some embodiments of the present invention, and other drawings can be obtained by those skilled in the art without inventive efforts, wherein:
fig. 1 is a schematic flow chart of a macroblock-level rate control method according to a first embodiment of the present invention;
FIG. 2 is a flowchart illustrating an embodiment of step S12 in FIG. 1;
FIG. 3 is a schematic flow chart illustrating another embodiment of step S12 in FIG. 1;
fig. 4 is a flowchart of a macroblock-level rate control method according to a second embodiment of the present invention;
fig. 5 is a schematic structural diagram of a macroblock-level rate control apparatus according to a first embodiment of the present invention;
fig. 6 is a flowchart of a macroblock-level rate control method according to a second embodiment of the present invention;
fig. 7 is a schematic structural diagram of a macroblock-level rate control apparatus according to a second embodiment of the present invention;
FIG. 8 is a flowchart illustrating a second embodiment of an electronic device according to the present invention;
fig. 9 is a schematic structural diagram of a computer-readable storage medium according to the present invention.
Detailed Description
The technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application, and it is obvious that the described embodiments are only a part of the embodiments of the present application, and not all of the embodiments. 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 application.
In the prior art, a document Rate control by R-lambda model for HEVC is a code Rate control method of video coding standard h.265/HEVC, and the design key points are that according to a hyperbolic function relationship between a code Rate R and a texture complexity D, it is further deduced that a hyperbolic function relationship also exists between the code Rate R and a lagrangian constant λ, and λ is closely related to a Rate distortion optimization process and a quantization parameter in video coding and directly affects a code Rate of actual coding, so that the code Rate generated in the video coding process is close to or even consistent with a set phase under the condition of setting an exact target code Rate through the hyperbolic model of the code Rate R and the lagrangian constant λ, thereby achieving the purpose of code Rate control. But its main disadvantages are: the coupling of the rate control function and the H.265 video coding standard is high, and the calculated Lagrangian constant lambda can be used in the coding mode decision process in the H.265 video coding standard, so that the whole rate control technology cannot be separated from the standard, which means that the rate control technology is limited to the standard, and the technology cannot be applied to other video coding standards; in addition, the lagrangian constant λ acted on by the algorithm can act on the mode selection process of the H265 coding standard, and the hardware coding and decoding chip has solidified the whole coding process, so that the rate control technology is difficult to integrate.
The patent discloses a self-adaptive macro-block-level code rate control system and a self-adaptive macro-block-level code rate control method suitable for video compression. The method divides an image into macro blocks with the size of 16x16, calculates a texture characteristic MAD value of each macro block, calculates a quantization parameter QP offset value of each macro block by setting 16 different MAD threshold values, and calculates a quantization parameter QP used by macro block coding by overlapping with a frame-level quantization parameter QP. The calculation formula of the macroblock-level quantization parameter QP is calculated according to the frame-level quantization parameter QP and the texture feature MAD of the macroblock, the value of the macroblock-level quantization parameter QP has no relation with the target size and the target code rate of the current frame, and the effect that the macroblock-level quantization parameter QP can control the target size of a single frame or the code rate of video coding cannot be proved.
The patent relates to an H.264/AVC code rate control method based on active macro block hiding. The method comprises the steps that different target coding bit numbers are distributed for NROI (non-region of interest) macroblocks and ROI macroblocks which are preset according to the target bit number of video frame coding; in the H.264/AVC standard, when an NROI macroblock is coded, skip mode coding is selected; when the ROI macro block is coded, coding is carried out by adopting a coding method specified by a standard; and after the current macro block is coded, starting the code rate control of the next macro block. NROI reduces the bits used and allocates the saved bits to the uncoded ROI macroblocks, so that the ROI gets more bits, improving the ROI coding quality and also improving the visual quality. The method of the patent can be realized only in the H.264/AVC standard, has high coupling with a code rate control algorithm on the standard open source reference software JM of the H.264/AVC, and cannot be applied to other video coding standards, software and hardware encoders and the like.
The invention provides a macro-block-level code rate control method which can effectively improve the accuracy of controlling the size of each frame of video code, thereby reducing the fluctuation problem of the whole code rate caused by control deviation, and the problems can cause delay and blockage of code stream in transmission. For most video coding and decoding software, hardware and the like, the method provided by the proposal can be suitable, has low algorithm using condition and cost and high independence, and can be integrated into different video coding standards for use.
The present invention will be described in detail below with reference to the accompanying drawings and examples.
Please refer to fig. 1, which is a flowchart illustrating a macroblock-level rate control method according to a first embodiment of the present invention. The method comprises the following steps:
step S11: and acquiring the first target coding pixel bit number of the current frame. (Rf)target)
Specifically, in an embodiment, a frame-level code rate control method is used to calculate the first target coding pixel bit number required for coding the current frame.
Step S12: and allocating a first target coding pixel bit number to each macro block in the current frame by using a mapping model so that each macro block of the current frame has a corresponding second target coding pixel bit number.
Specifically, the mapping model is:
Figure BDA0002689987290000091
wherein R ismbIs the actual number of coded pixel bits, ocmbAnd betambAs model parameters of the current block, QscaleMapping parameters for quantization parameter QP, specifically, QscaleThe relation to the quantization parameter QP is: qscale=0.85·2(QP-12)/6
Specifically, allocating a first target encoding pixel bit number to each macroblock in the current frame by using a mapping model, so that each macroblock in the current frame has a corresponding second target encoding pixel bit number, further includes: and (3) establishing a mapping model, specifically, the mapping model is shown in the formula (1).
Referring to fig. 2, the method for establishing the mapping model includes:
step S21: and coding the previous frame of the current frame by adopting a preset quantization parameter to obtain the actual coding pixel bit number of the previous frame and a block-level quantization parameter corresponding to each macro block in the previous frame.
Specifically, the current frame is the second frame, and the previous frame of the current frame is the first frame. For the first frame, a preset quantization parameter QP is adopted0And coding the first frame to obtain the actual coding pixel bit number of the first frame and the block-level quantization parameter corresponding to each macro block in the first frame.
Step S22: and predicting the actual coded pixel bit number corresponding to each macro block in the previous frame by using the actual coded pixel bit number of the previous frame, the preset quantization parameter and the block-level quantization parameter corresponding to each macro block in the first frame in combination with the gradient texture.
Specifically, the gradient texture includes a gradient texture of an encoded frame and a gradient texture of an encoded macroblock. The actual coding pixel bit number corresponding to each macro block in the first frame is predicted by using the actual coding pixel bit number of the first frame, the preset quantization parameter and the block-level quantization parameter corresponding to each macro block in the first frame in combination with the gradient texture in a manner that:
Figure BDA0002689987290000092
wherein R is0,mb predThe number of actual coded pixel bits, R, corresponding to each macroblock in the first framef actualThe Qscale0 is the quantization mapping parameter of the preset quantization parameter QP0, which is the actual number of coded pixel bits of the first frame, specifically,
Figure BDA0002689987290000101
qscale0, mb is a block-level quantization parameter corresponding to each macroblock of the first intermediate frame, specifically, Qscale0,mb=0.85×2(QPmb-12)/6Beta is a parameter constant, and in one embodiment, beta is taken to be-1.
Wherein Gmb is the gradient texture of the coding macro block, and Gf is the gradient texture of the coding frame, and the calculation method is as follows:
Figure BDA0002689987290000102
wherein, when G is the gradient texture G of the coding macro blockmbHere, w, h is the width and height 16 of the block, and G is the gradient texture G of the encoded framefHere, the width and height are the resolution of the video, such as 1920 × 1080. i, j are pixel coordinates of the current block or video frame, and Y (i, j) is a pixel value of the corresponding coordinate.
In this embodiment, the frame coding method is adopted for the first 1 frame, i.e. the first frame, so that the quantization parameters QP of all macroblocks in the frame are equal to the frame quantization parameter QP.
Step S23: and calculating parameters of a mapping model according to the actual coding pixel bit number corresponding to each macro block in the previous frame and the block-level quantization parameters corresponding to each macro block in the previous frame, and constructing the mapping model by using the parameters of the mapping model.
Specifically, the actual number of coded pixel bits R corresponding to each macroblock in the first frame is set0,mb predAnd the mapping value Q of the block-level quantization parameter corresponding to each macro block in the first framescale0,mbSubstituting the formula (1) into the above formula (1), and calculating the mapping parameters oc mb and β mb of the mapping model.
Substituting the calculated mapping parameters oc mb and β mb into the formula (1) to obtain the mapping model.
Specifically, in this embodiment, after the mapping model is obtained through calculation, the mapping model is used to obtain the block-level quantization parameter corresponding to each macroblock in the current frame through calculation.
Specifically, please refer to fig. 3, which includes:
step S31: and calculating to obtain a weight factor corresponding to each macro block in the current frame by using the parameters of the mapping model and the corresponding frame level quantization parameters.
Specifically, the way of calculating the weighting factor corresponding to each macroblock in the current frame by using the parameters of the mapping model and the corresponding frame-level quantization parameters is as follows:
Figure BDA0002689987290000112
wherein, taking the previous frame of the current frame as the first frame as an example for explanation, ω ismbA weighting factor corresponding to each macro block in the current frame, wherein oc mb and beta mb are model parameters, and Qscale isfThe mapped value of the quantization parameter may be, for example, Q for the corresponding frame level in the first framescale0,mb
Specifically, since the first frame adopts a frame coding manner, the corresponding frame-level quantization parameter in the first frame is the same as the block-level quantization parameter of all macroblocks in the frame.
Step S32: and calculating to obtain a second target coding pixel bit number of the current frame by using the weight factor corresponding to each macro block in the current frame, the number of macro blocks in the current frame and the first target coding pixel bit number of the current frame.
The weighting factor corresponding to each macro block in the current frame is in direct proportion to the second target coding pixel bit number of the current frame.
For example, the second target encoding pixel bit number of the current frame can be calculated as follows:
Figure BDA0002689987290000111
wherein N is the number of all macro blocks in one frame; for the jth macroblock, the allocated second target coding pixel bit number is Rmb alloc[j],Rf targetThe number of pixel bits is encoded for a first target of the current frame.
In the present application, a quantization parameter value of a current macroblock is calculated by using a mapping model and parameters. According to the method, according to the weight relation among different textures of each macro block, a macro block with complex textures is distributed with a large frame bit number proportion, a macro block with simple textures is distributed with a small frame bit number proportion, different macro block quantization parameters are calculated and used for coding macro blocks of each frame, the bit number of the current frame is controlled more reasonably, and the purpose of improving the picture quality of the current frame is achieved.
Step S13: and calculating to obtain a block-level quantization parameter corresponding to each macro block in the current frame according to the second target coding pixel bit number by using a mapping model.
Specifically, the second target encoding pixel bit number R of each macro block in the current frame calculated according to the above formula (2)mb alloc[j]And calculating to obtain a block-level quantization parameter QP corresponding to each macro block in the current frame by utilizing a mapping model.
Specifically, the obtained second target coding pixel bit number R is usedmb alloc[j]Substituting the obtained value into the formula (1) to further calculate and obtain a mapping value of the quantization parameter corresponding to each macro block of the current frame, and then calculating and obtaining the quantization parameter QP corresponding to each macro block of the current frame according to the relationship between the mapping value and the quantization parameter.
Step S14: and coding each macro block of the current frame according to the block-level quantization parameter corresponding to each macro block in the current frame so as to obtain the actual coding pixel bit number corresponding to each macro block of the current frame.
Specifically, each macroblock of the current frame is encoded by using the obtained block-level quantization parameter QP corresponding to each macroblock, and the actual number of coded pixel bits corresponding to each macroblock of the current frame is obtained.
Specifically, in an embodiment, the current frame shown in this embodiment is regarded as the second frame, and the previous frame of the current frame is regarded as the first frame. Then, for the first frame, the first frame is encoded by using the preset quantization parameter QP0 to obtain the actual number of coded pixel bits of the first frame and the block-level quantization parameter corresponding to each macroblock in the first frame. Predicting the corresponding macro block in the first frame by using the actual coding pixel bit number of the first frame, the preset quantization parameter and the block-level quantization parameter corresponding to each macro block in the first frame in combination with the gradient textureThe actual number of coded pixel bits. Then the actual coding pixel bit number R corresponding to each macro block in the first frame0,mb predAnd substituting the mapping value Qscale0, mb of the block-level quantization parameter corresponding to each macro block in the first frame into the formula (1), and calculating to obtain the mapping parameters oc mb, beta mb of the mapping model so as to establish the mapping model. Specifically, a weighting factor corresponding to each macro block in the current frame is calculated by using the parameters of the mapping model and the corresponding frame-level quantization parameters in the previous frame; and calculating to obtain a second target coding pixel bit number of the current frame by using the weight factor corresponding to each macro block in the current frame, the number of macro blocks in the current frame and the first target coding pixel bit number of the current frame. And calculating to obtain a block-level quantization parameter corresponding to each macro block in the current frame by using the mapping model according to the second target coding pixel bit number distributed to each macro block in the current frame. And coding each macro block of the current frame according to the block-level quantization parameter corresponding to each macro block in the current frame so as to obtain the actual coding pixel bit number corresponding to each macro block of the current frame. Specifically, because the quantization parameter controls the size of the lost data amount in the lossy quantization processing process, and has a direct influence on the size of the encoded frame, the macroblock-level rate control method described in this embodiment accurately controls the rate by accurately controlling the quantization parameter of each macroblock, and has the advantages of high rate control accuracy and low rate fluctuation. By calculating the quantization parameter of each macro block, the actual coding bit number of the video coding frame can be controlled to be closer to the target bit number, and the fluctuation caused by the control deviation of the video frame level code rate during coding is effectively reduced. The bit rate control method has the advantages of controlling the size of a single frame and improving the picture quality of a video coding frame, reasonably distributes the bit number of each macro block in the frame, for example, the macro block with complex texture distributes a larger frame bit number proportion, and the macro block with simple texture distributes a smaller frame bit number proportion. In addition, the code rate control method can be suitable for software coding and decoding and hardware coding and decoding chips. For theThe coding internal information which cannot be obtained in hardware like coding and decoding software, such as the coding bit number and texture characteristics of a macroblock level, can be obtained by calculating the texture complexity of the proposal and predicting the coding bit number of the macroblock level, so that the method of the proposal can be used for controlling the code rate of video coding and acts on a software and hardware coder.
Fig. 4 is a flowchart illustrating a macroblock-level rate control method according to a second embodiment of the present invention. Specifically, wherein steps S41 to S44 are the same as steps S11 to S14 shown in fig. 1, compared with the embodiment shown in fig. 1, the difference is that the embodiment further includes:
step S45: and updating the parameters of the mapping model by using the actual coding pixel bit number corresponding to each macro block of the current frame and the block-level quantization parameter corresponding to each macro block of the current frame to obtain an updated mapping model.
Specifically, the parameters of the mapping model are updated by using the actual number of coded pixel bits corresponding to each macroblock of the current frame and the block-level quantization parameter corresponding to each macroblock of the current frame in the following manner:
Figure BDA0002689987290000132
αk+1,mb′=αk,mb+α·(ln Rk,mb pred-ln Rk,mb′)·αk,mb
Figure BDA0002689987290000131
βk+1,mb=βk,mb+β·(ln Rk,mb pred-ln Rk,mb′)·ln Qscalek,mb
wherein, tau is a weight coefficient,αandβis the step size coefficient, k is the frame number, Rk,mb' indicates actual coding corresponding to each macroblock of the k-th frameNumber of pixel bits for updating parameters of code-controlled model, alphak+1,mbAnd betak+1,mbFor updating the coding model parameters of each macroblock in the current k +1 frame, the coding model parameters are used for constructing the macroblock coding model of formula (1), Rk,mb predFor the actual number of coded pixel bits, Qscale, corresponding to each macroblock in the kth frameR,mbQP mapping values for each different macroblock of the kth frame.
Specifically, when the mapping model is updated, the macro blocks at one position are updated in a one-to-one correspondence manner.
Step S46: and acquiring the first target coding pixel bit number of the next frame of the current frame.
Specifically, the following frame of the current frame is taken as the third frame for example. And calculating to obtain the first target coding pixel bit number required by the third frame coding by using a frame-level code rate control method.
Step S47: and distributing the first target coding pixel bit number of the next frame to each macro block in the next frame according to the updated mapping model so as to enable each macro block in the next frame to have a corresponding second target coding pixel bit number.
Specifically, the mapping model is represented by formula (1), wherein the mapping parameter ∈mbAnd betambThe mapping parameters are updated through the second frame.
Specifically, the second target encoding pixel bit can be allocated to each macroblock in the next frame according to the first target encoding pixel bit number of the next frame by using the above equation (2).
Specifically, a weighting factor corresponding to each macroblock in the next frame is calculated by using the updated parameters of the mapping model and the block-level quantization parameters corresponding to each macroblock in the current frame; calculating to obtain a second target coding pixel bit number of the next frame by using a weighting factor corresponding to each macro block in the next frame, the macro block number of the next frame and the first target coding pixel bit number of the next frame according to a formula (2); and the weighting factor corresponding to each macro block in the next frame is in direct proportion to the second target coding pixel bit number of the next frame.
Step S48: and calculating to obtain a block-level quantization parameter corresponding to each macro block in the next frame according to the second target coding pixel bit number by using the updated mapping model.
Specifically, the second target coding pixel allocated to each macroblock of the next frame calculated according to the above formula (2) is calculated by using a mapping model to obtain a block-level quantization parameter QP corresponding to each macroblock in the current frame.
Specifically, the obtained second target coding pixel bit number R is usedmb alloc[j]Substituting the obtained value into the formula (1) to further calculate and obtain a mapping value of the quantization parameter corresponding to each next macro block, and then calculating and obtaining the quantization parameter QP corresponding to each macro block of the next frame according to the relationship between the mapping value and the quantization parameter.
Step S49: and encoding each macro block of the next frame by using the block-level quantization parameter corresponding to each macro block in the next frame to obtain the actual encoding pixel bit number corresponding to each macro block of the next frame.
Specifically, each macroblock of the next frame is encoded by using the obtained block-level quantization parameter QP corresponding to each macroblock of the next frame, and then the actual number of coded pixel bits corresponding to each macroblock of the next frame is obtained.
Specifically, the macroblock-level code rate control method provided in the present invention is described by way of example. For example, when a 1080P video is encoded, encoding is performed under a target rate setting of 4096kbps controlled by an average rate, and other encoding settings are set as default settings.
And for different types of I/P/B frames of the coded frame, respectively and independently adopting the current macroblock-level code control model to carry out code rate control. Since the flows of different types of frames are consistent, the following takes an I frame as an example. For the first frame I frame encoding, a fixed quantization parameter QP is used0Coding is carried out, and after one frame is coded, the actual coding pixel bit number R of the current frame can be obtainedf actualQuantization parameter QP for each macroblock within a framemb. To obtain the actual pixel bits for each macroblock of the encoded frameNumber, using gradient texture GfNumber of frame-coded pixel bits Rf actualAnd current frame actual coding QP0To predict the number of coded pixel bits R of each macroblocko,mb pred
Using the predicted number of coded pixel bits R per macroblock of the first frame0,mb predAnd quantization parameter QP for each macroblockmbA mapping model is constructed using equation (1) above for macroblock-level coding of the second frame.
For the second detection, after the 1 st frame is encoded, the number R of encoding pixel bits of each macro block is predicted0,mb predAnd quantization parameter QP for each macroblockmbAnd updating the mapping model to obtain an updated mapping model. And calculating to obtain the first target coding pixel bit number required by the second frame coding by adopting a frame-level code rate control method. And distributing a second target coding pixel bit number for each macro block in the second frame according to the first target coding pixel bit number of the second frame by using the updated model. And calculating to obtain a block-level quantization parameter corresponding to each macro block in the second frame by utilizing the mapping model according to the second target coding pixel bit number distributed to each macro block in the second frame. And coding each macro block of the second frame according to the block-level quantization parameter corresponding to each macro block in the second frame to obtain the actual coded pixel bit number corresponding to each macro block of the second frame.
And for the third frame, after the 2 nd frame is coded, updating the mapping model through the actual coded pixel bit number corresponding to each macro block of the second frame and the quantization parameter of each macro block to obtain an updated mapping model. And calculating to obtain the first target coding pixel bit number required by the third frame coding by adopting a frame-level code rate control method. And distributing a second target coding pixel bit number for each macro block in the third frame according to the first target coding pixel bit number of the third frame by using the updated model. And calculating to obtain a block-level quantization parameter corresponding to each macro block in the third frame by using the mapping model according to the second target coding pixel bit number distributed to each macro block in the third frame. And coding each macro block of the third frame according to the block-level quantization parameter corresponding to each macro block in the third frame to obtain the actual coded pixel bit number corresponding to each macro block of the third frame.
And for the fourth frame, after the 3 rd frame is coded, updating the mapping model through the actual coded pixel bit number corresponding to each macro block of the third frame and the quantization parameter of each macro block to obtain an updated mapping model. The above steps are repeated here until the encoding is completed.
Specifically, because the quantization parameter controls the size of the lost data amount in the lossy quantization processing process, and has a direct influence on the size of the encoded frame, the macroblock-level rate control method described in this embodiment accurately controls the rate by accurately controlling the quantization parameter of each macroblock, and has the advantages of high rate control accuracy and low rate fluctuation. By calculating the quantization parameter of each macro block, the actual coding bit number of the video coding frame can be controlled to be closer to the target bit number, and the fluctuation caused by the control deviation of the video frame level code rate during coding is effectively reduced. The bit rate control method has the advantages of controlling the size of a single frame and improving the picture quality of a video coding frame, reasonably distributes the bit number of each macro block in the frame, for example, the macro block with complex texture distributes a larger frame bit number proportion, and the macro block with simple texture distributes a smaller frame bit number proportion. In addition, the code rate control method can be suitable for software coding and decoding and hardware coding and decoding chips. For the coded internal information which cannot be obtained in hardware like coding and decoding software, such as the coding bit number and texture characteristics of a macroblock level, the coded internal information can be obtained by calculating the texture complexity of the proposal and predicting the coding bit number of the macroblock level, so that the method of the proposal can be used for controlling the code rate of video coding and acting on a software and hardware coder.
Referring to fig. 5, a schematic structural diagram of a macroblock-level rate control apparatus according to a first embodiment of the present invention includes: an encoding information acquisition module 51, a bit allocation module 52, a calculation module 53 and an encoding module 54.
The encoding information obtaining module 51 is configured to obtain a first target encoding pixel bit number of the current frame. The bit allocation module 52 is configured to allocate a first target number of coded pixel bits to each macroblock in the current frame by using a mapping model, so that each macroblock in the current frame has a corresponding second target number of coded pixel bits. The calculating module 53 is configured to calculate, by using a mapping model, a block-level quantization parameter corresponding to each macroblock in the current frame according to the second target coding pixel bit number. The encoding module 54 is configured to encode each macroblock in the current frame according to the block-level quantization parameter corresponding to each macroblock in the current frame, so as to obtain an actual number of coded pixel bits corresponding to each macroblock in the current frame.
Referring to fig. 6, a flowchart of a macroblock-level rate control method according to a second embodiment of the present invention includes:
step S61: and coding the current frame by adopting a preset quantization parameter to obtain the actual coding pixel bit number of the current frame and a block-level quantization parameter corresponding to each macro block in the current frame.
Specifically, the present embodiment takes the current frame as the first frame as an example for explanation. For the current frame, a preset quantization parameter QP is adopted0And coding the current frame to obtain the actual coded pixel bit number of the current frame and the block-level quantization parameter corresponding to each macro block in the current frame.
Step S62: and predicting the actual coding pixel bit number corresponding to each macro block in the current frame by using the actual coding pixel bit number of the current frame, the preset quantization parameter and the block-level quantization parameter corresponding to each macro block in the current frame in combination with the gradient texture.
Specifically, the gradient texture includes a gradient texture of an encoded frame and a gradient texture of an encoded macroblock. The actual coding pixel bit number corresponding to each macro block in the current frame is predicted by combining the actual coding pixel bit number of the current frame, the preset quantization parameter and the block-level quantization parameter corresponding to each macro block of the current frame with the gradient texture:
Figure BDA0002689987290000181
wherein R is0,mb predThe number of actual coded pixel bits, R, corresponding to each macroblock in the first framef actualThe Qscale0 is the quantization mapping parameter of the preset quantization parameter QP0, which is the actual number of coded pixel bits of the first frame, specifically,
Figure BDA0002689987290000182
qscale0, mb is a block-level quantization parameter corresponding to each macroblock of the first intermediate frame, specifically, Qscale0,mb=0.85×2(QPmb-12)/6Beta is a parameter constant, and in one embodiment, beta is taken to be-1.
Wherein Gmb is the gradient texture of the coding macro block, and Gf is the gradient texture of the coding frame, and the calculation method is as follows:
Figure BDA0002689987290000183
wherein, when G is the gradient texture G of the coding macro blockmbHere, w, h is the width and height 16 of the block, and G is the gradient texture G of the encoded framefHere, the width and height are the resolution of the video, such as 1920 × 1080. i, j are pixel coordinates of the current block or video frame, and Y (i, j) is a pixel value of the corresponding coordinate.
In this embodiment, the frame coding method is adopted for the first 1 frame, i.e. the first frame, so that the quantization parameters QP of all macroblocks in the frame are equal to the frame quantization parameter QP.
Step S63: and calculating parameters of a mapping model according to the actual coding pixel bit number corresponding to each macro block in the current frame and the block-level quantization parameters corresponding to each macro block in the current frame, and constructing the mapping model by using the parameters of the mapping model.
Specifically, the actual number of coded pixel bits R corresponding to each macroblock in the first frame is set0,mb predAnd each macro block in the first frameMapping value Q of corresponding block-level quantization parameterscale0,mbSubstituting the formula:
Figure BDA0002689987290000185
and calculating to obtain mapping parameters of the mapping model, which are oc mb and beta mb.
Substituting the calculated mapping parameters oc mb and beta mb into the formula Rmb=∝mb·
Figure BDA0002689987290000184
And then a mapping model is obtained.
Specifically, in this embodiment, after the mapping model is obtained through calculation, the mapping model is used to obtain the block-level quantization parameter corresponding to each macroblock in the next frame of the current frame through calculation.
Step S64: and acquiring the first target coding pixel bit number of the next frame of the current frame.
Specifically, in an embodiment, a frame-level code rate control method is used to calculate a first target coding pixel bit number required for coding a next frame of a current frame. Specifically, the next frame of the current frame in the present embodiment may refer to the second frame.
Step S65: and allocating a first target coding pixel bit number to each macro block in the next frame by using a mapping model so that each macro block of the next frame has a corresponding second target coding pixel bit number.
Specifically, the mapping model is:
Figure BDA0002689987290000191
wherein R ismbIs the actual number of coded pixel bits, ocmbAnd betambAs model parameters of the current block, QscaleMapping parameters for quantization parameter QP, specifically, QscaleThe relation to the quantization parameter QP is: qscale=0.85·2(QP-12)/6
In this embodiment, allocating a second target encoding pixel bit number to each macroblock in the next frame of the current frame by using the mapping model according to the first target encoding pixel bit number of the next frame of the current frame specifically includes: and calculating to obtain a weight factor corresponding to each macro block in the next frame of the current frame by using the parameters of the mapping model and the corresponding frame-level quantization parameters in the current frame. Specifically, the way of calculating the weight factor corresponding to each macroblock in the next frame of the current frame by using the parameters of the mapping model and the corresponding frame-level quantization parameters is as follows:
Figure BDA0002689987290000192
wherein, taking the next frame of the current frame as the second frame as an example for explanation, ω ismbA weighting factor corresponding to each macro block in the next frame of the current frame, wherein oc mb and beta mb are model parameters, and Qscale isfThe mapped value of the quantization parameter may be, for example, Q for the corresponding frame level in the first framescale0,mb
Specifically, since the first frame adopts a frame coding manner, the corresponding frame-level quantization parameter in the first frame is the same as the block-level quantization parameter of all macroblocks in the frame.
And calculating to obtain a second target coding pixel bit number of the next frame of the current frame by using the weight factor corresponding to each macro block in the next frame of the current frame, the number of macro blocks in the next frame of the current frame and the first target coding pixel bit number of the next frame of the current frame. Specifically, the weighting factor corresponding to each macroblock in the next frame of the current frame is in a direct proportion to the number of second target coding pixel bits in the next frame of the current frame.
For example, the second target encoding pixel bit number of the next frame of the current frame can be calculated as follows:
Figure BDA0002689987290000201
wherein N is the number of all macro blocks in one frame; for the jth macroblock, divide intoThe second target coding pixel bit number is Rmb alloc[j],Rf targetThe number of pixel bits is encoded for a first target of a next frame of the current frame.
In the present application, a quantization parameter value of a current macroblock is calculated by using a mapping model and parameters. According to the method, according to the weight relation among different textures of each macro block, a macro block with complex textures is distributed with a large frame bit number proportion, a macro block with simple textures is distributed with a small frame bit number proportion, different macro block quantization parameters are calculated and used for coding macro blocks of each frame, the bit number of the current frame is controlled more reasonably, and the purpose of improving the picture quality of the current frame is achieved.
Step S66: and calculating to obtain a block-level quantization parameter corresponding to each macro block in the next frame according to the second target coding pixel bit number by using a mapping model.
Specifically, the second target coding pixel bit number of each macroblock in the next frame of the current frame, which is calculated according to the formula (2), is calculated by using a mapping model to obtain a block-level quantization parameter QP corresponding to each macroblock in the next frame of the current frame.
Specifically, the obtained second target coding pixel bit number R is usedmb alloc[j]Substitution formula
Figure BDA0002689987290000202
And then calculating to obtain a mapping value of the quantization parameter corresponding to each macro block of the next frame of the current frame, and calculating to obtain the quantization parameter QP corresponding to each macro block of the next frame of the current frame according to the relationship between the mapping value and the quantization parameter.
Step S67: and coding each macro block of the next frame of the current frame according to the block-level quantization parameter corresponding to each macro block in the next frame of the current frame so as to obtain the actual coded pixel bit number corresponding to each macro block of the next frame of the current frame.
Specifically, each macroblock of the next frame of the current frame is encoded by using the obtained block-level quantization parameter QP corresponding to each macroblock, and the actual number of coded pixel bits corresponding to each macroblock of the next frame of the current frame is further obtained.
Specifically, because the quantization parameter controls the size of the lost data amount in the lossy quantization processing process, and has a direct influence on the size of the encoded frame, the macroblock-level rate control method described in this embodiment accurately controls the rate by accurately controlling the quantization parameter of each macroblock, and has the advantages of high rate control accuracy and low rate fluctuation. By calculating the quantization parameter of each macro block, the actual coding bit number of the video coding frame can be controlled to be closer to the target bit number, and the fluctuation caused by the control deviation of the video frame level code rate during coding is effectively reduced. The bit rate control method has the advantages of controlling the size of a single frame and improving the picture quality of a video coding frame, reasonably distributes the bit number of each macro block in the frame, for example, the macro block with complex texture distributes a larger frame bit number proportion, and the macro block with simple texture distributes a smaller frame bit number proportion. In addition, the code rate control method can be suitable for software coding and decoding and hardware coding and decoding chips. For the coded internal information which cannot be obtained in hardware like coding and decoding software, such as the coding bit number and texture characteristics of a macroblock level, the coded internal information can be obtained by calculating the texture complexity of the proposal and predicting the coding bit number of the macroblock level, so that the method of the proposal can be used for controlling the code rate of video coding and acting on a software and hardware coder.
Fig. 7 is a schematic structural diagram of a macroblock-level rate control apparatus according to a second embodiment of the present invention, including: a first encoding module 71, a prediction module 72, a mapping model construction module 73, an encoding information acquisition module 74, a bit allocation module 75, a calculation module 76, and a second encoding module 77.
The first encoding module 71 encodes the current frame by using a preset quantization parameter to obtain an actual number of coded pixel bits of the current frame and a block-level quantization parameter corresponding to each macroblock in the current frame.
The prediction module 72 is configured to predict the actual number of coded pixel bits corresponding to each macroblock in the current frame by using the actual number of coded pixel bits of the current frame, the preset quantization parameter, and the block-level quantization parameter corresponding to each macroblock in the current frame in combination with the gradient texture.
The mapping model constructing module 73 is configured to calculate parameters of a mapping model according to the actual coded pixel bit number corresponding to each macroblock in the current frame and the block-level quantization parameter corresponding to each macroblock in the current frame, and construct the mapping model using the parameters of the mapping model.
The coding information obtaining module 74 is used to obtain the first target coding pixel bit number of the next frame of the current frame.
The bit allocation module 75 is configured to allocate the first target number of coded pixel bits to each macroblock in the next frame by using a mapping model, so that each macroblock in the next frame has a corresponding second target number of coded pixel bits.
The calculating module 76 is configured to calculate, by using a mapping model, a block-level quantization parameter corresponding to each macroblock in the next frame according to the second target coding pixel bit number.
The second encoding module 77 is configured to encode each macroblock of the next frame of the current frame according to the block-level quantization parameter corresponding to each macroblock of the next frame of the current frame, so as to obtain the actual number of coded pixel bits corresponding to each macroblock of the next frame of the current frame.
Fig. 8 is a schematic structural diagram of an electronic device according to a second embodiment of the invention. The electronic device comprises a memory 102 and a processor 101 connected to each other.
The memory 102 is used for storing program instructions for implementing the method for controlling the rate of coding at the level of a macroblock of the device described above.
The processor 101 is configured to execute program instructions stored in the memory 102.
The processor 101 may also be referred to as a Central Processing Unit (CPU). The processor 101 may be an integrated circuit chip having signal processing capabilities. The processor 101 may also be a general purpose processor, a Digital Signal Processor (DSP), an Application Specific Integrated Circuit (ASIC), a Field Programmable Gate Array (FPGA) or other programmable logic device, discrete gate or transistor logic, discrete hardware components. A general purpose processor may be a microprocessor or the processor may be any conventional processor or the like.
The storage 102 may be a memory bank, a TF card, etc., and may store all information in the electronic device, including the input raw data, the computer program, the intermediate operation result, and the final operation result, all stored in the storage 102. It stores and retrieves information based on the location specified by the controller. With the memory, the electronic device can only have the memory function to ensure the normal operation. The storage of electronic devices can be classified into a main storage (internal storage) and an auxiliary storage (external storage) according to the use, and also into an external storage and an internal storage. The external memory is usually a magnetic medium, an optical disk, or the like, and can store information for a long period of time. The memory refers to a storage component on the main board, which is used for storing data and programs currently being executed, but is only used for temporarily storing the programs and the data, and the data is lost when the power is turned off or the power is cut off.
In the several embodiments provided in the present application, it should be understood that the disclosed method and apparatus may be implemented in other ways. For example, the above-described apparatus embodiments are merely illustrative, and for example, a division of a module or a unit is merely a logical division, and an actual implementation may have another division, for example, a plurality of units or components may be combined or integrated into another system, or some features may be omitted, or not executed. In addition, the shown or discussed mutual coupling or direct coupling or communication connection may be an indirect coupling or communication connection through some interfaces, devices or units, and may be in an electrical, mechanical or other form.
Units described as separate parts may or may not be physically separate, and parts displayed as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the embodiment.
In addition, functional units in the embodiments of the present application may be integrated into one processing unit, or each unit may exist alone physically, or two or more units are integrated into one unit. The integrated unit can be realized in a form of hardware, and can also be realized in a form of a software functional unit.
The integrated unit, if implemented in the form of a software functional unit 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 application may be substantially implemented or contributed to by the prior art, or all or part of the technical solution may be embodied in 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 system server, a network device, or the like) or a processor (processor) to execute all or part of the steps of the method of the embodiments of the present application.
Please refer to fig. 9, which is a schematic structural diagram of a computer-readable storage medium according to the present invention. The storage medium of the present application stores a program file 201 capable of implementing all the above-mentioned macroblock-level rate control methods, where the program file 201 may be stored in the storage medium in the form of a software product, and includes several instructions to enable a computer device (which may be a personal computer, a server, or a network device, etc.) or a processor (processor) to execute all or part of the steps of the methods according to the embodiments of the present application. The aforementioned storage device includes: various media capable of storing program codes, such as a usb disk, a mobile hard disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a magnetic disk or an optical disk, or terminal devices, such as a computer, a server, a mobile phone, and a tablet.
The above description is only an embodiment of the present invention, and not intended to limit the scope of the present invention, and all modifications of equivalent structures and equivalent processes, which are made by using the contents of the present specification and the accompanying drawings, or directly or indirectly applied to other related technical fields, are included in the scope of the present invention.

Claims (13)

1. A method for macroblock-level rate control, comprising:
acquiring the first target coding pixel bit number of the current frame;
distributing a first target coding pixel bit number to each macro block in the current frame by using a mapping model so that each macro block of the current frame has a corresponding second target coding pixel bit number;
calculating to obtain a block-level quantization parameter corresponding to each macro block in the current frame according to the second target coding pixel bit number by using a mapping model;
and coding each macro block of the current frame according to the block-level quantization parameter corresponding to each macro block of the current frame to obtain the actual coding pixel bit number corresponding to each macro block of the current frame.
2. The method of claim 1, wherein the allocating a first target number of coded pixel bits to each macroblock of the current frame using a mapping model such that each macroblock of the current frame has a corresponding second target number of coded pixel bits comprises:
encoding the previous frame of the current frame by adopting a preset quantization parameter to obtain the actual encoding pixel bit number of the previous frame and a block-level quantization parameter corresponding to each macro block in the previous frame;
predicting the actual coding pixel bit number corresponding to each macro block in the previous frame by using the actual coding pixel bit number of the previous frame, the preset quantization parameter and the block-level quantization parameter corresponding to each macro block in the previous frame in combination with the gradient texture;
calculating parameters of a mapping model according to the actual coding pixel bit number corresponding to each macro block in the previous frame and the block-level quantization parameters corresponding to each macro block in the previous frame, and constructing the mapping model by using the parameters of the mapping model;
wherein the gradient texture comprises a gradient texture of an encoded frame and a gradient texture of an encoded macroblock.
3. The method of claim 2, wherein the allocating a first target number of coded pixel bits to each macroblock of the current frame using the mapping model such that each macroblock of the current frame has a corresponding second target number of coded pixel bits comprises:
calculating to obtain a weight factor corresponding to each macro block in the current frame by using the parameters of the mapping model and the corresponding frame level quantization parameters in the previous frame;
calculating to obtain a second target coding pixel bit number of the current frame by using a weight factor corresponding to each macro block in the current frame, the number of macro blocks in the current frame and the first target coding pixel bit number of the current frame;
the weighting factor corresponding to each macro block in the current frame is in direct proportion to the second target coding pixel bit number of the current frame.
4. The method of claim 1, wherein the obtaining the first target number of coded pixel bits for the current frame comprises:
and calculating to obtain the first target coding pixel bit number of the current frame by adopting a frame-level code rate control method.
5. The method of claim 4, wherein the encoding each macroblock of the current frame according to the block-level quantization parameter corresponding to each macroblock of the current frame to obtain the actual number of coded pixel bits corresponding to each macroblock of the current frame further comprises:
and updating the parameters of the mapping model by using the actual coding pixel bit number corresponding to each macro block of the current frame and the block-level quantization parameter corresponding to each macro block of the current frame to obtain an updated mapping model.
6. The method of claim 5, wherein the encoding each macroblock of the current frame according to the block-level quantization parameter corresponding to each macroblock of the current frame to obtain the actual number of coded pixel bits corresponding to each macroblock of the current frame further comprises:
acquiring the bit number of a first target coding pixel of a next frame of a current frame;
distributing a first target coding pixel bit number of a next frame to each macro block in the next frame by using the updated mapping model so that each macro block in the next frame has a corresponding second target coding pixel bit number;
calculating to obtain a block-level quantization parameter corresponding to each macro block in the next frame according to the second target coding pixel bit number by using the updated mapping model;
and encoding each macro block of the next frame by using the block-level quantization parameter corresponding to each macro block in the next frame to obtain the actual encoding pixel bit number corresponding to each macro block of the next frame.
7. The method of claim 6, wherein the allocating a first target number of coded pixel bits to each macroblock in the next frame using the updated mapping model such that each macroblock in the next frame has a corresponding second target number of coded pixel bits comprises:
calculating to obtain a weight factor corresponding to each macro block in the next frame by using the updated mapping model parameters and the block-level quantization parameters corresponding to each macro block in the current frame;
calculating to obtain a second target coding pixel bit number of the next frame by using the weight factor corresponding to each macro block in the next frame, the macro block number of the next frame and the first target coding pixel bit number of the next frame;
and the weighting factor corresponding to each macro block in the next frame is in direct proportion to the second target coding pixel bit number of the next frame.
8. An apparatus for macroblock-level rate control, comprising:
the encoding information acquisition module is used for acquiring the number of first target encoding pixel bits of the current frame;
a bit allocation module, configured to allocate a first target coding pixel bit number to each macroblock in the current frame by using a mapping model, so that each macroblock of the current frame has a corresponding second target coding pixel bit number;
the calculation module is used for calculating and obtaining a block-level quantization parameter corresponding to each macro block in the current frame according to the second target coding pixel bit number by using a mapping model;
and the coding module is used for coding each macro block of the current frame according to the block-level quantization parameter corresponding to each macro block of the current frame so as to obtain the actual coding pixel bit number corresponding to each macro block of the current frame.
9. A method for macroblock-level rate control, comprising:
encoding a current frame by adopting a preset quantization parameter to obtain the actual encoding pixel bit number of the current frame and a block-level quantization parameter corresponding to each macro block in the current frame;
predicting the actual coding pixel bit number corresponding to each macro block in the current frame by using the actual coding pixel bit number of the current frame, the preset quantization parameter and the block-level quantization parameter corresponding to each macro block in the current frame in combination with the gradient texture;
calculating parameters of a mapping model according to the actual coding pixel bit number corresponding to each macro block in the current frame and the block-level quantization parameters corresponding to each macro block in the current frame, and constructing the mapping model by using the parameters of the mapping model;
acquiring the bit number of a first target coding pixel of a next frame of a current frame;
distributing a first target coding pixel bit number of a next frame to each macro block in the next frame by using a mapping model so that each macro block of the next frame has a corresponding second target coding pixel bit number;
calculating to obtain a block-level quantization parameter corresponding to each macro block in the next frame according to the second target coding pixel bit number by using a mapping model;
and coding each macro block of the next frame of the current frame according to the block-level quantization parameter corresponding to each macro block in the next frame of the current frame so as to obtain the actual coded pixel bit number corresponding to each macro block of the next frame of the current frame.
10. The method of claim 9, wherein the allocating a first target number of coded pixel bits to each macroblock in the next frame using a mapping model such that each macroblock in the next frame has a corresponding second target number of coded pixel bits comprises:
calculating to obtain a weight factor corresponding to each macro block in the next frame of the current frame by using the parameters of the mapping model and the corresponding frame-level quantization parameters in the current frame;
calculating to obtain a second target coding pixel bit number of the next frame of the current frame by using a weight factor corresponding to each macro block in the next frame of the current frame, the number of macro blocks in the next frame of the current frame and the first target coding pixel bit number of the next frame of the current frame;
the weighting factor corresponding to each macro block in the next frame of the current frame is in direct proportion to the second target coding pixel bit number of the next frame of the current frame.
11. An apparatus for macroblock-level rate control, comprising:
the first coding module is used for coding a current frame by adopting a preset quantization parameter so as to obtain the actual coding pixel bit number of the current frame and a block-level quantization parameter corresponding to each macro block in the current frame;
the prediction module is used for predicting the actual coding pixel bit number corresponding to each macro block in the current frame by using the actual coding pixel bit number of the current frame, the preset quantization parameter and the block-level quantization parameter corresponding to each macro block in the current frame in combination with the gradient texture;
a mapping model construction module, configured to calculate parameters of a mapping model according to the actual coded pixel bit number corresponding to each macroblock in the current frame and the block-level quantization parameter corresponding to each macroblock in the current frame, and construct the mapping model using the parameters of the mapping model;
the encoding information acquisition module is used for acquiring the number of first target encoding pixel bits of the next frame of the current frame;
a bit allocation module, configured to allocate a first target number of coded pixel bits to each macroblock in the next frame by using a mapping model, so that each macroblock in the next frame has a corresponding second target number of coded pixel bits;
the calculation module is used for calculating and obtaining a block-level quantization parameter corresponding to each macro block in the next frame according to the second target coding pixel bit number by using a mapping model;
and the second coding module is used for coding each macro block of the next frame of the current frame according to the block-level quantization parameter corresponding to each macro block in the next frame of the current frame so as to obtain the actual coding pixel bit number corresponding to each macro block of the next frame of the current frame.
12. An electronic device, comprising: a memory and a processor, wherein the memory stores program instructions that the processor retrieves from the memory to perform the macroblock-level rate control method of any of claims 1-7 and/or claims 9-10.
13. A computer-readable storage medium, in which a program file is stored, the program file being executable to implement the macroblock-level rate control method according to any one of claims 1 to 7 and/or claims 9 to 10.
CN202010988369.3A 2020-09-18 2020-09-18 Macro block level code rate control method and related device Active CN112188208B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202010988369.3A CN112188208B (en) 2020-09-18 2020-09-18 Macro block level code rate control method and related device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202010988369.3A CN112188208B (en) 2020-09-18 2020-09-18 Macro block level code rate control method and related device

Publications (2)

Publication Number Publication Date
CN112188208A true CN112188208A (en) 2021-01-05
CN112188208B CN112188208B (en) 2022-08-09

Family

ID=73956437

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202010988369.3A Active CN112188208B (en) 2020-09-18 2020-09-18 Macro block level code rate control method and related device

Country Status (1)

Country Link
CN (1) CN112188208B (en)

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113438479A (en) * 2021-06-13 2021-09-24 北方工业大学 Code rate control based on CTU information entropy
CN114466189A (en) * 2021-12-27 2022-05-10 浙江大华技术股份有限公司 Code rate control method, electronic device and storage medium
WO2022213809A1 (en) * 2021-04-07 2022-10-13 百果园技术(新加坡)有限公司 Video coding method, apparatus and device, and storage medium
CN116074513A (en) * 2023-03-06 2023-05-05 北京朝歌数码科技股份有限公司 Video coding method applied to network camera, computer readable medium and electronic equipment

Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
EP1761068A1 (en) * 2005-08-31 2007-03-07 Thomson Licensing Method and apparatus for bit rate control in video signal encoding using a rate-distortion model
CN101188752A (en) * 2007-12-18 2008-05-28 方春 A self-adapted code rate control method based on relevancy
CN103533359A (en) * 2013-10-16 2014-01-22 武汉大学 H.264 code rate control method
CN108810530A (en) * 2018-07-12 2018-11-13 珠海亿智电子科技有限公司 A kind of AVC bit rate control methods based on human visual system
CN108965881A (en) * 2017-05-25 2018-12-07 福州瑞芯微电子股份有限公司 Bit rate control method, system, server and readable storage medium storing program for executing
CN110495174A (en) * 2018-04-04 2019-11-22 深圳市大疆创新科技有限公司 Coding method, device, image processing system and computer readable storage medium

Patent Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
EP1761068A1 (en) * 2005-08-31 2007-03-07 Thomson Licensing Method and apparatus for bit rate control in video signal encoding using a rate-distortion model
CN101188752A (en) * 2007-12-18 2008-05-28 方春 A self-adapted code rate control method based on relevancy
CN103533359A (en) * 2013-10-16 2014-01-22 武汉大学 H.264 code rate control method
CN108965881A (en) * 2017-05-25 2018-12-07 福州瑞芯微电子股份有限公司 Bit rate control method, system, server and readable storage medium storing program for executing
CN110495174A (en) * 2018-04-04 2019-11-22 深圳市大疆创新科技有限公司 Coding method, device, image processing system and computer readable storage medium
CN108810530A (en) * 2018-07-12 2018-11-13 珠海亿智电子科技有限公司 A kind of AVC bit rate control methods based on human visual system

Cited By (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2022213809A1 (en) * 2021-04-07 2022-10-13 百果园技术(新加坡)有限公司 Video coding method, apparatus and device, and storage medium
CN113438479A (en) * 2021-06-13 2021-09-24 北方工业大学 Code rate control based on CTU information entropy
CN113438479B (en) * 2021-06-13 2022-09-20 北方工业大学 Code rate control based on CTU information entropy
CN114466189A (en) * 2021-12-27 2022-05-10 浙江大华技术股份有限公司 Code rate control method, electronic device and storage medium
CN114466189B (en) * 2021-12-27 2024-05-28 浙江大华技术股份有限公司 Code rate control method, electronic equipment and storage medium
CN116074513A (en) * 2023-03-06 2023-05-05 北京朝歌数码科技股份有限公司 Video coding method applied to network camera, computer readable medium and electronic equipment

Also Published As

Publication number Publication date
CN112188208B (en) 2022-08-09

Similar Documents

Publication Publication Date Title
CN112188208B (en) Macro block level code rate control method and related device
US8259794B2 (en) Method and system for encoding order and frame type selection optimization
US11451787B2 (en) Method and apparatus for video encoding and decoding
KR101103699B1 (en) Video coding method and decoding method, their device, their program and program-recorded medium
US8406297B2 (en) System and method for bit-allocation in video coding
US20060056508A1 (en) Video coding rate control
US9621900B1 (en) Motion-based adaptive quantization
EP1745653A2 (en) Encoder with adaptive rate control for h.264
JP2001169281A (en) Device and method for encoding moving image
CN1604654A (en) Prediction method, apparatus, and medium for video encoder
WO2019104635A1 (en) System and method for controlling video coding at frame level
CN114466189B (en) Code rate control method, electronic equipment and storage medium
WO2019104611A1 (en) System and method for controlling video coding within image frame
WO2021077914A1 (en) Video coding method and apparatus, computer device and storage medium
CN113784126A (en) Image encoding method, apparatus, device and storage medium
TWI734865B (en) Method and encoder system for encoding video
US10003802B1 (en) Motion-based adaptive quantization
CN104038769A (en) Rate control method for intra-frame coding
Jing et al. A novel intra-rate estimation method for H. 264 rate control
JP5136470B2 (en) Moving picture coding apparatus and moving picture coding method
CN112584143B (en) Video coding method, device and system and computer readable storage medium
CN112866696A (en) 4K, 8K and 16K ultra-high-definition video coding optimization control method and device
EP1940176A2 (en) Method and device for coding a sequence of digitized images
US10003803B1 (en) Motion-based adaptive quantization
JP3779066B2 (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