CN112752106B - Video image frame coding control method and device and computer storage medium - Google Patents

Video image frame coding control method and device and computer storage medium Download PDF

Info

Publication number
CN112752106B
CN112752106B CN201911038750.7A CN201911038750A CN112752106B CN 112752106 B CN112752106 B CN 112752106B CN 201911038750 A CN201911038750 A CN 201911038750A CN 112752106 B CN112752106 B CN 112752106B
Authority
CN
China
Prior art keywords
image frame
value
quantization parameter
determining
overhead
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201911038750.7A
Other languages
Chinese (zh)
Other versions
CN112752106A (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.)
Beijing Xintang Sichuang Educational Technology Co Ltd
Original Assignee
Beijing Xintang Sichuang Educational 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 Beijing Xintang Sichuang Educational Technology Co Ltd filed Critical Beijing Xintang Sichuang Educational Technology Co Ltd
Priority to CN201911038750.7A priority Critical patent/CN112752106B/en
Publication of CN112752106A publication Critical patent/CN112752106A/en
Application granted granted Critical
Publication of CN112752106B publication Critical patent/CN112752106B/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 embodiment of the application provides a video image frame coding control method, a video image frame coding control device and a computer storage medium, wherein overhead values of n macro blocks in a first image frame in a motion estimation process are obtained, and the first image frame is an image frame which is coded; determining the number of macro blocks of the first image frame in each overhead value interval according to the acquired overhead values and the m overhead value intervals; and determining a target quantization parameter of the second image frame according to the number of macro blocks of the first image frame in each overhead value interval and an initial quantization parameter of the second image frame to be coded, determining a current quantization parameter of the second image frame based on the target quantization parameter and the initial quantization parameter, and coding the second image frame according to the current quantization parameter. When the quantization parameters of the video image frames are adjusted, the resources of the image frames are reasonably distributed, so that the resource waste is reduced.

Description

Video image frame coding control method and device and computer storage medium
Technical Field
The embodiment of the application relates to the technical field of electronic information, in particular to a video image frame coding control method and device and a computer storage medium.
Background
With the continuous development of the electronic information industry, for example, live video, video conference, live online education, etc., people have higher and higher requirements for video quality. The image pair is encoded and decoded, so that files of image data can be reduced, the image is convenient to store and transmit, and the resource distribution of the image frame can be more reasonable and the resource waste can be reduced by adjusting the quantization parameter of the image frame.
In the prior art, when the code rate between two consecutive coding frames is smaller than a preset threshold, the structural similarity of the previous coding frame is calculated, the structural similarity of the current coding frame is predicted according to the previous coding frame, and the absolute residual of the current coding frame is calculated according to the structural similarity, so that the quantization parameter of the current coding frame is adjusted.
However, in the encoding process, it is relatively complicated to calculate the structural similarity of the previous encoded frame, and meanwhile, when the scene is frequently switched, there is a difference in predicting the structural similarity of the current encoded frame according to the previous encoded frame, and when the quantization parameter of the video image frame is adjusted, the resource allocation of the current encoded frame is not reasonable, which causes resource waste.
Disclosure of Invention
In view of the above, an object of the present invention is to provide a method, an apparatus and a computer storage medium for controlling encoding of video image frames, so as to overcome the defect that resource is easily wasted due to unreasonable resource allocation of the image frames in the prior art.
In a first aspect, an embodiment of the present application provides a method for controlling encoding of a video image frame, where the method includes:
acquiring overhead values of n macro blocks in a first image frame in a motion estimation process, wherein the first image frame is an image frame which is coded, and n is the number of the macro blocks in the first image frame;
determining the number of macro blocks of the first image frame in each overhead value interval according to the acquired overhead value and m overhead value intervals, wherein m is an integer larger than 1 and smaller than n;
determining a target quantization parameter of a second image frame according to the number of macro blocks of a first image frame in each overhead value interval and an initial quantization parameter of the second image frame to be coded, wherein the first image frame is positioned in front of the second image frame in time sequence;
and determining a current quantization parameter of the second image frame based on the target quantization parameter and the initial quantization parameter, and encoding the second image frame according to the current quantization parameter.
Optionally, in an embodiment of the present application, determining a target quantization parameter of a second image frame according to the number of macroblocks of the first image frame in each overhead value interval and an initial quantization parameter of the second image frame to be encoded includes:
calculating the ratio of the number of macro blocks in each overhead value interval in the first image frame to the number of all macro blocks in the first image frame;
determining a first preset step length corresponding to each proportion value according to the matching result of each proportion value and a preset target condition;
and determining a target quantization parameter of the second image frame according to the initial quantization parameter and the first preset step length of the second image frame.
Optionally, in an embodiment of the present application, determining, according to a matching result between each ratio value and a preset target condition, a first preset step corresponding to each ratio value includes:
determining the value of the first preset step size as a first numerical value when R0+ R1+ R2 is greater than a first threshold; determining the value of the first preset step size as a second numerical value when R1+ R2+ R3 is greater than a second threshold value; determining the value of the first preset step size as a third value when R2+ R3+ R4 is greater than a third threshold; when in use
When R4+ R5+ R6 is greater than the fourth threshold, determining the value of the first preset step size as a fourth numerical value; determining the value of the first preset step size as a fifth numerical value when R5+ R6 is greater than a fifth threshold value;
wherein, the ratio values of the number of macroblocks of the 7 overhead value intervals in the first image frame, where m is equal to 7, to the number of all macroblocks of the first image frame are R0, R1, R2, R3, R4, R5, R6, respectively.
Optionally, in an embodiment of the present application, the method further includes:
respectively calculating the pixel value difference values of the pixels in the second image frame and the pixels at the corresponding positions in the reference frame of the second image frame according to a second preset step length increment aiming at the pixels in the second image frame;
determining the number of target pixels of which the pixel value difference is greater than or equal to a preset difference;
and when the ratio of the target pixel quantity in all the pixel value difference quantity is larger than or equal to the first ratio, subtracting the quantization constant from the initial quantization parameter to obtain a target quantization parameter of the second image frame.
Optionally, in an embodiment of the present application, the method further includes:
when the ratio of the number of the target pixels in the difference number of all the pixel values is smaller than the second ratio, taking the ratio of the number of the macro blocks with the overhead value equal to 0 to the number of all the macro blocks in the n macro blocks of the first image frame as a third ratio;
when the third ratio is larger than the preset ratio, determining a second preset step length corresponding to the third ratio;
and determining a target quantization parameter of the second image frame according to the initial quantization parameter and a second preset step length of the second image frame.
Optionally, in an embodiment of the present application, when the third ratio is greater than the preset ratio, determining a second preset step corresponding to the third ratio includes:
when the third ratio is larger than a sixth threshold, determining the value of the second preset step length as a sixth numerical value; and when the third ratio is larger than the seventh threshold and smaller than the sixth threshold, determining the value of the second preset step as a seventh numerical value.
Optionally, in an embodiment of the present application, the method further includes:
acquiring a sample image frame set, and calculating the overhead value of each macro block in the sample image frame set in the motion estimation process, wherein each sample image frame in the sample image frame set is an encoded image frame;
and determining m overhead value intervals according to the overhead value of each macro block in the sample image frame set in the motion estimation process.
Optionally, in an embodiment of the present application, determining m overhead value intervals according to the overhead value of each macroblock in the sample image frame set in the motion estimation process includes:
determining a sample overhead value interval according to the number of macro blocks in a sample image frame set and the overhead value corresponding to each macro block, and adjusting the sample overhead value interval according to the distribution condition of the overhead value of each macro block in a preset image frame in the sample overhead value interval to obtain m overhead value intervals.
Optionally, in an embodiment of the present application, determining the current quantization parameter of the second image frame based on the target quantization parameter and the initial quantization parameter comprises:
calculating the absolute value of the difference value between the initial quantization parameter and the target quantization parameter of the second image frame;
when the absolute value is less than or equal to a preset value, determining the target quantization parameter as a current quantization parameter;
and when the absolute value is larger than the preset value, determining the initial quantization parameter as the current quantization parameter.
In a second aspect, an embodiment of the present application provides an encoding control apparatus for a video image frame, including: the device comprises an acquisition module, a macro block quantity determination module, a quantization parameter determination module and an encoding module;
the acquisition module is used for acquiring overhead values of n macro blocks in a first image frame in the motion estimation process, wherein the first image frame is an image frame which is coded, and n is the number of the macro blocks in the first image frame;
the macro block number determining module is used for determining the number of macro blocks of the first image frame in each overhead value interval according to the acquired overhead value and m overhead value intervals, wherein m is an integer which is greater than 1 and smaller than n;
the quantization parameter determining module is used for determining a target quantization parameter of a second image frame according to the number of macro blocks of a first image frame in each overhead value interval and an initial quantization parameter of the second image frame to be coded, wherein the first image frame is positioned in front of the second image frame in time sequence;
and the encoding module is used for determining the current quantization parameter of the second image frame based on the target quantization parameter and the initial quantization parameter and encoding the second image frame according to the current quantization parameter.
In a third aspect, an embodiment of the present application provides an electronic device, including: at least one processor; storage means for storing at least one program; the at least one program, when executed by the at least one processor, causes the at least one processor to implement a method as described in the first aspect or any one of the embodiments of the first aspect.
In a fourth aspect, embodiments of the present application provide a computer storage medium storing a computer program, which when executed by a processor implements the method as described in the first aspect or any one of the embodiments of the first aspect.
In the embodiment of the application, overhead values of n macro blocks in a first image frame in a motion estimation process are obtained, wherein the first image frame is an image frame which is already coded, and n is the number of the macro blocks in the first image frame; determining the number of macro blocks of the first image frame in each overhead value interval according to the acquired overhead value and m overhead value intervals, wherein m is an integer larger than 1 and smaller than n; determining a target quantization parameter of a second image frame according to the number of macro blocks of the first image frame in each overhead value interval and an initial quantization parameter of the second image frame to be coded; and determining a current quantization parameter of the second image frame based on the target quantization parameter and the initial quantization parameter, and encoding the second image frame according to the current quantization parameter. The method comprises the steps of counting the number of macro blocks of a coded first image frame in m overhead value intervals, wherein the macro block overhead value of the first image frame is continuously updated, adjusting quantization parameters of a second image frame to be coded in time according to the distribution condition of the macro block overhead value of the first image frame, and adjusting the quantization parameters of the image frame to enable code rate distribution in the coding process to be more reasonable and reduce resource waste.
Drawings
Some specific embodiments of the present application will be described in detail below by way of illustration and not limitation with reference to the accompanying drawings. The same reference numbers in the drawings identify the same or similar elements or components. Those skilled in the art will appreciate that the drawings are not necessarily drawn to scale. In the drawings:
fig. 1 is a flowchart of a method for controlling encoding of video image frames according to an embodiment of the present disclosure;
fig. 2 is a schematic diagram of an overhead value interval according to an embodiment of the present disclosure;
fig. 3 is a schematic diagram illustrating a method for calculating the number of macro blocks according to an embodiment of the present disclosure;
fig. 4 is a schematic diagram of another example of calculating the number of macro blocks according to the present disclosure;
fig. 5 is a schematic diagram illustrating an adjustment of an image frame quantization parameter according to an embodiment of the present disclosure;
fig. 6 is a schematic diagram of another method for adjusting image frame quantization parameters according to an embodiment of the present application;
fig. 7 is a schematic diagram illustrating another method for adjusting a quantization parameter of an image frame according to an embodiment of the present disclosure;
fig. 8 is a schematic diagram of another method for adjusting a quantization parameter of an image frame according to an embodiment of the present application;
fig. 9 is a block diagram of an encoding control apparatus for video image frames according to an embodiment of the present application;
fig. 10 is a block diagram of an electronic device according to an embodiment of the present application.
Detailed Description
The following further describes specific implementation of the embodiments of the present invention with reference to the drawings.
Example one
An embodiment of the present application provides a method for controlling encoding of a video image frame, and fig. 1 is a flowchart of a method for controlling encoding of a video image frame according to an embodiment of the present application, and as shown in fig. 1, the method for controlling encoding of a video image frame includes the following steps:
step 101, acquiring overhead values of n macro blocks in a first image frame in a motion estimation process.
Wherein the first image frame is an image frame which has completed encoding, and n is the number of macro blocks in the first image frame.
It should be noted that the image frame is the minimum unit constituting the video, the video is composed of consecutive image frames, the transmission and storage of the video are realized by encoding and decoding the image frames in the video, and the video occupies a large amount of hardware resources in the transmission and storage process, for example, the occupation of CPU and memory, the occupation of time, and the like. The occupation of hardware resources is taken as the energy value consumed by the video in the transmission and storage processes, and the overhead value is used for representing the energy value consumed by the video in the transmission and storage processes. The image frame comprises at least one non-overlapping macro block, when the image frame is coded, scenes in adjacent image frames in a video have certain correlation, the relative offset between the adjacent image frames is obtained according to the positions of the macro blocks in the adjacent image frames, a block which is most similar to a current macro block is found for each macro block according to a matching criterion and is used as a matching block, the process of obtaining the relative offset between the matching block and the current macro block is used as a motion estimation process, when the image frame is decoded, the corresponding macro block is found from the decoded image frame through the relative offset and the motion estimation process, the position of the macro block in the image frame is obtained, and the image frame is decoded to obtain the image frame.
The image frame comprises at least one macro block, the motion estimation process of the image frame is a process for coding the macro block, a matching block of the macro block is searched in the motion estimation process, energy values are consumed, and each macro block corresponds to an overhead value in the motion estimation process. The first image frame is an image frame which has already been encoded, for example, the first image frame is 1280 × 720, the first image frame is divided into macroblocks according to 16 × 16, 3600 macroblocks of 16 × 16 can be obtained, the image frame is divided into 45 rows and 80 columns, the positions of the macroblocks are represented by (i, j) according to rows and columns, i is used for representing the rows of the macroblocks in the image frame, i is greater than or equal to 0 and less than 45, j is used for representing the columns of the macroblocks in the image frame, j is greater than or equal to 0 and less than 80, and the overhead value of each macroblock is calculated according to the row and column index.
In the description of the first image frame in the embodiment of the present application, it is assumed that the first image frame includes n macroblocks, where n is the number of macroblocks in the first image frame. Optionally, the first image frame is a second image frame in the image frames, and here, differences between the image frames as an I frame, a P frame, and a B frame are introduced first, and for example, the I frame, the P frame, and the B frame are used to represent transmitted video pictures in the h.264 compression standard. The image frames can be I frames, P frames and B frames, the I frames are intra-coded frames and are independent frames with all information, the independent frames can be independently decoded without referring to other image frames, and the first frame in the image frames is always the I frame because the first frame is a key frame. The P frame is an inter-frame coding frame, which needs to be coded with reference to the previous I frame, and is used to represent the difference between the current frame picture and the previous frame, and the difference defined by the current frame needs to be superimposed on the previously buffered picture during decoding, so as to generate the final picture. The B frame is a bidirectionally encoded frame, indicates a difference between a current frame and a preceding and succeeding frames, and when the B frame is decoded, not only a preceding buffer picture but also a decoded picture are obtained, and a final picture is obtained by superimposing the preceding and succeeding pictures on the data of the current frame. In a possible implementation manner, when calculating the overhead value of the macroblock in the encoded image frame, the first frame in the image frame is an I frame, which is an independent frame with all information, and does not need a matching block, and there is no motion estimation process, and the overhead value of the macroblock in the second frame of the encoded image frame may be calculated without calculating the overhead value of the first frame in the image frame, or the overhead value of the macroblock in the third frame of the encoded image frame may be calculated, that is, the first image frame is a third frame in the image frame sequence or a frame after the third frame.
Optionally, in an embodiment of the present application, before step 101 or step 102, the following steps may also be performed: acquiring a sample image frame set, and calculating the overhead value of each macro block in the sample image frame set in the motion estimation process, wherein each sample image frame in the sample image frame set is an encoded image frame; and determining m overhead value intervals according to the overhead value of each macro block in the sample image frame set in the motion estimation process.
Optionally, in an embodiment of the present application, a sample overhead value interval is determined according to the number of macro blocks in a sample image frame set and an overhead value corresponding to each macro block, and the sample overhead value interval is adjusted according to a distribution condition of the overhead value of each macro block in a preset image frame in the sample overhead value interval, so as to obtain m overhead value intervals.
At least one sample image frame is acquired as a set of sample image frames, for example, sample image frames having a resolution of 1920 × 1080, 1280 × 720, 832 × 480, 640 × 360. The sample image frames are all encoded image frames, the overhead value of each macro block in at least one sample image frame in the motion estimation process is calculated, and the overhead value of each macro block is greater than or equal to 0. For example, in the h.264 compression standard, the maximum number of macroblocks of a P frame may be 16 × 16, and the minimum number may be 4 × 4, the smaller the macroblock is, the larger the overhead value is needed, the size of the macroblock is used to indicate the complexity of the image frame, by analyzing the distribution of the number of macroblocks, the overhead value interval is pre-divided based on the distribution of the whole macroblock overhead values in the sample image frame, or the overhead value interval may be pre-divided by an empirical value and a massive data test, and the sample overhead value interval is determined, for example, one of the overhead value intervals is divided into [100,500 ]. And adjusting the sample overhead value interval according to the distribution condition of the overhead value of each macro block in the preset image frame in the sample overhead value interval. The preset image frame may be other sample image frames, the sample overhead value interval is verified according to the other sample image frames, whether the division of the sample overhead value interval is the optimal division is verified, and the division of the sample overhead value interval is adjusted to obtain m overhead value intervals. For example, as shown in fig. 2, fig. 2 is a schematic diagram of an overhead value interval provided in the present embodiment, where fig. 2 shows 7 overhead value intervals, a 0 th overhead value interval is [0,100 ], a1 st overhead value interval is [100,500), a2 nd overhead value interval is [500,1000), a3 rd overhead value interval is [1000,2000 ], a4 th overhead value interval is [2000,3000 ], a5 th overhead value interval is [3000,4000 ], and a 6 th overhead value interval is [4000, + ∞), where a numerical range of the overhead value interval and the number of the divisional overhead value intervals may be changed and adjusted according to an actual situation.
Furthermore, other sample image frames may also be acquired, the cost value of each macro block in the other sample image frames in the motion estimation process is calculated, a cost value interval corresponding to at least one other sample image frame is further determined, and the sample cost value interval determined in the embodiment of the present application is determined or changed according to the at least one other cost value interval. For example, in the process of adjusting the quantization parameter of the image frame, the video image frame with the excess parameter adjusted may be combined, the overhead value interval is verified by adjusting the overall distribution of the macro block overhead values of the video image frame with the excess parameter, it is verified whether the division of the overhead value interval is the optimal division, the division of the overhead value interval is adjusted in time, the overhead value interval is re-determined, and the adjusted overhead value interval may make the division of the overhead value interval more reasonable, and further determine the quantization parameter of the image frame to be encoded, and through the adjustment of the quantization parameter of the image frame to be encoded, the allocation of the code rate in the encoding process is more reasonable, and the reasonable allocation of the resources is achieved.
Here, it should be noted that the overhead value interval may be obtained by obtaining a sample image frame set, calculating an overhead value of each macro block in the image frame set in a motion estimation process, and determining m overhead value intervals according to the overhead value of each macro block in the sample image frame set in the motion estimation process; or m overhead value intervals may be set according to an actual situation, which is not limited in the embodiment of the present application.
Step 102 may also be performed after acquiring the overhead values of the n macroblocks in the first image frame in the motion estimation process.
And step 102, determining the number of macro blocks of the first image frame in each overhead value interval according to the acquired overhead value and the m overhead value intervals.
Wherein m is an integer greater than 1 and less than n.
Optionally, in an embodiment of the present application, the first image frame is a video image frame that has been already encoded, for example, the first image frame is 1280 × 720, the first image frame is divided into macroblocks according to 16 × 16, which may obtain 3600 macroblocks of 16 × 16, the image frame is divided into 45 rows and 80 columns, the positions of the macroblocks are represented by (i, j) according to the rows and columns, i is used to represent the rows of the macroblocks in the image frame, 0 ≦ i < 45, j is used to represent the columns of the macroblocks in the image frame, 0 ≦ j < 80, the overhead value of each macroblock is calculated according to the row and column index, and (3,15) the macroblock represents the macroblock located in the 3 rd row and the 15 th column. For example, as shown in fig. 3, fig. 3 is a schematic diagram for calculating the number of macroblocks in each overhead value interval provided by the embodiment of the present application, where count (0) in fig. 3 represents the number of macroblocks of a macroblock overhead value in a 0 th overhead value interval, count (1) represents the number of macroblocks of a macroblock overhead value in a1 st overhead value interval, count (2) represents the number of macroblocks of a macroblock overhead value in a2 nd overhead value interval, count (3) represents the number of macroblocks of a macroblock overhead value in a3 rd overhead value interval, count (4) represents the number of macroblocks of a macroblock overhead value in a4 th overhead value interval, count (5) represents the number of macroblocks of a macroblock overhead value in a5 th overhead value interval, and count (6) represents the number of macroblocks of a macroblock overhead value in a 6 th overhead value interval. For example, the overhead value of the (3,15) th macroblock is 560, and the (3,15) th macroblocks are distributed in the 2 nd overhead value interval [500,1000 ] according to the overhead value 560 of the macroblock and the overhead value interval; the overhead value of the (33,72) th macroblock is 1088, and the (33,72) th macroblock is distributed in the 3 rd overhead value interval [1000,2000 ] according to the overhead value 1088 of the macroblock and the overhead value interval; the number of macroblocks in each overhead value interval is determined according to the overhead value and the overhead value interval of each macroblock according to the row-column index, for example, after statistics, 100 macroblocks in the first image frame are in the 1 st overhead value interval [100,500 ], and 500 macroblocks in the first image frame are in the 2 nd overhead value interval [500,1000 ].
Optionally, in an embodiment of the present application, the number of macroblocks in the first image frame with a cost value of 0 is calculated, as shown in fig. 4, fig. 4 is a schematic diagram of another method for calculating the number of macroblocks provided in the embodiment of the present application, and zerocount in fig. 4 represents the number of macroblocks with a cost value equal to 0, for example, the cost value of 300 macroblocks in the first image frame is equal to 0.
Step 103 may also be performed after determining the number of macroblocks in each overhead value interval of the first image frame according to the acquired overhead values and the m overhead value intervals.
And 103, determining a target quantization parameter of the second image frame according to the number of macro blocks of the first image frame in each overhead value interval and the initial quantization parameter of the second image frame to be coded.
Wherein the first image frame temporally precedes the second image frame.
It should be noted that the second image frame is an image frame to be encoded, optionally, the first image frame is located before the second image frame in time sequence, the first image frame may be a previous encoded image frame of the second image frame, and the first image frame may also be a previous two encoded image frames of the second image frame, which is not limited in this application. The image frame coding process is a process of compressing an image and can be adjusted through a quantization parameter, the quantization is to reduce the coding length of the image frame on the premise of not reducing the visual effect and reduce unnecessary information in visual reply, the reasonable allocation of resources is achieved through the adjustment of the quantization parameter of the image frame, the resource waste is reduced, and the quantization parameter can be adjusted according to factors such as the actual condition of the image frame and the overhead value when the image frame is coded. For example, in the h.264 compression standard, an image frame is encoded and decoded by encoding and decoding a luminance signal Y and two chrominance signals U and V, the luminance signal Y representing a gray level value for describing brightness, the chrominance signals U and V describing color and saturation of the image frame, and if only the luminance signal Y and not the chrominance signals U and V, the image frame is a black-white-gray image; quantization step (QP) at the time of encoding and decoding an image frame is the number of quantization step (Qstep), and when encoding a luminance (lupp) component, the quantization step Qstep has 52 values, the quantization parameter QP takes a value of 0 to 51, and when the quantization parameter QP takes the minimum value of 0, the quantization step Qstep is 0.625, which means that the quantization accuracy is the highest, the image frame is finer, and the amount of data generated is larger in the same image quality; when the quantization parameter QP takes the maximum value of 51, the quantization step Qstep is 224, which indicates that the quantization accuracy is the lowest, the coarser the image frame, and the smaller the amount of data generated in the same image quality; when the Chroma (Chroma) component is coded, the quantization step size Qstep has 40 values, and the quantization parameter QP takes 0-39 values. The quantization parameter QP and the quantization step size Qstep have a linear relationship, the quantization step size Qstep increases with the increase of the quantization parameter QP, the quantization parameter QP increases by 6, and the quantization step size Qstep increases by one time.
Optionally, the target quantization step size of the second image frame may also be determined according to the number of macroblocks in each overhead value interval of n macroblocks of the first image frame and the initial quantization step size of the second image frame. The embodiments of the present application are illustrated in order to adjust the quantization parameter of the second image frame, and do not represent that the present application is limited thereto.
The initial quantization parameter of the second image frame may be set to a maximum value, may also be set to a minimum value, and may also be a default value, which is not limited to the present invention. And determining a target quantization parameter of the second image frame according to the number of the n macro blocks of the first image frame in each overhead value interval and the initial quantization parameter of the second image frame. There may be three possible implementations, which are described herein.
In a possible implementation manner, a ratio value of the number of macro blocks of each overhead value interval in the first image frame to the number of all macro blocks of the first image frame is calculated; determining a first preset step length corresponding to each proportion value according to the matching result of each proportion value and a preset target condition; and determining a first preset step length corresponding to each proportion value according to the matching result of each proportion value and a preset target condition, and determining a target quantization parameter of the second image frame according to the initial quantization parameter and the first preset step length of the second image frame.
Determining the number of macroblocks in each overhead value interval according to the step 102, and calculating a ratio of the number of macroblocks in each overhead value interval to the number of all macroblocks in the first image frame, for example, as shown in fig. 5, fig. 5 is a schematic diagram of adjusting image frame quantization parameters according to an embodiment of the present application, in fig. 5, a ratio of macroblocks in each overhead value interval is calculated according to the number of macroblocks in each overhead value interval, where the ratio is denoted by Rk, k is greater than or equal to 0, fig. 5 shows a ratio of 7 macroblocks, R0 denotes a ratio of macroblocks in 0 th overhead value interval, R1 denotes a ratio of macroblocks in 1 st overhead value interval, R2 denotes a ratio of macroblocks in 2 nd overhead value interval, R3 denotes a ratio of macroblocks in 3 rd overhead value interval, R4 denotes a ratio of macroblocks in 4 th overhead value interval, r5 represents the ratio of the macroblock in the 5 th overhead value interval, and R6 represents the ratio of the macroblock in the 6 th overhead value interval. For example, the first image frame is 1280 × 720, the first image frame is divided into macroblocks according to 16 × 16, 3600 macroblocks of 16 × 16 can be obtained, after statistics, 100 macroblocks in the first image frame are within the 1 st overhead value interval [100,500 ], 500 macroblocks in the first image frame are within the 2 nd overhead value interval [500,1000 ], the proportion value of the macroblocks within the 1 st overhead value interval [100,500) is 1/36, and the proportion value of the macroblocks within the 2 nd overhead value interval [500,1000) is 5/36. C0, C1, C2, C3 and C4 in fig. 5 are constants, a1, a2, a3, a4 and a5 are constants, ilumaQp is an initialized quantization parameter of the second image frame, and ilumaQp may be set to a maximum value, a minimum value or a default value, and optionally, in fig. 5, the initialized quantization parameter ilumaQp is a default quantization parameter in the encoding process. The occupation ratio of 7 overhead value interval macro blocks is taken as an example, and the proportions of at least two overhead value interval macro blocks are added and summed. In the embodiment of the present application, when the quantization parameter is adjusted, adjacent scale values Rk are combined, and there may be more than 40 combinations, and the number of scale values Rk in each combination does not exceed 3, and repeated tests by the inventors have found that adjustment of the quantization parameter by summation of the following 5 ratios can cover substantially all possibilities, and therefore, R0+ R1+ R2, R1+ R2+ R3, R2+ R3+ R4, R4+ R5+ R6, R5+ R6, and the like are explained below.
Optionally, in an embodiment of the present application, determining, according to a matching result between each ratio value and a preset target condition, a first preset step corresponding to each ratio value includes: determining the value of the first preset step size as a first numerical value when R0+ R1+ R2 is greater than a first threshold; determining the value of the first preset step size as a second numerical value when R1+ R2+ R3 is greater than a second threshold value; determining the value of the first preset step size as a third value when R2+ R3+ R4 is greater than a third threshold; determining the value of the first preset step size as a fourth numerical value when R4+ R5+ R6 is greater than a fourth threshold value; determining the value of the first preset step size as a fifth numerical value when R5+ R6 is greater than a fifth threshold value; wherein m of the m overhead value intervals is equal to 7, and the ratio values of the number of macroblocks of the 7 overhead value intervals in the first image frame to the number of all macroblocks of the first image frame are respectively R0, R1, R2, R3, R4, R5 and R6. The first preset threshold, the second preset threshold, the third preset threshold, the fourth preset threshold and the fifth preset threshold can be set according to actual conditions, and can be set to be the same or different; the first numerical value, the second numerical value, the third numerical value, the fourth numerical value and the fifth numerical value can be set according to actual conditions, can be set to be the same, and can also be set to be different. The present application is not limited thereto, but only by way of example, and the present application is not limited thereto.
Describing the quantization parameters of the adjusted image frame by 5 examples in fig. 5, when R0+ R1+ R2> C0, the constant C0 takes a value of 0.75, the quantization parameter of the second image frame is adjusted to ilumaQp-a1, and the constant a1 takes a value of 1; when R1+ R2+ R3> C1, the constant C1 is 0.7, the quantization parameter of the second image frame is adjusted to ilumaQp — a2, and the constant a2 is 1; when R2+ R3+ R4> C2, the constant C2 is 0.65, the quantization parameter of the second image frame is adjusted to ilumaQp — ilumaQp-a3, and the constant a3 is 2; when R4+ R5+ R6> C3, the constant C3 is 0.6, the quantization parameter of the second image frame is adjusted to ilumaQp — a4, and the constant a4 is 2; when R5+ R6> C4, the constant C4 is 0.65, the quantization parameter of the second image frame is adjusted to ilumaQp — a5, and the constant a5 is 2. The constants C0-C4 in FIG. 5 can be set and adjusted according to actual conditions; the constants a1-a5 may be any integer from 0 to 4, and may be set and adjusted according to actual situations, and herein, the embodiments of the present application are only exemplary and are not limited.
In one possible implementation manner, a ratio of the number of macroblocks with the overhead value equal to 0 to the number of all macroblocks in the n macroblocks of the first image frame is used as a third ratio; when the third ratio is larger than the preset ratio, determining a second preset step length corresponding to the third ratio; and determining a target quantization parameter of the second image frame according to the initial quantization parameter and a second preset step length of the second image frame.
Optionally, in an embodiment of the present application, when the third ratio is greater than the preset ratio, determining a second preset step corresponding to the third ratio includes: when the third ratio is larger than a sixth threshold, determining the value of the second preset step length as a sixth numerical value; and when the third ratio is larger than the seventh threshold and smaller than the sixth threshold, determining the value of the second preset step as a seventh numerical value.
The ratio of the number of macroblocks whose overhead value is equal to 0 to the number of all macroblocks in the m macroblocks of the first image frame is taken as a third ratio. For example, the first image frame is 1280 × 720, the first image frame is divided into macroblocks according to 16 × 16, 3600 macroblocks of 16 × 16 can be obtained, the number of the macroblocks with the overhead value equal to 0 is 1800 after statistics, and the proportion of the macroblocks with the overhead value equal to 0 is 1/2. For example, as shown in fig. 6, fig. 6 is a schematic diagram of another method for adjusting an image frame quantization parameter provided in an embodiment of the present application, fig. 6 illustrates the adjustment of the image frame quantization parameter by using 3 examples, where the ratio of the number of macroblocks with an overhead value equal to 0 to the number of all macroblocks is represented by ZeroRate, when the ZeroRate > Z0, the constant Z0 is 0.75, the quantization parameter of the second image frame is adjusted to ilumaQp-m0, and the constant m0 is 1; when Z0> ZeroRate > Z1, the constant Z1 takes a value of 0.65, the quantization parameter of the second image frame is adjusted to ilumaQp — m1, and the constant m1 takes a value of 2.
Optionally, in an embodiment of the present application, when the third occupancy is equal to 1, that is, the overhead value of each macroblock in n macroblocks of the first image frame is constantly equal to 0, the following adjustment may be performed on the quantization parameter of the second image frame, where an example is described here, when the ZeroRate is equal to 1, the quantization parameter of the second image frame is adjusted to ilumaQp ═ ilumaQp + m2, and the constant m2 is equal to 1, because when the occupancy of the macroblock overhead value is equal to 0 is equal to 1, that is, the overhead values of n macroblocks of the first image frame are constantly equal to 0, it is described that excessive resource allocation is not required when the second image frame is encoded at this time, and the resource allocation of the image frame may be reasonably realized by increasing the quantization parameter of the second image frame, so that the resource occupied by the second image frame is reduced; by adjusting the quantization parameter of the second image frame to be encoded, the code rate distribution in the encoding process is more reasonable, the code rate value is reduced, the resource waste is reduced, and the resource utilization rate is improved. The constants Z0, Z1 and Z2 in FIG. 6 can be set and adjusted according to actual conditions; the constants m0 and m1 may be any integer from 0 to 4, and the constant m2 may be any integer from 0 to 3, and may be set and adjusted according to actual situations.
In a possible implementation manner, for pixels in the second image frame, pixel value difference values of the pixels in the second image frame and pixels at corresponding positions in a reference frame of the second image frame are respectively calculated according to a second preset step increment; determining the number of target pixels of which the pixel value difference is greater than or equal to a preset difference; and when the ratio of the target pixel number in all the pixel value difference numbers is larger than or equal to the first ratio, subtracting the quantization constant from the initial quantization parameter to obtain a target quantization parameter of the second image frame.
For example, I-frames, P-frames, and B-frames are used to represent transmitted video pictures in the h.264 compression standard. The image frames can be I frames, P frames and B frames, the I frames are intra-frame coding frames and are independent frames with all information, decoding can be independently performed without referring to other image frames, and the first frame in the image frames is always the I frame. P-frames are inter-coded frames that require reference to a previous I-frame for encoding. The B frame is a bidirectional encoded frame, and when the B frame is decoded, not only a previous buffered picture but also a picture after decoding is acquired. Optionally, the second image frame is any one of the image frames to be encoded, and the first frame of the image frame to be encoded is an I frame. The positions of the macro blocks of the reference frame of the second image frame and the second image frame are corresponding, the positions of the macro blocks containing pixel values are corresponding, the pixel value difference between the reference frame of the second image frame and the pixels at the corresponding positions of the second image frame is calculated, the pixel value difference is represented by Di, the preset difference is represented by Si, and the number of target pixels with the pixel value difference Di being more than or equal to Si is counted. The macroblock is composed of pixel values, and here, the adjustment of the quantization parameter of the second image frame is exemplified by five examples.
Optionally, in a first example, the second image frame is 1280 × 720, there are 921600 pixel values, 921600 pixel value difference values between a reference frame of the second image frame and a pixel at a corresponding position of the second image frame are calculated, 691200 target pixels meeting Di ≧ Si in 921600 pixel value difference values are set, the preset number of pixels is 460800, the target number of pixels is greater than the preset number of pixels, a quantization constant is subtracted from the initial quantization parameter to obtain a target quantization parameter ilumaQp of the second image frame, ilumaQp is an initialized quantization parameter of the second image frame, and may be set to a maximum value or a default value.
Optionally, in a second example, the second image frame is 1280 × 720, and has 921600 pixel values, and the reference frame of the second image frame and the pixel at the corresponding position of the second image frame may be taken as a step size of 128, and has 7200 pixel values; or, taking values of the reference frame of the second image frame and the pixels at the corresponding positions of the second image frame according to the step length of 512, wherein the values have 1800 pixel values; the reference frame of the second image frame and the position pixel corresponding to the second image frame may also be subjected to value taking according to other step lengths, and the pixel value of the second image frame is subjected to value taking according to a preset step length, so that the encoding efficiency may be improved. Here, the pixel value of the corresponding position of the second image frame and the reference frame of the second image frame is described with a step size of 128, a difference value of 7200 pixel values between the reference frame of the second image frame and the corresponding position of the second image frame is calculated, 4320 target pixels satisfying Di ≧ Si in the 7200 pixel value difference values are set, the number of preset pixels is 3600, the number of target pixels is greater than the number of preset pixels, the initial quantization parameter is subtracted by the quantization constant to obtain a target quantization parameter ilumaQp of the second image frame, which is ilumaQp-T, which is an initialized quantization parameter of the second image frame, and may be set to a maximum value or a default value.
Optionally, in a third example, a pixel value difference between a pixel in a reference frame of the second image frame and a pixel at a corresponding position in the second image frame is calculated; determining the number of target pixels of which the pixel value difference is greater than or equal to a preset difference; and when the target proportion value is larger than or equal to the preset proportion value, subtracting the quantization constant from the initial quantization parameter to obtain a target quantization parameter of the second image frame. Illustratively, the macroblock is composed of pixel values, for example, 1280 × 720 for the second image frame, there are 921600 pixel values, 921600 pixel value differences between pixels at corresponding positions of the second image frame and a reference frame of the second image frame are calculated, 691200 target pixels satisfying Di ≧ Si among 921600 pixel value differences are calculated, the ratio of the target pixel number 691200 in the second image pixel value number 921600 is calculated to obtain a target ratio value of 0.75, the preset ratio value is set to 0.5, the target ratio value is greater than the preset ratio value, the quantization constant is subtracted from the initial quantization parameter to obtain a target quantization parameter ilumaQp ═ ilumaQp-T for the second image frame, the ilumaQp is an initialized quantization parameter for the second image frame, and may be set to a maximum value, which may be a default value, where, the present embodiment is not limited, and T is a constant and may be set according to actual situations.
Optionally, in a fourth example, the value of the pixel at the corresponding position of the reference frame of the second image frame and the second image frame is described with a step size of 128, where every 128 pixels in 921600 pixel values have a pixel value of 7200, a difference value of 7200 pixel values between the reference frame of the second image frame and the pixel at the corresponding position of the second image frame is calculated, 4320 target pixels satisfying Di ≧ Si in the 7200 pixel value difference values, a ratio of the target pixel number 4320 in the second image pixel value number 7200 is calculated to obtain a target ratio value of 0.6, the preset ratio value is set to 0.5, the target ratio value is greater than the preset ratio value, the quantization parameter ilumaQp of the second image frame obtained by subtracting the quantization constant from the initial quantization parameter is ilumaQp-T, the ilumaQp is the initial quantization parameter of the second image frame, and may be a default value, and the embodiment of the present application is not limited, t is a constant and can be set according to actual conditions.
Optionally, in a fifth example, a pixel value luminance component difference value and a chrominance component difference value of a reference frame of the second image frame and a pixel at a corresponding position of the second image frame are calculated; determining the number of target pixels of which the pixel value brightness component difference value and the chrominance component difference value are greater than or equal to a preset difference value; and when the target proportion value is larger than or equal to the preset proportion value, subtracting the quantization constant from the initial quantization parameter to obtain a target quantization parameter of the second image frame. For example, in the h.264 compression standard, an image frame is encoded and decoded by encoding and decoding a luminance signal Y for describing brightness and two chrominance signals U and V for describing color and saturation of the image frame. Di represents a pixel value difference, i takes values of 0,1 and 2, D0 represents a luminance Y component difference, D1 represents a chrominance U component difference, D2 represents a chrominance V component difference, Si represents a preset difference, i takes values of 0,1 and 2, S0 represents a luminance Y component preset difference, takes a value of 3, S1 represents a chrominance U component preset difference, takes a value of 2, and S2 represents a chrominance V component preset difference, takes a value of 2. The ratio of the luminance component to the chrominance component is different during encoding and decoding of the image frame, and for example, 4:2:0 means that there are 4 luminance components and 2 chrominance components in every 4 pixels. When the preset difference value setting is performed on the luminance component and the chrominance component, the setting may be performed according to an actual situation, which is only described as an example and is not limited in the embodiment of the present application. And determining the number of target pixels of which the pixel value brightness component difference value and the chrominance component difference value are greater than or equal to a preset difference value. As shown in fig. 7, fig. 7 is a schematic diagram of another image frame quantization parameter adjustment method provided by an embodiment of the present application, in fig. 7, Index is used as an Index of a pixel value to indicate a position of the pixel value, Di is greater than or equal to Si, i is 0,1, 2, j in calsum (j) is 0,1, calsum (0) indicates a target number of pixels satisfying D0 greater than or equal to S0 in a luminance Y component pixel value difference value, and calsum (1) indicates a target number of pixels satisfying D1 greater than or equal to S1 and D2 greater than or equal to S2 in a chrominance U, V component pixel value difference value; SR (0) represents the proportion value of the second image pixel value number of the target pixels satisfying D0 ≧ S0 in the luminance Y-component pixel value difference values, and SR (1) represents the proportion value of the second image pixel value number of the target pixels satisfying D1 ≧ S1 and D2 ≧ S2 in the chrominance U, V-component pixel value difference values. Illustratively, the second image frame is 1280 × 720, 921600 pixel values are provided, the step size is set to 128, one pixel value is taken every 128 pixels, 7200 pixels are provided, 3600 target pixels satisfying D0 ≧ S0 among the luminance Y-component pixel value difference values, the occupied proportion among the second image pixel value number 7200 is 0.5, a target proportion value SR (0) is obtained as 0.5, 2520 target pixels satisfying D1 ≧ S1 and D2 ≧ S2 among the chrominance U, V-component pixel value difference values, the occupied proportion among the second image pixel value number 7200 is 0.35, a target proportion value SR (1) is obtained as 0.35, a preset difference value DR (0) is set as 0.25, a preset difference value DR (1) is set as 0.25, a target proportion value SR (0) is greater than a preset proportion value DR 0, and a target proportion value SR (1) is greater than a preset proportion value DR 1, the second image frame is judged to be switched to the scene, subtracting the quantization constant from the initial quantization parameter to obtain a target quantization parameter ilumaQp-T of the second image frame,
the ilemaqp is an initialized quantization parameter of the second image frame, and may be set to a maximum value, or may be a default value, and the constant T takes a value of 2, and may be set according to an actual situation, which is not limited in this embodiment of the present application.
Here, it is understood that, when the target quantization parameter of the second image frame is adjusted according to the luminance component and the chrominance component, the quantization constant may be determined directly according to the ratio of the difference value of the luminance component of the pixel value and the number of target pixels of which the difference value of the chrominance component is greater than or equal to the preset difference value, without taking the preset step length; or determining a quantization constant according to the pixel value brightness component difference value and the target pixel number of which the chroma component difference value is greater than or equal to a preset difference value; or the number of the pixel value brightness component difference values and the number of the chrominance component difference values can be reduced according to a preset step length, and then a quantization constant is determined according to the target pixel number of the pixel value brightness component difference values and the chrominance component difference values which are more than or equal to the preset difference values; the method for determining the quantization constant is the same as described above, and is not described herein again. In fig. 7, the quantization constant is determined by a ratio of the preset step size and the target pixel value number, which is only an exemplary illustration and does not represent that the embodiment of the present application is limited thereto.
In the three possible implementation manners, when the image frame is coded, the image frame can be independently any one possible implementation manner without the limitation of the sequence; or the combination of any two possible implementation manners, wherein the possible implementation manners in the combination are not limited by the sequence; the present invention may also be a combination of three possible implementation manners, and the possible implementation manners in the combination are not limited by the order, so that the present invention is only exemplary and is not limited. Here, a combination of three possible implementations is described by taking a specific example. When the coding of the video image frame is controlled, whether the second image frame is a scene switching frame or not is judged, and then the quantization parameter of the second image frame is adjusted. Fig. 8 is a schematic diagram of another image frame quantization parameter adjustment provided in an embodiment of the present application, and as shown in fig. 8, a first frame in the image frames is an I frame, is an independent frame with all information, is a reference frame, does not need a matching block, has no motion estimation process, does not calculate an overhead value of the first frame in the image frames, and a second image frame is any one of the image frames to be encoded, and when the image frame is an I frame, other encoding processes are directly performed; optionally, the second image frame starts from the second frame, a pixel value luminance component difference value and a chrominance component difference value of a pixel at a position corresponding to the reference frame of the second image frame and the second image frame are calculated, and the number of target pixels of which the pixel value luminance component difference value and the chrominance component difference value are greater than or equal to a preset difference value is determined; calculating the ratio of the number of the target pixels to the number of the second image pixel values to obtain a target proportion value, judging the second image frame to be a scene switching frame when the target proportion value is greater than or equal to a preset proportion value, and adjusting the target quantization parameters of the second image frame according to the quantization parameters of the scene switching frame; and when the target proportion value is smaller than the preset proportion value, judging that the second image frame is not a scene switching frame, and adjusting the target quantization parameter of the second image frame according to the number of the macro blocks of at least one macro block of the first image frame in each overhead value interval and the initial quantization parameter of the second image frame.
In order to avoid the problem that the quantization parameter of the second image frame is adjusted too much to cause a large increase in the code rate, the embodiment of the present invention may further perform step 104 after step 103.
Step 104: and determining a current quantization parameter of the second image frame based on the target quantization parameter and the initial quantization parameter, and encoding the second image frame according to the current quantization parameter.
Optionally, determining the current quantization parameter of the second image frame based on the target quantization parameter and the initial quantization parameter includes: calculating the absolute value of the difference value between the initial quantization parameter and the target quantization parameter of the second image frame; when the absolute value is less than or equal to a preset value, determining the target quantization parameter as a current quantization parameter; and when the absolute value is larger than the preset value, determining the initial quantization parameter as the current quantization parameter.
Determining a target quantization parameter of the second image frame according to the steps 101 to 103, wherein the initial quantization parameter is a quantization parameter of the second image frame before adjustment, the target quantization parameter is a quantization parameter of the second image frame after adjustment, and the quantization parameter is determined after comparing the quantization parameter of the second image frame after adjustment with the quantization parameter of the second image frame before adjustment, so that excessive adjustment of the quantization parameter of the second image frame can be prevented, unreasonable code rate allocation in the encoding process is realized, and resource waste is caused.
Here, when the quantization parameter of the second image frame is adjusted, a quantization constant may be added to the initial quantization parameter of the second image frame, or the quantization constant may be subtracted from the initial quantization parameter of the second image frame, and the quantization constant may be a negative number. The initial value of the quantization parameter may be set to a maximum value, a minimum value, or a default value. When the initial value of the quantization parameter is set to be the maximum value, the quantization constant is subtracted from the initial quantization parameter of the second image frame when the quantization parameter is adjusted, when the initial value of the quantization parameter is set to be the minimum value, the quantization constant is added to the initial quantization parameter of the second image frame when the quantization parameter is adjusted, and when the initial value of the quantization parameter is set to be the default value, the quantization constant is added to or subtracted from the initial quantization parameter of the second image frame when the quantization parameter is adjusted.
The overhead value of the first image frame in the motion estimation process is continuously updated in an iterative manner, and the quantization parameter of the second image frame is adjusted according to the overhead value of the first image frame in the motion estimation process, so that the resource allocation is reasonable, and the resource waste is reduced. For example, after the quantization parameter of the Second image frame is adjusted according to the overhead value of the first image frame in the motion estimation process, the Second image frame without adjusting the quantization parameter and after adjusting the quantization parameter may be evaluated by using test data such as peak signal-to-noise ratio (PSNR), Bit rate (Bit), frame rate (frame Per Second, FPS), and the like, as shown in table 1, where table 1 is an index provided by the embodiment of the present application after adjusting the quantization parameter.
-- Y PSNR U PSNR V PSNR BIT FPS
yuv1 0.047 0.054 0.04 0.83% -5.04%
yuv2 0.104 0.038 0.061 0.98% -8.56%
yuv3 0.095 0.06 -0.028 0.70% -10.82%
yuv4 0.166 0.08 0.098 1.85% -10.82%
avg 0.103 0.058 0.04275 1.09% -8.81%
PSNR in table 1 represents a gain value of luminance component Y, PSNR represents a gain value of chrominance component U, vpnr represents a gain value of chrominance component V, BIT is used to represent a code rate of a video frame, the code rate is used to represent the number of BITs of data transmitted per unit time during data transmission, and the video frame becomes clearer as the code rate is higher. The FPS is used for representing the frame rate of video frames, the frame rate is used for representing the frame number of pictures transmitted in 1 second, the number of pictures displayed per second influences the smoothness of the pictures, and is in direct proportion to the smoothness of the pictures, the higher the frame rate is, the smoother the pictures are, the more resources are occupied, the smaller the frame rate is, the more jumping motion effect is caused to the pictures, and the less resources are occupied. The indexes after the quantization parameters are adjusted in table 1 include a gain value of the luminance component Y, a gain value of the chrominance component U, a gain value of the chrominance component V, a bit rate of the video frame, and a frame rate of the video frame, and table 1 shows the indexes and the average values after the quantization parameters are adjusted in 4 numbers. The gain value of the brightness component Y in the average value is 0.103dB, the gain value of the chrominance component U is 0.058dB, the gain value of the chrominance component V is 0.04275dB, the BIT rate of the video frame is increased by 1.09%, the frame rate FPS of the video frame is reduced by 8.81%, and the resource occupied by the image frame is obviously improved in the index after the quantization parameter is adjusted.
The method comprises the steps of acquiring an overhead value of at least one macro block in a first image frame in a motion estimation process, wherein the first image frame is an image frame which is already encoded; determining the number of the macro blocks of at least one macro block of the first image frame in each overhead value interval according to the acquired overhead value and at least one overhead value interval; and determining a target quantization parameter of the second image frame according to the number of the macro blocks of at least one macro block of the first image frame in each overhead value interval and the initial quantization parameter of the second image frame to be coded. When the quantization parameters of the image frames are adjusted, the resources of the image frames are reasonably distributed, so that the resource waste is reduced.
Example II,
An embodiment of the present application provides a device 90 for controlling encoding of a video image frame, as shown in fig. 9, fig. 9 is a structural diagram of the device for controlling encoding of a video image frame provided by the present application, where the device for controlling encoding of a video image frame includes: an obtaining module 901, a macroblock number determining module 902, a quantization parameter determining module 903 and an encoding module 904;
an obtaining module 901, configured to obtain overhead values of n macroblocks in a first image frame in a motion estimation process, where the first image frame is an image frame that has already been encoded, and n is the number of macroblocks in the first image frame;
a macroblock number determining module 902, configured to determine, according to the obtained overhead value and m overhead value intervals, the number of macroblocks in each overhead value interval of the first image frame, where m is an integer greater than 1 and smaller than n;
a quantization parameter determining module 903, configured to determine a target quantization parameter of a second image frame according to the number of macroblocks in each overhead value interval of a first image frame and an initial quantization parameter of the second image frame to be encoded, where the first image frame is located before the second image frame in time sequence.
And an encoding module 904, configured to determine a current quantization parameter of the second image frame based on the target quantization parameter and the initial quantization parameter, and encode the second image frame according to the current quantization parameter.
Example III,
Based on the video image frame coding control method described in the first embodiment, the number of macroblocks of the coded first image frame in m overhead value intervals is counted, wherein the macroblock overhead value of the first image frame is continuously updated, and the quantization parameter of the second image frame to be coded is timely adjusted according to the distribution of the macroblock overhead value of the first image frame, so that when the quantization parameter of the image frame is adjusted, the resource waste is reduced by reasonably allocating the bit rate of the image frame. An embodiment of the present application provides an electronic device, as shown in fig. 10, fig. 10 is a structural diagram of an electronic device provided in an embodiment of the present application, where the electronic device 100 includes: at least one processor 1001; the memory 1002, the memory storing at least one program 1012, when executed by the at least one processor 1001, causes the at least one processor 1001 to implement the method as described in the first embodiment.
Optionally, the electronic device 100 may further include a bus 1003 and a communication interface 1004, and the at least one processor 1001, the memory 1002 and the communication interface 1004 communicate with each other through the bus 1003.
Example four,
Based on the method for controlling encoding of video image frames described in the first embodiment, the present application provides a computer storage medium storing a computer program, which when executed by a processor implements the method described in the first embodiment.
The image similarity calculation device of the embodiment of the present application exists in various forms, including but not limited to:
(1) a mobile communication device: such devices are characterized by mobile communications capabilities and are primarily targeted at providing voice, data communications. Such terminals include: smart phones (e.g., iphones), multimedia phones, functional phones, and low-end phones, among others.
(2) Ultra mobile personal computer device: the equipment belongs to the category of personal computers, has calculation and processing functions and generally has the characteristic of mobile internet access. Such terminals include: PDA, MID, and UMPC devices, etc., such as ipads.
(3) A portable entertainment device: such devices can display and play multimedia content. This type of device comprises: audio, video players (e.g., ipods), handheld game consoles, electronic books, and smart toys and portable car navigation devices.
(4) And other electronic equipment with data interaction function.
Thus, particular embodiments of the present subject matter have been described. Other embodiments are within the scope of the following claims. In some cases, the actions recited in the claims can be performed in a different order and still achieve desirable results. In addition, the processes depicted in the accompanying figures do not necessarily require the particular order shown, or sequential order, to achieve desirable results. In some embodiments, multitasking and parallel processing may be advantageous.
For convenience of description, the above devices are described as being divided into various units by function, and are described separately. Of course, the functionality of the units may be implemented in one or more software and/or hardware when implementing the present application.
As will be appreciated by one skilled in the art, embodiments of the present application may be provided as a method, apparatus, or computer program product. Accordingly, the present application may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, the present application may take the form of a computer program product embodied on one or more computer-usable computer storage media (including, but not limited to, disk storage, CD-ROM, optical storage, and the like) having computer-usable program code embodied therein.
The present application is described with reference to flowchart illustrations and/or block diagrams of methods, apparatus, and computer program products according to embodiments of the application. It will be understood that each flow and/or block of the flow diagrams and/or block diagrams, and combinations of flows and/or blocks in the flow diagrams and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instruction means which implement the function specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
In a typical configuration, a computing device includes one or more processors (CPUs), input/output interfaces, network interfaces, and memory.
The memory may include forms of volatile memory in a computer readable medium, Random Access Memory (RAM) and/or non-volatile memory, such as Read Only Memory (ROM) or flash memory (flash RAM). Memory is an example of a computer-readable medium.
Computer-readable media, including both non-transitory and non-transitory, removable and non-removable media, may implement information storage by any method or technology. The information may be computer readable instructions, data structures, modules of a program, or other data. Examples of computer storage media for a computer include, but are not limited to, phase change memory (PRAM), Static Random Access Memory (SRAM), Dynamic Random Access Memory (DRAM), other types of Random Access Memory (RAM), Read Only Memory (ROM), Electrically Erasable Programmable Read Only Memory (EEPROM), flash memory or other memory technology, compact disc read only memory (CD-ROM), Digital Versatile Discs (DVD) or other optical storage, magnetic cassettes, magnetic tape magnetic disk storage or other magnetic storage devices, or any other non-transmission medium that can be used to store information that can be accessed by a computing device. As defined herein, a computer readable medium does not include a transitory computer readable medium such as a modulated data signal and a carrier wave.
It should also be noted that the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other identical elements in the process, method, article, or apparatus that comprises the element.
As will be appreciated by one skilled in the art, embodiments of the present application may be provided as a method, system, or computer program product. Accordingly, the present application may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, the present application may take the form of a computer program product embodied on one or more computer-usable computer storage media (including, but not limited to, disk storage, CD-ROM, optical storage, and the like) having computer-usable program code embodied therein.
The application may be described in the general context of computer-executable instructions, such as program modules, being executed by a computer. Generally, program modules include routines, programs, objects, components, data structures, etc. that perform particular transactions or implement particular abstract data types. The application may also be practiced in distributed computing environments where transactions are performed by remote processing devices that are linked through a communications network. In a distributed computing environment, program modules may be located in both local and remote computer storage media including memory storage devices.
The embodiments in the present specification are described in a progressive manner, and the same and similar parts among the embodiments are referred to each other, and each embodiment focuses on the differences from the other embodiments. In particular, for the system embodiment, since it is substantially similar to the method embodiment, the description is simple, and for the relevant points, reference may be made to the partial description of the method embodiment.
The above are merely examples of the present application and are not intended to limit the present application. Various modifications and changes may occur to those skilled in the art. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application should be included in the scope of the claims of the present application.

Claims (12)

1. A method for controlling encoding of a video image frame, the method comprising:
acquiring overhead values of n macro blocks in a first image frame in a motion estimation process, wherein the first image frame is an image frame which is coded already, and n is the number of the macro blocks in the first image frame;
determining the number of macro blocks of the first image frame in each overhead value interval according to the acquired overhead values and m overhead value intervals, wherein m is an integer larger than 1 and smaller than n;
determining a target quantization parameter of a second image frame to be coded according to the number of macro blocks of the first image frame in each overhead value interval and an initial quantization parameter of the second image frame, wherein the first image frame is positioned in front of the second image frame in time sequence;
determining a current quantization parameter of the second image frame based on the target quantization parameter and the initial quantization parameter, and encoding the second image frame according to the current quantization parameter.
2. The method of claim 1, wherein determining a target quantization parameter for a second image frame to be encoded according to the number of macroblocks in each overhead value interval of the first image frame and an initial quantization parameter for the second image frame comprises:
calculating a ratio value of the number of macro blocks of each overhead value interval in the first image frame to the number of all macro blocks of the first image frame;
determining a first preset step length corresponding to each proportion value according to the matching result of each proportion value and a preset target condition;
and determining a target quantization parameter of the second image frame according to the initial quantization parameter of the second image frame and the first preset step length.
3. The method of claim 2, wherein determining a first preset step corresponding to each ratio value according to a matching result of each ratio value and a preset target condition comprises:
determining the value of the first preset step size as a first numerical value when R0+ R1+ R2 is greater than a first threshold; determining the value of the first preset step size as a second numerical value when R1+ R2+ R3 is greater than a second threshold value; determining the value of the first preset step size as a third value when R2+ R3+ R4 is greater than a third threshold; determining the value of the first preset step size as a fourth numerical value when R4+ R5+ R6 is greater than a fourth threshold value; determining the value of the first preset step size as a fifth numerical value when R5+ R6 is greater than a fifth threshold value;
wherein the m is equal to 7, and the ratio values of the number of macroblocks of the 7 overhead value intervals in the first image frame to the number of all macroblocks of the first image frame are R0, R1, R2, R3, R4, R5 and R6, respectively.
4. The method of claim 1, further comprising:
respectively calculating pixel value difference values of pixels in a second image frame and pixels at corresponding positions in a reference frame of the second image frame according to a second preset step increment aiming at the pixels in the second image frame;
determining the number of target pixels of which the pixel value difference is greater than or equal to a preset difference;
and when the ratio of the target pixel number in all the pixel value difference numbers is larger than or equal to a first ratio, subtracting a quantization constant from the initial quantization parameter to obtain a target quantization parameter of the second image frame.
5. The method of claim 4, further comprising:
when the ratio of the target pixel number in the difference number of all pixel values is smaller than a second ratio, taking the ratio of the number of macroblocks with overhead value equal to 0 to the number of all macroblocks in n macroblocks of the first image frame as a third ratio;
when the third ratio is larger than the preset ratio, determining a second preset step length corresponding to the third ratio;
and determining a target quantization parameter of the second image frame according to the initial quantization parameter of the second image frame and the second preset step length.
6. The method according to claim 5, wherein when the third ratio is greater than the preset ratio, determining a second preset step corresponding to the third ratio comprises:
when the third ratio is larger than a sixth threshold, determining the value of a second preset step length as a sixth numerical value; and when the third ratio is larger than a seventh threshold and smaller than a sixth threshold, determining the value of the second preset step as a seventh numerical value.
7. The method of claim 1, further comprising:
acquiring a sample image frame set, and calculating a cost value of each macro block in the sample image frame set in a motion estimation process, wherein each sample image frame in the sample image frame set is an encoded image frame;
and determining the m overhead value intervals according to the overhead value of each macro block in the sample image frame set in the motion estimation process.
8. The method of claim 7, wherein determining the m cost value intervals from the cost value of each macroblock in the sample image frame set in a motion estimation process comprises:
determining a sample overhead value interval according to the number of macro blocks in the sample image frame set and the overhead value corresponding to each macro block, and adjusting the sample overhead value interval according to the distribution condition of the overhead value of each macro block in a preset image frame in the sample overhead value interval to obtain the m overhead value intervals.
9. The method of any of claims 1-8, wherein determining the current quantization parameter for the second image frame based on the target quantization parameter and the initial quantization parameter comprises:
calculating the absolute value of the difference value between the initial quantization parameter and the target quantization parameter of the second image frame;
when the absolute value is less than or equal to a preset value, determining the target quantization parameter as the current quantization parameter;
and when the absolute value is larger than a preset value, determining the initial quantization parameter as the current quantization parameter.
10. An encoding control apparatus for video image frames, comprising: the device comprises an acquisition module, a macro block quantity determination module, a quantization parameter determination module and an encoding module;
the acquiring module is configured to acquire overhead values of n macroblocks in a first image frame in a motion estimation process, where the first image frame is an image frame that has already been encoded, and n is the number of macroblocks in the first image frame;
the macroblock number determining module is configured to determine, according to the obtained overhead value and m overhead value intervals, the number of macroblocks in each overhead value interval of the first image frame, where m is an integer greater than 1 and smaller than n;
the quantization parameter determination module is configured to determine a target quantization parameter of a second image frame to be encoded according to the number of macroblocks of the first image frame in each overhead value interval and an initial quantization parameter of the second image frame, where the first image frame is located before the second image frame in time sequence;
the encoding module is configured to determine a current quantization parameter of the second image frame based on the target quantization parameter and the initial quantization parameter, and encode the second image frame according to the current quantization parameter.
11. An electronic device, comprising: a processor and a memory, the memory having a computer program stored thereon; the processor is configured to execute the computer program stored in the memory to implement the method of any one of claims 1-9.
12. A computer storage medium, characterized in that it stores a computer program which, when executed by a processor, implements the method according to any one of claims 1-9.
CN201911038750.7A 2019-10-29 2019-10-29 Video image frame coding control method and device and computer storage medium Active CN112752106B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201911038750.7A CN112752106B (en) 2019-10-29 2019-10-29 Video image frame coding control method and device and computer storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201911038750.7A CN112752106B (en) 2019-10-29 2019-10-29 Video image frame coding control method and device and computer storage medium

Publications (2)

Publication Number Publication Date
CN112752106A CN112752106A (en) 2021-05-04
CN112752106B true CN112752106B (en) 2022-02-18

Family

ID=75641601

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201911038750.7A Active CN112752106B (en) 2019-10-29 2019-10-29 Video image frame coding control method and device and computer storage medium

Country Status (1)

Country Link
CN (1) CN112752106B (en)

Families Citing this family (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114051144A (en) * 2021-11-09 2022-02-15 京东科技信息技术有限公司 Video compression method and device, computer equipment and storage medium
CN116688495B (en) * 2022-11-04 2024-04-19 荣耀终端有限公司 Frame rate adjusting method and related device
CN115580723B (en) * 2022-12-09 2023-06-09 中南大学 Method, system, equipment and medium for optimizing coding of screen content image

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
KR20070034869A (en) * 2005-09-26 2007-03-29 삼성전자주식회사 Apparatus and method for controlling bit rate of video encoder
CN101313581A (en) * 2005-11-22 2008-11-26 汤姆森许可贸易公司 Method and device for coding a video image
CN105491377A (en) * 2015-12-15 2016-04-13 华中科技大学 Video decoding macro-block-grade parallel scheduling method for perceiving calculation complexity
CN109413427A (en) * 2017-08-17 2019-03-01 腾讯科技(深圳)有限公司 A kind of video frame coding method and terminal

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US9661329B2 (en) * 2014-04-30 2017-05-23 Intel Corporation Constant quality video coding

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
KR20070034869A (en) * 2005-09-26 2007-03-29 삼성전자주식회사 Apparatus and method for controlling bit rate of video encoder
CN101313581A (en) * 2005-11-22 2008-11-26 汤姆森许可贸易公司 Method and device for coding a video image
CN105491377A (en) * 2015-12-15 2016-04-13 华中科技大学 Video decoding macro-block-grade parallel scheduling method for perceiving calculation complexity
CN109413427A (en) * 2017-08-17 2019-03-01 腾讯科技(深圳)有限公司 A kind of video frame coding method and terminal

Also Published As

Publication number Publication date
CN112752106A (en) 2021-05-04

Similar Documents

Publication Publication Date Title
KR102307771B1 (en) Video encoding method, computer device and storage medium
CN112752106B (en) Video image frame coding control method and device and computer storage medium
CN113766226A (en) Image encoding method, apparatus, device and storage medium
US10200687B2 (en) Sample adaptive offset for high dynamic range (HDR) video compression
CN108810545B (en) Method, apparatus, computer readable medium and electronic device for video encoding
CN111010495B (en) Video denoising processing method and device
CN105472205B (en) Real-time video noise reduction method and device in encoding process
CN108012163B (en) Code rate control method and device for video coding
CN112073735B (en) Video information processing method and device, electronic equipment and storage medium
CN112672149B (en) Video processing method and device, storage medium and server
CN106961603A (en) Intracoded frame code rate allocation method and device
US20170180745A1 (en) Prediction method and Electronic Apparatus of encoding mode of variable resolution
CN109089121B (en) Motion estimation method and device based on video coding and electronic equipment
CN110740316A (en) Data coding method and device
CN107820095B (en) Long-term reference image selection method and device
CN115118964A (en) Video encoding method, video encoding device, electronic equipment and computer-readable storage medium
US20080267284A1 (en) Moving picture compression apparatus and method of controlling operation of same
CN111629206A (en) Video encoding method, video playing method, related device and medium
Cho et al. Improvement of JPEG XL lossy image coding using region adaptive dct block partitioning structure
US20230108722A1 (en) Allocating bit rate between video streams using machine learning
CN113973202A (en) Video encoding method, device, equipment and storage medium
CN117354524B (en) Method, device, equipment and computer medium for testing coding performance of encoder
CN114449283B (en) Data processing method, device, computer equipment and storage medium
CN111050175A (en) Method and apparatus for video encoding
CN117376551B (en) Video coding acceleration method and electronic equipment

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