Method and apparatus for determining coding mode, electronic device, storage medium and program product
By calculating the encoding cost of transform block groups in parallel and selecting an appropriate encoding method, the problem of low efficiency in hardware parallel computing in existing technologies is solved, and a more efficient video encoding process is achieved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- MOORE THREADS TECH CO LTD
- Filing Date
- 2025-08-18
- Publication Date
- 2026-07-21
AI Technical Summary
In existing video encoding technologies, the encoding method of transform coefficient groups has low parallelism, resulting in low efficiency of hardware parallel computing and increased hardware implementation latency.
By computing the encoding cost of each group in the transform block in parallel, a suitable encoding method is selected for encoding, including encoding all coefficients of the first group, encoding the last non-zero coefficient and the coefficients before it of the second group, and encoding all zeros of the third group, thereby improving the degree of hardware parallel computing.
It improves the parallel computing efficiency of hardware, reduces the latency and storage costs of hardware implementation, and reduces computational complexity.
Smart Images

Figure CN120730074B_ABST
Abstract
Description
Technical Field
[0001] This disclosure relates to the field of video coding, and more particularly to a method, apparatus, electronic device, storage medium, and program product for determining a coding method. Background Technology
[0002] Encoding video to compress its data volume is a necessary technical means to reduce video storage costs and improve video transmission efficiency. However, compressing data volume also means distortion. Therefore, how to encode video to achieve a low frame rate and low distortion has become a hot topic in the field of video encoding.
[0003] When encoding video, video frames are divided into multiple Transform Units (TUs), each TU is further divided into multiple Transform Blocks (TBs), and each TB is further divided into multiple Coefficient Groups (CGs). Each CG contains multiple transform coefficients to be encoded. Current technologies suffer from low parallelism in determining the encoding method for CGs, which hinders parallel computing in hardware and significantly increases hardware implementation latency. Summary of the Invention
[0004] In view of this, this disclosure proposes a method, apparatus, electronic device, storage medium, and program product for determining an encoding method. The method of the embodiments of this disclosure improves the degree of parallel computing of hardware and reduces the latency of hardware implementation.
[0005] According to one aspect of this disclosure, a method for determining an encoding scheme is provided. The method includes: in response to acquiring coefficients of groups included in a transform block of a video frame; for each acquired group containing all coefficients, starting to calculate the encoding cost of that group using all coefficients; the encoding cost calculations of multiple groups in the transform block are performed in parallel; wherein the transform block includes multiple groups, each group includes multiple coefficients, and the encoding cost of a group includes the cost of not encoding the group and the cost of encoding the group using at least one encoding scheme; and determining the groups to be encoded in the transform block and the encoding scheme of the encoded groups based on the calculated encoding costs of the multiple groups.
[0006] In one possible implementation, the grouping encoding method includes one of a first group encoding method, a second group encoding method, and a third group encoding method. The first group encoding method includes encoding all coefficients in the group; the second group encoding method includes encoding the last non-zero coefficient and the coefficients before it in the group, while other coefficients are not encoded; the third group encoding method includes encoding a first identifier, which indicates that all coefficients in the group are zero.
[0007] In one possible implementation, determining the group to be encoded in the transform block and the encoding method of the group to be encoded based on the calculated encoding cost of the plurality of groups includes: when there are groups containing non-zero coefficients, selecting one group from all groups containing non-zero coefficients according to the encoding cost of the plurality of groups and encoding it using the second encoding method; encoding the group before the selected group that contains non-zero coefficients using the first encoding method; encoding the group before the selected group that has all zero coefficients using the third encoding method; and not encoding the group after the selected group.
[0008] In one possible implementation, the method further includes: for any group, when the group includes non-zero coefficients, determining whether to set the coefficients in the group to zero based on the encoding cost of the group; and updating the coefficients in the group when the determination result is to set the coefficients in the group to zero.
[0009] In one possible implementation, the method further includes: when there are groups containing non-zero coefficients, determining the encoding method of the transform block based on the encoding cost of the plurality of groups and the encoding method of the group being encoded, wherein the encoding method of the transform block is one of a first block encoding method and a second block encoding method; when there are no groups containing non-zero coefficients, the transform block is encoded using the first block encoding method; wherein the first block encoding method includes encoding a second identifier, the second identifier indicating that all coefficients in the transform block are zero; and the second encoding method includes encoding the group being encoded using the determined encoding methods of each group.
[0010] In one possible implementation, determining the encoding method of the transform block based on the encoding costs of the plurality of groups and the encoding method of the encoded groups includes: accumulating the cost of not encoding the plurality of groups and the cost of encoding the second identifier to obtain the cost of encoding the transform block using the first block encoding method; accumulating the cost of encoding the encoded groups using the determined encoding method, the cost of not encoding the unencoded groups, and the cost of encoding the fourth identifier to obtain the cost of encoding the transform block using the second block encoding method, where the fourth identifier indicates that the transform block includes non-zero coefficients; comparing the cost of encoding the transform block using the first block encoding method and the cost of encoding the transform block using the second block encoding method, and determining the corresponding encoding method with the smaller value as the encoding method of the transform block.
[0011] In one possible implementation, the step of calculating the encoding cost of the group using all coefficients includes: prequantizing each coefficient, calculating the encoding cost of each coefficient based on the prequantization value, and updating the coefficients based on the prequantization value; calculating the cost of encoding the group using the first encoding method based on the encoding cost of each coefficient; selecting a coefficient from the group based on the position of the non-zero coefficients in the group as the last non-zero coefficient when encoding the group using the second encoding method; and calculating the cost of encoding the group using the second encoding method based on the encoding cost of each coefficient and the position of the last non-zero coefficient.
[0012] In one possible implementation, the pre-quantization of each coefficient includes: determining M quantization values for the current coefficient based on the amplitude of the current coefficient, where M is an integer greater than 1; obtaining M queues corresponding to the group based on the M quantization values of each coefficient included in the group, where the i-th queue includes the i-th quantization value of each coefficient, 1≤i≤M, and i is an integer; calculating the cost of encoding the current coefficient with the i-th quantization value as the pre-quantization value based on the quantization values in the i-th queue, and obtaining the i-th first value; comparing the M first values, and determining the quantization value corresponding to the smallest first value as the pre-quantization value of the current coefficient.
[0013] In one possible implementation, selecting a coefficient from the group based on the position of the non-zero coefficients in the group as the last non-zero coefficient when the group is encoded using the second group encoding method includes: obtaining a candidate coefficient set based on the position of the non-zero coefficients in the group, the candidate coefficient set including at least one coefficient with a pre-quantized non-zero value, the order of any two candidate coefficients in the candidate coefficient set being the same as the order of the two candidate coefficients in the group; in response to calculating the encoding cost of any two adjacent candidate coefficients and other coefficients between the two adjacent candidate coefficients, designating the two adjacent candidate coefficients as a first candidate coefficient and a second candidate coefficient, respectively; determining the relationship between the encoding costs of the first candidate coefficient and the second candidate coefficient when they are selected as the group, based on the encoding costs of the first candidate coefficient, the second candidate coefficient, and the other coefficients; deleting the candidate coefficient with the higher corresponding cost from the candidate coefficient set; and determining the remaining candidate coefficient as the selected coefficient when there is one candidate coefficient remaining in the candidate coefficient set.
[0014] In one possible implementation, the step of determining whether to set the coefficients in any given group to zero based on the group's encoding cost when the group includes non-zero coefficients includes:
[0015] The cost of encoding the group using the first encoding method and the cost of encoding the third identifier are summed to obtain a second value, wherein the third identifier indicates that the group includes non-zero coefficients; when the cost of encoding the group using the third encoding method is less than the second value, it is determined that the coefficients included in the group are set to zero; when the second value is less than the cost of encoding the group using the third encoding method, it is determined that the coefficients included in the group are not set to zero.
[0016] In one possible implementation, selecting a group from all groups including non-zero coefficients for encoding using the second group encoding method based on the encoding costs of the plurality of groups includes: taking all groups including non-zero coefficients as candidate groups to obtain a candidate group set, wherein the order of any two candidate groups in the candidate group set is the same as the order of the two candidate groups in the transform block; in response to the calculated encoding costs of any two adjacent candidate groups and other groups between the two adjacent candidate groups, designating the two adjacent candidate groups as a first candidate group and a second candidate group respectively; determining the relationship between the encoding costs of the first candidate group and the second candidate group when they are selected as the chosen group, based on the encoding costs of the first candidate group, the second candidate group, and the other groups; deleting the candidate group with the larger corresponding cost from the candidate group set; and when one candidate group remains in the candidate group set, selecting that candidate group as the chosen group.
[0017] According to another aspect of this disclosure, an apparatus for determining an encoding method is provided. The apparatus includes: a first calculation module, configured to, in response to acquiring coefficients of groups included in a transform block in a video frame, calculate the encoding cost of a group based on all coefficients acquired for each group, wherein the encoding cost calculations of multiple groups in the transform block are performed in parallel; wherein the transform block includes multiple groups, each group includes multiple coefficients, and the encoding cost of a group includes the cost of not encoding the group and the cost of encoding the group in at least one encoding method; and a first determination module, configured to determine the groups to be encoded in the transform block and the encoding method of the encoded groups based on the calculated encoding costs of the multiple groups.
[0018] In one possible implementation, the first calculation module includes a first calculation unit, a second calculation unit, a third calculation unit, and a fourth calculation unit. The first calculation unit is used to calculate the encoding cost of coefficients; the second calculation unit is used to calculate the cost of not encoding a group and the cost of encoding a group using a third group encoding method based on the encoding cost of the coefficients; the third calculation unit is used to calculate the cost of encoding a group using a first group encoding method based on the encoding cost of the coefficients; the fourth calculation unit is used to calculate the cost of encoding a group using a second group encoding method based on the encoding cost of the coefficients; when the group includes non-zero coefficients, the first calculation unit inputs the encoding cost of the coefficients into the second calculation unit, the third calculation unit, and the fourth calculation unit; when all coefficients in the group are zero, the first calculation unit inputs the encoding cost of the coefficients into the second calculation unit.
[0019] In one possible implementation, the grouping encoding method includes one of a first group encoding method, a second group encoding method, and a third group encoding method. The first group encoding method includes encoding all coefficients in the group; the second group encoding method includes encoding the last non-zero coefficient and the coefficients before it in the group, while other coefficients are not encoded; the third group encoding method includes encoding a first identifier, which indicates that all coefficients in the group are zero.
[0020] In one possible implementation, the first determining module is specifically used to, when there are groups including non-zero coefficients, select one group from all groups including non-zero coefficients according to the encoding cost of the plurality of groups and encode it using the second group encoding method; the groups before the selected group that include non-zero coefficients are encoded using the first group encoding method; the groups before the selected group that have all zero coefficients are encoded using the third group encoding method; and the groups after the selected group are not encoded.
[0021] In one possible implementation, the apparatus further includes: a judgment module, configured to, for any given group, determine whether to set the coefficients in the group to zero based on the encoding cost of the group when the group includes non-zero coefficients; and an update module, configured to update the coefficients in the group when the judgment result is that the coefficients in the group should be set to zero.
[0022] In one possible implementation, the apparatus further includes: a second determining module, configured to, when there are groups including non-zero coefficients, determine the encoding method of the transform block based on the encoding cost of the plurality of groups and the encoding method of the group being encoded, wherein the encoding method of the transform block is one of a first block encoding method and a second encoding method; when there are no groups including non-zero coefficients, the transform block is encoded using the first block encoding method; wherein the first block encoding method includes encoding a second identifier, the second identifier indicating that all coefficients in the transform block are zero; and the second encoding method includes encoding the group being encoded using the determined encoding methods of each group.
[0023] In one possible implementation, the second determining module is specifically used to: accumulate the cost of not encoding the plurality of groups and the cost of encoding the second identifier to obtain the cost of encoding the transform block using the first block encoding method; accumulate the cost of encoding the encoded groups using the determined encoding method, the cost of not encoding the unencoded groups, and the cost of encoding the fourth identifier to obtain the cost of encoding the transform block using the second block encoding method, where the fourth identifier indicates that the transform block includes non-zero coefficients; compare the cost of encoding the transform block using the first block encoding method and the cost of encoding the transform block using the second block encoding method, and determine the corresponding encoding method with the smaller value as the encoding method of the transform block.
[0024] In one possible implementation, the first calculation unit is specifically used to prequantize each coefficient, calculate the encoding cost of each coefficient based on the prequantization value, and update the coefficient based on the prequantization value; the device further includes a first selection unit, used to select a coefficient from the group based on the position of the non-zero coefficient in the group, as the last non-zero coefficient when the group is encoded using the second group encoding method; the fourth calculation unit is specifically used to calculate the cost of encoding the group using the second group encoding method based on the encoding cost of each coefficient and the position of the last non-zero coefficient.
[0025] In one possible implementation, the first computing unit is specifically used to: determine M quantization values for the current coefficient based on the amplitude of the current coefficient, where M is an integer greater than 1; obtain M queues corresponding to the group based on the M quantization values of each coefficient included in the group, where the i-th queue includes the i-th quantization value of each coefficient, 1≤i≤M, and i is an integer; calculate the cost of encoding the current coefficient with the i-th quantization value as the prequantization value based on the quantization values in the i-th queue, and obtain the i-th first value; compare the M first values and determine the quantization value corresponding to the smallest first value as the prequantization value of the current coefficient.
[0026] In one possible implementation, the first selection unit is specifically configured to: obtain a candidate coefficient set based on the position of non-zero coefficients in the group, the candidate coefficient set including at least one coefficient with a prequantized non-zero value, wherein the order of any two candidate coefficients in the candidate coefficient set is the same as the order of the two candidate coefficients in the group; in response to calculating the encoding cost of any two adjacent candidate coefficients and other coefficients between the two adjacent candidate coefficients, designate the two adjacent candidate coefficients as the first candidate coefficient and the second candidate coefficient, respectively; determine the relationship between the encoding costs of the group when the first candidate coefficient and the second candidate coefficient are selected as the selected coefficients based on the encoding costs of the first candidate coefficient, the second candidate coefficient, and the other coefficients; delete the corresponding candidate coefficient with the higher cost from the candidate coefficient set; and when one candidate coefficient remains in the candidate coefficient set, determine that candidate coefficient as the selected coefficient.
[0027] In one possible implementation, the first judgment module is specifically used to: accumulate the cost of encoding the group using the first group encoding method and the cost of encoding the third identifier to obtain a second value, wherein the third identifier indicates that the group includes non-zero coefficients; when the cost of encoding the group using the third group encoding method is less than the second value, determine that the coefficients included in the group are set to zero; when the second value is less than the cost of encoding the group using the third group encoding method, determine that the coefficients included in the group are not set to zero.
[0028] In one possible implementation, the first determining module is specifically configured to: take all groups including non-zero coefficients as candidate groups to obtain a candidate group set, wherein the order of any two candidate groups in the candidate group set is the same as the order of the two candidate groups in the transform block; in response to the calculated encoding costs of any two adjacent candidate groups and other groups between the two adjacent candidate groups, designate the two adjacent candidate groups as a first candidate group and a second candidate group, respectively; determine the relationship between the encoding costs of the first candidate group and the second candidate group when they are selected as the selected groups, based on the encoding costs of the first candidate group, the second candidate group, and the other groups; delete the corresponding candidate group with the larger cost from the candidate group set; and when one candidate group remains in the candidate group set, designate that candidate group as the selected group.
[0029] According to another aspect of this disclosure, an electronic device is provided, including a memory, a processor, and a computer program stored in the memory, wherein the processor executes the computer program to implement the steps of the above-described method.
[0030] According to another aspect of this disclosure, a non-volatile computer-readable storage medium is provided, on which a computer program is stored, which, when executed by a processor, implements the steps of the above-described method.
[0031] According to another aspect of this disclosure, a computer program product is provided, including a computer program or a non-volatile computer-readable storage medium carrying the computer program, wherein the computer program, when executed by a processor, implements the steps of the above-described method.
[0032] According to the encoding method of this disclosure, in response to obtaining the coefficients of the groups included in the transform block of a video frame, for each group whose coefficients are all obtained, the encoding cost of that group is calculated using all coefficients, and the encoding cost calculations of multiple groups in the transform block are performed in parallel; wherein, the transform block includes multiple groups, each group includes multiple coefficients, and the encoding cost of a group includes the cost of not encoding the group and the cost of encoding the group using at least one encoding method; based on the calculated encoding costs of multiple groups, the groups to be encoded in the transform block and the encoding method of the encoded groups are determined. Since the encoding cost of any group can be calculated as soon as all coefficients of that group are obtained, the encoding costs of different groups can be calculated in parallel, improving the degree of parallel computing in the hardware and reducing the latency of hardware implementation.
[0033] Other features and aspects of this disclosure will become clear from the following detailed description of exemplary embodiments with reference to the accompanying drawings. Attached Figure Description
[0034] The accompanying drawings, which are included in and form part of this specification, illustrate exemplary embodiments, features, and aspects of this disclosure together with the specification and serve to explain the principles of this disclosure.
[0035] Figure 1 A schematic diagram showing the relationship between transform blocks, groups, and coefficients is provided.
[0036] Figure 2 This illustrates an exemplary application scenario of a method for determining an encoding scheme according to embodiments of the present disclosure.
[0037] Figure 3 A schematic diagram illustrating the flow of a method for determining an encoding method according to an embodiment of the present disclosure is shown.
[0038] Figure 4 A schematic diagram illustrating the process of prequantizing coefficients according to an embodiment of the present disclosure is shown.
[0039] Figure 5 This diagram illustrates the process of determining the last non-zero coefficient when a group is encoded in a second group encoding manner according to an embodiment of the present disclosure.
[0040] Figure 6 This diagram illustrates the determination of a candidate coefficient set and the updating of the candidate coefficient set according to embodiments of the present disclosure.
[0041] Figure 7 This diagram illustrates the process of selecting a second group of encoding methods for grouping according to an embodiment of the present disclosure.
[0042] Figure 8 This diagram illustrates the determination and updating of a candidate grouping set according to an embodiment of the present disclosure.
[0043] Figure 9 A schematic diagram showing the structure of an apparatus for determining an encoding method according to an embodiment of the present disclosure is provided.
[0044] Figure 10 A block diagram of an electronic device 1900 according to an embodiment of the present disclosure is shown. Detailed Implementation
[0045] Various exemplary embodiments, features, and aspects of this disclosure will now be described in detail with reference to the accompanying drawings. The same reference numerals in the drawings denote elements that have the same or similar functions. Although various aspects of the embodiments are shown in the drawings, they are not necessarily drawn to scale unless specifically indicated otherwise.
[0046] As used herein, the terms “comprising,” “including,” “having,” or variations thereof are open-ended and include one or more of the stated features, integrals, elements, steps, components, or functions, but do not exclude the presence or addition of one or more other features, integrals, elements, steps, components, functions, or groups thereof.
[0047] When an element is referred to as “connected,” “coupled,” “responding,” or a variation thereof relative to another element, it may be directly connected, coupled, or responding to another element, or there may be an intermediate element present.
[0048] Although the terms first, second, third, etc., may be used herein to describe various elements / operations, these elements / operations should not be limited by these terms. These terms are only used to distinguish one element / operation from another. Therefore, without departing from the teachings of the inventive concept, a first element / operation in some embodiments may be referred to as a second element / operation in other embodiments.
[0049] The term “exemplary” as used herein means “serving as an example, embodiment, or illustration.” Any embodiment illustrated herein as “exemplary” is not necessarily to be construed as superior to or better than other embodiments.
[0050] Furthermore, to better illustrate this disclosure, numerous specific details are set forth in the following detailed description. Those skilled in the art will understand that this disclosure can be practiced without certain specific details. In some instances, methods, means, components, and circuits well known to those skilled in the art have not been described in detail in order to highlight the main points of this disclosure.
[0051] The following section will first introduce the existing coding methods. To make the description more concise, the term "coefficient" will be used to refer to "transform coefficients" and "group" will be used to refer to "transform coefficient groups".
[0052] Rate-Distortion Optimization Quantization (RDOQ) is an important coding method in video coding used to balance bitrate and distortion during the coding process. The core idea of RDOQ is to combine the coding process with bitrate-distortion optimization criteria, and to achieve more efficient coding by selecting the most suitable coding method for each block of the transform block and for each coefficient of the block.
[0053] Figure 1 A schematic diagram showing the relationship between transform blocks, groups, and coefficients is provided.
[0054] like Figure 1 As shown, the transformation block may include 4×4 groups (group g1-group g16), and each group may include 4×4 coefficients (for example, group 1 includes coefficients x1-x16).
[0055] The coefficients are obtained by transforming the quantization coefficients. Due to the influence of the quantization coefficient transformation rules, in practical applications, groups containing non-zero coefficients are mostly concentrated in the upper left corner of the transform block; within each group, non-zero coefficients are also mostly concentrated in the upper left corner. During the encoding of the transform block, since all coefficients in all scanned groups are zero before the first group containing non-zero coefficients (which, according to group numbering, is the last group containing non-zero coefficients in the transform block) is encountered, encoding can begin from the first scanned group containing non-zero coefficients. Similarly, during the encoding of a single group, since all scanned coefficients are zero before the first non-zero coefficient (which, according to coefficient numbering, is the last non-zero coefficient in the group), encoding can begin only from the first scanned non-zero coefficient.
[0056] In this case, diagonal scanning becomes a scanning scheme with a lower bit rate. For example... Figure 1As shown, one diagonal scanning method involves scanning from the bottom right corner to the top left corner. The group numbers within the transform block gradually increase from the top left corner to the bottom right corner, and the coefficient numbers within each group gradually increase from the top left corner to the bottom right corner. In other words, the group numbering order is the reverse of the group scanning order, and the coefficient numbering order is the reverse of the coefficient scanning order.
[0057] In actual encoding, in order to save bit rate, it is usually not possible to directly determine whether each group should be encoded and the encoding method of the encoded group based on the value of the coefficient. Instead, the coefficient is prequantized and the encoding cost of each group is calculated. Based on the encoding cost of each group, it is determined whether each group should be encoded and the encoding method of the encoded group.
[0058] The existing approach prequantizes the coefficients within a group sequentially according to the scanning order. The scan starts from the bottom right corner of the transform block, while data acquisition is usually done row by row from top to bottom or column by column from left to right. Therefore, the last transformed coefficient acquired is the coefficient of the first prequantization, and subsequent coefficients are also serially quantized. This reduces the degree of parallel computing in the hardware and increases the hardware implementation latency.
[0059] In view of this, this disclosure proposes a method, apparatus, electronic device, storage medium, and program product for determining an encoding method. The method of the embodiments of this disclosure improves the degree of parallel computing of hardware and reduces the complexity and latency of hardware implementation.
[0060] Furthermore, the method in this embodiment requires less data to be cached, thus reducing hardware storage costs.
[0061] Furthermore, the method of this disclosure embodiment performs fewer calculations when determining the encoding cost of the transform block, thus reducing computational complexity.
[0062] Figure 2 This illustrates an exemplary application scenario of a method for determining an encoding scheme according to embodiments of the present disclosure.
[0063] like Figure 2As shown, the encoding method determination method of this disclosure embodiment can be executed by a processor on a first device. After the first device acquires a video frame to be encoded, it can use the processor to divide the video frame into multiple transform blocks, and each transform block into multiple groups. For each transform block, the processor executes the encoding method determination method of this disclosure embodiment, calculates the encoding cost of each group, determines whether each group should be encoded based on the calculated cost, and determines the encoding method of the encoded groups. Further, the processor can determine the encoding method of the transform block based on the calculated cost and the determined encoding method of the groups, and encodes the transform block according to the determined encoding method. The encoding result of the video frame can be obtained based on the encoding result of each transform block, and then the encoding result of the video frame is stored on the first device. The data size of the encoding result of the video frame is smaller than the data size of the video frame.
[0064] Figure 3 A schematic diagram illustrating the flow of a method for determining an encoding method according to an embodiment of the present disclosure is shown.
[0065] like Figure 3 As shown, in one possible implementation, the method includes:
[0066] S31, in response to obtaining the coefficients of the groups included in the transform block in the video frame, for each group whose coefficients are obtained, the encoding cost calculation of the group is started using all the coefficients. The encoding cost calculation of multiple groups in the transform block is performed in parallel. The transform block includes multiple groups, each group includes multiple coefficients, and the encoding cost of the group includes the cost of not encoding the group and the cost of encoding the group in at least one encoding method.
[0067] S32, based on the calculated encoding costs of multiple groups, determine the groups to be encoded in the transform block and the encoding method of the encoded groups.
[0068] For example, such as Figure 1 As shown, a transform block may include multiple groups, each group comprising multiple coefficients. In step S31, the processor may acquire the coefficients of the groups included in the transform block in the same manner as in the prior art, for example, acquiring them row-by-row from top to bottom, or column-by-column from left to right. The scan order may be as follows: Figure 1 The scanning order is shown from the bottom right to the top left. This embodiment of the disclosure does not limit the order of coefficient acquisition or scanning. In response to acquiring the coefficients of the groups included in the transform block, the encoding cost can be calculated for each group after all coefficients of that group have been acquired. That is, the encoding cost calculations for multiple groups in the transform block are performed in parallel.
[0069] The encoding cost of a packet includes the cost of not encoding the packet and the cost of encoding the packet using at least one encoding method.
[0070] Block encoding means that each coefficient within a block is treated as zero and not encoded. During decoding, the block is decoded into a block containing all coefficients of zero. Therefore, the cost of not encoding a block is equal to the sum of the costs of not encoding each coefficient within the block. Since the code rate is zero when coefficients are not encoded, the cost of not encoding coefficients can be represented by the distortion when coefficients are quantized to 0.
[0071] This disclosure does not limit the specific encoding methods used to calculate the cost of encoding packets, nor does it limit the details of the cost calculation for encoding packets using any encoding method, as long as the cost of encoding packets using any encoding method can reflect the encoding distortion and bit rate. Exemplary encoding methods for packets and exemplary calculation methods for the cost of encoding packets using each encoding method are given later.
[0072] In step S32, the groups to be encoded in the transform block and the encoding method of the encoded groups can be determined based on the calculated encoding costs of multiple groups.
[0073] This disclosure does not limit the specific implementation of step S32, as long as the group to be encoded in the transform block and the encoding method of the encoded group can be determined. For example, optional combinations of encoding situations for each group can be determined. Based on the encoding costs of multiple groups, the encoding cost of the transform block under each combination is calculated. If the encoding cost of the transform block under a certain combination is smaller, the group to be encoded and the encoding method of the encoded group can be determined based on the encoding situation corresponding to that combination. Another example is that for each group, the cost of not encoding the group and the cost of encoding with at least one encoding method can be directly compared. If the cost of not encoding is smaller, it is determined that the group is not encoded; if the cost of encoding with a certain encoding method is smaller, it is determined that the group is encoded with that encoding method. Details of the implementation of step S32 are given later.
[0074] According to the encoding method of this disclosure, in response to obtaining the coefficients of the groups included in the transform block of a video frame, for each group whose coefficients are all obtained, the encoding cost of that group is calculated using all coefficients, and the encoding cost calculations of multiple groups in the transform block are performed in parallel; wherein, the transform block includes multiple groups, each group includes multiple coefficients, and the encoding cost of a group includes the cost of not encoding the group and the cost of encoding the group using at least one encoding method; based on the calculated encoding costs of multiple groups, the groups to be encoded in the transform block and the encoding method of the encoded groups are determined. Since the encoding cost of any group can be calculated as soon as all coefficients of that group are obtained, the encoding costs of different groups can be calculated in parallel, improving the degree of parallel computing in the hardware and reducing the latency of hardware implementation.
[0075] In existing technologies, the encoding cost of each coefficient needs to be cached, which makes data storage cost very high and requires a larger cache in hardware implementation. However, in the embodiments of this disclosure, whether a group is encoded and the encoding method of the encoded group are both based on the encoding cost of the group. Therefore, only the encoding cost of the group needs to be cached, resulting in a smaller amount of data to be cached and reducing hardware storage costs.
[0076] The following section introduces various encoding methods for grouping.
[0077] In one possible implementation, the grouping encoding method includes one of the following: a first group encoding method, a second group encoding method, and a third group encoding method.
[0078] The first group of encoding methods includes all coefficients in the encoding group;
[0079] The second coding method includes the last non-zero coefficient in the coding group and the coefficients before it; other coefficients are not coded.
[0080] The third group of encoding methods includes encoding the first identifier, which indicates that all coefficients in the group are zero.
[0081] The first encoding scheme includes all coefficients in the encoded group. Each coefficient, regardless of whether its value is zero, needs to be encoded under the first encoding scheme. The cost of encoding the group using the first encoding scheme can be represented by the sum of the code rate and distortion for each coefficient within the group.
[0082] The second encoding method encodes the last non-zero coefficient in the block and all coefficients preceding it, leaving other coefficients unencoded. Unencoded coefficients are treated as zero and decoded as zero during decoding. The last non-zero coefficient refers to the largest non-zero coefficient in the block's coefficient number sequence, either the last one to be encoded counting from the top left corner of the block in reverse scan order, or the first one counting from the bottom right corner in scan order. All coefficients after the last non-zero coefficient (with larger coefficient numbers) do not need to be encoded, regardless of whether they are zero or not. When calculating the cost of encoding a block using the second encoding method, if the block contains more than one non-zero coefficient, it can be determined which non-zero coefficient is most suitable to be set as the last non-zero coefficient. The cost of encoding a block using the second encoding method can be represented as the sum of the code rate for encoding the coefficients that need to be encoded within the block and the distortion of all coefficients within the block.
[0083] Under both the first and second group encoding methods, the coefficients can be encoded in scanning order. See the example for scanning order. Figure 1 Related descriptions.
[0084] The third group of encoding methods includes encoding the first identifier, which indicates that all coefficients in the group are zero.
[0085] The grouping options in this disclosure are not limited to the examples described above, and will not be repeated here. For clarity, the following examples use the first, second, and third grouping options as examples.
[0086] It should be understood that the code rate for encoding the first identifier is obviously less than the code rate for encoding all coefficients within a block. Therefore, if, when obtaining the coefficients of a block, all coefficients in a particular block are found to be zero, it can be determined that the final encoding of that block has only two possibilities: no encoding or encoding using the third encoding method. In this case, when all coefficients of any block are obtained and all coefficients are zero, only the cost of not encoding that block and the cost of encoding that block using the third encoding method need to be calculated.
[0087] For a block containing non-zero coefficients, if quantizing all coefficients in the block to zero results in minimal distortion, then encoding the block using the third encoding scheme may be less costly than encoding it using the first or second encoding scheme. Therefore, if, when obtaining the coefficients of the blocks included in the transform block, a block containing non-zero coefficients is found, there are four possible encoding scenarios for that block: no encoding, encoding using the first encoding scheme, encoding using the second encoding scheme, or encoding using the third encoding scheme. In this case, when all coefficients of any block are obtained, including non-zero coefficients, the cost of not encoding that block and the cost of encoding it using the first, second, or third encoding scheme can be calculated.
[0088] The following describes an exemplary implementation of calculating the encoding cost of a group by using all the coefficients included in the group.
[0089] For example, when calculating the encoding cost of a group, the cost of not encoding each coefficient can be calculated. By summing the costs of not encoding all coefficients in the group, the cost of not encoding the group can be obtained. The cost of not encoding a coefficient can be represented by the distortion when the coefficient is quantized to 0. For example, suppose group 1 includes coefficients x1-x16 as 4030 2010 1001 0000. Then the distortion when 4030 2010 1001 0000 is considered as 0000 0000 0000 0000 is the cost of not encoding group 1.
[0090] Since each coefficient is considered 0 when the blocks are encoded using the third group coding method, the distortion of the blocks encoded using the third group coding method is the same as that of the blocks not being encoded, and is equal to the cost of not encoding the blocks. Based on this, the cost of not encoding the blocks and the code rate of the first identifier can be summed to obtain the cost of encoding the blocks using the third group coding method.
[0091] The calculation of the cost of not encoding different coefficients within a group can be performed in parallel to improve the computational efficiency of the group's encoding cost.
[0092] The following describes an exemplary calculation method for the cost of encoding the group using the first and second group encoding methods.
[0093] In one possible implementation, the encoding cost of the group is calculated using all coefficients, including:
[0094] Each coefficient is prequantized, the encoding cost of each coefficient is calculated based on the prequantized value, and the coefficient is updated based on the prequantized value.
[0095] Calculate the cost of encoding the group using the first group encoding method based on the encoding cost of each coefficient;
[0096] Based on the position of the non-zero coefficients in the group, select one coefficient from the group as the last non-zero coefficient when the group is encoded using the second group encoding method;
[0097] Calculate the cost of encoding this group using the second group encoding method based on the encoding cost of each coefficient and the position of the last non-zero coefficient.
[0098] For example, coefficients have various characteristics, including sign (indicating whether the coefficient is positive or negative), magnitude (indicating the absolute value of the coefficient), identifier A (indicating whether the coefficient is zero), identifier B (existing when the coefficient is set to the last non-zero coefficient, indicating that the coefficient is set to the last non-zero coefficient), etc.
[0099] When coefficients need to be encoded, their amplitudes can be pre-quantized to make them easier to encode. However, pre-quantization may introduce distortion. The encoding cost for each coefficient can be calculated based on its pre-quantized value, and then the coefficients can be updated accordingly. This disclosure does not limit the specific method of pre-quantizing coefficients; exemplary implementations are given below.
[0100] When encoding coefficients, either a first coefficient encoding method or a second coefficient encoding method may be used. The first coefficient encoding method includes the prequantized value of the coefficient, its sign, and an identifier indicating whether the prequantized value is zero (identifier A). During decoding, if identifier A indicates the prequantized value of the coefficient is zero, the coefficient is directly decoded as zero. If identifier A indicates the prequantized value is not zero, the prequantized value and sign of the coefficient are determined, and the coefficient is restored. The second coefficient encoding method includes the prequantized value of the coefficient, its sign, and an identifier indicating that the coefficient is set to the last non-zero coefficient (identifier B).
[0101] Therefore, the cost of encoding each coefficient using the first coefficient encoding method and the cost of encoding non-zero coefficients using the second coefficient encoding method can be calculated. The cost of encoding a coefficient using the first coefficient encoding method can be represented by the sum of the pre-quantized value of the coefficient, the code rate of the sign and identifier A, and the distortion after pre-quantization. The cost of encoding a coefficient using the second coefficient encoding method can be represented by the sum of the pre-quantized value of the coefficient, the code rate of the sign and identifier B, and the distortion after pre-quantization. To simplify the calculation, the cost of encoding a coefficient using the second coefficient encoding method can be obtained by adding the code rate of identifier B and subtracting the code rate of identifier A to the cost of encoding a coefficient using the first coefficient encoding method.
[0102] Since the first coding scheme requires encoding all coefficients, the cost of encoding the group using the first coding scheme is calculated based on the encoding cost of each coefficient. This can be achieved by summing the costs of encoding each coefficient in the group using the first coding scheme. For example, suppose the prequantized values of coefficients x1-x16 in group 1 are 4030 2010 1001 0000. Then, the sum of the distortion of each coefficient being quantized to 4030 2010 10010000 and the code rate of encoding the value, sign, and identifier A of 4030 2010 1001 0000 is the cost of encoding group 1 using the first coding scheme.
[0103] In this way, the cost of encoding the group using the first group encoding method can be calculated.
[0104] In the second encoding method, the last non-zero coefficient in the group and the coefficients preceding it (with smaller coefficient numbers) are encoded, while the coefficients following it (with larger coefficient numbers) are not encoded. In this case, the last non-zero coefficient can be encoded using the second coefficient encoding method, and the coefficients preceding it can be encoded using the first coefficient encoding method. Therefore, based on the prequantized value of each coefficient, a coefficient can be selected from the group as the last non-zero coefficient when encoding the group using the second encoding method. This disclosure does not limit the specific method of selecting the last non-zero coefficient; exemplary implementations are given below.
[0105] Based on the encoding cost of each coefficient and the position of the last non-zero coefficient, calculate the cost of encoding the group using the second encoding method. This can be achieved by summing the cost of encoding the last non-zero coefficient using the second encoding method, the cost of encoding the coefficients before the last non-zero coefficient using the first encoding method, and the cost of not encoding the coefficients after the last non-zero coefficient.
[0106] The calculation of the encoding cost of different coefficients within a group, and the calculation of the cost of encoding the same coefficient within a group using different encoding methods, can be performed in parallel. Furthermore, it can be performed in parallel with the calculation of the cost of not encoding coefficients within a group, thereby improving the computational efficiency of the encoding cost of the group.
[0107] The following describes an exemplary method for prequantizing coefficients. Figure 4 A schematic diagram illustrating the process of prequantizing coefficients according to an embodiment of the present disclosure is shown.
[0108] like Figure 4 As shown, in one possible implementation, prequantization of each coefficient includes:
[0109] Step S41: Based on the amplitude of the current coefficient, determine M quantization values for the current coefficient, where M is an integer greater than 1;
[0110] Step S42: Based on the M quantization values of each coefficient included in the group, obtain the M queues corresponding to the group. The i-th queue includes the i-th quantization value of each coefficient, 1≤i≤M, where i is an integer.
[0111] Step S43: Based on the quantized values in the i-th queue, calculate the cost of encoding the current coefficient using the i-th quantized value as the prequantized value, and obtain the i-th first value;
[0112] Step S44: Compare the M first values and determine the quantization value corresponding to the smallest first value as the prequantization value of the current coefficient.
[0113] For example, each coefficient in the group can be initially quantized based on existing technology. Based on the result of the initial quantization, M quantization values are determined for each coefficient as candidate quantization values. The correspondence between the initial quantization result and the M quantization values can be predetermined, and a lookup table for the M quantization values can be generated. When executing the encoding method determination method of this disclosure embodiment, the M quantization values are determined by looking up the table based on the result of the initial quantization.
[0114] Table 1 shows an example of a lookup table for M quantized values. M = 2, and the M quantized values include the first quantized value and the second quantized value.
[0115] Table 1
[0116] 0 0 0 1 0 1 2 1 2 ··· ··· ··· N N-1 N
[0117] As shown in Table 1, the result of the initial quantization is an integer greater than or equal to 0, and the first quantization value and the second quantization value are also integers greater than or equal to 0. In one example, when the result of the initial quantization is 0, the first quantization value and the second quantization value are equal to 0; when the result of the initial quantization is 1, the first quantization value is equal to 0, and the second quantization value is equal to 1; when the result of the initial quantization is 2, the first quantization value is equal to 1, and the second quantization value is equal to 2; when the result of the initial quantization is N (N is greater than 0), the first quantization value is equal to N-1, and the second quantization value is equal to N.
[0118] The embodiments disclosed herein do not impose any restrictions on the values of the M quantization values, as long as the M quantization values are close to the result of the initial quantization.
[0119] This disclosure does not limit the specific method of initial quantization, as long as the coefficients after initial quantization are close to the magnitudes of the coefficients and are simpler and easier to encode. If the coefficients are already easy to encode, initial quantization may not be necessary. This disclosure does not limit whether pre-quantization of the coefficients is required before encoding.
[0120] Based on the M quantized values of each coefficient in the group, M queues corresponding to the group are obtained. The i-th queue includes the i-th quantized value of each coefficient, 1≤i≤M, where i is an integer. For example, the first queue corresponding to the group can be obtained based on the first quantized value of each coefficient in the group, and the second queue corresponding to the group can be obtained based on the second quantized value of each coefficient in the group.
[0121] For example, suppose that the coefficients x1-x16 included in group 1 are 4030 3010 1001 0000 after initial quantization. Then the first queue could be 3020 2000 0000 0000, and the second queue could be 4030 3010 1001 0000.
[0122] Based on the quantized values in the i-th queue, the cost of encoding the current coefficient using the i-th quantized value as a pre-quantized value is calculated to obtain the i-th first value. For example, based on multiple first quantized values in the first queue, the first context information of each coefficient can be determined. The context information of the coefficient may include whether the coefficient is greater than or equal to 1, the number of coefficients greater than or equal to 1 encoded before encoding the coefficient, the number of coefficients greater than or equal to 2 encoded before encoding the coefficient, etc. The specific content of the context information is not limited in this embodiment. The first context information of the coefficient refers to the context information when each coefficient is quantized to the first quantized value. Based on the first context information of each coefficient, the cost of encoding the coefficient can be calculated. For example, the cost of encoding the first quantized value, symbol, and identifier A using the first coefficient encoding method can be calculated to obtain the first first value.
[0123] Similarly, based on the multiple second quantization values in the second queue, the second context information of each coefficient can be determined. The second context information of a coefficient refers to the context information when each coefficient is quantized to a second quantization value. Based on the second context information of each coefficient, the cost of encoding that coefficient can be calculated. For example, the cost of encoding the second quantization value, symbol, and identifier A using the first coefficient encoding method can be calculated to obtain the second first value.
[0124] Calculating the first value based on the contextual information of the coefficients can be achieved using existing technology, and will not be elaborated here.
[0125] Compare the M first values and determine the quantization value corresponding to the smallest first value as the prequantization value of the current coefficient. For example, suppose that the first quantization value of coefficient x1 in group 1 is x11 and the second quantization value is x12. If the first first value is less than the second first value, then the first quantization value x11 can be determined as the prequantization value of coefficient x1.
[0126] Existing technology, when pre-quantizing coefficients, traverses the groups included in the transform block according to the group scanning order. For each group, it traverses the coefficients and performs initial quantization according to the scanning order of the coefficients within the group. Based on the obtained initial quantization results, it searches for non-zero coefficients in the transform block. When a non-zero coefficient is found, it further determines the position of the first non-zero coefficient scanned in the scanning order. If the first non-zero coefficient scanned in the scanning order is not found, the pre-quantized value of the coefficient is directly determined to be zero. If the position of the first non-zero coefficient scanned in the scanning order is found, candidate quantization values of the coefficient are determined based on the pre-quantization results. According to the coefficient scanning order, the cost of encoding each candidate quantization value is estimated using the coefficient's context information, and the candidate quantization value corresponding to the smallest cost is determined as the coefficient's pre-quantized value. After quantizing each coefficient, the context information of the next coefficient in the scanning order is updated; that is, groups must be quantized sequentially according to their order, and coefficients within a group must be quantized sequentially, reducing the hardware parallelism. The encoding method according to the embodiments of this disclosure eliminates the dependence of the coefficient order on the determination of the context information of the coefficients, so that the context information of each coefficient can be determined in parallel, further improving the degree of parallelism.
[0127] Existing technologies calculate the cost of encoding coefficients differently depending on whether a coefficient is the last non-zero coefficient during pre-quantization, increasing the complexity of hardware implementation. In this embodiment, the cost of not encoding is calculated for each coefficient, and the cost of encoding non-zero coefficients using either a first or second coefficient encoding method is calculated, reducing the complexity of hardware implementation.
[0128] Existing technologies require storing three alternative quantization values for most coefficients. In this embodiment, the minimum value of M is 2, so that only a minimum of two alternative quantization values need to be stored for each coefficient, reducing hardware storage costs.
[0129] The following describes another exemplary method for prequantizing coefficients.
[0130] In one possible implementation, each coefficient is pre-quantized, including:
[0131] Based on the amplitude of the current coefficient, determine M quantization values for the current coefficient, where M is an integer greater than 1;
[0132] Using the last coefficient in the group as the current coefficient, and using the context information of the current coefficient, calculate the cost of encoding the current coefficient with the i-th quantization value as the prequantization value, and obtain the i-th first value, 1≤i≤M, where i is an integer;
[0133] Compare the M first values, determine the quantization value corresponding to the smallest first value as the prequantization value of the current coefficient, and update the context information of the previous coefficient based on the prequantization value of the current coefficient;
[0134] Using the previous coefficient as the current coefficient, the process is repeated, using the context information of the current coefficient, to calculate the cost of encoding the current coefficient with the i-th quantization value as the prequantization value, and the subsequent steps.
[0135] For example, each coefficient in the group can be initially quantized based on existing technology, and M quantization values can be determined for each coefficient based on the results of the initial quantization. The initial quantization can be implemented based on existing technology, and the method for determining the M quantization values has been described above and will not be repeated here.
[0136] Using the last coefficient in the group (in coefficient number order) as the current coefficient, and employing the context information of the current coefficient, the cost of encoding the current coefficient with the i-th quantized value as the pre-quantized value is calculated, yielding the i-th first value, where 1 ≤ i ≤ M, and i is an integer. For example, assuming M quantized values include the first and second quantized values, the cost of encoding the first quantized value, symbol, and identifier A of the coefficient can be calculated, yielding the first first value; similarly, the cost of encoding the second quantized value, symbol, and identifier A of the coefficient can be calculated, yielding the second first value. Examples of the coefficient's context information can be found in the relevant description above. The calculation of the first value can be implemented using existing technology and will not be elaborated upon here.
[0137] By comparing the M first values, the quantized value corresponding to the smallest first value is determined as the prequantized value of the current coefficient. The context information of the previous coefficient (in coefficient number order) is updated based on the prequantized value of the current coefficient. Then, using the previous coefficient as the current coefficient, the process is repeated, using the context information of the current coefficient, to calculate the cost of encoding the current coefficient with the i-th quantized value as the prequantized value, and the subsequent steps. By traversing all coefficients within a group, the prequantized value of each coefficient can be determined.
[0138] For example, when group 1 includes coefficients x1-x16, coefficient x16 is used as the current coefficient, and the M first values corresponding to coefficient x16 are calculated. The M first values corresponding to coefficient x16 are compared; if the i-th first value is smaller, then the i-th quantization value of coefficient x16 is determined as the prequantization value of coefficient x16. Subsequently, coefficients x15-x1 are used sequentially as the current coefficients to determine the prequantization values.
[0139] In this way, the determined pre-quantized values are more accurate.
[0140] If the calculation method of the i-th first value is the same as the calculation method of the cost of encoding the coefficient using the first coefficient encoding method when the i-th quantized value is used as the prequantized value, the i-th first value can be directly used as the cost of encoding the coefficient using the first coefficient encoding method.
[0141] It should be understood that the cost of encoding the i-th quantized value, symbol, and identifier B in the second coefficient encoding method can also be calculated based on the context information of the coefficients, and used as the i-th first value. The embodiments of this disclosure do not limit the specific calculation method used when calculating the first value.
[0142] This disclosure does not limit the specific prequantization method for the coefficients, as long as the prequantized coefficients are close to the magnitudes of the coefficients and are simpler and easier to encode. If the coefficients are already easy to encode, prequantization may not be necessary. This disclosure does not limit whether prequantization of the coefficients is required before encoding.
[0143] The following describes an exemplary method for determining the last non-zero coefficient when the group is encoded using the second group encoding method. Figure 5 This diagram illustrates the process of determining the last non-zero coefficient when a group is encoded in a second group encoding manner according to an embodiment of the present disclosure.
[0144] like Figure 5 As shown, in one possible implementation, a coefficient is selected from the group based on the position of the non-zero coefficients in the group, and used as the last non-zero coefficient when the group is encoded using the second group encoding method, including:
[0145] Step S51: Based on the position of the non-zero coefficients in the group, a candidate coefficient set is obtained. The candidate coefficient set includes at least one non-zero coefficient, and the order of any two candidate coefficients in the candidate coefficient set is the same as the order of the two candidate coefficients in the group.
[0146] Step S52: In response to calculating the encoding cost of any two adjacent candidate coefficients and other coefficients between the two adjacent candidate coefficients, the two adjacent candidate coefficients are respectively used as the first candidate coefficient and the second candidate coefficient.
[0147] Step S53: Based on the encoding costs of the first candidate coefficient, the second candidate coefficient, and other coefficients, determine the relationship between the costs of grouping and encoding when the first candidate coefficient and the second candidate coefficient are selected as coefficients.
[0148] Step S54: Remove the candidate coefficients with higher costs from the candidate coefficient set;
[0149] Step S55: When there is one remaining candidate coefficient in the candidate coefficient set, that candidate coefficient is determined as the selected coefficient.
[0150] For example, a candidate coefficient set can be obtained first based on the position of the non-zero coefficients in the group, and the candidate coefficient set can include at least one coefficient with a pre-quantized non-zero value. The order of any two candidate coefficients in the candidate coefficient set is the same as the order of the two candidate coefficients in the group.
[0151] A candidate coefficient set can be formed by arbitrarily selecting a certain number of coefficients from the non-zero coefficients in the group. Alternatively, certain selection conditions can be set to select non-zero coefficients that meet the conditions to form the candidate coefficient set. Or, the candidate coefficient set can be formed directly based on all non-zero coefficients in the group. This disclosure does not limit the specific method of obtaining the candidate coefficient set.
[0152] Below is an example of the selection criteria for coefficients in the candidate coefficient set.
[0153] In one possible implementation, the candidate coefficient set is obtained by selecting the last coefficient greater than or equal to 1 in the group, the last coefficient greater than or equal to 2 in the group, and the non-zero coefficients between the last coefficient greater than or equal to 1 and the last coefficient greater than or equal to 2.
[0154] Due to the transformation, non-zero coefficients are usually concentrated in the upper left corner of the group, and the non-zero coefficients with earlier coefficient numbers are usually greater than or equal to those with later coefficient numbers. In this case, setting a non-zero coefficient with a very low coefficient number as the last non-zero coefficient will result in significant distortion. Therefore, it may be more appropriate to set a non-zero coefficient with a higher coefficient number as the last non-zero coefficient. Coefficients in the candidate coefficient set can be selected from the non-zero coefficients with higher coefficient numbers.
[0155] In this context, the last coefficient greater than or equal to 1 in a group refers to the last coefficient greater than or equal to 1 determined by the coefficient numbering order, and the first coefficient greater than or equal to 1 according to the scanning order. Similarly, the last coefficient greater than or equal to 2 in a group also refers to the last coefficient greater than or equal to 2 determined by the coefficient numbering order, and the first coefficient greater than or equal to 2 according to the scanning order.
[0156] For example, you can select the last coefficient greater than or equal to 1 in the group, the last coefficient greater than or equal to 2 in the group, and the non-zero coefficients between the last coefficient greater than or equal to 1 and the last coefficient greater than or equal to 2 to obtain a set of candidate coefficients.
[0157] Figure 6 This diagram illustrates the determination of a candidate coefficient set and the updating of the candidate coefficient set according to embodiments of the present disclosure.
[0158] like Figure 6 As shown, assuming that the prequantized coefficients x1-x16 in group 1 are 4030 2010 1001 0000 respectively, then the last coefficient greater than or equal to 1 is coefficient x12, the last coefficient greater than or equal to 2 is coefficient x5, and the non-zero coefficients between coefficients x5 and x12 include coefficients x7 and x9. Therefore, the candidate coefficient set can be [2, 1, 1, 1].
[0159] In this way, the number of comparisons required to determine the last non-zero coefficient can be reduced, improving the efficiency of determining the last non-zero coefficient. Furthermore, when the coefficients in the candidate coefficient set are set to have the last non-zero coefficient, the cost of grouping them and encoding them using the second group encoding method is relatively small, thus reducing the waste of computing resources.
[0160] In response to calculating the encoding cost of any two adjacent candidate coefficients and other coefficients between the two adjacent candidate coefficients, the two adjacent candidate coefficients are respectively designated as the first candidate coefficient and the second candidate coefficient.
[0161] For example, such as Figure 6 As shown, for the candidate coefficient set [2,1,1,1], assuming that the encoding cost of coefficients x9-x12 has been calculated, coefficient x9 can be used as the first candidate coefficient and coefficient x12 as the second candidate coefficient.
[0162] Based on the encoding costs of the first candidate coefficient, the second candidate coefficient, and other coefficients, determine the relationship between the costs of grouping and encoding when the first candidate coefficient and the second candidate coefficient are selected as coefficients.
[0163] Assuming that coefficient x9 is set as the last non-zero coefficient, the cost of encoding the group in the second group encoding method can be equal to the sum of the first coefficient encoding cost of the coefficients before coefficient x9 (coefficient x1-coefficient x8), the second coefficient encoding cost of coefficient x9, and the cost of not encoding the coefficients after coefficient x9 (coefficient x10-coefficient x16).
[0164] Assuming that coefficient x12 is set as the last non-zero coefficient, the cost of encoding the group in the second group encoding method can be equal to the sum of the first coefficient encoding cost of the coefficients before coefficient x12 (coefficient x1-coefficient x11), the second coefficient encoding cost of coefficient x12, and the cost of not encoding the coefficients after coefficient x12 (coefficient x13-coefficient x16).
[0165] It can be seen that the cost of encoding the group in the second group coding method when coefficient x9 is set as the last non-zero coefficient is the same as the cost of encoding the group in the second group coding method when coefficient x12 is set as the last non-zero coefficient. The only difference is the cost corresponding to coefficient x9-coefficient x12 used.
[0166] Based on this, according to the encoding costs of the first candidate coefficient, the second candidate coefficient, and other coefficients, the relationship between the costs of grouping and encoding when the first candidate coefficient and the second candidate coefficient are selected is determined, including:
[0167] The cost of encoding the first candidate coefficient using the second coefficient encoding method, the cost of not encoding the second candidate coefficient, and the cost of not encoding other coefficients between the first and second candidate coefficients are summed to obtain the representative value of the cost of encoding the group when the group is encoded using the second group encoding method and the first candidate coefficient is the last non-zero coefficient.
[0168] The cost of encoding the second candidate coefficient using the second coefficient encoding method, the cost of encoding the first candidate coefficient using the first coefficient encoding method, and the cost of encoding other coefficients between the first and second candidate coefficients using the first coefficient encoding method are summed to obtain the representative value of the cost of encoding the group when the group is encoded using the second group encoding method and the second candidate coefficient is the last non-zero coefficient.
[0169] The relationship between the two calculated representative values can represent the relationship between the cost of grouping and encoding when the first candidate coefficient and the second candidate coefficient are selected as coefficients.
[0170] For example, with Figure 6For example, when coefficient x9 is the first candidate coefficient and coefficient x12 is the second candidate coefficient, the sum of the encoding cost of coefficient x9 as the second coefficient and the cost of not encoding coefficient x10 - coefficient x12 is the representative value of the cost of encoding this group when it is encoded using the second group encoding method and the first candidate coefficient x9 is the last non-zero coefficient. Similarly, the sum of the encoding costs of coefficients x9 - x11 as the first coefficient and the encoding costs of coefficient x12 as the second coefficient is the representative value of the cost of encoding this group when it is encoded using the second group encoding method and the second candidate coefficient x12 is the last non-zero coefficient. If the representative value corresponding to coefficient x9 is larger, it indicates that the cost of encoding the group is greater when the first candidate coefficient is selected; if the representative value corresponding to coefficient x12 is larger, it indicates that the cost of encoding the group is greater when the second candidate coefficient is selected.
[0171] This disclosure does not limit the specific calculation method for the representative value of the cost of encoding the group. To simplify the process, the representative value of the cost of encoding the group can be obtained by directly summing the first coefficient encoding cost of the coefficients before the first candidate coefficient (in coefficient encoding order), the second coefficient encoding cost of the first candidate coefficient, and the cost of not encoding the coefficients after the first candidate coefficient (in coefficient encoding order). This sum is used as the representative value of the cost of encoding the group when the group is encoded using the second group encoding method and the first candidate coefficient is the last non-zero coefficient. Alternatively, the representative value of the cost of encoding the group can be obtained by directly summing the second coefficient encoding cost of the coefficients before the second candidate coefficient (in coefficient encoding order), the second coefficient encoding cost of the second candidate coefficient, and the cost of not encoding the coefficients after the second candidate coefficient (in coefficient encoding order). As long as the representative value can characterize the cost of encoding the group using the second group encoding method when the first candidate coefficient and the second candidate coefficient are respectively set as the last non-zero coefficient.
[0172] Remove the candidate coefficients with higher costs from the candidate coefficient set. For example... Figure 6 As shown, the representative value corresponding to coefficient x9 is larger, so coefficient x9 is removed from the candidate coefficient set, and the candidate coefficient set is updated to [2,1,1].
[0173] Similarly, once the encoding cost of any two adjacent candidate coefficients and all other coefficients between them is calculated, a first candidate coefficient and a second candidate coefficient can be set, a representative value comparison can be performed, and one of the first or second candidate coefficients can be removed from the candidate coefficient set based on the comparison result. When only one candidate coefficient remains in the candidate coefficient set, that candidate coefficient is selected as the last non-zero coefficient. Figure 6 As shown, coefficients x9, x7, and x5 are successively removed from the candidate coefficient set, leaving only coefficient x12 in the final candidate coefficient set. Therefore, coefficient x12 can be set as the last non-zero coefficient when group 1 is encoded using the second encoding method. The cost of encoding group 1 using the second encoding method is equal to the sum of the first coefficient encoding cost of the coefficients before x12 (coefficient x1 - coefficient x11), the second coefficient encoding cost of x12, and the cost of not encoding the coefficients after x12 (coefficient x13 - coefficient x16).
[0174] In this way, the cost of encoding the calculated groups using the second encoding method is lower.
[0175] Existing technologies determine the last non-zero coefficient in a transform block. Therefore, the encoding cost of all coefficients traversed before determining the last non-zero coefficient needs to be stored for use in determining the last non-zero coefficient in subsequent coefficients, resulting in significant storage pressure. In this embodiment, when determining the last non-zero coefficient within a group, only the encoding cost of the coefficients within the group is used, reducing storage pressure.
[0176] In one possible implementation, the method further includes:
[0177] For any given block, if the block contains non-zero coefficients, determine whether to set the coefficients in the block to zero based on the encoding cost of the block.
[0178] If the result of the judgment is to set the coefficients in the group to zero, then update the coefficients in the group.
[0179] For example, as described above, when encoding groups, if a group contains very few non-zero coefficients, encoding the group as if all coefficients are zero may be less costly. Therefore, for any given group containing non-zero coefficients, the cost can be determined based on the calculated cost of that group to decide whether to set the coefficients in that group to zero. This step can be completed before step S32.
[0180] In one possible implementation, for any given block, if the block contains non-zero coefficients, based on the encoding cost of the block, determine whether to set the coefficients in the block to zero, including:
[0181] The cost of encoding the group using the first encoding method is summed with the cost of encoding the third identifier to obtain the second value, where the third identifier indicates that the group includes non-zero coefficients.
[0182] If the cost of encoding the group using the third encoding method is less than the second value, then the coefficients included in the group are set to zero.
[0183] If the second value is less than the cost of encoding the group using the third group encoding method, it is determined that the coefficients of the group should not be set to zero.
[0184] For example, as described above, when a group is encoded as a group with all coefficients equal to zero (third group encoding method), only the first identifier indicating that all coefficients within the group are zero can be encoded. Correspondingly, when a group is encoded as a group that includes non-zero coefficients but excludes the last non-zero coefficient (first group encoding method), in addition to encoding the coefficients that need to be encoded, a third identifier indicating that the group includes non-zero coefficients can also be encoded.
[0185] The cost of encoding the first identifier and the cost of encoding the third identifier can be pre-calculated. When calculating the encoding cost of the coefficients, the cost of not encoding the group and the cost of encoding the first identifier can be accumulated to obtain a fifth value. The cost of encoding the group using the first group encoding method and the cost of encoding the third identifier can be accumulated to obtain a second value.
[0186] When the cost of encoding the group using the third encoding method is less than the second value, it can be assumed that setting the coefficients within the group to zero reduces the cost of encoding the group, thus determining to set the coefficients included in the group to zero.
[0187] When the second value is less than the cost of encoding the group using the third group encoding method, it can be considered that setting the coefficients in the group to zero increases the cost of encoding the group, and thus it is determined that the coefficients included in the group should not be set to zero.
[0188] In one possible implementation, the method further includes:
[0189] If the judgment result is not to set the coefficients in the group to zero, the cost of encoding the group using the first group encoding method is updated to the third value.
[0190] For example, if the cost of encoding a group using the first encoding method is not superimposed when calculating the cost of encoding the third identifier, then after determining the third value, the cost of encoding the group using the first encoding method can be updated to the third value.
[0191] It should be understood that in step S31, when calculating the cost of encoding the group using the first encoding method, the cost of encoding the third identifier can be superimposed. In this case, the cost of encoding the group using the first encoding method and the cost of encoding the group using the third encoding method can be directly compared. If the cost corresponding to the third encoding method is smaller, it is determined that the coefficients in the group should be set to zero; if the cost of the first encoding method is smaller, it is determined that the coefficients in the group should not be set to zero. This disclosure embodiment does not limit the specific implementation method of determining whether the coefficients in the group should be set to zero.
[0192] If the result of the judgment is to set the coefficients in the group to zero, the coefficients in the group can be updated, that is, the values of all coefficients in the group are updated to 0.
[0193] The following describes an exemplary implementation of determining the groups to be encoded in the transform block and the encoding method of the encoded groups.
[0194] In one possible implementation, based on the calculated encoding costs of multiple groups, the groups to be encoded in the transform block and the encoding method of the encoded groups are determined, including:
[0195] When there are groups containing non-zero coefficients, based on the encoding cost of multiple groups, one group is selected from all groups containing non-zero coefficients and encoded using the second encoding method. Groups before the selected group that contain non-zero coefficients are encoded using the first encoding method. Groups before the selected group that have all zero coefficients are encoded using the third encoding method. Groups after the selected group are not encoded.
[0196] For example, if a transform block contains multiple groups, and these groups are encoded using the second coding scheme, the coefficients within those groups will be treated as the last non-zero coefficients. As described above, groups containing non-zero coefficients are mostly concentrated in the upper left corner of the transform block; similarly, the non-zero coefficients within these groups are also mostly concentrated in the upper left corner. Therefore, coefficients preceding a given coefficient in the transform block are more important, while those following it are less important. In other words, groups preceding those encoded using the second coding scheme (those scanned earlier) can be encoded using the first coding scheme to ensure more accurate decoded data. Groups following those encoded using the second coding scheme (those scanned earlier) can be encoded using the third coding scheme to achieve a lower bit rate.
[0197] Therefore, selecting different groups for encoding using the second coding method has a significant impact on the overall coding cost of the transform block. In this case, based on the coding costs of multiple groups, one group can be selected from all groups including non-zero coefficients for encoding using the second coding method. Groups preceding the selected group and including non-zero coefficients are encoded using the first coding method, and groups preceding the selected group with all zero coefficients are encoded using the third coding method. Groups following the selected group are not encoded.
[0198] The following describes an exemplary method for selecting groups to be encoded using the second encoding method. Figure 7 This diagram illustrates the process of selecting a second group of encoding methods for grouping according to an embodiment of the present disclosure.
[0199] like Figure 7 As shown, in one possible implementation, based on the encoding cost of multiple groups, one group is selected from all groups including those with non-zero coefficients and encoded using a second encoding method, including:
[0200] Step S71: Take all groups including non-zero coefficients as candidate groups to obtain a candidate group set. The order of any two candidate groups in the candidate group set is the same as the order of the two candidate groups in the transform block.
[0201] Step S72: In response to the calculation of the encoding costs of any two adjacent candidate groups and other groups between the two adjacent candidate groups, the two adjacent candidate groups are respectively designated as the first candidate group and the second candidate group.
[0202] Step S73: Based on the encoding costs of the first candidate group, the second candidate group, and other groups, determine the relationship between the encoding costs of the first candidate group and the second candidate group when they are selected as the transform blocks.
[0203] Step S74: Delete the candidate group with the higher cost from the candidate group set;
[0204] Step S75: When there is one remaining candidate group in the candidate group set, select that candidate group as the selected group.
[0205] For example, all groups including non-zero coefficients can be taken as candidate groups to obtain a candidate group set, and the order of any two candidate groups in the candidate group set can be the same as the order of the two candidate groups in the transform block.
[0206] Figure 8 This diagram illustrates the determination and updating of a candidate grouping set according to an embodiment of the present disclosure.
[0207] like Figure 8 As shown, assuming that transform block 1 includes groups g1 to g16, and according to the group numbering order, groups g1, g3, g5, and g7 include non-zero coefficients. Then the candidate group set can be [g1, g3, g5, g7].
[0208] In response to the calculation of the encoding costs of any two adjacent candidate groups in the candidate group set and other groups between the two adjacent candidate groups, the candidate group that comes first in the order of the two adjacent candidate groups can be designated as the first candidate group and the candidate group that comes later in the order of the second candidate group.
[0209] For example, for a candidate group set [g1,g3,g5,g7], assuming the encoding cost of group g3-g5 has been calculated, group g3 can be used as the first candidate group and group g5 as the second candidate group.
[0210] Based on the encoding costs of the first candidate group, the second candidate group, and other groups, the relative costs of encoding the transform block when the first and second candidate groups are selected can be determined. At this point, it can be assumed that the transform block is encoded using a second-block encoding method. The second-block encoding method includes encoding the groups using a defined encoding method for each group.
[0211] Assuming that group g3 is set to be encoded using the second group encoding method, the cost of encoding the transform block can be equal to the cost of encoding the groups before group g3 (group g1 and group g2) using a determined encoding method (which may be the first or third group encoding method), the cost of encoding group 3 using the second group encoding method, and the cost of not encoding the groups after group 3 (group g4 to group g16).
[0212] Assuming that group g5 is set to be encoded using the second group encoding method, the cost of encoding the transform block can be equal to the cost of encoding the groups before group g5 (group g1-group g4) using a determined encoding method (which may be the first or third group encoding method), the cost of encoding group g5 using the second group encoding method, and the cost of not encoding the groups after group g5 (group g6-group g16).
[0213] It can be seen that the cost of encoding the transform block when group g3 is encoded using the second group encoding method is the same as the cost of encoding the transform block when group g5 is encoded using the second group encoding method. The only difference is which cost corresponding to group g3-group g5 is used.
[0214] Based on this, according to the encoding costs of the first candidate group, the second candidate group, and other groups, the relationship between the costs of encoding the transform block when the first candidate group and the second candidate group are selected is determined, including:
[0215] The cost of encoding the first candidate group using the second group encoding method, the cost of not encoding the second candidate group, and the cost of not encoding other groups between the first and second candidate groups are summed to obtain the representative value of the cost of encoding the transform block when the first candidate group is encoded using the second group encoding method.
[0216] The cost of encoding the second candidate group using the second encoding method, the cost of encoding the first candidate group using the first encoding method, the cost of encoding the group with all zero coefficients between the first and second candidate groups using the third encoding method, and the cost of encoding the group with non-zero coefficients between the first and second candidate groups using the first encoding method are summed to obtain the representative value of the cost of encoding the transform block when the second candidate group is encoded using the second encoding method.
[0217] The relationship between the two calculated representative values can represent the relationship between the cost of encoding the transform block when the first candidate group and the second candidate group are selected groups.
[0218] For example, when group g3 is the first candidate group and group g5 is the second candidate group, the sum of the cost of encoding group g3 using the second group coding method and the cost of not encoding group g4 and group g5 is the representative value of the cost of encoding the transform block when the first candidate group is encoded using the second group coding method. Group g4 already includes a group with all coefficients being zero. Therefore, the sum of the cost of encoding group g3 using the first group coding method, the cost of encoding group g4 using the third group coding method, and the cost of encoding group g5 using the second group coding method is the representative value of the cost of encoding the transform block when the second candidate group is encoded using the second group coding method.
[0219] This disclosure does not limit the specific calculation method for the representative value of the cost of encoding the transform block. To simplify the process, the cost of encoding the transform block using the first group encoding method for the group before the first candidate group (in the group encoding order) and including non-zero coefficients, the cost of encoding the transform block using the third group encoding method for the group before the first candidate group (in the group encoding order) and all coefficients are zero, the cost of encoding the first candidate group using the second group encoding method, and the cost of not encoding the transform block for the group after the first candidate group (in the group encoding order) are directly accumulated as the representative value of the cost of encoding the transform block when the first candidate group is encoded using the second group encoding method. Alternatively, the cost of encoding the transform block using the first group coding method can be directly accumulated as follows: the cost of encoding the transform block using the third group coding method for the transform block before the second candidate group (in the group coding order) and including non-zero coefficients; the cost of encoding the transform block using the second group coding method for the transform block before the second candidate group (in the group coding order) and all zero coefficients; the cost of encoding the second candidate group using the second group coding method; and the cost of not encoding the transform block for the transform block after the second candidate group (in the group coding order). This accumulated cost serves as a representative value for the cost of encoding the transform block when the second candidate group is encoded using the second group coding method. Any representative value that can characterize the cost of encoding the transform block when the first and second candidate groups are encoded using the second group coding method is acceptable.
[0220] Remove the candidate group with the higher cost from the candidate group set. For example, with Figure 8 For example, if the representative value of group g3 is larger, then the number of group g3 will be removed from the candidate group set, and the candidate group set will be updated to [g1, g5, g7].
[0221] Similarly, once the encoding cost of any two adjacent candidate groups and all other groups between them is calculated (i.e., a first candidate group and a second candidate group are set, a comparison of representative values is performed, and one of the first or second candidate groups is deleted from the candidate group set based on the comparison result), and a candidate group remains in the candidate group set, that candidate group is selected and encoded using the second encoding method. For example... Figure 8 As shown, groups g3, g7, and g1 are successively removed from the candidate group set, and finally only group g5 remains in the candidate group set. Group g5 can then be set as the selected group and encoded using the second group encoding method.
[0222] In this way, the encoding cost of the transform block is reduced.
[0223] In existing technologies, it is necessary to traverse the coefficients in the transform block according to the scanning order to determine the candidate coefficients of the last non-zero coefficient in the transform block (in coefficient number order). Then, based on the scanning order of the candidate coefficients, the first non-zero coefficient scanned in the transform block according to the scanning order is determined, and this coefficient is encoded using the second group encoding method. Therefore, the determination of the last non-zero coefficient in the transform block and the determination of the group encoded using the second group encoding method cannot be separated and need to be determined based on the cost of the coefficients in the entire transform block, which is difficult to implement in hardware. Compared with existing technologies, in the embodiments of this disclosure, the determination of the last non-zero coefficient in the group and the determination of the group encoded using the second group encoding method are decoupled into independent steps. Furthermore, the determination of the last non-zero coefficient in the group and the group encoded using the second group encoding method no longer depends on the cost of the coefficients in the entire transform block, simplifying the hardware implementation.
[0224] The method for determining the encoding mode in this embodiment can also be used to determine the encoding mode of a transform block.
[0225] In one possible implementation, the method further includes:
[0226] When there are groups containing non-zero coefficients, the encoding method of the transform block is determined based on the encoding cost of multiple groups and the encoding method of the groups to be encoded. The encoding method of the transform block is one of the first block encoding method and the second block encoding method.
[0227] When there are no groups containing non-zero coefficients, the transform block is encoded using the first block encoding method;
[0228] The first encoding method includes encoding a second identifier, which indicates that all coefficients in the transform block are zero; the second encoding method includes encoding the groups to be encoded using a defined encoding method for each group.
[0229] For example, there are two encoding options for the transform block.
[0230] The first block encoding method includes encoding a second identifier, which indicates that all coefficients in the transform block are zero. When any transform block is encoded using the first block encoding method, each group within the transform block is considered to have all coefficients zero and is not encoded.
[0231] The second encoding method involves encoding the groups to be encoded using a defined encoding method for each group. Under the second encoding method, the groups to be encoded can be encoded according to the scanning order of each group.
[0232] If it is determined that the transform block does not include non-zero coefficients, or if it is determined that the transform block no longer includes non-zero coefficients after all groups have completed coefficient updates, then there are no groups in the transform block that include non-zero coefficients. In this case, it can be directly determined that multiple groups will not be encoded, and the encoding method of the transform block can be directly determined as the encoding method of the first block.
[0233] When there are groups containing non-zero coefficients, if such groups are few, the cost of encoding the transform block using the first block encoding method may be less than the cost of encoding the transform block using the second block encoding method. Therefore, when there are groups containing non-zero coefficients, the encoding method of the transform block can be determined based on the encoding costs of multiple groups and the encoding methods of the groups being encoded. In this case, the encoding method of the transform block can be either the first block encoding method or the second block encoding method. Once the encoding method of the transform block is determined, the transform block can be encoded to obtain the encoded result.
[0234] The first and second block encoding methods are both existing encoding methods in the prior art. This disclosure does not limit the details of the first and second block encoding methods, or the details of calculating the cost of encoding the transform block using the first and second block encoding methods, as long as the encoding cost of the transform block under any encoding method can reflect the encoding distortion and bit rate.
[0235] This disclosure does not limit the details of determining the encoding method of the transform block. An example of determining the encoding method of the transform block is given below.
[0236] In one possible implementation, the encoding scheme of the transform block is determined based on the encoding costs of multiple groups and the encoding scheme of the groups to be encoded, including:
[0237] The cost of not encoding multiple groups and the cost of encoding the second identifier are added together to obtain the cost of encoding the transform block using the first block encoding method.
[0238] The cost of encoding the blocks using the determined encoding method, the cost of not encoding the blocks, and the cost of encoding the fourth identifier are summed to obtain the cost of encoding the transform block using the second block encoding method. The fourth identifier indicates that the transform block includes non-zero coefficients.
[0239] Compare the cost of encoding the transform block using the first block encoding method with the cost of encoding the transform block using the second block encoding method, and determine the encoding method of the transform block with the smaller value.
[0240] For example, as described above, when a transform block is encoded as a transform block with all coefficients equal to zero (first block encoding method), only the second identifier indicating that all coefficients in the transform block are zero can be encoded. Correspondingly, when a transform block is encoded as a transform block including non-zero coefficients (second group encoding method), in addition to encoding the groups that need to be encoded, a fourth identifier indicating that the transform block includes non-zero coefficients can also be encoded.
[0241] The cost of encoding the second identifier and the cost of encoding the fourth identifier can be pre-calculated. The cost of not encoding multiple groups and the cost of encoding the second identifier can be accumulated as the cost of encoding the transform block using the first block encoding method. The cost of encoding the determined groups using the determined encoding method, the cost of not encoding the determined groups, and the cost of encoding the fourth identifier can be accumulated as the cost of encoding the transform block using the second block encoding method.
[0242] Compare the cost of encoding the transform block using the first block encoding method with the cost of encoding the transform block using the second block encoding method, and determine the encoding method of the transform block with the smaller value.
[0243] In this way, the cost of encoding transform blocks using a defined encoding scheme is reduced.
[0244] In existing technologies, determining whether a transform block should be encoded as a transform block with all coefficients zero involves accumulating the encoding costs of the coefficients to obtain the encoding cost of the transform block. This results in a large number of calculations and increases the complexity of hardware implementation. The method disclosed in this invention obtains the encoding cost of the transform block by accumulating the encoding costs of the groups, reducing the number of calculations and lowering the complexity of hardware implementation.
[0245] In existing technologies, it is necessary to traverse the coefficients multiple times from the initial acquisition of coefficients to determining the encoding method of the transform block. However, the embodiments of this disclosure only require traversing the coefficients in the transform block once to determine the encoding method of the transform block, thereby improving the efficiency of determining the encoding method of the transform block.
[0246] Figure 9 A schematic diagram showing the structure of an apparatus for determining an encoding method according to an embodiment of the present disclosure is provided.
[0247] like Figure 9 As shown, in one possible implementation, the device includes:
[0248] The first calculation module 91 is configured to respond to obtaining the coefficients of the groups included in the transform block in the video frame, and to calculate the encoding cost of the group by means of all the coefficients of any group after obtaining all the coefficients of the group. The encoding cost calculation of multiple groups in the transform block is performed in parallel. The transform block includes multiple groups, each group includes multiple coefficients, and the encoding cost of the group includes the cost of not encoding the group and the cost of encoding the group in at least one encoding method.
[0249] The first determining module 92 is used to determine the group to be encoded in the transform block and the encoding method of the group to be encoded based on the calculated encoding cost of the multiple groups.
[0250] In one possible implementation, the first calculation module includes a first calculation unit, a second calculation unit, a third calculation unit, and a fourth calculation unit. The first calculation unit is used to calculate the encoding cost of coefficients; the second calculation unit is used to calculate the cost of not encoding a group and the cost of encoding a group using a third group encoding method based on the encoding cost of the coefficients; the third calculation unit is used to calculate the cost of encoding a group using a first group encoding method based on the encoding cost of the coefficients; the fourth calculation unit is used to calculate the cost of encoding a group using a second group encoding method based on the encoding cost of the coefficients; when the group includes non-zero coefficients, the first calculation unit inputs the encoding cost of the coefficients into the second calculation unit, the third calculation unit, and the fourth calculation unit; when all coefficients in the group are zero, the first calculation unit inputs the encoding cost of the coefficients into the second calculation unit.
[0251] In one possible implementation, the grouping encoding method includes one of a first group encoding method, a second group encoding method, and a third group encoding method. The first group encoding method includes encoding all coefficients in the group; the second group encoding method includes encoding the last non-zero coefficient and the coefficients before it in the group, while other coefficients are not encoded; the third group encoding method includes encoding a first identifier, which indicates that all coefficients in the group are zero.
[0252] In one possible implementation, the first determining module is specifically used to, when there are groups including non-zero coefficients, select one group from all groups including non-zero coefficients according to the encoding cost of the plurality of groups and encode it using the second group encoding method; the groups before the selected group that include non-zero coefficients are encoded using the first group encoding method; the groups before the selected group that have all zero coefficients are encoded using the third group encoding method; and the groups after the selected group are not encoded.
[0253] In one possible implementation, the apparatus further includes: a judgment module, configured to, for any given group, determine whether to set the coefficients in the group to zero based on the encoding cost of the group when the group includes non-zero coefficients; and an update module, configured to update the coefficients in the group when the judgment result is that the coefficients in the group should be set to zero.
[0254] In one possible implementation, the apparatus further includes: a second determining module, configured to, when there are groups including non-zero coefficients, determine the encoding method of the transform block based on the encoding cost of the plurality of groups and the encoding method of the group being encoded, wherein the encoding method of the transform block is one of a first block encoding method and a second encoding method; when there are no groups including non-zero coefficients, the transform block is encoded using the first block encoding method; wherein the first block encoding method includes encoding a second identifier, the second identifier indicating that all coefficients in the transform block are zero; and the second encoding method includes encoding the group being encoded using the determined encoding methods of each group.
[0255] In one possible implementation, the second determining module is specifically used to: accumulate the cost of not encoding the plurality of groups and the cost of encoding the second identifier to obtain the cost of encoding the transform block using the first block encoding method; accumulate the cost of encoding the encoded groups using the determined encoding method, the cost of not encoding the unencoded groups, and the cost of encoding the fourth identifier to obtain the cost of encoding the transform block using the second block encoding method, where the fourth identifier indicates that the transform block includes non-zero coefficients; compare the cost of encoding the transform block using the first block encoding method and the cost of encoding the transform block using the second block encoding method, and determine the corresponding encoding method with the smaller value as the encoding method of the transform block.
[0256] In one possible implementation, the first calculation unit is specifically used to prequantize each coefficient, calculate the encoding cost of each coefficient based on the prequantization value, and update the coefficient based on the prequantization value; the device further includes a first selection unit, used to select a coefficient from the group based on the position of the non-zero coefficient in the group, as the last non-zero coefficient when the group is encoded using the second group encoding method; the fourth calculation unit is specifically used to calculate the cost of encoding the group using the second group encoding method based on the encoding cost of each coefficient and the position of the last non-zero coefficient.
[0257] In one possible implementation, the first computing unit is specifically used to: determine M quantization values for the current coefficient based on the amplitude of the current coefficient, where M is an integer greater than 1; obtain M queues corresponding to the group based on the M quantization values of each coefficient included in the group, where the i-th queue includes the i-th quantization value of each coefficient, 1≤i≤M, and i is an integer; calculate the cost of encoding the current coefficient with the i-th quantization value as the prequantization value based on the quantization values in the i-th queue, and obtain the i-th first value; compare the M first values and determine the quantization value corresponding to the smallest first value as the prequantization value of the current coefficient.
[0258] In one possible implementation, the first selection unit is specifically configured to: obtain a candidate coefficient set based on the position of non-zero coefficients in the group, the candidate coefficient set including at least one coefficient with a prequantized non-zero value, wherein the order of any two candidate coefficients in the candidate coefficient set is the same as the order of the two candidate coefficients in the group; in response to calculating the encoding cost of any two adjacent candidate coefficients and other coefficients between the two adjacent candidate coefficients, designate the two adjacent candidate coefficients as the first candidate coefficient and the second candidate coefficient, respectively; determine the relationship between the encoding costs of the group when the first candidate coefficient and the second candidate coefficient are selected as the selected coefficients based on the encoding costs of the first candidate coefficient, the second candidate coefficient, and the other coefficients; delete the corresponding candidate coefficient with the higher cost from the candidate coefficient set; and when one candidate coefficient remains in the candidate coefficient set, determine that candidate coefficient as the selected coefficient.
[0259] In one possible implementation, the first judgment module is specifically used to: accumulate the cost of encoding the group using the first group encoding method and the cost of encoding the third identifier to obtain a second value, wherein the third identifier indicates that the group includes non-zero coefficients; when the cost of encoding the group using the third group encoding method is less than the second value, determine that the coefficients included in the group are set to zero; when the second value is less than the cost of encoding the group using the third group encoding method, determine that the coefficients included in the group are not set to zero.
[0260] In one possible implementation, the first determining module is specifically configured to: take all groups including non-zero coefficients as candidate groups to obtain a candidate group set, wherein the order of any two candidate groups in the candidate group set is the same as the order of the two candidate groups in the transform block; in response to the calculated encoding costs of any two adjacent candidate groups and other groups between the two adjacent candidate groups, designate the two adjacent candidate groups as a first candidate group and a second candidate group, respectively; determine the relationship between the encoding costs of the first candidate group and the second candidate group when they are selected as the selected groups, based on the encoding costs of the first candidate group, the second candidate group, and the other groups; delete the corresponding candidate group with the larger cost from the candidate group set; and when one candidate group remains in the candidate group set, designate that candidate group as the selected group.
[0261] In some embodiments, the functions or modules of the apparatus provided in this disclosure can be used to perform the methods described in the above method embodiments. The specific implementation can be referred to the description of the above method embodiments, and for the sake of brevity, it will not be repeated here.
[0262] This disclosure also provides an electronic device, including a memory, a processor, and a computer program stored in the memory, wherein the processor executes the computer program to implement the steps of the above method.
[0263] This disclosure also provides a non-volatile computer-readable storage medium storing a computer program thereon, which, when executed by a processor, implements the steps of the above-described method.
[0264] This disclosure also provides a computer program product, including a computer program or a non-volatile computer-readable storage medium carrying the computer program, wherein the computer program, when executed by a processor, implements the steps of the above method.
[0265] Figure 10 A block diagram of an electronic device 1900 according to an embodiment of the present disclosure is shown. For example, the electronic device 1900 may be provided as a server or a terminal device. (Refer to...) Figure 10 The electronic device 1900 includes a processing component 1922, which further includes one or more processors, and memory resources represented by memory 1932 for storing instructions, such as application programs, that can be executed by the processing component 1922. The application programs stored in memory 1932 may include one or more modules, each corresponding to a set of instructions. Furthermore, the processing component 1922 is configured to execute instructions to perform the methods described above.
[0266] Electronic device 1900 may also include a power supply component 1926 configured to perform power management of electronic device 1900, a wired or wireless network interface 1950 configured to connect electronic device 1900 to a network, and an input / output interface 1958 (I / O interface). Electronic device 1900 can operate on an operating system, such as Windows Server, stored in memory 1932. TM Mac OS X TM Unix TM Linux TM FreeBSD TM Or similar.
[0267] In an exemplary embodiment, a non-volatile computer-readable storage medium is also provided, such as a memory 1932 including computer program instructions that can be executed by a processing component 1922 of an electronic device 1900 to perform the above-described method.
[0268] Computer-readable storage media can be tangible devices capable of holding and storing programs / instructions used by instruction execution devices. Computer-readable storage media can be, for example—but not limited to—electrical storage devices, magnetic storage devices, optical storage devices, electromagnetic storage devices, semiconductor storage devices, or any suitable combination of the foregoing. More specific examples (a non-exhaustive list) of computer-readable storage media include: portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), static random access memory (SRAM), portable compact disc read-only memory (CD-ROM), digital multifunction disc (DVD), memory sticks, floppy disks, mechanical encoding devices, such as punch cards or recessed protrusions storing instructions thereon, and any suitable combination of the foregoing. The computer-readable storage media used herein are not to be construed as transient signals themselves, such as radio waves or other freely propagating electromagnetic waves, electromagnetic waves propagating through waveguides or other transmission media (e.g., light pulses through fiber optic cables), or electrical signals transmitted through wires.
[0269] The computer program (or computer-readable program instructions) described herein can be downloaded from a computer-readable storage medium to various computing / processing devices, or downloaded via a network, such as the Internet, local area network, wide area network, and / or wireless network, to an external computer or external storage device. The network may include copper transmission cables, fiber optic transmission, wireless transmission, routers, firewalls, switches, gateway computers, and / or edge servers. A network adapter card or network interface in each computing / processing device receives the computer-readable program instructions from the network and forwards them to the computer-readable storage medium in the respective computing / processing device.
[0270] The computer program (or computer program instructions) used to perform the operations of this disclosure may be assembly instructions, instruction set architecture (ISA) instructions, machine instructions, machine-dependent instructions, microcode, firmware instructions, state setting data, or source code or object code written in any combination of one or more programming languages, including object-oriented programming languages such as Smalltalk, C++, etc., and conventional procedural programming languages such as the "C" language or similar programming languages. The computer-readable program instructions may execute entirely on the user's computer, partially on the user's computer, as a standalone software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving a remote computer, the remote computer may be connected to the user's computer via any type of network—including a local area network (LAN) or a wide area network (WAN)—or may be connected to an external computer (e.g., via the Internet using an Internet service provider). In some embodiments, electronic circuitry, such as programmable logic circuitry, field-programmable gate arrays (FPGAs), or programmable logic arrays (PLAs), is personalized by utilizing state information from the computer-readable program instructions to implement various aspects of this disclosure.
[0271] Various aspects of this disclosure are described herein with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of this disclosure. It should be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer-readable program instructions.
[0272] These computer-readable program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing apparatus to produce a machine such that, when executed by the processor of the computer or other programmable data processing apparatus, they create means for implementing the functions / actions specified in one or more blocks of the flowchart and / or block diagram. These computer-readable program instructions can also be stored in a computer-readable storage medium that causes a computer, programmable data processing apparatus, and / or other device to operate in a particular manner; thus, the computer-readable medium storing the instructions comprises an article of manufacture that includes instructions for implementing aspects of the functions / actions specified in one or more blocks of the flowchart and / or block diagram.
[0273] Computer-readable program instructions may also be loaded onto a computer, other programmable data processing apparatus, or other device to cause a series of operational steps to be performed on the computer, other programmable data processing apparatus, or other device to produce a computer-implemented process, thereby causing the instructions executed on the computer, other programmable data processing apparatus, or other device to perform the functions / actions specified in one or more boxes of a flowchart and / or block diagram.
[0274] The flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of systems, methods, and computer program products according to various embodiments of the present disclosure. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of an instruction containing one or more executable instructions for implementing a specified logical function. In some alternative implementations, the functions marked in the blocks may occur in a different order than those shown in the drawings. For example, two consecutive blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in the block diagrams and / or flowcharts, and combinations of blocks in the block diagrams and / or flowcharts, may be implemented using a dedicated hardware-based system that performs the specified function or action, or using a combination of dedicated hardware and computer instructions.
[0275] The various embodiments of this disclosure have been described above. These descriptions are exemplary and not exhaustive, nor are they limited to the disclosed embodiments. Many modifications and variations will be apparent to those skilled in the art without departing from the scope and spirit of the described embodiments. The terminology used herein is chosen to best explain the principles, practical application, or technical improvements to the embodiments in the market, or to enable others skilled in the art to understand the embodiments disclosed herein.
Claims
1. A method for determining an encoding scheme, characterized in that, The method includes: In response to obtaining the coefficients of the groups included in the transform block in the video frame, once all the coefficients of any group are obtained, the encoding cost calculation for that group is started using all the coefficients. The encoding cost calculations for multiple groups in the transform block are performed in parallel. The transform block includes multiple groups, each group includes multiple coefficients, and the encoding cost of a group includes the cost of not encoding the group and the cost of encoding the group in at least one encoding method. Based on the calculated encoding costs of the multiple groups, the groups to be encoded in the transform block and the encoding method of the encoded groups are determined. The grouping encoding method includes a first group encoding method, a second group encoding method, and a third group encoding method. The first group encoding method includes encoding all coefficients in the group; the second group encoding method includes encoding the last non-zero coefficient and the coefficients before it in the group, and other coefficients are not encoded; the third group encoding method includes encoding a first identifier, which indicates that all coefficients in the group are zero. The step of calculating the encoding cost of the group using all coefficients includes: prequantizing each coefficient, calculating the encoding cost of each coefficient based on the prequantization value, and updating the coefficients based on the prequantization value; calculating the cost of encoding the group using the first encoding method based on the encoding cost of each coefficient; selecting a coefficient from the group based on the position of the non-zero coefficients in the group as the last non-zero coefficient when encoding the group using the second encoding method; and calculating the cost of encoding the group using the second encoding method based on the encoding cost of each coefficient and the position of the last non-zero coefficient. The prequantization of each coefficient includes: determining M quantization values for the current coefficient based on its amplitude, where M is an integer greater than 1; obtaining M queues corresponding to the group based on the M quantization values of each coefficient included in the group, where the i-th queue includes the i-th quantization value of each coefficient, 1≤i≤M, and i is an integer; calculating the cost of encoding the current coefficient using the i-th quantization value as the prequantization value based on the quantization values in the i-th queue, and obtaining the i-th first value; comparing the M first values and determining the quantization value corresponding to the smallest first value as the prequantization value of the current coefficient.
2. The method according to claim 1, characterized in that, The step of determining the group to be encoded in the transform block and the encoding method of the group to be encoded based on the calculated encoding costs of the multiple groups includes: When there are groups containing non-zero coefficients, based on the encoding cost of the multiple groups, one group is selected from all groups containing non-zero coefficients and encoded using the second encoding method. Groups before the selected group that contain non-zero coefficients are encoded using the first encoding method. Groups before the selected group that have all zero coefficients are encoded using the third encoding method. Groups after the selected group are not encoded.
3. The method according to claim 2, characterized in that, The method further includes: For any given block, if the block contains non-zero coefficients, determine whether to set the coefficients in the block to zero based on the encoding cost of the block. If the result of the judgment is to set the coefficients in the group to zero, then update the coefficients in the group.
4. The method according to claim 1, characterized in that, The method further includes: When there are groups containing non-zero coefficients, the encoding method of the transform block is determined based on the encoding cost of the multiple groups and the encoding method of the groups being encoded. The encoding method of the transform block is one of a first block encoding method and a second block encoding method. When there is no group containing non-zero coefficients, the transform block is encoded using the first block encoding method; The first block encoding method includes encoding a second identifier, the second identifier indicating that all coefficients in the transform block are zero; the second block encoding method includes encoding the encoded group according to a defined encoding method for each group.
5. The method according to claim 4, characterized in that, Determining the encoding method of the transform block based on the encoding costs of the multiple groups and the encoding method of the groups to be encoded includes: The cost of not encoding the multiple groups and the cost of encoding the second identifier are summed to obtain the cost of encoding the transform block using the first block encoding method. The cost of encoding the coded groups in a determined encoding method, the cost of not encoding the uncoded groups, and the cost of encoding the fourth identifier are summed to obtain the cost of encoding the transform block in the second block encoding method, wherein the fourth identifier indicates that the transform block includes non-zero coefficients; The cost of encoding the transform block using the first block encoding method and the cost of encoding the transform block using the second block encoding method are compared, and the corresponding encoding method with the smaller value is determined as the encoding method of the transform block.
6. The method according to claim 1, characterized in that, The step of selecting a coefficient from the group based on the position of the non-zero coefficients in the group, and using it as the last non-zero coefficient when encoding the group using the second group encoding method, includes: A candidate coefficient set is obtained based on the position of the non-zero coefficients in the group. The candidate coefficient set includes at least one coefficient with a pre-quantized non-zero value. The order of any two candidate coefficients in the candidate coefficient set is the same as the order of the two candidate coefficients in the group. In response to calculating the encoding cost of any two adjacent candidate coefficients and other coefficients between the two adjacent candidate coefficients, the two adjacent candidate coefficients are respectively designated as the first candidate coefficient and the second candidate coefficient. Based on the encoding costs of the first candidate coefficient, the second candidate coefficient, and the other coefficients, determine the relationship between the encoding costs of the group when the first candidate coefficient and the second candidate coefficient are selected as coefficients. Remove the candidate coefficient with the higher cost from the candidate coefficient set; If there is one remaining candidate coefficient in the set of candidate coefficients, that candidate coefficient is selected.
7. The method according to claim 3, characterized in that, For any given group, when the group contains non-zero coefficients, determining whether to set the coefficients in the group to zero based on the group's encoding cost includes: The cost of encoding the group using the first encoding method is summed with the cost of encoding the third identifier to obtain a second value, wherein the third identifier indicates that the group includes non-zero coefficients; When the cost of encoding the group using the third encoding method is less than the second value, it is determined that the coefficients included in the group are set to zero. If the second value is less than the cost of encoding the group using the third group encoding method, it is determined that the coefficients of the group should not be set to zero.
8. The method according to claim 2, characterized in that, The step of selecting one group from all groups including those with non-zero coefficients and encoding it using the second group encoding method based on the encoding cost of the plurality of groups includes: All groups including non-zero coefficients are taken as candidate groups to obtain a candidate group set, wherein the order of any two candidate groups in the candidate group set is the same as the order of the two candidate groups in the transform block; In response to the calculation of the encoding cost of any two adjacent candidate groups and other groups between the two adjacent candidate groups, the two adjacent candidate groups are respectively designated as the first candidate group and the second candidate group; Based on the encoding costs of the first candidate group, the second candidate group, and the other groups, determine the relationship between the encoding costs of the transform block when the first candidate group and the second candidate group are selected groups. Remove the candidate group with the higher cost from the candidate group set; If there is one remaining candidate group in the candidate group set, that candidate group shall be selected.
9. A device for determining an encoding method, characterized in that, The device includes: The first calculation module is configured to respond to obtaining the coefficients of the groups included in the transform block in the video frame, and to calculate the encoding cost of the group by means of all the coefficients of any group after obtaining all the coefficients of the group. The encoding cost calculation of multiple groups in the transform block is performed in parallel. The transform block includes multiple groups, each group includes multiple coefficients, and the encoding cost of the group includes the cost of not encoding the group and the cost of encoding the group in at least one encoding method. The first determining module is used to determine the group to be encoded in the transform block and the encoding method of the group to be encoded based on the calculated encoding cost of the multiple groups. The grouping encoding method includes a first group encoding method, a second group encoding method, and a third group encoding method. The first group encoding method includes encoding all coefficients in the group; the second group encoding method includes encoding the last non-zero coefficient and the coefficients before it in the group, and other coefficients are not encoded; the third group encoding method includes encoding a first identifier, which indicates that all coefficients in the group are zero. The step of calculating the encoding cost of the group using all coefficients includes: prequantizing each coefficient, calculating the encoding cost of each coefficient based on the prequantization value, and updating the coefficients based on the prequantization value; calculating the cost of encoding the group using the first encoding method based on the encoding cost of each coefficient; selecting a coefficient from the group based on the position of the non-zero coefficients in the group as the last non-zero coefficient when encoding the group using the second encoding method; and calculating the cost of encoding the group using the second encoding method based on the encoding cost of each coefficient and the position of the last non-zero coefficient. The prequantization of each coefficient includes: determining M quantization values for the current coefficient based on its amplitude, where M is an integer greater than 1; obtaining M queues corresponding to the group based on the M quantization values of each coefficient included in the group, where the i-th queue includes the i-th quantization value of each coefficient, 1≤i≤M, and i is an integer; calculating the cost of encoding the current coefficient using the i-th quantization value as the prequantization value based on the quantization values in the i-th queue, and obtaining the i-th first value; comparing the M first values and determining the quantization value corresponding to the smallest first value as the prequantization value of the current coefficient.
10. The apparatus according to claim 9, characterized in that, The first computing module includes a first computing unit, a second computing unit, a third computing unit, and a fourth computing unit. The first calculation unit is used to calculate the encoding cost of the coefficients; The second calculation unit is used to calculate the cost of not encoding the group and the cost of encoding the group using the third group encoding method based on the encoding cost of the coefficient; The third calculation unit is used to calculate the cost of encoding the group in the first group encoding method based on the encoding cost of the coefficients; The fourth calculation unit is used to calculate the cost of encoding the group in the second group encoding method based on the encoding cost of the coefficient; When the grouping includes non-zero coefficients, the first calculation unit inputs the encoding cost of the coefficients into the second calculation unit, the third calculation unit, and the fourth calculation unit; When all coefficients in the group are zero, the first calculation unit inputs the encoding cost of the coefficients into the second calculation unit.
11. An electronic device comprising a memory, a processor, and a computer program stored in the memory, characterized in that, The processor executes the computer program to implement the steps of the method according to any one of claims 1 to 8.
12. A non-volatile computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the steps of the method according to any one of claims 1 to 8.
13. A computer program product comprising a computer program, or a non-volatile computer-readable storage medium carrying a computer program, characterized in that, When the computer program is executed by a processor, it implements the steps of the method according to any one of claims 1 to 8.