Coding Method, Apparatus, Device, and Storage Medium

By calculating the pixel gradient value and cost information of the macroblock in the video encoding algorithm, and optimizing the quantization parameter offset value, the problem of inaccurate offset value of the macroblock quantization parameter is solved, and the quality and compression efficiency of video encoding are improved.

CN114845105BActive Publication Date: 2025-07-04ALIBABA GROUP HOLDING LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202110137797.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-02-01
Publication Date
2025-07-04
Estimated Expiration
2041-02-01

AI Technical Summary

Technical Problem

In the existing video encoding algorithm, the calculation of the offset value of the quantization parameter of the macroblock is not accurate enough, which affects the encoding effect.

Method used

By calculating the pixel gradient value of the macroblock, combining the genetic cost and intra prediction cost, the calculation method of the quantized parameter offset value of the macroblock is optimized to more accurately reflect the degree of influence of the macroblock on future frames.

Benefits of technology

Improve the quality and compression efficiency of video encoding and optimize the encoding effect.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114845105B_ABST
    Figure CN114845105B_ABST
Patent Text Reader

Abstract

The present invention provides an encoding method, apparatus, device, and storage medium. The method includes: determining the pixel gradient values, genetic costs, intra-prediction costs, and quantization parameters of a target frame image corresponding to multiple macroblocks respectively; determining the quantization parameter offset values corresponding to the multiple macroblocks respectively according to the pixel gradient values, genetic costs, and intra-prediction costs corresponding to the multiple macroblocks respectively; determining the quantization parameters of the multiple macroblocks according to the quantization parameter offset values corresponding to the multiple macroblocks respectively and the quantization parameters of the target frame image; and encoding the target frame image according to the quantization parameters of the multiple macroblocks. When encoding a certain frame image in a video, during the process of calculating the quantization parameter offset values of each macroblock in this frame image, considering the pixel gradient information of each macroblock, the calculation result of the quantization parameter offset value of the macroblock can more accurately reflect the influence degree of the macroblock on future frames, making the encoding effect of the video better.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of video encoding technology, and in particular, to an encoding method, apparatus, device, and storage medium. Background Art

[0002] By encoding a video, the space occupied by the video can be compressed. Currently, a commonly used video encoding algorithm is the Macroblock Tree (Mbtree) algorithm, which can achieve a high compression efficiency.

[0003] During the execution of the Mbtree algorithm, when encoding any frame image in a video, it is necessary to calculate the quantization parameters of each macroblock in this frame image in order to complete the encoding of this frame image based on the quantization parameters of each macroblock. In order to calculate the quantization parameter offset values of each macroblock in this frame image, it is necessary to first calculate the quantization parameter offset values of each macroblock in this frame image. It can be seen that the accuracy of the quantization parameter offset value of a macroblock will directly affect the final encoding effect. Summary of the Invention

[0004] Embodiments of the present invention provide an encoding method, apparatus, device, and storage medium, which can improve the encoding effect.

[0005] In a first aspect, an embodiment of the present invention provides an encoding method, which includes:

[0006] Determine the pixel gradient values, genetic costs, intra-prediction costs, and quantization parameters of the target frame image corresponding to each of the multiple macroblocks in the target frame image, where the target frame image is a frame image to be currently encoded in the video to be encoded;

[0007] Determine the quantization parameter offset values corresponding to each of the multiple macroblocks according to the pixel gradient values, genetic costs, and intra-prediction costs corresponding to each of the multiple macroblocks;

[0008] Determine the quantization parameters corresponding to each of the multiple macroblocks according to the quantization parameter offset values corresponding to each of the multiple macroblocks and the quantization parameters of the target frame image;

[0009] Encode the target frame image according to the quantization parameters corresponding to each of the multiple macroblocks.

[0010] In a second aspect, an embodiment of the present invention provides an encoding apparatus, which includes:

[0011] A first determination module, configured to determine the pixel gradient values, genetic costs, intra-prediction costs, and quantization parameters of the target frame image corresponding to each of the multiple macroblocks in the target frame image, where the target frame image is a frame image to be currently encoded in the video to be encoded;

[0012] A second determination module, configured to determine a quantization parameter offset value corresponding to each of the multiple macroblocks according to the pixel gradient value, genetic cost, and intra prediction cost corresponding to each of the multiple macroblocks;

[0013] A third determination module, configured to determine a quantization parameter corresponding to each of the multiple macroblocks according to the quantization parameter offset value corresponding to each of the multiple macroblocks and the quantization parameter of the target frame image;

[0014] An encoding module, configured to encode the target frame image according to the quantization parameter corresponding to each of the multiple macroblocks.

[0015] In a third aspect, an embodiment of the present invention provides an electronic device, including: a memory and a processor; wherein, an executable code is stored on the memory, and when the executable code is executed by the processor, the processor can at least implement the encoding method as described in the first aspect.

[0016] In a fourth aspect, an embodiment of the present invention provides a non-transitory machine-readable storage medium, on which an executable code is stored. When the executable code is executed by a processor of an electronic device, the processor can at least implement the encoding method as described in the first aspect.

[0017] During the encoding process of a certain video, it is necessary to encode frame by frame according to the display order of each frame image in the video. The current frame image to be encoded is referred to as the target frame image. When it is necessary to encode the target frame image, it is necessary to determine the quantization parameter offset value corresponding to each of the multiple macroblocks in the target frame image and the quantization parameter of the target frame image, so as to determine the quantization parameter corresponding to each of the multiple macroblocks according to the quantization parameter offset value corresponding to each of the multiple macroblocks and the quantization parameter of the target frame image, and finally complete the encoding of the target frame image based on the quantization parameter corresponding to each of the multiple macroblocks.

[0018] It can be seen that the accuracy of the determination result of the quantization parameter offset value of the macroblock has an important impact on the final encoding effect. Specifically, for a certain macroblock in the target frame image, if the amount of reference information it provides for future frames (i.e., frames whose encoding order is after the target frame image) is more, it means that its importance is higher, and the encoding quality of this macroblock area should be improved. Then, it is necessary to reduce the quantization parameter offset value of this macroblock, so that the quantization parameter of this macroblock is smaller, so that the quality of the encoded video will be better and the compression efficiency will be higher.

[0019] In order to more accurately measure the quantization parameter offset value of a macroblock, in the embodiments of the present invention, by calculating the pixel gradient value of the macroblock, using the pixel gradient value to reflect the influence degree of the macroblock on future frames, and determining the quantization parameter offset value of the macroblock in combination with the pixel gradient value, genetic cost, and intra-prediction cost, the determined quantization parameter offset value can be made more reasonable, thereby further improving the video coding quality and compression efficiency. BRIEF DESCRIPTION OF THE DRAWINGS

[0020] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following will briefly introduce the drawings required for the description of the embodiments. Obviously, the drawings in the following description are some embodiments of the present invention. For those of ordinary skill in the art, without creative efforts, other drawings can also be obtained based on these drawings.

[0021] Figure 1 It is a flowchart of an encoding method provided by an embodiment of the present invention;

[0022] Figure 2 It is a schematic diagram of an encoding structure provided by an embodiment of the present invention;

[0023] Figure 3 It is a schematic diagram of an inheritance information amount distribution result provided by an embodiment of the present invention;

[0024] Figure 4 It is a schematic diagram of the structure of an encoding device provided by an embodiment of the present invention;

[0025] Figure 5 For Figure 4 It is a schematic diagram of the structure of an electronic device corresponding to the encoding device shown in the embodiment. DETAILED DESCRIPTION OF THE EMBODIMENTS

[0026] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the following will clearly and completely describe the technical solutions in the embodiments of the present invention with reference to the drawings in the embodiments of the present invention. Obviously, the described embodiments are some, but not all, of the embodiments of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by those of ordinary skill in the art without creative efforts fall within the protection scope of the present invention.

[0027] The terms used in the embodiments of the present invention are only for the purpose of describing specific embodiments and are not intended to limit the present invention. The singular forms "a", "said", and "the" used in the embodiments of the present invention and the appended claims are also intended to include the plural forms unless the context clearly indicates otherwise. "Plural" generally includes at least two.

[0028] Depending on the context, as used herein, the terms "if" and "when" can be interpreted as "when" or "while" or "in response to determining" or "in response to detecting". Similarly, depending on the context, the phrase "if determined" or "if detecting (stated condition or event)" can be interpreted as "when determined" or "in response to determining" or "when detecting (stated condition or event)" or "in response to detecting (stated condition or event)".

[0029] In addition, the step timings in the following method embodiments are only examples and not strictly limited.

[0030] The video coding algorithm adopted in the embodiments of the present invention is the Mbtree algorithm. In the Mbtree algorithm, the concept of macroblock is defined. Briefly, a pixel region with a set size in a frame of image constitutes a macroblock, such as 16*16 pixels. A frame of image can include multiple macroblocks. A video is composed of several frames of images arranged in sequence. During the video coding process, each frame of image is encoded in sequence according to the timing order. In the Mbtree algorithm, each macroblock is processed. Thus, if a certain frame of image in the video needs to be encoded currently, the quantization parameters of each macroblock in this frame of image need to be obtained to complete the encoding of this frame of image in combination with the quantization parameters of these macroblocks (specifically refer to the implementation of existing related technologies).

[0031] The working principle of the Mbtree algorithm is briefly as follows: According to the amount of information contributed by a macroblock to future frames (frames located after the currently encoded frame in the coding order) in inter-frame prediction, that is, the reference situation, the quantization parameters of the macroblock are adjusted. In short, if the amount of information contributed by the macroblock to future frames is more, its importance is higher, and the coding quality of the macroblock area should be improved and its quantization parameters should be reduced. On the contrary, the quantization parameters of the macroblock area are increased.

[0032] To know the contribution degree of the current macroblock to future frames, it is necessary to backtrack from future frames how much information comes from the current macroblock. Since future frames have not been encoded yet, forward prediction (lookahead) needs to be used for prediction. That is to say, for each macroblock, the reference situation of the macroblock in a certain number of frames (the number is determined based on the preset lookahead) is predicted forward to finally determine the quantization parameters of the macroblock.

[0033] During the process of calculating the quantization parameters of a macroblock, it is necessary to first calculate the quantization parameter offset value of this macroblock and the quantization parameter of the frame of image where the macroblock is located (frame-level quantization parameter). Then, the quantization parameter offset value of the macroblock is added to the quantization parameter of the frame of image, and the sum result is the quantization parameter of the macroblock (block-level quantization parameter).

[0034] In the embodiment of the present invention, the calculation method of the quantization parameter of a frame of image is not changed, only the calculation method of the quantization parameter offset value of the macroblock is changed, that is, an optimization of the way of calculating the quantization parameter offset value of the macroblock by the traditional Mbtree algorithm. Among them, the traditional Mbtree algorithm calculates the quantization parameter offset value of the macroblock only based on the genetic cost and the intra-frame prediction cost of the macroblock. By adopting the calculation method of the quantization parameter offset value of the macroblock provided by the embodiment of the present invention, the quantization parameter of the macroblock finally calculated based on the quantization parameter offset value can more accurately reflect the contribution degree of the macroblock to the future frame.

[0035] The encoding scheme provided by the embodiment of the present invention can be applied to any video encoding scenario, such as various application scenarios involving video encoding such as video live broadcast, video on demand, audio-video communication, multimedia production, and multimedia data processing. The encoding scheme can be executed by an electronic device, which can be a video server providing video or a terminal device, such as a live broadcast terminal. By encoding the video, it can be compressed to an appropriate size.

[0036] The following introduces the solution provided by the embodiment of the present invention in conjunction with the following embodiments.

[0037] Figure 1 It is a flowchart of an encoding method provided by an embodiment of the present invention. As Figure 1 shown, the method may include the following steps:

[0038] 101. Determine the pixel gradient value, genetic cost, intra-frame prediction cost corresponding to each of the multiple macroblocks in the target frame image, and the quantization parameter of the target frame image, where the target frame image is a frame image to be currently encoded in the video to be encoded.

[0039] 102. Determine the quantization parameter offset value corresponding to each of the multiple macroblocks according to the pixel gradient value, genetic cost, and intra-frame prediction cost corresponding to each of the multiple macroblocks.

[0040] 103. Determine the quantization parameter corresponding to each of the multiple macroblocks according to the quantization parameter offset value corresponding to each of the multiple macroblocks and the quantization parameter of the target frame image.

[0041] 104. Encode the target frame image according to the quantization parameter corresponding to each of the multiple macroblocks.

[0042] In an embodiment of the present invention, a frame image to be currently encoded in a video to be encoded is referred to as a target frame image. The target frame image contains multiple macroblocks. For each macroblock, multiple parameters need to be calculated, such as: pixel gradient value, propagate_cost, intra_cost, inter_cost, and motion vector.

[0043] Among them, the calculation processes of other parameters will be introduced below. Here, only the calculation process of the pixel gradient value will be mainly introduced.

[0044] Specifically, for any one of the multiple macroblocks, the pixel gradient value corresponding to the any one macroblock can be determined according to the pixel gradient values corresponding to the pixels in the any one macroblock.

[0045] Specifically, assume that a macroblock consists of 16*16, that is, 256 pixels. Each pixel can have two pixel gradient values: a horizontal gradient value and a vertical gradient value. Among them, for any pixel i, assume its pixel position is (x, y). Then, the difference between the pixel value of pixel i and the pixel value of its left adjacent pixel (position (x - 1, y)) can be used as the horizontal gradient value of pixel i, and the difference between the pixel value of pixel i and the pixel value of its upper adjacent pixel (position (x, y + 1)) can be used as the vertical gradient value of pixel i.

[0046] It can be understood that when within the macroblock, if pixel i has no left adjacent pixel and / or no upper adjacent pixel, the horizontal gradient value and vertical gradient value of pixel i can be determined according to a preset calculation method, such as presetting the pixel value of the left adjacent / upper adjacent pixel as a certain set value.

[0047] After obtaining the pixel gradient values of each pixel in the macroblock, optionally, the pixel gradient values of each pixel can be added together, and the sum result is used as the pixel gradient value of the macroblock. Among them, adding the pixel gradient values of each pixel can be: adding all the horizontal gradient values and vertical gradient values of the 256 pixels together to finally obtain a value, and this value is used as the pixel gradient value of the macroblock.

[0048] Of course, the method for calculating the pixel gradient value of a macroblock is not limited to the above example, and other methods that can fuse the pixel gradient values of each pixel can be used.

[0049] In the embodiments of the present invention, the reason for calculating the pixel gradient information of a macroblock is that the influence degree of the macroblock on future frames, that is, the contribution degree to the coding of future frames, can be determined based on the pixel gradient information of the macroblock. If the pixel gradient value of a certain macroblock is smaller, it can be considered that at this time it corresponds to a slowly changing scene, and its influence on future frames is greater. At this time, it is necessary to reduce the quantization parameter offset value of this macroblock calculated by the traditional Mbtree algorithm. On the contrary, if the pixel gradient value of a certain macroblock is larger, it can be considered that its influence on future frames is smaller. At this time, it is necessary to increase the quantization parameter offset value of this macroblock calculated by the traditional Mbtree algorithm. Because the human eye can tolerate certain defects in rapidly changing scenes, but relatively speaking, the human eye is quite sensitive to certain defects in smooth scenes. Note that the smoothness mentioned here refers to the change frequency of the scene along the time dimension, rather than the scene in the pixel domain in the ordinary sense.

[0050] In this way, when calculating the quantization parameter offset value of each macroblock, considering the pixel gradient information of each macroblock, the influence degree of each macroblock on future frames can be more accurately measured, and a more reasonable quantization parameter offset value can be obtained.

[0051] After obtaining the pixel gradient values of each macroblock, the quantization parameter offset values of each macroblock can be finally determined by combining the genetic cost and intra-frame prediction cost of each macroblock that have been obtained.

[0052] Optionally, in the process of determining the quantization parameter offset values corresponding to multiple macroblocks in the target frame image, the adjustment factors corresponding to the multiple macroblocks can be first determined according to the pixel gradient values corresponding to the multiple macroblocks, and then the quantization parameter offset values corresponding to the multiple macroblocks can be determined according to the adjustment factors, genetic cost, and intra-frame prediction cost corresponding to the multiple macroblocks.

[0053] Among them, the function of the adjustment factor is to achieve the following adjustment purpose: if the pixel gradient value of the macroblock is smaller, the quantization parameter offset value of this macroblock calculated by the traditional Mbtree algorithm is reduced. On the contrary, if the pixel gradient value of the macroblock is larger, the quantization parameter offset value of this macroblock calculated by the traditional Mbtree algorithm is increased.

[0054] To achieve the above purpose, the following transformation rules will be presented for the pixel gradient value corresponding to the macroblock, the adjustment factor corresponding to the macroblock, and the quantization parameter offset value corresponding to the macroblock:

[0055] If the pixel gradient value corresponding to any macroblock is larger, the adjustment factor corresponding to the any macroblock is larger, and the quantization parameter offset value corresponding to the any macroblock is larger.

[0056] On the contrary, if the pixel gradient value corresponding to the any macroblock is smaller, the adjustment factor corresponding to the any macroblock is smaller, and the quantization parameter offset value corresponding to the any macroblock is smaller.

[0057] Based on this, any method for determining the adjustment factor can be applied as long as the determination method can meet the above regular requirements.

[0058] Two optional methods for determining the adjustment factor will be introduced below. Here, it is first assumed that the adjustment factors corresponding to multiple macroblocks have been determined. At this time, based on the following formula, the quantization parameter offset values corresponding to multiple macroblocks can be determined:

[0059]

[0060] Among them, taking any macroblock Bi as an example, QpOffset represents the quantization parameter offset value of macroblock Bi, intra_cost represents the intra-frame prediction cost of macroblock Bi, propagate_cost represents the genetic cost of macroblock Bi, and gradientCostWeight represents the adjustment factor corresponding to macroblock Bi.

[0061] Under the traditional Mbtree algorithm, the formula for calculating the quantization parameter offset value of macroblock Bi is:

[0062]

[0063] By comparison, in the embodiment of the present invention, in the process of calculating the quantization parameter offset value of a macroblock, by considering the pixel gradient information of the macroblock, the influence of each macroblock on the future frame can be more accurately measured, and a more reasonable quantization parameter offset value can be obtained.

[0064] After calculating the quantization parameter offset values corresponding to multiple macroblocks in the target frame image, the quantization parameter of each macroblock is obtained by adding the quantization parameter offset value of each macroblock to the quantization parameter of the target frame image. Then, based on the quantization parameters corresponding to multiple macroblocks, the encoding of the target frame image is completed. The above process is performed on each frame image in the video to be encoded, and the encoding of each frame image is completed, that is, the encoding of the video is completed.

[0065] Two optional implementation methods for calculating the adjustment factor corresponding to a macroblock are introduced below.

[0066] In an optional embodiment, the calculation of the adjustment factors corresponding to multiple macroblocks can be implemented in the following manner:

[0067] According to the pixel gradient values corresponding to multiple macroblocks, the average pixel gradient value, the first pixel gradient value, and the second pixel gradient value are determined, where the first pixel gradient value is greater than the average pixel gradient value, and the second pixel gradient value is less than the average pixel gradient value;

[0068] For any one of multiple macroblocks, if the pixel gradient value corresponding to the any one of the macroblocks is greater than or equal to the average pixel gradient value, determine a first adjustment factor corresponding to the any one of the macroblocks according to the average pixel gradient value and the first pixel gradient value;

[0069] If the pixel gradient value corresponding to any one of the macroblocks is less than the average pixel gradient value, determine a second gradient adjustment factor corresponding to the any one of the macroblocks according to the average pixel gradient value and the second pixel gradient value, and the first gradient adjustment factor is greater than the second adjustment factor.

[0070] Wherein, the first pixel gradient value may be the maximum pixel gradient value among the pixel gradient values corresponding to the multiple macroblocks respectively, and the second pixel gradient value may be the minimum pixel gradient value among the pixel gradient values corresponding to the multiple macroblocks respectively.

[0071] In the above implementation manner, taking the average pixel gradient value as the comparison object, when the pixel gradient value of a certain macroblock is greater than or equal to the average pixel gradient value, it is considered that the pixel gradient value of this macroblock is relatively large and the influence degree on the future frame is small, then a larger adjustment factor is assigned to this macroblock. In this way, according to the above formula for calculating the quantization parameter offset value, a larger quantization parameter offset value can be obtained. On the contrary, when the pixel gradient value of a certain macroblock is less than the average pixel gradient value, it is considered that the pixel gradient value of this macroblock is relatively small and the influence degree on the future frame is large, then a smaller adjustment factor is assigned to this macroblock. In this way, according to the above formula for calculating the quantization parameter offset value, a smaller quantization parameter offset value can be obtained.

[0072] Optionally, taking any one macroblock Bi as an example, if the pixel gradient value of the macroblock Bi is greater than or equal to the average pixel gradient value, the determination method of the first adjustment factor corresponding to the macroblock Bi may be:

[0073] Determine a first difference between the pixel gradient value corresponding to the macroblock Bi and the average pixel gradient value, and a second difference between the first pixel gradient value and the second pixel gradient value;

[0074] Determine the quotient of the first difference and the second difference;

[0075] Determine the sum result of the quotient and a set value as the first adjustment factor corresponding to the macroblock Bi.

[0076] The above calculation process can be expressed by the formula as:

[0077]

[0078] Among them, idx represents the macroblock number, gradientcost[idx] represents the pixel gradient value of the macroblock, avergradientcost represents the average pixel gradient value, and gradientMax represents the first pixel gradient value. In this formula, the above-set numerical value takes 1.

[0079] Optionally, taking any macroblock Bj as an example, if the pixel gradient value of the macroblock Bj is less than the average pixel gradient value, the determination method of the second adjustment factor corresponding to the macroblock Bj can be:

[0080] Determine the third difference between the pixel gradient value corresponding to the macroblock Bj and the average pixel gradient value, and the fourth difference between the second pixel gradient value and the average pixel gradient value;

[0081] Determine the quotient of the third difference and the fourth difference;

[0082] Determine the difference between the set numerical value and the quotient as the second adjustment factor corresponding to the macroblock Bj.

[0083] The above calculation process can be expressed by the formula:

[0084]

[0085] Among them, gradientMin represents the second pixel gradient value. In this formula, the above-set numerical value takes 1.

[0086] The above introduces an implementation method for calculating the adjustment factor corresponding to the macroblock.

[0087] In another alternative embodiment, the calculation of the adjustment factor corresponding to each of multiple macroblocks can also be implemented in the following manner:

[0088] Determine the average pixel gradient value according to the pixel gradient values corresponding to each of the multiple macroblocks;

[0089] For any one of the multiple macroblocks, determine the quotient of the pixel gradient value corresponding to the any one macroblock and the average pixel gradient value as the adjustment factor corresponding to the any one macroblock.

[0090] In this implementation manner, it is also possible to achieve the purpose that the adjustment factor corresponding to the macroblock with a high pixel gradient value is also high, and the adjustment factor corresponding to the macroblock with a low pixel gradient value is also low.

[0091] In summary, in the embodiments of the present invention, when encoding a certain frame of an image in a video, in the process of calculating the quantization parameter offset values of each macroblock in this frame of image, considering the respective pixel gradient information of the macroblocks can make the calculation results of the quantization parameter offset values of the macroblocks more truly and accurately reflect the influence degree of the macroblocks on future frames, thereby making the encoding effect of the video more optimized and the compression efficiency improved.

[0092] As described above, in the process of calculating the quantization parameter offset value of a macroblock, in addition to calculating information related to pixel gradient such as the pixel gradient value and adjustment factor of the macroblock, information such as the propagate_cost, intra_cost, inter_cost, and motion vector of the macroblock also needs to be used. The following briefly introduces the calculation process of this information and the overall process of video coding.

[0093] When encoding a video to be encoded, first determine multiple frames of images in the video to be encoded according to the preset lookahead number of forward prediction frames, and then perform the following two steps:

[0094] First, traverse each frame of image from the last frame of image in the multiple frames of images to the target frame image to be encoded currently, and perform the following steps for each macroblock in the currently traversed frame image: Determine the intra_cost, inter_cost, and motion vector of each macroblock in the currently traversed frame image.

[0095] Second, traverse each frame of image from the last frame of image in the multiple frames of images to the target frame image to be encoded currently, and calculate the amount of information provided by each macroblock in the previous frame image of the currently traversed frame image for future frames, that is, the propagate_cost.

[0096] After repeatedly executing the above process through multiple loops, the propagate_cost of each macroblock in the target frame image (the frame image that needs to be encoded currently) will finally be obtained. By calculating the intra_cost and pixel gradient value of each macroblock in the target frame image, the quantization parameter offset value of each macroblock in the target frame image can finally be calculated based on the formula given above. Furthermore, according to the quantization parameter offset value of each macroblock in the target frame image and the quantization parameter of the target frame image, the quantization parameter of each macroblock in the target frame image can be determined. Finally, encode the target frame image according to the quantization parameter of each macroblock in the target frame image.

[0097] For ease of understanding the above loop calculation process, in combination with Figure 2 and Figure 3 to exemplarily illustrate the above loop calculation process.

[0098] Assume that the coding structure of the video is the IPPP structure shown in Figure 2 (only for example here, videos with other coding structures are also applicable to this solution), where I and P are two frame types. In addition, in Figure 2 assume that the lookahead number of forward prediction frames is 50 frames, that is, the lookahead window length is 50 frames.

[0099] Assume that currently, the first frame image in the video needs to be encoded. Then, the first frame image to the 50th frame image are required to complete the encoding of the first frame image.

[0100] Specifically, it is necessary to traverse frame by frame starting from the 50th frame image until the currently required first frame image to be encoded is traversed. When each frame image is traversed, it is necessary to calculate the intra-frame prediction cost, inter-frame prediction cost, and motion vector of each macroblock in the current frame image (referring to the currently traversed frame image as the current frame image).

[0101] Assume that the current frame image is the 50th frame image, and assume that each frame image contains 4 macroblocks. Then, the 4 macroblocks contained in the 50th frame image can be represented as A50, B50, C50, and D50. Then, the intra-frame prediction cost of each macroblock can be calculated based on these 4 macroblocks contained in the 50th frame image. Assume that the calculation results of the intra-frame prediction costs of these 4 macroblocks are respectively represented as: intra_cost_A50, intra_cost_B50, intra_cost_C50, intra_cost_D50.

[0102] In addition, it is necessary to perform inter-frame prediction on the cost of each macroblock in the 50th frame image referring to the previous frame image, i.e., the 49th frame image, to obtain the inter-frame prediction costs of these 4 macroblocks in the 50th frame image. Assume that the calculation results of the inter-frame prediction costs of these 4 macroblocks are respectively represented as: inter_cost_A50, inter_cost_B50, inter_cost_C50, inter_cost_D50.

[0103] Meanwhile, during the inter-frame prediction process, it is also necessary to record the motion vectors of these 4 macroblocks in the 50th frame image, which are respectively represented as: MVA50, MVB50, MVC50, MVD50.

[0104] So far, when the 50th frame image is traversed for the first time, the above parameter information is obtained. After that, the 49th frame image is traversed. Assume that the 4 macroblocks contained in the 49th frame image are represented as A49, B49, C49, D49. Based on the same calculation process, the intra-frame prediction costs of these 4 macroblocks contained in the 49th frame image can be obtained: intra_cost_A49, intra_cost_B49, intra_cost_C49, intra_cost_D49, the inter-frame prediction costs of these 4 macroblocks: inter_cost_A49, inter_cost_B49, inter_cost_C49, inter_cost_D49, and the motion vectors of these 4 macroblocks, which are respectively represented as: MVA49, MVB49, MVC49, MVD49.

[0105] And so on, until the first frame of the image is traversed, and the intra-prediction cost of the 4 macroblocks included in the first frame of the image can be obtained.

[0106] It should be noted that since the first frame of the image is the first frame, and only the intra-prediction cost, pixel gradient value, and genetic cost of each macroblock in the first frame of the image are required to calculate the quantization parameter offset value of each macroblock in the first frame of the image according to the formula in the above text. Therefore, for the first frame of the image, it is not necessary to calculate the inter-prediction cost and motion vector of each macroblock therein.

[0107] The specific calculation processes of the above intra-prediction cost, inter-prediction cost, and motion vector can be implemented with reference to existing related technologies and will not be elaborated here.

[0108] So far, the execution process of the above first step has been completed.

[0109] The main purpose of the execution process of the second step is: starting from the last frame, that is, the 50th frame, loop to calculate the amount of information provided by each macroblock in the previous frame of the current frame to the future frame, that is, the genetic cost propagate_cost. Among them, the genetic cost of each macroblock in the 50th frame image, which is the last frame, is initialized to 0.

[0110] Taking the current frame as the 50th frame image as an example, at this time, it is necessary to calculate the amount of information provided by each macroblock in its previous frame image, that is, the 49th frame image, to the future frame, and this amount of information is represented by the genetic cost propagate_cost. To complete this calculation, it can be specifically implemented through the following steps:

[0111] (1). First, calculate the amount of information inherited by each macroblock in the 50th frame image from the 49th frame image.

[0112] Among them, the calculation formula for the amount of information buf inherited by each macroblock in the i-th frame image from the (i - 1)-th frame image is:

[0113] buf_i = (0.5 * intra_cost_i + propagate_cost_i) * propagate_faction_i

[0114]

[0115] Among them, buf_i represents the amount of information inherited by any macroblock in the i-th frame from the (i - 1)-th frame image, intra_cost_i represents the intra-frame prediction cost of any macroblock in the i-th frame, inter_cost_i represents the inter-frame prediction cost of any macroblock in the i-th frame, and propagate_faction_i represents the inheritance rate of any macroblock in the i-th frame. The inheritance rate represents how much of the macroblock's information comes from the reference frame.

[0116] Based on the above formula, it can be known that:

[0117] Taking the macroblock A50 in the 50th frame image as an example, the amount of information inherited by macroblock A50 from the 49th frame image can be expressed as:

[0118] buf_A50 = (0.5 * intra_cost_A50 + propagate_cost_A50) * propagate_faction_A50

[0119] Among them, In addition, according to the preset conditions, it can be known that propagate_cost_A50 = 0.

[0120] Similarly, the amounts of information buf_B50, buf_C50, and buf_D50 inherited by other macroblocks B50, C50, and D50 in the 50th frame image from the 49th frame image can be calculated.

[0121] (2) Taking macroblock A50 as an example, distribute buf_A50 to different macroblocks in its reference frame image, i.e., the 49th frame image, according to the motion vector of macroblock A50, and determine the amount of information provided by different macroblocks in the 49th frame image for macroblock A50.

[0122] The distribution result is as Figure 3 shown. In Figure 3 assuming that according to the motion vector of macroblock A50, the corresponding reference block C50 of macroblock A50 in the 49th frame image is found. Among them, it is assumed that the reference block C50 actually covers two macroblocks included in the 49th frame image: A49 and B49. Among them, the overlapping area between the reference block C50 and macroblock A49 is denoted as R1, and the overlapping area between the reference block C50 and macroblock B49 is denoted as R2. Then, the amounts of information provided by macroblocks A49 and B49 for macroblock A50 can be determined according to the area ratios of regions R1 and R2 to the area of macroblock A50 respectively:

[0123] The amount of information provided by macroblock A49 for macroblock A50 is expressed as: buf_A50 * the area of region R1 / the area of macroblock A50.

[0124] The amount of information provided by macroblock B49 for macroblock A50 is expressed as: the area of the buf_A50*R21 region / the area of macroblock A50.

[0125] For the other macroblocks B50, C50, and D50 included in the 50th frame image, the processing of these two steps (1) and (2) is performed. Eventually, the amount of information provided by each macroblock in the 49th frame image for each macroblock in the 50th frame image can be obtained.

[0126] (3) After (1) and (2), the amount of information provided by each macroblock in the 49th frame image for different macroblocks in the future frame image, i.e., the 50th frame image, is obtained. The amount of information provided by any macroblock in the 49th frame image for different macroblocks in the 50th frame image is accumulated to obtain the amount of information provided by this any macroblock in the 49th frame image for the future frame image, that is, the genetic cost of this any macroblock.

[0127] Specifically, assume that macroblock A49 in the 49th frame image provides the amount of information for macroblocks A50 and B50 in the 50th frame image respectively. Add the amount of information provided by macroblock A49 for macroblocks A50 and B50 respectively, and the amount of information provided by macroblock A49 in the 49th frame image for the future frame image, i.e., the 50th frame image, can be obtained, which is also the genetic cost corresponding to macroblock 49: propagate_cost_A49. Similarly, the genetic cost corresponding to each macroblock in the 49th frame image is obtained.

[0128] The above description is based on the 50th frame image and the 49th frame image as examples. It can be understood that after calculating the genetic cost of each macroblock in the 49th frame image, update the current frame image to the 49th frame image, and repeat steps (1), (2), and (3). The genetic cost of each macroblock in the 48th frame image can be obtained, and so on, until the genetic cost of each macroblock in the first frame image is calculated.

[0129] It can be understood that after calculating the quantization parameter offset values of each macroblock in the first frame image based on the genetic cost, pixel gradient value, and intra-frame prediction cost of each macroblock in the first frame image that has been obtained, and then calculating the quantization parameters of each macroblock in the first frame image in combination with the quantization parameters of the first frame image, after completing the encoding of the first frame image based on the quantization parameters of each macroblock in the first frame image, the image to be encoded next becomes the second frame image. At this time, the 50 frames of images from the second frame image to the fifty-second frame image will be used in the encoding process of the second frame image. Continuing to repeat the execution process of the above first step and second step, the encoding of the second frame image can be completed, and so on, until the encoding of all frame images in the video is completed.

[0130] The encoding device of one or more embodiments of the present invention will be described in detail below. Those skilled in the art can understand that these encoding devices can all be configured by using commercially available hardware components through the steps taught by this solution.

[0131] Figure 4 The structural schematic diagram of an encoding device provided for an embodiment of the present invention is shown in Figure 4 As shown, the device includes: a first determination module 11, a second determination module 12, a third determination module 13, and an encoding module 14.

[0132] The first determination module 11 is configured to determine the pixel gradient value, genetic cost, intra-frame prediction cost corresponding to each of a plurality of macroblocks in the target frame image, and the quantization parameter of the target frame image, where the target frame image is a frame image to be currently encoded in the video to be encoded.

[0133] The second determination module 12 is configured to determine the quantization parameter offset value corresponding to each of the plurality of macroblocks according to the pixel gradient value, genetic cost, and intra-frame prediction cost corresponding to each of the plurality of macroblocks.

[0134] The third determination module 13 is configured to determine the quantization parameter corresponding to each of the plurality of macroblocks according to the quantization parameter offset value corresponding to each of the plurality of macroblocks and the quantization parameter of the target frame image.

[0135] The encoding module 14 is configured to encode the target frame image according to the quantization parameter corresponding to each of the plurality of macroblocks.

[0136] Optionally, the first determination module 11 is specifically configured to: for any one of the plurality of macroblocks, determine the pixel gradient value corresponding to the any one of the macroblocks according to the pixel gradient values corresponding to the pixels in the any one of the macroblocks.

[0137] Optionally, the second determination module 12 is specifically configured to: determine the adjustment factor corresponding to each of the plurality of macroblocks according to the pixel gradient values corresponding to each of the plurality of macroblocks; and determine the quantization parameter offset value corresponding to each of the plurality of macroblocks according to the adjustment factor, genetic cost, and intra-frame prediction cost corresponding to each of the plurality of macroblocks.

[0138] Wherein, if the pixel gradient value corresponding to any one of the macroblocks is larger, the adjustment factor corresponding to the any one of the macroblocks is larger, and the quantization parameter offset value corresponding to the any one of the macroblocks is larger; if the pixel gradient value corresponding to any one of the macroblocks is smaller, the adjustment factor corresponding to the any one of the macroblocks is smaller, and the quantization parameter offset value corresponding to the any one of the macroblocks is smaller.

[0139] In an alternative embodiment, the second determination module 12 is specifically configured to: determine an average pixel gradient value, a first pixel gradient value, and a second pixel gradient value according to the pixel gradient values corresponding to the multiple macroblocks, where the first pixel gradient value is greater than the average pixel gradient value, and the second pixel gradient value is less than the average pixel gradient value; for any one of the multiple macroblocks, if the pixel gradient value corresponding to the any one of the macroblocks is greater than or equal to the average pixel gradient value, determine a first adjustment factor corresponding to the any one of the macroblocks according to the average pixel gradient value and the first pixel gradient value; if the pixel gradient value corresponding to the any one of the macroblocks is less than the average pixel gradient value, determine a second gradient adjustment factor corresponding to the any one of the macroblocks according to the average pixel gradient value and the second pixel gradient value, and the first gradient adjustment factor is greater than the second adjustment factor.

[0140] Optionally, the second determination module 12 is specifically configured to: determine a first difference between the pixel gradient value corresponding to the any one of the macroblocks and the average pixel gradient value, and a second difference between the first pixel gradient value and the average pixel gradient value; determine a quotient of the first difference and the second difference; determine a sum result of the quotient and a set value as the first adjustment factor corresponding to the any one of the macroblocks.

[0141] Optionally, the second determination module 12 is specifically configured to: determine a third difference between the pixel gradient value corresponding to the any one of the macroblocks and the average pixel gradient value, and a fourth difference between the second pixel gradient value and the average pixel gradient value; determine a quotient of the third difference and the fourth difference; determine a difference between the set value and the quotient as the second adjustment factor corresponding to the any one of the macroblocks.

[0142] In an alternative embodiment, the second determination module 12 may also be configured to: determine an average pixel gradient value according to the pixel gradient values corresponding to the multiple macroblocks; for any one of the multiple macroblocks, determine a quotient of the pixel gradient value corresponding to the any one of the macroblocks and the average pixel gradient value as an adjustment factor corresponding to the any one of the macroblocks.

[0143] Figure 4 The illustrated device may execute the encoding scheme provided in the foregoing Figures 1 to 3 For the detailed execution process and technical effects, refer to the description in the foregoing embodiments, which will not be elaborated herein.

[0144] In a possible design, the structure of the foregoing Figure 4 illustrated encoding device may be implemented as an electronic device. As Figure 5As shown, the electronic device may include: a processor 21 and a memory 22. Among them, executable code is stored on the memory 22. When the executable code is executed by the processor 21, the processor 21 can at least implement the encoding method provided in the foregoing Figures 1 to 3 illustrated embodiment.

[0145] Optionally, the device may further include: a communication interface 23 for communicating with other devices.

[0146] In addition, an embodiment of the present invention provides a non-transitory machine-readable storage medium. Executable code is stored on the non-transitory machine-readable storage medium. When the executable code is executed by a processor of an electronic device, the processor can at least implement the encoding method provided in the foregoing Figures 1 to 3 illustrated embodiment.

[0147] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separated. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of this embodiment. A person of ordinary skill in the art can understand and implement it without creative effort.

[0148] Through the description of the above embodiments, those skilled in the art can clearly understand that each embodiment can be implemented by means of adding a necessary general hardware platform. Of course, it can also be implemented by a combination of hardware and software. Based on this understanding, the above technical solution, in essence, or the part that contributes to the prior art, can be embodied in the form of a computer product. The present invention can adopt the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk memories, CD-ROMs, optical memories, etc.) containing computer-usable program codes.

[0149] Finally, it should be noted that: the above embodiments are only used to illustrate the technical solutions of the present invention, and are not intended to limit them; although the present invention has been described in detail with reference to the foregoing embodiments, those of ordinary skill in the art should understand that: they can still modify the technical solutions described in the foregoing embodiments, or perform equivalent replacements for some of the technical features; and these modifications or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present invention.

Claims

1. A coding method, characterized in that, Including: Determine the pixel gradient values, genetic costs, intra-prediction costs corresponding to multiple macroblocks in the target frame image, and the quantization parameter of the target frame image, where the target frame image is a frame image to be currently encoded in the video to be encoded; Determine the average pixel gradient value, the first pixel gradient value, and the second pixel gradient value according to the pixel gradient values corresponding to the multiple macroblocks respectively, where the first pixel gradient value is greater than the average pixel gradient value, and the second pixel gradient value is less than the average pixel gradient value; Determine the adjustment factors corresponding to the multiple macroblocks respectively according to the pixel gradient values, the average pixel gradient value, the first pixel gradient value, and the second pixel gradient value corresponding to the multiple macroblocks; Determine the quantization parameter offset values corresponding to the multiple macroblocks respectively according to the adjustment factors, genetic costs, and intra-prediction costs corresponding to the multiple macroblocks; Determine the quantization parameters corresponding to the multiple macroblocks respectively according to the quantization parameter offset values and the quantization parameter of the target frame image corresponding to the multiple macroblocks; Encode the target frame image according to the quantization parameters corresponding to the multiple macroblocks.

2. The method according to claim 1, characterized in that, The determination of the pixel gradient values corresponding to the multiple macroblocks in the target frame image includes: For any one of the multiple macroblocks, determine the pixel gradient value corresponding to the any one of the macroblocks according to the pixel gradient values corresponding to the pixels in the any one of the macroblocks.

3. The method according to claim 1, characterized in that, If the pixel gradient value corresponding to any one of the multiple macroblocks is larger, the adjustment factor corresponding to the any one of the macroblocks is larger, and the quantization parameter offset value corresponding to the any one of the macroblocks is larger; if the pixel gradient value corresponding to the any one of the macroblocks is smaller, the adjustment factor corresponding to the any one of the macroblocks is smaller, and the quantization parameter offset value corresponding to the any one of the macroblocks is smaller.

4. The method according to claim 1, wherein The determination of the adjustment factors corresponding to the multiple macroblocks respectively according to the pixel gradient values, the average pixel gradient value, the first pixel gradient value, and the second pixel gradient value corresponding to the multiple macroblocks includes: For any one of the multiple macroblocks, if the pixel gradient value corresponding to the any one of the macroblocks is greater than or equal to the average pixel gradient value, determine the first adjustment factor corresponding to the any one of the macroblocks according to the average pixel gradient value and the first pixel gradient value; If the pixel gradient value corresponding to the any one of the macroblocks is less than the average pixel gradient value, determine the second adjustment factor corresponding to the any one of the macroblocks according to the average pixel gradient value and the second pixel gradient value, and the first adjustment factor is greater than the second adjustment factor.

5. The method according to claim 4, wherein The determination of the first adjustment factor corresponding to the any one of the macroblocks according to the average pixel gradient value and the first pixel gradient value includes: Determine the first difference between the pixel gradient value corresponding to the any one of the macroblocks and the average pixel gradient value, and the second difference between the first pixel gradient value and the average pixel gradient value; Determine the quotient of the first difference and the second difference; Determine the sum of the quotient and the set value as the first adjustment factor corresponding to the any one of the macroblocks.

6. The method according to claim 4, wherein Determining the second adjustment factor corresponding to any macroblock according to the average pixel gradient value and the first pixel gradient value includes: Determining a third difference between the pixel gradient value corresponding to any macroblock and the average pixel gradient value, and a fourth difference between the second pixel gradient value and the average pixel gradient value; Determining the quotient of the third difference and the fourth difference; Determining the difference between a set value and the quotient as the second adjustment factor corresponding to any macroblock.

7. The method according to claim 1, wherein The method includes: For any macroblock among the multiple macroblocks, determining the quotient of the pixel gradient value corresponding to any macroblock and the average pixel gradient value as the adjustment factor corresponding to any macroblock.

8. An encoding device, characterized in that, Including: A first determination module, configured to determine the pixel gradient value, genetic cost, intra prediction cost corresponding to each of multiple macroblocks in a target frame image, and the quantization parameter of the target frame image, where the target frame image is a frame image to be currently encoded in a video to be encoded; A second determination module, configured to determine an average pixel gradient value, a first pixel gradient value, and a second pixel gradient value according to the pixel gradient values corresponding to each of the multiple macroblocks, where the first pixel gradient value is greater than the average pixel gradient value, and the second pixel gradient value is less than the average pixel gradient value; determining the adjustment factor corresponding to each of the multiple macroblocks according to the pixel gradient values, the average pixel gradient value, the first pixel gradient value, and the second pixel gradient value corresponding to each of the multiple macroblocks; determining the quantization parameter offset value corresponding to each of the multiple macroblocks according to the adjustment factor, genetic cost, and intra prediction cost corresponding to each of the multiple macroblocks; A third determination module, configured to determine the quantization parameter corresponding to each of the multiple macroblocks according to the quantization parameter offset value corresponding to each of the multiple macroblocks and the quantization parameter of the target frame image; An encoding module, configured to encode the target frame image according to the quantization parameters corresponding to each of the multiple macroblocks.

9. An electronic device, characterized in that, Including: A memory and a processor; wherein, an executable code is stored on the memory, and when the executable code is executed by the processor, the processor executes the encoding method according to any one of claims 1 to 7.

10. A non-transitory machine-readable storage medium, characterized in that, An executable code is stored on the non-transitory machine-readable storage medium, and when the executable code is executed by a processor of an electronic device, the processor executes the encoding method according to any one of claims 1 to 7.

Citation Information

Patent Citations

  • CU-level QP allocation algorithm based on video complexity

    CN111901597A

  • CU-level QP allocation algorithm suitable for AVS2 encoder

    CN112004088A