Rate distortion optimization quantization method and device
By determining the mapping group in the super block in video encoding and calculating the difference in the number of coded bits, the problem of large amount of calculation in the existing RDOQ technology is solved, and more efficient coding and resource utilization is achieved.
Patent Information
- Application Number
- CN202210617816.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-06-01
- Publication Date
- 2025-05-06
- Estimated Expiration
- 2042-06-01
AI Technical Summary
The existing RDOQ technology has a large amount of calculation, resulting in inefficiency and serious waste of computing resources.
By determining multiple mapping groups in the superblock, each mapping group including context and initial quantization levels, the encoding number difference of each mapping group is calculated, and the target quantization level for each element is determined based on this difference.
The calculation amount of RDOQ is reduced, the encoding efficiency is improved, and the waste of computing resources is avoided.
Smart Images

Figure CN115022636B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of video coding, and in particular to a rate-distortion optimization quantization method, device, computer equipment, and computer-readable storage medium. Background Art
[0002] The current mainstream video coding standards are all based on the hybrid video coding framework, in which quantization plays an important role and is also the source of video loss. Take RDOQ (Rate-Distortion Optimization Quantization) technology as an example. It has been applied to HEVC (High Efficiency Video Coding), AV1 and other video coding standards to improve video coding performance and save bit rate.
[0003] However, the existing RDOQ technology has a large amount of computation, resulting in low efficiency and serious waste of computing resources. Summary of the invention
[0004] The purpose of the embodiments of the present application is to provide a rate-distortion optimization quantization method, apparatus, computer device, and computer-readable storage medium, which can be used to solve the problems described above.
[0005] One aspect of an embodiment of the present application further provides a rate-distortion optimization quantization method, including:
[0006] Determine a plurality of mapping groups in a super block, each mapping group including a context and an initial quantization level; wherein the super block is a coding block unit in a video frame to be coded, the super block includes a plurality of elements, and the context is used to represent correlation information between an element associated with a corresponding mapping group and a plurality of adjacent elements;
[0007] Determine a coding bit number difference value for each mapping group, where the coding bit number difference value is a difference between the coding bit number of the initial quantization level in the corresponding mapping group and the coding bit number of the initial quantization level in the corresponding mapping group minus one; and
[0008] Based on the difference in the number of coded bits of each mapping group, a target quantization level of each element in the super block is determined.
[0009] Optionally, also include:
[0010] The mapping relationship between each mapping group and the corresponding encoding bit number difference is stored in a bit number difference array, wherein the bit number difference array includes a first bit number difference array and a second bit number difference array; wherein:
[0011] The first bit number difference array corresponds to an initial quantization level whose level is lower than a first preset value;
[0012] The second bit number difference array corresponds to an initial quantization level between a second preset value and a third preset value.
[0013] Optionally, the super block corresponds to multiple transform units;
[0014] The step of determining a target quantization level for each element in the super block based on the difference in the number of coded bits of each mapping group comprises:
[0015] Determining the context of each element in the transform unit;
[0016] The transformation unit is scanned in a preset order, and when a current element in the transformation unit is scanned, the following operations are performed:
[0017] In response to the initial quantization level of the current element being a non-zero value, obtaining the initial quantization level and the target context of the current element; wherein the current element is one of the elements in the transform unit;
[0018] querying a target mapping group from the mapping groups according to the initial quantization level of the current element and the target context; and
[0019] The target quantization level of the current element is determined according to the target coding bit number difference in the target mapping group.
[0020] Optionally, the method further comprises: saving the mapping relationship between the position of each element and the context of each element in a context array;
[0021] The acquiring the initial quantization level and the target context of the current element in response to the initial quantization level of the current element being a non-zero value includes: querying the target context from the context array according to the position of the current element.
[0022] Optionally, determining the target quantization level of the current element according to the target encoding bit number difference in the target mapping group includes:
[0023] In response to the target coding bit number difference being not greater than a reference threshold, determining the initial quantization level of the current element as the target quantization level of the current element;
[0024] In response to the target coding bit number difference being greater than the reference threshold, determining an initial quantization level of the current element minus one as a target quantization level of the current element.
[0025] Optionally, the method further includes determining the reference threshold:
[0026] Determine a first value obtained by dividing the quantization step by λ, where λ is a fixed value;
[0027] Determine a second value obtained by subtracting one from twice the initial quantization level of the current element;
[0028] Determine a third value obtained by multiplying the second value by the quantization step size;
[0029] Determine a fourth value obtained by subtracting twice the transformation coefficient of the current element from the third value;
[0030] A fifth value obtained by multiplying the first value and the fourth value is determined, and a negative number of the fifth value is determined as the reference threshold.
[0031] Optionally, also include:
[0032] In response to the initial quantization level of the current element being a zero value, the current element is skipped and the next element of the current element is scanned.
[0033] Optionally, the number of coded bits of the initial quantization level in the corresponding mapping group is obtained according to the context and the initial quantization level in the corresponding mapping group;
[0034] The number of coded bits of the initial quantization level minus one in the corresponding mapping group is obtained according to the context in the corresponding mapping group and the initial quantization level minus one.
[0035] One aspect of an embodiment of the present application provides a rate-distortion optimization quantization device, including:
[0036] A first determination module is used to determine a plurality of mapping groups in a super block, each mapping group including a context and an initial quantization level; wherein the super block is a coding block unit in a video frame to be coded, the super block includes a plurality of elements, and the context is used to represent correlation information between an element associated with a corresponding mapping group and a plurality of adjacent elements;
[0037] A second determination module is configured to determine a coding bit number difference value for each mapping group, where the coding bit number difference value is a difference between the coding bit number of the initial quantization level in the corresponding mapping group and the coding bit number of the initial quantization level in the corresponding mapping group minus one; and
[0038] The third determination module is used to determine the target quantization level of each element in the super block based on the difference in the number of coded bits of each mapping group.
[0039] One aspect of an embodiment of the present application provides a computer device, which includes a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor is used to implement the steps of the rate-distortion optimization quantization method as described above when executing the computer program.
[0040] One aspect of an embodiment of the present application provides a computer-readable storage medium, which stores a computer program. The computer program can be executed by at least one processor to enable the at least one processor to perform the steps of the rate-distortion optimization quantization method as described above.
[0041] The rate-distortion optimization quantization method, device, computer equipment, and computer-readable storage medium provided by the embodiments of the present application include the following advantages: the mapping group of "initial quantization level, context, and coding bit number difference" of the super block is obtained in advance, and when determining a certain element, it is not necessary to calculate the coding bit number Rate of the initial quantization level of this element and the coding bit number Rate corresponding to the initial quantization level of this element minus one. low , it is only necessary to obtain the coding bit number difference ΔRate according to the context and initial quantization level of this element, and to determine whether to adjust the quantization level of this element according to the coding bit number difference ΔRate, thereby reducing the calculation amount of RDOQ, improving coding efficiency and avoiding waste of computing resources. BRIEF DESCRIPTION OF THE DRAWINGS
[0042] Figure 1 A diagram schematically shows an application environment of a rate-distortion optimization quantization method according to an embodiment of the present application;
[0043] Figure 2 The flowchart of the rate-distortion optimization quantization method according to the first embodiment of the present application is schematically shown;
[0044] Figure 3 The sub-flow chart of step S204 is schematically shown;
[0045] Figure 4 Another sub-flow chart of step S204 is schematically shown;
[0046] Figure 5 Another sub-flow chart of step S204 is schematically shown;
[0047] Figure 6 The steps of determining the reference threshold are schematically shown;
[0048] Figure 7 A block diagram of a rate-distortion optimization quantization device according to Embodiment 2 of the present application is schematically shown;
[0049] Figure 8The hardware architecture diagram of a computer device suitable for implementing the rate-distortion optimization quantization method according to the third embodiment of the present application is schematically shown. DETAILED DESCRIPTION
[0050] In order to make the purpose, technical solutions and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not intended to limit the present application. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in the field without making creative work are within the scope of protection of the present application.
[0051] It should be noted that the descriptions involving "first", "second", etc. in the embodiments of the present application are only for descriptive purposes and cannot be understood as indicating or implying their relative importance or implicitly indicating the number of technical features indicated. Therefore, the features defined as "first" and "second" may explicitly or implicitly include at least one of the features. In addition, the technical solutions between the various embodiments can be combined with each other, but they must be based on the ability of ordinary technicians in the field to implement them. When the combination of technical solutions is contradictory or cannot be implemented, it should be deemed that such combination of technical solutions does not exist and is not within the scope of protection required by this application.
[0052] In the description of the present application, it should be understood that the numerical labels before the steps do not indicate the order in which the steps are executed, but are only used to facilitate the description of the present application and to distinguish each step, and therefore should not be understood as a limitation on the present application.
[0053] The following is an explanation of the terms used in this application:
[0054] AV1: is an open source and royalty-free video codec developed by the non-profit industry alliance "Alliance for Open Media (AOMedia)". Depending on the use case, AV1 can achieve higher compression efficiency than VP9 and H.264.
[0055] Context (hereinafter referred to as context) indicates the relationship with adjacent elements and is used to provide association information of adjacent elements.
[0056] Quantization refers to the process of mapping the continuous value of a signal (or a large number of possible discrete values) to a finite number of discrete amplitudes. It is a many-to-one mapping. In the video encoding process, after the residual signal undergoes discrete cosine transform (DCT), the transform coefficients usually have a large range. Therefore, quantizing the transform coefficients can effectively reduce the signal value space and thus obtain a better bit rate. However, due to the many-to-one mapping nature, the quantization process will inevitably introduce data loss. Quantization is an important source of video distortion in video encoding.
[0057] RDOQ (Rate Distortion Optimized Quantization): A coefficient optimization algorithm. Specifically: In video coding, distortion and bit rate are both factors that affect coding performance. Among them, distortion reflects video quality (quantization is an important source of distortion), and bit rate reflects compression rate. Reducing distortion generally increases bit rate; reducing bit rate generally increases distortion. Therefore, in order to balance distortion and bit rate, video coding needs to balance distortion and bit rate, thereby introducing rate-distortion optimized quantization (RDOQ) technology, which combines the quantization process with the RDO (rate-distortion optimization) criterion. For a transform coefficient, multiple optional quantization values are given, and the RDO criterion is used to select the optimal quantization value (quantization level).
[0058] In order to facilitate those skilled in the art to understand the technical solutions provided by the embodiments of the present application, the relevant technologies are described below:
[0059] The AV1 encoding process includes the following processes: unit division, intra-frame prediction, inter-frame prediction, transformation, quantization, etc.
[0060] Unit division: Divide the image into multiple units and decode the image in units. For example, the image can be divided into 128x128 units, which is the largest coding unit (super block). The super block can be further divided into four equal parts (SPLIT) or two equal parts (HORZ, VERT). The sub-units of the four equal parts can be further divided.
[0061] Intra-frame prediction: removes spatial redundancy within a frame and obtains a residual unit whose pixel value is smaller than the coding unit.
[0062] Inter-frame prediction: removes temporal redundancy between frames and obtains a residual unit whose pixel value is smaller than the coding unit.
[0063] Transformation: For example, the low-frequency information and the high-frequency information are separated by DCT (discrete cosine transform), and the residual unit is transformed into a "transform unit (TU)". It should be noted that other transformation methods can also be used.
[0064] Quantization: Based on the quantization step size, the transform coefficients in the TU are quantized to obtain a quantization level, reducing the amount of data used to represent the coefficients.
[0065] RDOQ: It means to fine-tune the quantization level obtained by quantization to save bit rate without affecting the video quality.
[0066] One of the RDOQ processes used for AV1 encoding is as follows:
[0067] Step 1: Scan the transform coefficients in the TU in sequence according to the scanning order (Z-shaped, horizontal or vertical scanning). Assume that the current scanning position is scanPos, and the bit number of the current element Rate=0, until all elements in the TU are processed.
[0068] Step 2: Get the transform coefficient of the current scanning position scanPos, and obtain the initial quantization level level (absolute value) and the sign bit sign.
[0069] Step 3: If level is 0, the current element does not need to be adjusted, level = 0, and continue to process the next element.
[0070] Step 4: If level<=2, obtain the context required for encoding BR, recorded as ctx_br, and obtain the number of bits brrate required for encoding BR according to ctx_br and level, and execute Rate+=brrate+512, where 512 is the number of bits required for encoding sign.
[0071] Step 5: If 3<=level<=14, in addition to encoding BR, it is also necessary to obtain the context for encoding LR, recorded as ctx_lr, and obtain the number of bits lrrate required for encoding LR based on ctx_lr and level, and execute Rate+=lrrate.
[0072] Step 6: If level>=15, in addition to encoding the previous BR and LR, it is also necessary to obtain the number of bits hrrate for encoding HR according to level, and execute Rate+=hrrate.
[0073] Step 7: Get the distortion Dist caused by encoding the current element level.
[0074] Assuming that the transform coefficient corresponding to the current element is tqc, the inverse quantization coefficient of level is dqc, then Dist = (tqc-dqc)*(tqc-dqc).
[0075] Step 8: Calculate the rate-distortion cost RD of the current element encoded as level, RD = λ*Rate+Dist.
[0076] Among them, λ is the Lagrangian parameter in rate-distortion optimization, and its value has a corresponding functional relationship with the quantization parameter QP.
[0077] Step 9: Repeat steps 2 to 8 above, assuming that the element to be encoded is level-1, and get the new bit rate Rate low , the new distortion Dist low, and the new rate - distortion cost RD low .
[0078] Step Ten: Compare the magnitudes of RD and RD low . If RD low < RD, it indicates that it is more appropriate to encode the absolute value of the current element as level - 1.
[0079] As described above, there will be the following problems during the process of determining the level of each element, which leads to a large computational amount of RDOQ.
[0080] 1. The RDOQ algorithm dynamically adjusts the level of each element, but during the calculation of brrate and lrrate, it is necessary to calculate the context according to the latest level of adjacent elements, resulting in a large computational amount of RDOQ.
[0081] 2. During the process of the RDOQ algorithm adjusting the level of each element, it is necessary to calculate the bitrates in both the level and level - 1 cases. That is to say, the Rate needs to be calculated twice at each scanPos position, doubling the calculation.
[0082] In view of the above problems, the present application aims to provide a rate - distortion optimization quantization scheme for AV1 to solve the above problems. Specifically: 1. For all elements of the super - block, use the instruction - set optimization method to uniformly calculate the context. Subsequently, even if the level is updated, the context is no longer calculated. Since instruction - set optimization is used, the context of multiple elements can be calculated in this way, saving time; 2. No longer calculate Rate and Rate low separately, but only need to obtain the encoding bit - number difference ΔRate according to the context and level, and compare its magnitude relationship with - dequant / λ·((2level - 1)·dequant - 2tqc) to determine whether to adjust the quantization level. The explanations of each parameter are detailed later.
[0083] The following provides an exemplary application environment of the present application. For example, it can be used in the computer device 10000 as shown in Figure 1 .
[0084] The computer device 10000 can be configured to access the content (such as, video) and services of the server.
[0085] The computer device 10000 may include an electronic device carrying or connected to a display panel, such as a mobile device, a tablet device, a laptop computer, a workstation, a virtual reality device, a gaming device, a digital streaming device, a vehicle user terminal, a smart TV, a set-top box, etc., and may also include a virtualized computing instance. The virtualized computing instance may include a virtual machine, such as a simulation of a computer system, an operating system, a server, etc.
[0086] Computer device 10000 can be associated with one or more users. A single user can also use one or more of computer devices 10000 to access a server. Computer device 10000 can travel to various locations and use different networks to access a server. Computer device 10000 can include multiple client programs, such as: a video codec, which is used to provide encoding and decoding services. Among them, the video codec can encode and compress a video or image to facilitate the transmission or storage of the video or image.
[0087] In the following, several embodiments are provided in the above exemplary application environment to illustrate the rate-distortion optimized quantization scheme.
[0088] Embodiment 1
[0089] It should be noted that the execution subject of this embodiment may be the computer device 10000.
[0090] Figure 2 The flowchart of the rate-distortion optimization quantization method according to the first embodiment of the present application is schematically shown.
[0091] like Figure 2 As shown, the rate-distortion optimization quantization method may include steps S200 to S204, wherein:
[0092] Step S200, determining multiple mapping groups in a super block, each mapping group includes a context and an initial quantization level; wherein the super block is a coding block unit in a video frame to be encoded, the super block includes multiple elements, and the context is used to represent the correlation information between the elements associated with the corresponding mapping group and multiple adjacent elements.
[0093] Superblock is a coding block unit defined for AV1 coding, and its size can be 128x128. A video frame to be encoded can include multiple superblocks. A superblock can be divided into multiple transform units (TU). Each TU includes multiple elements, and each element corresponds to a transform coefficient. For example, if the size of the TU is 4x4, there are 4x4 elements, that is, a maximum of 4x4 transform coefficients.
[0094] In an exemplary application, a plurality of super blocks are divided according to a video frame to be encoded, and each super block is associated with a corresponding region in the video frame to be encoded. After the video frame to be encoded undergoes unit division, intra-frame / inter-frame prediction, and transformation, the transform coefficients of each element in the super block are obtained. Then, the transform coefficients are quantized to convert the transform coefficients into initial quantization levels.
[0095] First, the initial quantization level of an element can be calculated as follows (taking element A as an example):
[0096] level = floor(c / Qstep+f); where level represents the initial quantization level of element A, c represents the transform coefficient of element A, Qstep represents the quantization step, floor is a floor function, and f controls the rounding relationship. It should be noted that the above calculation method is only exemplary and can also be obtained by other calculation methods.
[0097] Second: The context of an element can be obtained in the following way (taking element A as an example):
[0098] Since element A is correlated with multiple adjacent elements, the quantization levels of several previously processed elements can be used to construct a context in the TU. For example, the sum of the quantization levels of the elements used as the context of element A can be determined based on the scanning order (Z-shaped, horizontal or vertical scanning).
[0099] It should be noted that different initial quantization levels have different encoding methods and contexts. The specific calculation of context can refer to the technical specifications of AV1, such as: if level≤2, determine the context (the sum of the quantization levels of five adjacent elements) required for encoding BR (base range). If 3≤level≤14, determine the context (the sum of the quantization levels of three adjacent elements) required for encoding LR (lowrange). If level≥15, determine the context required for encoding HR (high range).
[0100] The above describes how to obtain the context and initial quantization level of an element. It should be noted that transforming the transform coefficient of an element into the initial quantization level of the element achieves compression of the video frame to be encoded to a certain extent, but in order to further save the bit rate, after obtaining the initial quantization level of each element, this embodiment also fine-tunes the initial quantization level of the element through RDOQ without affecting the video quality.
[0101] Step S202 : determining a coding bit number difference for each mapping group, where the coding bit number difference is the difference between the coding bit number of the initial quantization level in the corresponding mapping group and the coding bit number of the initial quantization level minus one in the corresponding mapping group.
[0102] RDOQ is to strike a balance between distortion and bit rate, and in this embodiment, it is reflected in whether to fine-tune the initial quantization level.
[0103] The fine-tuning is to select between an element "initial quantization level" and the element's "initial quantization level minus one". If the rate-distortion cost of replacing the "initial quantization level" with the "initial quantization level minus one" is large, then the replacement is not performed. On the contrary, if the rate-distortion cost is small, then the replacement is performed.
[0104] As described in step S202, the basis for determining whether to perform fine-tuning in this embodiment is: the difference in the number of coding bits.
[0105] In order to obtain the accurate difference in the number of coded bits, the number of coded bits of the initial quantization level in the corresponding mapping group is obtained according to the context and the initial quantization level in the corresponding mapping group, and the number of coded bits of the initial quantization level minus one in the corresponding mapping group is obtained according to the context and the initial quantization level minus one in the corresponding mapping group.
[0106] The following provides an example of the difference in the number of coded bits:
[0107] First, based on the context-based coding algorithm, the number of coding bits can be calculated according to the context and the initial quantization level, so that a lookup table including multiple sets of "context, quantization level, number of coding bits" can be obtained.
[0108] Secondly, taking mapping group X as an example, the calculation process of its corresponding encoding bit number difference △Rate is:
[0109] (1) According to the context and initial quantization level of mapping group X, the corresponding number of coding bits (Rate) is calculated.
[0110] ①If level≤2, obtain the context required for encoding BR, and obtain the number of coding bits brrate from the above query table based on the context and level. Execute Rate+=brrate+512. 512 is the number of coding bits required for sign. ②If 3≤level≤14, obtain the context required for encoding LR, and obtain the number of coding bits lrrate from the above query table based on the context and level. Execute Rate+=lrrate. ③If level≥15, obtain the context required for encoding HR, and obtain the number of coding bits hrrate based on the context and level. Execute Rate+=hrrate.
[0111] (2) Calculate the number of coded bits (Rate) when the initial quantization level is reduced by one (level-1) low ). The calculation process can refer to the above.
[0112] (3) The rate corresponding to the "initial quantization level" minus the rate corresponding to the "initial quantization level minus one" low , and get △Rate.
[0113] Based on the above exemplary process, the encoding bit number difference △Rate of each mapping group can be obtained. Since the encoding bit number difference △Rate of each mapping group is calculated in advance, it is not necessary to calculate the Rate corresponding to the "initial quantization level" and the Rate corresponding to the "initial quantization level minus one" element by element. low , thus saving computing resources.
[0114] As an optional embodiment, the method further includes:
[0115] The mapping relationship between each mapping group and the corresponding encoding bit number difference is stored in a bit number difference array, wherein the bit number difference array includes a first bit number difference array and a second bit number difference array; wherein:
[0116] The first bit number difference array corresponds to an initial quantization level whose level is lower than a first preset value;
[0117] The second bit number difference array corresponds to an initial quantization level between a second preset value and a third preset value.
[0118] Lower than the first preset value, which is ≤2.
[0119] Between the second preset value and the third preset value is between 3 (including the endpoint) and 14 (including the endpoint).
[0120] The above embodiment provides a query service for subsequent quantization level adjustment by setting a bit number difference array, thereby improving efficiency.
[0121] Step S204: determining a target quantization level for each element in the super block based on the difference in the number of coded bits of each mapping group.
[0122] Taking element A as an example, if the rate-distortion cost of replacing the "initial quantization level" with the "initial quantization level minus one" is large, the "initial quantization level" of element A is used as the target quantization cost. On the contrary, if the rate-distortion cost is small, the "initial quantization level minus one" of element A is used as the target quantization cost.
[0123] The rate-distortion optimization quantization method provided in the embodiment of the present application obtains the mapping group of "initial quantization level, context and coding bit number difference" of the super block in advance. When determining a certain element, it is not necessary to calculate the coding bit number Rate of the initial quantization level of this element and the coding bit number Rate corresponding to the initial quantization level of this element minus one one by one. low , it is only necessary to obtain the coding bit number difference ΔRate according to the context and initial quantization level of this element, and to determine whether to adjust the quantization level of this element according to the coding bit number difference ΔRate, thereby reducing the amount of RDOQ calculation, improving coding efficiency and avoiding waste of computing resources.
[0124] As an optional embodiment, the super block corresponds to multiple transform units (TUs).
[0125] like Figure 3As shown, the step S204 can be implemented by the following steps: step S300, determining the context of each element in the transform unit; step S302, scanning the transform unit in a preset order (Z-shaped, horizontal, vertical scanning), when scanning the current element in the transform unit, performing operations such as steps S3021-S3024: step S3021, in response to the initial quantization level of the current element being a non-zero value, obtaining the initial quantization level and target context of the current element; wherein the current element is one of the elements in the transform unit; step S3022, querying the target mapping group from the mapping group according to the initial quantization level of the current element and the target context; and step S3023, determining the target quantization level of the current element according to the target coding bit number difference in the target mapping group. Step S3024, in response to the initial quantization level of the current element being a zero value, skipping the current element, and scanning the next element of the current element. The next element is used as the current element and repeats steps S3021-S3024. Compared to the need to calculate the context individually in real time each time an element is scanned, the present embodiment can use the instruction set optimization method to uniformly calculate the context in advance, and the subsequent quantization level update of the adjacent elements no longer calculates the context. Since the context of multiple elements is calculated using the instruction set optimization, time is saved. In addition, in the present embodiment, when the current element is scanned, the context can be obtained immediately, and the target coding bit number difference can be quickly obtained, so as to determine whether to adjust the quantization level based on the target coding bit number difference.
[0126] In another optional embodiment, if Figure 4As shown, the step S204 can be implemented by the following steps: step S400, determining the context of each element in the transform unit; step S402, saving the mapping relationship between the position of each element and the context of each element in the context array; step S404, scanning the transform unit in a preset order, and when the current element in the transform unit is scanned, performing the following operations: step S4041, in response to the initial quantization level of the current element being a non-zero value, obtaining the initial quantization level of the current element, and querying the target context from the context array according to the position of the current element; step S4042, querying the target mapping group from the mapping group according to the initial quantization level of the current element and the target context; and step S4043, determining the target quantization level of the current element according to the target coding bit number difference in the target mapping group. Step S4044, in response to the initial quantization level of the current element being a zero value, skipping the current element, and scanning the next element of the current element. The next element is used as the current element and steps S4041-S4044 are repeated. Compared to the need to calculate the context individually in real time each time an element is scanned, the present embodiment can use instruction set optimization to uniformly calculate the context in advance, and the subsequent quantization level update of adjacent elements no longer calculates the context. Since the context of multiple elements is calculated using instruction set optimization, time is saved. In addition, in the present embodiment, when the current element is scanned, the previously set context array can be queried to quickly query the context of the current element and quickly obtain the target coding bit number difference, so as to determine whether to adjust the quantization level based on the target coding bit number difference.
[0127] For easier understanding, an exemplary application is provided below.
[0128] There are NxM elements distributed in a TU, where N and M are natural numbers.
[0129] ① Determine the context of all elements (NxM) in TU, and store the relationship between the position of each element and the context in the context array.
[0130] When scanning TU, when scanning to the current element (such as element A):
[0131] ② Obtain the transformation coefficient qcoeff and initial quantization level level (absolute value) of element A.
[0132] ③Determine whether the level of element A is 0.
[0133] ④ If the level of element A is 0, the quantization level of element A does not need to be adjusted, and the next element can be processed.
[0134] ⑤ If the level of element A is not 0, further determine whether to adjust the quantization level of element A. Since the coding bit difference of each mapping group (context-initial quantization level) is determined in advance, the coding bit difference of element A can be quickly located according to the level of element A and the context of element A, and then determine whether to adjust the quantization level according to the coding bit difference of element A.
[0135] In an optional embodiment, if Figure 5 As shown, the step S204 "determining the target quantization level of each element in the super block based on the difference in the number of coded bits of each mapping group" may include: step S500, in response to the difference in the number of target coded bits being not greater than a reference threshold, determining the initial quantization level of the current element as the target quantization level of the current element; step S502, in response to the difference in the number of target coded bits being greater than the reference threshold, determining the initial quantization level of the current element minus one as the target quantization level of the current element. Since it is not necessary to calculate Rate and Rate for each element separately, low Instead, it is only necessary to quickly obtain the coding bit number difference ΔRate (such as the target coding bit number difference) according to the context and level, and determine whether to adjust the quantization level according to the comparison between the target coding bit number difference and the reference threshold, thereby effectively reducing the calculation amount of RDOQ and achieving resource saving.
[0136] In an optional embodiment, in order to save computing resources and ensure the accuracy of determining whether to adjust the quantization level, as Figure 6 As shown, the method includes the steps of determining the reference threshold: step S600, determining a first value obtained by dividing the quantization step by λ, where λ is a fixed value; step S602, determining a second value obtained by subtracting one from twice the initial quantization level of the current element; step S604, determining a third value obtained by multiplying the second value by the quantization step; step S606, determining a fourth value obtained by subtracting twice the transformation coefficient of the current element from the third value; step S608, determining a fifth value obtained by multiplying the first value by the fourth value, and determining the negative of the fifth value as the reference threshold.
[0137] That is, the reference threshold is: -dequant / λ·(((2level)-1)·dequant-2tqc). Wherein, dequant is the quantization step size, λ is the Lagrange parameter, · is the multiplication, level is the initial quantization level, and tqc is the transformation coefficient of the current element.
[0138] If the target coding bit number difference is greater than -dequant / λ·(((2level)-1)·dequant-2tqc), the target quantization level is the initial quantization level of the current element minus 1. Otherwise, the target quantization level is the initial quantization level of the current element.
[0139] The following is the derivation process of the above formula:
[0140] RD=λ·Rate+Dist
[0141] RD low =λ·Rate low +Dist low
[0142] RD low <RD
[0143] λ·Rate low +Dist low <λ·Rate+Dist
[0144] λ·(Rate-Rate low )>Dist low -Dist
[0145] λ·ΔRate>(tqc-dq low ) 2 -(tqc-dq) 2
[0146] λ·ΔRate>(dq low -dq)(dq low +dq-2tqc)
[0147] ∵dq=level·dequant,dq low =(level-1)·dequant
[0148] ∴λ·ΔRate>-dequant·((2level-1)·dequant-2tqc)
[0149]
[0150] in:
[0151] RD is the rate-distortion cost corresponding to the initial quantization level of the current element;
[0152] RD low The rate-distortion cost corresponding to the initial quantization level of the current element minus one;
[0153] Rate is the number of coded bits corresponding to the initial quantization level of the current element;
[0154] Rate low The number of coded bits corresponding to the initial quantization level of the current element minus one;
[0155] λ is the Lagrangian parameter;
[0156] Dist is the distortion corresponding to the initial quantization level of the current element;
[0157] Dist low The distortion corresponding to the initial quantization level of the current element minus one;
[0158] tqc is the transformation coefficient of the current element;
[0159] dq is the dequantization coefficient corresponding to the initial quantization level of the current element;
[0160] dq low The dequantization coefficient corresponding to the initial quantization level of the current element minus one;
[0161] level is the initial quantization level of the current element;
[0162] dequant is the quantization step size;
[0163] △Rate is the difference in the number of bits;
[0164] · is the multiplication sign;
[0165] ∴ means "because";
[0166] ∵ means "so".
[0167] The above provides the adjustment details and principles of RDOQ level. Experiments have shown that the overall encoding time can be accelerated by 20% with a bit rate loss of 0.3%, greatly reducing the time overhead of live on-demand.
[0168] Embodiment 2
[0169] Figure 7 The block diagram of the rate-distortion optimization quantization device according to the second embodiment of the present application is schematically shown. The rate-distortion optimization quantization device can be divided into one or more program modules, one or more program modules are stored in a storage medium, and are executed by one or more processors to complete the embodiment of the present application. The program module referred to in the embodiment of the present application refers to a series of computer program instruction segments that can complete specific functions. The following description will specifically introduce the functions of each program module in this embodiment. Figure 7As shown, the rate-distortion optimization quantization device 700 may include a first determination module 710, a second determination module 720, and a third determination module 730, wherein:
[0170] A first determination module 710 is used to determine a plurality of mapping groups in a super block, each mapping group including a context and an initial quantization level; wherein the super block is a coding block unit in a video frame to be coded, the super block includes a plurality of elements, and the context is used to represent correlation information between an element associated with a corresponding mapping group and a plurality of adjacent elements;
[0171] A second determination module 720 is configured to determine a coding bit number difference for each mapping group, where the coding bit number difference is a difference between the coding bit number of the initial quantization level in the corresponding mapping group and the coding bit number of the initial quantization level in the corresponding mapping group minus one; and
[0172] The third determination module 730 is configured to determine a target quantization level for each element in the super block based on the difference in the number of coded bits of each mapping group.
[0173] As an optional embodiment, the rate-distortion optimization quantization device 700 further includes a first storage module (not marked), which is used to:
[0174] The mapping relationship between each mapping group and the corresponding encoding bit number difference is stored in a bit number difference array, wherein the bit number difference array includes a first bit number difference array and a second bit number difference array; wherein:
[0175] The first bit number difference array corresponds to an initial quantization level whose level is lower than a first preset value;
[0176] The second bit number difference array corresponds to an initial quantization level between a second preset value and a third preset value.
[0177] As an optional embodiment, the super block corresponds to multiple transform units;
[0178] The third determining module 730 is further configured to:
[0179] Determine the context of each element in the transform unit;
[0180] The transformation unit is scanned in a preset order, and when a current element in the transformation unit is scanned, the following operations are performed:
[0181] In response to the initial quantization level of the current element being a non-zero value, obtaining the initial quantization level and the target context of the current element; wherein the current element is one of the elements in the transform unit;
[0182] According to the initial quantization level of the current element and the target context, querying a target mapping group from the mapping groups; and
[0183] The target quantization level of the current element is determined according to the target coding bit number difference in the target mapping group.
[0184] As an optional embodiment, the rate-distortion optimization quantization device 700 further includes a second storage module (not marked), which is used to:
[0185] The mapping relationship between the position of each element and the context of each element is stored in the context array;
[0186] The third determination module 730 is further configured to query the target context from the context array according to the position of the current element.
[0187] As an optional embodiment, the third determining module 730 is further configured to:
[0188] In response to the target coding bit number difference being not greater than a reference threshold, determining the initial quantization level of the current element as the target quantization level of the current element;
[0189] In response to the target coding bit number difference being greater than the reference threshold, determining an initial quantization level of the current element minus one as a target quantization level of the current element.
[0190] As an optional embodiment, the rate-distortion optimized quantization device 700 further includes a fourth determining module (not labeled), configured to:
[0191] Determine a first value obtained by dividing the quantization step by λ, where λ is a fixed value;
[0192] Determine a second value obtained by subtracting one from twice the initial quantization level of the current element;
[0193] Determine a third value obtained by multiplying the second value by the quantization step size;
[0194] Determine a fourth value obtained by subtracting twice the transformation coefficient of the current element from the third value;
[0195] A fifth value obtained by multiplying the first value and the fourth value is determined, and a negative number of the fifth value is determined as the reference threshold.
[0196] As an optional embodiment, the third determining module 730 is further configured to:
[0197] In response to the initial quantization level of the current element being a zero value, the current element is skipped and the next element of the current element is scanned.
[0198] As an optional embodiment, the number of coding bits of the initial quantization level within the corresponding mapping group is obtained according to the context and the initial quantization level within the corresponding mapping group; the number of coding bits of the initial quantization level minus one within the corresponding mapping group is obtained according to the context and the initial quantization level minus one within the corresponding mapping group.
[0199] Embodiment 3
[0200] Figure 8 The hardware architecture diagram of a computer device 10000 suitable for implementing the rate-distortion optimization quantization method according to the third embodiment of the present application is schematically shown. The computer device 10000 is a device that can automatically perform numerical calculations and / or information processing according to pre-set or stored instructions. For example, it can be a smart phone, a tablet computer, a PC, a virtual reality device, etc. Figure 8 As shown, the computer device 10000 includes at least but is not limited to: a memory 10010, a processor 10020, and a network interface 10030 that can communicate with each other through a system bus. Among them:
[0201] The memory 10010 includes at least one type of computer-readable storage medium, and the readable storage medium includes a flash memory, a hard disk, a multimedia card, a card-type memory (e.g., an SD or DX memory, etc.), a random access memory (RAM), a static random access memory (SRAM), a read-only memory (ROM), an electrically erasable programmable read-only memory (EEPROM), a programmable read-only memory (PROM), a magnetic memory, a magnetic disk, an optical disk, etc. In some embodiments, the memory 10010 may be an internal storage module of the computer device 10000, such as a hard disk or a memory of the computer device 10000. In other embodiments, the memory 10010 may also be an external storage device of the computer device 10000, such as a plug-in hard disk equipped on the computer device 10000, a smart memory card (Smart Media Card, referred to as SMC), a secure digital (Secure Digital, referred to as SD) card, a flash card, etc. Of course, the memory 10010 may also include both the internal storage module of the computer device 10000 and its external storage device. In this embodiment, the memory 10010 is generally used to store an operating system and various application software installed in the computer device 10000, such as program code of a rate-distortion optimization quantization method, etc. In addition, the memory 10010 can also be used to temporarily store various data that have been output or are to be output.
[0202] In some embodiments, the processor 10020 may be a central processing unit (CPU), a controller, a microcontroller, a microprocessor, or other data processing chips. The processor 10020 is generally used to control the overall operation of the computer device 10000, such as performing control and processing related to data interaction or communication with the computer device 10000. In this embodiment, the processor 10020 is used to run the program code stored in the memory 10010 or process data.
[0203] The network interface 10030 may include a wireless network interface or a wired network interface, and the network interface 10030 is generally used to establish a communication link between the computer device 10000 and other computer devices. For example, the network interface 10030 is used to connect the computer device 10000 to an external user terminal through a network, and to establish a data transmission channel and a communication link between the computer device 10000 and the external user terminal. The network may be a wireless or wired network such as an intranet, the Internet, the Global System of Mobile communication (GSM), Wideband Code Division Multiple Access (WCDMA), 4G network, 5G network, Bluetooth, Wi-Fi, etc.
[0204] It should be pointed out that Figure 8 Only a computer device having components 10010 - 10030 is shown, but it should be understood that implementation of all of the components shown is not a requirement, and more or fewer components may be implemented instead.
[0205] In this embodiment, the rate-distortion optimized quantization method stored in the memory 10010 can also be divided into one or more program modules and executed by one or more processors (processor 10020 in this embodiment) to complete the embodiment of the present application.
[0206] Embodiment 4
[0207] The present application also provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps of the rate-distortion optimization quantization method in Embodiment 1, 2 or 3 are implemented.
[0208] In this embodiment, the computer-readable storage medium includes flash memory, hard disk, multimedia card, card-type memory (for example, SD or DX memory, etc.), random access memory (RAM), static random access memory (SRAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), programmable read-only memory (PROM), magnetic memory, disk, optical disk, etc. In some embodiments, the computer-readable storage medium can be an internal storage unit of a computer device, such as a hard disk or memory of the computer device. In other embodiments, the computer-readable storage medium can also be an external storage device of a computer device, such as a plug-in hard disk equipped on the computer device, a smart memory card (Smart Media Card, referred to as SMC), a secure digital (Secure Digital, referred to as SD) card, a flash card, etc. Of course, the computer-readable storage medium can also include both the internal storage unit of the computer device and its external storage device. In this embodiment, the computer-readable storage medium is generally used to store an operating system and various application software installed on the computer device, such as the program code of the rate-distortion optimization quantization method in the embodiment. In addition, the computer-readable storage medium can also be used to temporarily store various types of data that have been output or are to be output.
[0209] Obviously, those skilled in the art should understand that the modules or steps of the above-mentioned embodiments of the present application can be implemented by a general computing device, they can be concentrated on a single computing device, or distributed on a network composed of multiple computing devices, and optionally, they can be implemented by a program code executable by a computing device, so that they can be stored in a storage device and executed by the computing device, and in some cases, the steps shown or described can be executed in a different order from that herein, or they can be made into individual integrated circuit modules, or multiple modules or steps therein can be made into a single integrated circuit module for implementation. In this way, the embodiments of the present application are not limited to any specific combination of hardware and software.
[0210] It should be noted that the above are only preferred embodiments of the present application, and the patent protection scope of the present application is not limited thereto. Any equivalent structure or equivalent process transformation made using the contents of the specification and drawings of the present application, or directly or indirectly applied in other related technical fields, are also included in the patent protection scope of the present application.
Claims
1. A rate-distortion optimization quantization method, characterized in that: include: Determine a plurality of mapping groups in a super block, each mapping group including a context and an initial quantization level; wherein the super block is a coding block unit in a video frame to be coded, the super block includes a plurality of elements, and the context is used to represent correlation information between an element associated with a corresponding mapping group and a plurality of adjacent elements; Determine a coding bit number difference value for each mapping group, where the coding bit number difference value is a difference between the coding bit number of the initial quantization level in the corresponding mapping group and the coding bit number of the initial quantization level in the corresponding mapping group minus one; and Determining a target quantization level for each element in the super block based on a difference in the number of coded bits of each mapping group; Wherein, the super block corresponds to a plurality of transform units; The step of determining a target quantization level for each element in the super block based on the difference in the number of coded bits of each mapping group comprises: Determining the context of each element in the transform unit; The transformation unit is scanned in a preset order, and when a current element in the transformation unit is scanned, the following operations are performed: In response to the initial quantization level of the current element being a non-zero value, obtaining the initial quantization level and the target context of the current element; wherein the current element is one of the elements in the transform unit; querying a target mapping group from the mapping groups according to the initial quantization level of the current element and the target context; The target quantization level of the current element is determined according to the target coding bit number difference in the target mapping group.
2. The rate-distortion optimization quantization method according to claim 1, characterized in that: Also includes: The mapping relationship between each mapping group and the corresponding encoding bit number difference is stored in a bit number difference array, wherein the bit number difference array includes a first bit number difference array and a second bit number difference array; wherein: The first bit number difference array corresponds to an initial quantization level whose level is lower than a first preset value; The second bit number difference array corresponds to an initial quantization level between a second preset value and a third preset value.
3. The rate-distortion optimization quantization method according to claim 1, characterized in that: The method further comprises: storing the mapping relationship between the position of each element and the context of each element in a context array; The acquiring the initial quantization level and the target context of the current element in response to the initial quantization level of the current element being a non-zero value includes: querying the target context from the context array according to the position of the current element.
4. The rate-distortion optimization quantization method according to claim 1, characterized in that: The determining the target quantization level of the current element according to the target encoding bit number difference in the target mapping group includes: In response to the target coding bit number difference being not greater than a reference threshold, determining the initial quantization level of the current element as the target quantization level of the current element; In response to the target coding bit number difference being greater than the reference threshold, determining an initial quantization level of the current element minus one as a target quantization level of the current element.
5. The rate-distortion optimization quantization method according to claim 4, characterized in that: It also includes determining the reference threshold: Determine a first value obtained by dividing the quantization step by λ, where λ is a fixed value; Determine a second value obtained by subtracting one from twice the initial quantization level of the current element; Determine a third value obtained by multiplying the second value by the quantization step size; Determine a fourth value obtained by subtracting twice the transformation coefficient of the current element from the third value; A fifth value obtained by multiplying the first value and the fourth value is determined, and a negative number of the fifth value is determined as the reference threshold.
6. The rate-distortion optimization quantization method according to claim 1, characterized in that: Also includes: In response to the initial quantization level of the current element being a zero value, the current element is skipped and the next element of the current element is scanned.
7. The rate-distortion optimization quantization method according to any one of claims 1 to 6, characterized in that: The number of coded bits of the initial quantization level in the corresponding mapping group is obtained according to the context and the initial quantization level in the corresponding mapping group; The number of coded bits of the initial quantization level minus one in the corresponding mapping group is obtained according to the context in the corresponding mapping group and the initial quantization level minus one.
8. A rate-distortion optimization quantization device, characterized in that: include: A first determination module is used to determine a plurality of mapping groups in a super block, each mapping group including a context and an initial quantization level; wherein the super block is a coding block unit in a video frame to be coded, the super block includes a plurality of elements, and the context is used to represent correlation information between an element associated with a corresponding mapping group and a plurality of adjacent elements; A second determination module is configured to determine a coding bit number difference value for each mapping group, where the coding bit number difference value is a difference between the coding bit number of the initial quantization level in the corresponding mapping group and the coding bit number of the initial quantization level in the corresponding mapping group minus one; and A third determination module is used to determine the target quantization level of each element in the super block based on the difference in the number of coded bits of each mapping group; wherein the super block corresponds to multiple transform units; The method of determining the target quantization level of each element in the super block based on the difference in the number of coding bits of each mapping group includes: determining the context of each element in the transformation unit; scanning the transformation units in a preset order, and when the current element in the transformation unit is scanned, performing the following operations: in response to the initial quantization level of the current element being a non-zero value, obtaining the initial quantization level and target context of the current element; wherein the current element is one of the elements in the transformation unit; querying a target mapping group from the mapping group according to the initial quantization level of the current element and the target context; and determining the target quantization level of the current element according to the difference in the number of target coding bits in the target mapping group.
9. A computer device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, it is used to implement the steps of the rate-distortion optimized quantization method described in any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and the computer program can be executed by at least one processor to enable the at least one processor to perform the steps of the rate-distortion optimized quantization method according to any one of claims 1 to 7.
11. A computer program product, characterized in that The method comprises a computer program which can be executed by at least one processor to enable the at least one processor to perform the steps of the rate-distortion optimized quantization method according to any one of claims 1 to 7.
Citation Information
Patent Citations
Rate-distortion quantization for context-adaptive variable length coding (CAVLC)
CN102017633A
Level decision in rate distortion optimized quantization
CN104221375A