Image encoding method, apparatus and device

By repeatedly encoding the image coding block and adjusting the QP offset value, the problem of uneven image quality after encoding is solved, achieving more efficient image quality optimization and bitrate allocation, and improving the overall quality and uniformity of the encoded image.

CN116800967BActive Publication Date: 2026-07-31HUAWEI TECH CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
HUAWEI TECH CO LTD
Filing Date
2022-03-15
Publication Date
2026-07-31

AI Technical Summary

Technical Problem

Existing image coding methods result in uneven image quality after encoding, with potential regional quality differences, and fail to effectively utilize the characteristics of the human visual system for bitrate allocation.

Method used

By encoding each coded block in the image at least twice, adjusting the quantization parameter QP based on the quality parameters of the previous encoding, optimizing the quality of the coded block using the QP offset value, and allocating the bit rate using the characteristics of the human visual system, the image quality is ensured to be balanced.

Benefits of technology

It improves the overall quality of the encoded image, achieves uniformity of image quality and higher coding efficiency, and adapts to the visual needs of different regions.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116800967B_ABST
    Figure CN116800967B_ABST
Patent Text Reader

Abstract

This application discloses an image encoding method, apparatus, and device for ensuring the quality of the encoded image. The method includes: after acquiring a first image, the encoding device acquires a first QP corresponding to each coded block in at least one coded block of the first image; then, based on the first QP corresponding to each coded block, it encodes each coded block in the at least one coded block to obtain first image data. The encoding device determines a second QP corresponding to each coded block based on the quality parameters of each coded block in the first image data; and based on the second QP corresponding to each coded block, it encodes each coded block in the at least one coded block to obtain second image data. Through this method, the encoding device can adjust the encoding parameters QP of the current encoding based on the quality of the previous actual encoding, thereby ensuring the quality of the encoded image.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of images, and more particularly to an image encoding method, apparatus, and device. Background Technology

[0002] With the development of information technology, images and videos have become major components of digital information content. To facilitate transmission, images and videos need better compression encoding to reduce their file size and improve their perceived quality. Currently, this goal can be achieved through the following two aspects:

[0003] On the one hand, improving prediction accuracy (e.g., enhancing more prediction patterns) and the energy concentration of transforms (e.g., more flexible transforms) through the research of more sophisticated coding tools can improve video compression rates. Major video coding standards organizations (e.g., Moving Picture Experts Group-Advanced Video Coding (MPEG-AVC), High Efficiency Video Coding (HEVC), Audio Video Coding Standard (AVS) 1 / 2 / 3, etc.) have been working in this area.

[0004] On the other hand, within the standard framework, during video compression, the subjective and objective effects of encoding are improved based on the characteristics of the human visual system (HVS). For example, adaptive quantization (AQ) technology allocates the bitrate based on texture intensity, edge intensity, brightness, or temporal features. This achieves better encoded image quality at a given bitrate.

[0005] In current encoding methods, the encoder predetermines the quantization parameter (QP) for encoding and allocates the bit rate based on the QP. However, the quality of the encoded image is related to many factors. Encoding with a predetermined QP may result in suboptimal image quality, with significant differences in quality between different regions of the encoded image.

[0006] Therefore, there is a need in this field for an image coding scheme that can guarantee the quality of the encoded image. Summary of the Invention

[0007] This application provides an image encoding method, apparatus, and device to ensure the quality of the encoded image.

[0008] In a first aspect, this application provides an image encoding method. The method includes: after acquiring a first image, an encoding device can acquire a first QP corresponding to each coded block in at least one coded block of the first image; then, based on the first QP corresponding to each coded block, encode each coded block in the at least one coded block to obtain first image data. The encoding device can determine a second QP corresponding to each coded block based on the quality parameters of each coded block in the first image data; and based on the second QP corresponding to each coded block, encode each coded block in the at least one coded block to obtain second image data.

[0009] Using this method, the encoding device can encode an image at least twice, adjusting the QP (Quality Points) of each encoding block based on the quality parameters obtained from the previous encoding, and then encoding the image again based on the adjusted QP. In this way, the encoding device can adjust the encoding parameters QP for the current encoding based on the quality of the previous encoding, thus ensuring the quality of the encoded image.

[0010] In one possible design, for any one of the at least one coding blocks (hereinafter referred to as the first coding block), the encoding device can determine a first QP offset value corresponding to the first coding block based on the target quality parameters of the first image and the quality parameters of the first coding block in the first image data; then, based on the first QP corresponding to the first coding block and the first QP offset value corresponding to the first coding block, a second QP corresponding to the first coding block is determined. With this design, the encoding device can first determine the first QP offset value corresponding to the first coding block, and then determine the second QP corresponding to the first coding block based on the first QP offset value. Generally, the first QP offset value is smaller than the second QP; thus, the computational load for determining the first QP offset value is smaller, and the resources required for transmitting or storing the first QP offset value are also less.

[0011] In one possible design, the encoding device can determine the first QP offset value corresponding to the first coded block in the following manner:

[0012] When the quality parameter of the first coding block is greater than the target quality parameter of the first image, and the difference between the quality parameter of the first coding block and the target quality parameter of the first image is within a first range, the encoding device can determine that the first QP offset value corresponding to the first coding block is equal to the QP offset value corresponding to the first range; wherein, the first QP offset value corresponding to the first coding block is a positive number; or

[0013] When the quality parameter of the first coding block is less than the target quality parameter of the first image, and the absolute value of the difference between the quality parameter of the first coding block and the target quality parameter of the first image is within a second range, the encoding device can determine that the absolute value of the first QP offset value corresponding to the first coding block is equal to the QP offset value corresponding to the second range; wherein, the first QP offset value corresponding to the first coding block is negative; or

[0014] When the quality parameter of the first coding block is equal to the target quality parameter of the first image, the encoding device can determine that the first QP offset value corresponding to the first coding block is 0.

[0015] This design allows for a negative QP offset when the coding quality of a block in the first image is lower than the target quality. This allows for adjusting the QP to improve the coding quality of the block, bringing it closer to the target quality. Conversely, a positive QP offset when the coding quality of a block in the first image is higher than the target quality. This allows for adjusting the QP to lower the coding quality of the block, bringing it closer to the target quality. Thus, when the target bitrate is fixed, the encoding device can allocate bitrates within the first image. Specifically, it can lower the bitrate of blocks with coding quality exceeding the target quality and allocate the saved codewords to blocks with coding quality below the target quality, thereby increasing the bitrate of those blocks and improving the overall coding quality of the first image, resulting in a more balanced coding quality. When the target bitrate is variable, this design can reduce the overall bitrate required for the image by lowering the quality of blocks with coding quality exceeding the target quality.

[0016] In one possible design, after encoding each of the at least one coding blocks according to a first QP corresponding to each coding block, the encoding device can compare the first image data and the first image to obtain the quality parameters of each coding block in the first image data. With this design, the encoding device can accurately determine the quality parameters of each coding block after encoding each of the at least one coding blocks according to the first QP corresponding to each coding block.

[0017] In one possible design, for any one of the at least one coding blocks (hereinafter referred to as the second coding block), the encoding device can encode the second coding block according to the first QP corresponding to the second coding block in the following manner:

[0018] The encoding device can quantize the second coding block according to the first QP corresponding to the second coding block to obtain quantized data; then, according to the first QP corresponding to the second coding block, the quantized data can be dequantized and detransformed to obtain detransformed residual data; then, the encoding device can obtain the reconstructed data of the second coding block according to the prediction data and residual data of the second coding block, and filter the reconstructed data to obtain the image data corresponding to the second coding block in the first image data.

[0019] With this design, when encoding each of the at least one coding blocks according to the first QP corresponding to each coding block, the first image data for the next encoding can be determined without outputting the bitstream, thereby improving the encoding efficiency.

[0020] In one possible design, for any one of the at least one coding blocks (hereinafter referred to as the third coding block), the encoding device can encode the third coding block according to first information and a second QP corresponding to the third coding block. The first information can be intermediate data obtained when encoding the third coding block according to the first QP corresponding to the third coding block. For example, the first information may include at least one of the following: a prediction mode of the third coding block determined when encoding the third coding block according to the first QP corresponding to the third coding block; and a motion vector of the third coding block determined when encoding the third coding block according to the first QP corresponding to the third coding block. With this design, when encoding each coding block in the at least one coding block according to the second QP corresponding to each coding block, the intermediate results obtained from encoding each coding block according to the first QP corresponding to each coding block can be reused. In other words, the intermediate results of the previous encoding can be reused in this encoding, thereby simplifying the encoding process and improving encoding efficiency.

[0021] In one possible design, after encoding each of the at least one coding block according to the second QP corresponding to each coding block, the encoding device may store second information. This second information can be used to represent the quality parameters of each coding block in the second image data.

[0022] Optionally, the second information may be a matrix containing quality parameters for each coded block in the second image data.

[0023] With this design, after encoding the first image, the encoding device can save second information to represent the quality parameters of each encoded block in the second image data; in this way, when encoding subsequent images in the video containing the first image, the encoding device can refer to the second information, thereby improving the encoding quality of the subsequent images.

[0024] In one possible design, the first image may be the nth frame of a video, where n is a positive integer. After saving the second information, the encoding device can encode subsequent images in the video based on the second information of the first image. Specifically, the encoding device can acquire the (n+1)th frame of the video (hereinafter referred to as the second image), which contains N coded blocks, where N is a positive integer. The encoding device can determine at least one target coded block associated with a fourth coded block in the second image from the at least one coded block in the first image; wherein the fourth coded block can be any one of the N coded blocks, and the content of the fourth coded block is included in the at least one target coded block. After determining the quality parameters of the at least one target coded block in the second image data based on the second information, the encoding device can predict the quality parameters of the encoded fourth coded block based on the quality parameters of the at least one target coded block, and determine the third QP corresponding to the fourth coded block accordingly. Then, the encoding device can encode the fourth coded block based on the third QP corresponding to the fourth coded block.

[0025] This design allows the encoding device to encode the first image in a video at least twice, thereby improving the encoding quality of the first image. Then, based on the improved encoding quality of the first image, the encoding device can encode the second image in the video once. Specifically, based on the encoding quality of the target coded block in the improved first image, the encoding device predicts the encoding quality of similar coded blocks in subsequent images of the video, and adjusts the QP (Quality Per Count) based on the predicted encoding quality, thereby improving the encoding quality of similar coded blocks in subsequent images of the video, and consequently improving the encoding quality of the second image.

[0026] In one possible design, the encoding device can determine a second QP offset value corresponding to the fourth coded block based on the target quality parameters of the second image and the predicted quality parameters of the encoded fourth coded block, and then determine a third QP corresponding to the fourth coded block based on the second QP offset value. With this design, the encoding device can first determine the second QP offset value corresponding to the fourth coded block, and then determine the third QP corresponding to the fourth coded block based on the second QP offset value. Generally, the second QP offset value is smaller than the third QP; thus, the computational workload for determining the second QP offset value is smaller, and the resources required for transmitting or storing the second QP offset value are also less.

[0027] In one possible design, the encoding device can determine the second QP offset value corresponding to the fourth coding block in the following manner:

[0028] When the quality parameter of the fourth coding block is greater than the target quality parameter of the second image, and the difference between the quality parameter of the fourth coding block and the target quality parameter of the second image is within a third range, the encoding device can determine that the second QP offset value corresponding to the fourth coding block is equal to the QP offset value corresponding to the third range; wherein, the second QP offset value corresponding to the fourth coding block is a positive number; or

[0029] When the quality parameter of the fourth coding block is less than the target quality parameter of the second image, and the absolute value of the difference between the quality parameter of the fourth coding block and the target quality parameter of the second image is within a fourth range, the encoding device can determine that the absolute value of the second QP offset value corresponding to the fourth coding block is equal to the QP offset value corresponding to the fourth range; wherein, the second QP offset value corresponding to the fourth coding block is negative; or

[0030] When the quality parameter of the fourth coding block after prediction is equal to the target quality parameter of the second image, the encoding device can determine that the second QP offset value corresponding to the fourth coding block is 0.

[0031] This design allows for a negative second QP offset when the quality of a coded block in the second image is lower than the target quality of the second image; thus, the coding quality of that block can be improved by reducing the QP. Conversely, a positive second QP offset occurs when the quality of a coded block in the second image is higher than the target quality of the first image; thus, the required bitrate for that block can be reduced by increasing the QP, and the saved bitrate can be used to improve the coding quality of coded blocks in the second image whose quality is lower than the target quality of the second image. In this way, the overall coding quality of the second image can be improved without increasing the overall bitrate.

[0032] In one possible design, the quality parameters of any coding block may include at least one of the following: peak signal-to-noise ratio, structural similarity, and multi-scale structural similarity.

[0033] In a second aspect, an image encoding apparatus is provided, including units for performing the steps of the first aspect and any possible design of the first aspect.

[0034] Thirdly, an image encoding device is provided, including a processor and a memory coupled to the processor. The memory can be used to store program code; the processor can invoke the program code stored in the memory to execute the methods described in the first aspect and any possible design of the first aspect.

[0035] Fourthly, embodiments of this application also provide a computer program that, when run on a computer, causes the computer to perform the methods described in the first aspect and any possible design of the first aspect.

[0036] Fifthly, embodiments of this application also provide a computer-readable storage medium storing a computer program that, when executed by a computer, causes the computer to perform the methods described in the first aspect and any possible design of the first aspect.

[0037] In a sixth aspect, embodiments of this application also provide a chip for reading a computer program stored in a memory and executing the methods described in the first aspect and any possible design of the first aspect.

[0038] In a seventh aspect, embodiments of this application also provide a chip system including a processor for supporting a computer device in implementing the methods described in the first aspect and any possible design of the first aspect. In one possible design, the chip system further includes a memory for storing programs and data necessary for the computer device. The chip system may be composed of chips or may include chips and other discrete devices.

[0039] The technical effects that can be achieved by any of the second to seventh aspects mentioned above can be referred to the description of the technical effects that can be achieved by the first aspect and any possible design in the first aspect. Where there is repetition, no further discussion will be given. Attached Figure Description

[0040] Figure 1 This is a structural diagram of an encoding device;

[0041] Figure 2 This is a schematic diagram of an AQ scheme;

[0042] Figure 3A flowchart illustrating an image encoding method provided in this application embodiment;

[0043] Figure 4 A structural diagram of an encoding device provided in an embodiment of this application;

[0044] Figure 5 A schematic diagram of a processing flow of the QP adjustment module 33 provided in an embodiment of this application;

[0045] Figure 6 A schematic diagram of another processing flow of the QP adjustment module 33 provided in an embodiment of this application;

[0046] Figure 7 A structural diagram of another encoding device provided in an embodiment of this application;

[0047] Figure 8 This is a structural diagram of the predictive coding module 41 provided in an embodiment of this application;

[0048] Figure 9 A schematic diagram illustrating an encoding method provided in an embodiment of this application;

[0049] Figure 10 A structural diagram of another encoding device provided in the embodiments of this application;

[0050] Figure 11 A schematic diagram of the processing flow of the QP calculation module 116 provided in the embodiments of this application;

[0051] Figure 12 A schematic diagram illustrating the association relationship of coded blocks provided in an embodiment of this application;

[0052] Figure 13 A structural diagram of an image encoding device provided in an embodiment of this application;

[0053] Figure 14 This is a structural diagram of an image encoding device provided in an embodiment of this application. Detailed Implementation

[0054] This application provides an image encoding method, apparatus, and device to ensure the quality of the encoded image. The method, apparatus, and device are based on the same technical concept. Since the principles for solving the problem are similar, the implementations of the apparatus, apparatus, and method can be mutually referenced, and repeated details will not be elaborated further.

[0055] According to the scheme provided in this application, after acquiring a first image, the encoding device can acquire a first QP corresponding to each coding block in at least one coding block of the first image; then, based on the first QP corresponding to each coding block, it encodes each coding block in the at least one coding block (hereinafter referred to as first encoding) to obtain first image data. The encoding device determines a second QP corresponding to each coding block based on the quality parameters of each coding block in the first image data; and encodes each coding block in the at least one coding block based on the second QP corresponding to each coding block to obtain second image data. Through this scheme, the encoding device can encode the image at least twice, adjusting the QP of the corresponding coding block based on the quality parameters of each coding block obtained in the previous encoding, and then encoding the image based on the adjusted QP. In this way, the encoding device can adjust the QP of the current encoding based on the quality of the previous encoding, thereby ensuring the image quality after the current encoding.

[0056] The following explanations of some terms used in the embodiments of this application are provided to facilitate understanding by those skilled in the art.

[0057] 1) Image encoding typically involves processing (e.g., by compression) the original image to reduce the amount of data required to represent the image, representing the image or the information contained in the image with fewer bits, thereby enabling more efficient storage and / or transmission.

[0058] 2) Video coding generally refers to the processing of image sequences that form a video or video sequence. Video coding typically involves processing (e.g., by compression) the raw video images to reduce the amount of data required to represent those images, thereby enabling more efficient storage and / or transmission. In the field of video coding, the terms "picture," "frame," or "image" can be used synonymously.

[0059] 3) A block is a processing unit for image or video encoding, also known as an image block.

[0060] Each image may include at least one block. Some video coding standards further extend the concept of a block. For example, the H.264 standard includes macroblocks (MBs), which can be further divided into multiple prediction blocks (partitions) that can be used for predictive coding. Another example is the HEVC standard, which employs basic concepts such as coding units (CUs), prediction units (PUs), and transform units (TUs). A CU is the basic unit for partitioning and coding an image. A PU corresponds to a prediction block and is the basic unit for predictive coding. A TU corresponds to a transform block and is the basic unit for transforming the prediction residual. CUs, PUs, and TUs are all essentially blocks.

[0061] In this paper, for ease of description and understanding, the image block to be encoded in the current encoded image is referred to as the encoding block; the block in the reference image that provides prediction information for the encoding block is referred to as the prediction block, where the prediction information can represent the pixel value, sample value or sample signal in the prediction block.

[0062] 4) Encoding devices are a general term for devices capable of encoding images or videos. Examples of encoding devices include desktop computers, laptops, tablets, set-top boxes, mobile phones, televisions, cameras, camcorders, display devices, digital media players, video game consoles, and video streaming devices.

[0063] In this application embodiment, the number of nouns, unless otherwise specified, refers to "singular nouns or plural nouns," that is, "one or more." "At least one" means one or more, and "more than one" means two or more. "And / or" describes the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent: A alone, A and B simultaneously, and B alone. "At least one of the following" or similar expressions refer to any combination of these items, including any combination of single or plural items.

[0064] In addition, it should be understood that in the description of this application, the words "first" and "second" are used only for the purpose of distinguishing descriptions and should not be construed as indicating or implying relative importance, nor should they be construed as indicating or implying order.

[0065] For ease of understanding this application, please refer to the following references. Figure 1 This section describes the encoding process performed by the encoding device.

[0066] like Figure 1As shown, according to the functional logic division in the encoding process, the encoding device may include an encoder 10 and a code control module 20. The encoder 10 includes: an intra-frame prediction module 102, an inter-frame prediction module 104, a mode decision and residual calculation module 106, a transform and quantization module 108, an inverse quantization and inverse transform module 110, a filtering module 112, and an entropy coding module 114.

[0067] The following explanation uses the encoding device to encode the current coded block in the input image Fn (i.e., the nth frame of the video, where n is a positive integer) as an example. The current coded block can be any coded block in the input image Fn.

[0068] The code control module 20 can provide the encoder 10 with the frame-level QP (i.e., QP_frame) of the input image Fn and the block-level ΔQP of the current coding block. The block-level ΔQP of the current coding block is the offset value between the QP of the current coding block and the frame-level QP of the image in which the current coding block is located.

[0069] The code control module 20 determines the frame-level QP of Fn through frame-level code control. Specifically, the code control module 20 calculates the frame-level QP of the input image Fn based on at least one of the following: the size of the output bitstream corresponding to the video containing the input image Fn, the target bitrate, and other control parameters (such as scene switching information between the preceding and following two frames, and the allowed bitrate fluctuation range). For example, when the ratio of the size of the output bitstream corresponding to the video containing the input image Fn to the time is greater than the target bitrate, the code control module 20 can increase the frame-level QP of the input image Fn to reduce the bitrate corresponding to the input image Fn, thereby reducing the overall bitrate of the video containing the input image Fn and bringing it closer to the target bitrate. Conversely, when the ratio of the size of the output bitstream corresponding to the video containing the input image Fn to the time is less than the target bitrate, the code control module 20 can decrease the frame-level QP of the input image Fn to increase the bitrate corresponding to the input image Fn, thereby increasing the overall bitrate of the video containing the input image Fn and bringing it closer to the target bitrate.

[0070] The method by which the code control module 20 determines the block-level ΔQP of the current coding block can refer to the following... Figure 2 The explanation will not be elaborated here.

[0071] The intra-prediction module 102 can acquire reference data (e.g., reconstructed data already encoded at adjacent positions) of the current coded block in the input image Fn. Then, the intra-prediction module 102 can select an intra-prediction mode based on one or more predetermined prediction modes, and output the cost (e.g., cost = distortion + lambda * bits, where cost is the cost; distortion is the distortion, which can be measured using the sum square of difference (SSD); bits is the number of bits used to encode the variable quantization coefficients; and lambda is the weight) and prediction data corresponding to the selected optimal mode. The prediction data may include information such as the prediction angle identifier of the prediction block, and the optimal mode is the mode with the lowest cost. The mode used for prediction by the intra-prediction module 102 can be referred to as the intra-prediction mode.

[0072] The inter-frame prediction module 104 may include a motion estimation unit and a motion compensation unit. The motion estimation unit can find the most similar prediction block to be encoded in the reference image Fn-1 (i.e., the (n-1)th frame image in the video). The similarity can be measured according to a user-specified metric, such as the sum of absolutes of prediction residuals (SAD) or SSD. In mainstream video encoders, the motion estimation process also includes fractional pixel interpolation and search operations. The motion estimation result yields the optimal motion vector (MV); the optimal MV is the MV corresponding to the prediction block most similar to the current encoded block. The motion compensation unit can extract or generate prediction blocks based on the motion vector determined by the motion estimation unit and obtain prediction data; the prediction data may include the prediction block identifier, MV, and other information. When n is an integer greater than 1, the inter-frame prediction module 104 can be used for prediction. The mode of using the inter-frame prediction module 104 for prediction can be called the inter-frame prediction mode.

[0073] The mode decision and residual calculation module 106 may include a mode decision unit and a residual calculation unit. The mode decision unit selects whether to use intra-frame prediction mode or inter-frame prediction mode for prediction. For example, when the cost of encoding using intra-frame prediction mode is less than or equal to the cost of encoding using inter-frame prediction mode, the mode decision unit can choose to use intra-frame prediction mode; when the cost of encoding using intra-frame prediction mode is greater than the cost of encoding using inter-frame prediction mode, the mode decision unit can choose to use inter-frame prediction mode. The residual calculation unit calculates the pixel value difference between the pixels of the current coded block and the pixels of the predicted block obtained by the prediction mode (intra-frame prediction mode or inter-frame prediction mode) selected by the mode decision unit, i.e., the residual.

[0074] The transform and quantization module 108 may include a transform unit and a quantization unit. The transform unit transforms the residuals, converting them into transform coefficients. Commonly used transforms may include one of the following: discrete cosine transform (DCT), discrete sine transform (DST), wavelet transform, etc. The quantization unit quantizes the transform coefficients. Quantization refers to reducing the amount of data used to represent the quantized coefficients, thereby achieving further compression. Specifically, the quantization unit determines the QP (i.e., QP_frame + ΔQP) of the current coding block based on the block-level ΔQP from the code control module and the frame-level QP (QP_frame) of the input image Fn; and uses the quantization step size defined by the QP of the current coding block to quantize the transform coefficients, obtaining quantized data (also called quantized transform coefficients or quantized transformed coefficients).

[0075] The inverse quantization and inverse transform module 110 may include an inverse quantization unit and an inverse transform unit. The inverse quantization unit can be used to inverse quantize the quantized data to obtain inverse quantized transform coefficients. The inverse transform unit is used to perform inverse transform processing on the inverse quantized transform coefficients (e.g., inverse DCT, inverse integer transform, or a conceptually similar inverse transform process) to obtain the inverse transform residual (also known as the reconstructed residual).

[0076] The filtering module 112 can filter the reconstructed data to obtain the image data of the current coded block (also called reconstructed data, reconstructed image, or reconstructed block), thereby reducing distortion and improving image quality. The reconstructed data is determined based on the residual after the inverse transform; for example, it can be the result of adding the predicted data and the residual after the inverse transform. Since the image data output by the filtering module 112 has undergone quantization processing and may contain distortion, this image data can also be called quantized-distorted reconstructed data. After filtering all coded blocks of the input image, the filtering module 112 can output the reconstructed image of the input image (i.e.,...). Figure 1 The reconstructed image Fn is shown in the image. Additionally, the filtering module 112 can output filtering information (e.g., sample-adaptive offset (SAO) mode information and compensation information) to the entropy coding module 114. The filtering module 112 may include at least one of the following: a deblocking filter, a SAO filter, a bilateral filter, an adaptive loop filter (ALF), a sharpening or smoothing filter, or a cooperative filter.

[0077] The entropy coding module 114 applies an entropy coding scheme to one or more of the quantized data, prediction data, SAO mode information, and compensation information to obtain an encoded bitstream and outputs the bitstream. The entropy coding scheme can be one of the following: variable length coding (VLC), context adaptive VLC (CAVLC), arithmetic coding, context adaptive binary arithmetic coding (CABAC), syntax-based context-adaptive binary arithmetic coding (SBAC), probability interval partitioning entropy (PIPE), etc. Additionally, the entropy coding module 114 can also report the number of bits in the bitstream to the code control module 20.

[0078] It should be understood that, although Figure 1 This explanation uses encoder 10 as an example of a video encoder; however, this application can also be used in the field of image coding. In this case, Figure 1 The encoder 10 in the image can be an image encoder, and the encoder 10 may not include the inter-frame prediction module 104 and the mode decision unit.

[0079] Encoding devices can improve the subjective and objective quality of the encoded result through the AQ scheme during encoding. The following section combines... Figure 2 Explain the AQ scheme. For example... Figure 2 As shown, in the AQ scheme, the encoding device (e.g., the code control module 20 in the encoding device) can analyze the original image and determine the QP offset value of the current coding block based on spatial, temporal, and luminance features, thereby adjusting the QP of the current coding block. These will be explained in detail below.

[0080] QP adjustment based on spatial characteristics: The encoding device performs texture analysis on the input image Fn (also known as the original image) and determines the first QP offset value (i.e., ΔQP1) for the current coding block based on the texture analysis results. Optionally, the encoding device calculates the variance of the luminance and chrominance of the current coding block in the input image Fn, and calculates ΔQP1 for the current coding block based on this variance. The larger the variance of the current coding block, the larger ΔQP1. For example, the AQ algorithm used in the open-source encoders of x264 and x265 calculates ΔQP1 using this method. This method mainly utilizes HVS characteristics, using a larger quantization step size for coding blocks containing complex frequency components, thereby reducing the impact on vision.

[0081] QP Adjustment Based on Temporal Characteristics: The encoding device can perform temporal analysis, that is, determine a second QP offset value (i.e., ΔQP2) for the current coding block based on the temporal correlation of the video sequence. Optionally, the encoding device determines ΔQP2 based on the contribution of the current coding block to other coding blocks (e.g., uncoded coding blocks), thereby adjusting the encoded image quality of the current coding block. Generally, the more information of a coding block is referenced by other coding blocks, the smaller the ΔQP2 of that coding block, and the higher the encoded image quality. Conversely, the larger the ΔQP2 of that coding block, the worse the encoded image quality. For example, the macroblock tree (Mbtree) and coding unit tree (Cutree) techniques in x264 and x265 use this method to calculate ΔQP2.

[0082] QP adjustment based on luminance characteristics: The encoding device can perform luminance analysis, that is, determine the third QP offset value (ΔQP3) for the current coding block based on the luminance. Utilizing the different sensitivity of the human eye to distortion in different luminance ranges, the encoding device can set a ΔQP3 corresponding to the luminance of the current coding block. Through this method, different bitrates can be allocated for different luminance blocks based on the characteristics of human vision, thereby achieving reasonable bitrate allocation and improving subjective image quality.

[0083] Using the AQ scheme described above, the QP of the current coding block is calculated as follows: QP = ΔQP1 + ΔQP2 + ΔQP3 + QP_frame = ΔQP + QP_frame. Here, QP_frame is the frame-level QP of the image containing the current coding block; ΔQP is the QP offset of the current coding block (also known as block-level ΔQP).

[0084] It should be understood that in practical applications, one or more of the above methods for adjusting QP can be selected. For example, the encoding device can adjust the QP of the current coding block based on spatial and luma characteristics; in this case, the QP of the current coding block = ΔQP1 + ΔQP3 + QP_frame = ΔQP + QP_frame. As another example, the encoding device can adjust the QP of the current coding block based on luma characteristics; in this case, the QP of the current coding block = ΔQP3 + QP_frame = ΔQP + QP_frame.

[0085] Using the AQ scheme described above to determine ΔQP may present the following problems.

[0086] In the aforementioned AQ scheme, the encoding device determines the ΔQP of the current coding block before encoding it, and then adjusts the QP accordingly; that is, the encoding device determines the QP of the current coding block based on a "pre-analysis / prediction" method. However, the actual encoding effect is also affected by factors such as the prediction mode, transformation size, target bit rate, and the complexity of the scene's temporal and spatial domains. When encoding with a pre-determined QP, the quality of different regions within the encoded image may vary significantly; for example, some regions may be clear and contain many details, while others may be blurry.

[0087] Furthermore, in the aforementioned AQ scheme, the encoding device determines the QP offset value based on the original image, without considering the encoding pressure in the actual scenario (e.g., target bitrate, current QP). When the target bitrate is low, due to bitrate limitations, if the QP of an image block cannot be too low, it may lead to lower encoding quality in some coded blocks within the image, resulting in potentially uneven image encoding quality. In addition, in current mainstream video coding standards, the relationship between quantization step size and QP is a non-linear exponential relationship. For example, as QP increases, a change of 1 in QP corresponds to a significant increase in the quantization step size, which in turn significantly increases the impact on image encoding quality, potentially leading to uneven image encoding quality.

[0088] To ensure the quality of the encoded image, this application provides an image encoding method. See below for details. Figure 3 The flowchart shown below provides a detailed explanation of the method's process.

[0089] S301: The encoding device acquires a first image. The first image contains at least one encoded block.

[0090] The first image is the image to be encoded. The first image can be a single image or a frame from a video (e.g., the nth frame, where n is a positive integer).

[0091] In addition, the encoding device can acquire the first image from locally stored images or videos, from images or videos from other devices, or from images previewed by a camera device.

[0092] S302: The encoding device acquires a first QP corresponding to each coding block in at least one coding block in the first image.

[0093] The encoding device may include Figure 1 The code control module 20 is shown. The encoding device can determine the first QP corresponding to each coding block based on the frame-level QP of the first image and the block-level ΔQP corresponding to each coding block obtained from the code control module 20.

[0094] For example, the first coding block is any coding block in the first image; after the encoding device obtains the frame-level QP (QP_frame1a) of the first image and the block-level ΔQP (i.e. ΔQPa) corresponding to the first coding block from the code control module 20, it can determine that the first QP corresponding to the first coding block is QP_frame1a+ΔQPa.

[0095] S303: The encoding device encodes each of the at least one encoding blocks according to the first QP corresponding to each encoding block to obtain the first image data.

[0096] The first image data can be reconstructed data or reconstruction data.

[0097] Optionally, S303 can be implemented in one of the following ways:

[0098] Method 1: Encoding device adopts Figure 1 The entire encoding process shown encodes each of the at least one of the above-mentioned coding blocks, outputs a bitstream, and obtains the first image data. For details, please refer to [the documentation / reference needed]. Figure 1 The explanation will not be repeated here.

[0099] Method 2: Encoding device adopts Figure 1 The partial encoding process shown encodes each of the at least one encoding block mentioned above to obtain the first image data.

[0100] The implementation process of Method 2 will be explained below using the second coding block as an example. The second coding block can be any of the above-mentioned coding blocks.

[0101] For the second coding block, S303 may include A1-A4.

[0102] A1: The encoding device performs quantization processing on the second coding block according to the first QP corresponding to the second coding block to obtain quantized data.

[0103] A2: The encoding device performs inverse quantization and inverse transformation on the quantized data according to the first QP corresponding to the second encoding block, and obtains the residual data after inverse transformation.

[0104] A3: The encoding device obtains the reconstructed data of the second coding block based on the prediction data and residual data of the second coding block.

[0105] A4: The encoding device filters the reconstructed data to obtain the image data corresponding to the second encoding block in the first image data.

[0106] For details, please refer to A1-A4. Figure 1 The explanation will not be repeated here.

[0107] In this second method, the first image data to be used for the next encoding can be determined in this encoding, without the need to output the bitstream, thereby improving encoding efficiency.

[0108] S304: The encoding device determines the second QP corresponding to each encoding block based on the quality parameters of each encoding block in the first image data.

[0109] The encoding device can obtain the quality parameters of each coded block in the first image data by comparing the first image data and the first image; then, the encoding device can determine the second QP corresponding to each coded block based on the quality parameters of each coded block in the first image data. The quality parameters of any coded block may include at least one of the following: peak signal-to-noise ratio (PSNR), structure similarity indexmetric (SSIM), and multiple scalar structure similarity indexmetric (MS-SSIM).

[0110] The implementation process of S304 will be explained below using the first coding block as an example. The first coding block can be any coding block from at least one coding block in the first image.

[0111] For the first coded block, S304 may include B1-B2.

[0112] B1: The encoding device can determine the first QP offset value (hereinafter referred to as ΔQP4a) corresponding to the first coding block based on the target quality parameters of the first image and the quality parameters of the first coding block in the first image data.

[0113] The target quality parameters of the first image can be fixed or variable.

[0114] In some possible implementations, the target quality parameters of the first image may be fixed target quality parameters input by the user.

[0115] In other possible implementations, the encoding device can adjust the target quality parameter based on the image content and encoding pressure. For example, with a fixed target bitrate, the encoding device can determine the average quality parameter of the encoded image as the target quality parameter of the first image; alternatively, it can determine the target quality parameter of the first image as the sum of the average quality parameter of the encoded image and a first offset value, where the first offset value can be positive, negative, or 0. Thus, when the scene displayed in the image is relatively simple, fewer codewords are required for encoding (i.e., lower encoding pressure), the image encoding quality is better, and the average quality parameter of the encoded image will also be higher (assuming a higher quality parameter equates to higher quality), resulting in a larger target quality parameter for the first image. Conversely, when the scene displayed in the image is more complex, more codewords are required for encoding (i.e., higher encoding pressure), the image encoding quality is lower, and the average quality parameter of the encoded image will also be lower, resulting in a smaller target quality parameter for the first image.

[0116] Optionally, the encoding device may perform B1 by the following steps:

[0117] When the quality parameter of the first coding block is greater than the target quality parameter of the first image (that is, the coding quality of the first coding block is higher than the target quality of the first image), and the difference between the quality parameter of the first coding block and the target quality parameter of the first image is within a first range, the encoding device can determine that ΔQP4a corresponding to the first coding block is equal to the QP offset value corresponding to the first range; wherein, ΔQP4a corresponding to the first coding block is a positive number. Thus, when the coding quality of the first coding block is higher than the target quality of the first image, the encoding device can increase the QP of the first coding block, thereby reducing the bitrate of the first coding block while meeting the quality requirements.

[0118] When the quality parameter of the first coding block is less than the target quality parameter of the first image (that is, the coding quality of the first coding block is lower than the target quality of the first image), and the absolute value of the difference between the quality parameter of the first coding block and the target quality parameter of the first image is within a second range, the encoding device can determine that the absolute value of ΔQP4a corresponding to the first coding block is equal to the QP offset value corresponding to the second range; wherein, ΔQP4a corresponding to the first coding block is a negative number. Thus, when the coding quality of the first coding block is lower than the target quality of the first image, the encoding device can reduce the QP of the first coding block, thereby improving the coding quality of the first coding block.

[0119] When the quality parameter of the first coding block is equal to the target quality parameter of the first image, the encoding device can determine that ΔQP4a corresponding to the first coding block is 0.

[0120] Using this method, when the coding quality of a coded block in the first image is lower than the target quality of the first image, ΔQP4a is a negative value; therefore, the coding quality of the coded block can be improved by decreasing QP, bringing it closer to the target quality. When the coding quality of a coded block in the first image is higher than the target quality of the first image, ΔQP4a is a positive value; therefore, the coding quality of the coded block can be reduced by increasing QP, bringing it closer to the target quality.

[0121] In this way, when the target bit rate is fixed (i.e., constant bit rate (CBR)), the encoding device can allocate bit rates within the first image. That is, it can reduce the bit rate of the encoding blocks whose encoding quality exceeds the target quality and allocate the saved codewords to the encoding blocks whose encoding quality is lower than the target quality, so as to increase the bit rate of the encoding blocks whose encoding quality is lower than the target quality. This can improve the overall encoding quality of the first image and make the encoding quality of the first image more balanced.

[0122] When the target bitrate is variable, this method can reduce the overall bitrate required for the image by reducing the quality of coding blocks whose coding quality exceeds the target quality.

[0123] Furthermore, this method can also be used in layered coding of SHVC and SVC (e.g., quality-layered coding). Generally, for layered coding, the higher the number of layers, the smaller the QP used, and the better the coding quality. The encoding device can dynamically adjust the QP of higher layers based on whether the coding quality of each layer in the coding block reaches the target quality. For example, when the coding quality of a certain layer in the coding block is greater than or equal to the target quality, it is not necessary to further increase the target quality of higher layers in that coding block; specifically, when encoding coding blocks at the same position in higher layers, it is not necessary to further reduce the QP, and the same QP or a larger QP can be used, thereby reducing the code rate of higher layers while ensuring that the target quality is achieved, and thus reducing the overall code rate.

[0124] B2: The encoding device determines the second QP corresponding to the first coding block based on the first QP corresponding to the first coding block and ΔQP4a corresponding to the first coding block.

[0125] The encoding device may include Figure 1 The code control module 20 is shown. The encoding device can re-obtain the frame-level QP (QP_frame1a) of the first image and the block-level ΔQP (i.e., ΔQPa) of the first coding block from the code control module 20, and determine the first QP corresponding to the first coding block accordingly; alternatively, it can directly obtain the first QP determined in S302. Then, the encoding device can determine the second QP corresponding to the first coding block as QP_frame1a + ΔQPa + ΔQP4a.

[0126] S305: The encoding device encodes each coding block in at least one coding block in the first image according to the second QP corresponding to each coding block, to obtain the second image data.

[0127] The second image data can be reconstructed data or reconstruction data.

[0128] Optionally, S305 can be implemented in one of the following ways:

[0129] Method 1: Encoding device adopts Figure 1 The entire encoding process shown encodes each of the at least one of the above-mentioned coding blocks, outputs a bitstream, and obtains the second image data. For details, please refer to [the documentation / reference needed]. Figure 1 The explanation is simply that the QP of the current coding block is replaced with the second QP, which will not be elaborated here.

[0130] Method 2: The encoding device uses the intermediate results in S303 to encode each of the above-mentioned at least one encoding block, outputs a bitstream, and obtains the second image data.

[0131] The implementation process of Method 2 will be explained below using the third coding block as an example. The third coding block can be any of the above-mentioned coding blocks.

[0132] In mode 2, the encoding device can encode the third coding block based on the first information (i.e., intermediate results) and the second QP corresponding to the third coding block.

[0133] The first information may include at least one of the following: the prediction mode of the third coding block determined in step S303, that is, the prediction mode of the third coding block determined when encoding the third coding block according to the first QP corresponding to the third coding block; and the MV of the third coding block determined in step S303, that is, the MV of the third coding block determined when encoding the third coding block according to the first QP corresponding to the third coding block.

[0134] For example, when the encoding device determines in S303 that the prediction mode of the third coding block is intra-frame prediction mode, in S305, the encoding device no longer needs to determine whether to use intra-frame prediction mode or inter-frame prediction mode, but can directly use intra-frame prediction mode to determine the prediction data, perform residual calculation, and use the second QP corresponding to the third coding block for subsequent coding operations.

[0135] For example, when the encoding device determines that the prediction mode of the third coding block is inter-frame prediction mode in S303 and determines the MV corresponding to the third coding block, in S305, the encoding device no longer needs to determine whether to use intra-frame prediction mode or inter-frame prediction mode. It can directly use the inter-frame prediction mode and the MV corresponding to the third coding block to determine the prediction data, perform residual calculation, and use the second QP corresponding to the third coding block for subsequent encoding operations.

[0136] Using this method 2, the intermediate results of the previous encoding can be reused, thereby simplifying the encoding process and improving encoding efficiency.

[0137] It should be understood that this application is not limited to encoding an image twice, but may also encode an image more than twice (e.g., three, four, or even more times). When an image is encoded more than twice, the encoding device may adjust the QP corresponding to each of the at least one encoding block in the current encoding based on the quality parameters of each encoding block obtained in the previous encoding.

[0138] It should be understood that the above method can also be applied to video encoding. For example, the encoding device may encode each frame of a video using the above method, or it may encode keyframes in a video (e.g., images of moving objects in the video) using the above method.

[0139] Through the steps S301-S305 described above, the encoding device can encode the image at least twice. Based on the quality parameters of each encoding block obtained from the previous encoding, the QP of each encoding block is adjusted, and then the image is encoded again based on the adjusted QP. In this way, the encoding device can adjust the encoding parameters QP of the current encoding based on the quality of the previous actual encoding, thereby ensuring the quality of the encoded image.

[0140] Optionally, in one implementation of the above method, after S305, the method further includes:

[0141] S306: The encoding device stores the second information. This second information can be used to represent the quality parameters of each coded block in the second image data.

[0142] Optionally, the second information is a matrix (also called a quality matrix) containing the quality parameters of each coded block in the second image data. Alternatively, the second information can take other forms, such as a table showing the correspondence between each coded block and its quality parameters in the second image data.

[0143] Using this method, after encoding the first image, the encoding device can save second information that represents the quality parameters of each encoded block in the second image data; thus, when encoding subsequent images in the video containing the first image, the encoding device can refer to the second information, thereby improving the encoding quality of the subsequent images.

[0144] Optionally, in one implementation of the above method, when the first image is the nth frame image in the video, after S306, the method may further include:

[0145] S307: The encoding device acquires the second image.

[0146] The second image can be the image to be encoded. The second image can be the (n+1)th frame of the video and contains N coded blocks, where N is a positive integer.

[0147] The method by which the encoding device acquires the second image can be referenced from the method by which the encoding device acquires the first image in S301, and will not be repeated here.

[0148] S308: The encoding device determines, among the at least one encoding block in the first image, at least one target encoding block associated with the fourth encoding block in the second image. The fourth encoding block may be any one of the N encoding blocks.

[0149] In a video, a scene may correspond to multiple frames, and these frames may contain similar blocks. Thus, the content of the fourth coded block in the second image may be contained within at least one target coded block in the first image. By performing motion estimation on the first and second images, the encoding device can determine at least one target coded block in the first image that is associated with the fourth coded block.

[0150] S309: The encoding device determines the quality parameters of at least one target coding block in the second image data based on the second information.

[0151] For example, when the second information is a matrix containing the quality parameters of each coded block in the second image data, the encoding device can determine the quality parameters of the encoded at least one target coded block in the first image by looking up the quality matrix.

[0152] For example, when the second information is a table showing the correspondence between each coded block and quality parameters in the second image data, the encoding device can determine the quality parameters of at least one target coded block encoded in the first image by looking up the table.

[0153] S310: The encoding device predicts the quality parameters of the fourth encoding block after encoding based on the quality parameters of at least one target encoding block.

[0154] In some possible ways, when the fourth coding block is associated with at least one target coding block, the coding device can predict that the quality parameters of the fourth coding block are the quality parameters of that target coding block.

[0155] In other possible approaches, when the fourth coding block is associated with at least one target coding block and there are multiple target coding blocks, the encoding device can predict the quality parameter of the fourth coding block as a weighted average of the quality parameters of the multiple target coding blocks. The weight of the quality parameter for each target coding block can be the same, or it can be proportional to the pixel value corresponding to the content of the fourth coding block contained in each target coding block.

[0156] S311: The encoding device determines the third QP corresponding to the fourth coding block based on the predicted quality parameters of the fourth coding block.

[0157] The quality parameters of the fourth coding block may include at least one of the following: PSNR, SSIM, MS-SSIM.

[0158] Optionally, S311 includes C1-C2.

[0159] C1: The encoding device determines the second QP offset value (hereinafter referred to as ΔQP4b) corresponding to the fourth coding block based on the target quality parameters of the second image and the predicted quality parameters of the fourth coding block.

[0160] The method for obtaining the target quality parameters of the second image can refer to the method for obtaining the target quality parameters of the first image, and will not be repeated here.

[0161] Optionally, the encoding device may perform C1 by the following steps:

[0162] When the quality parameter of the fourth coding block is greater than the target quality parameter of the second image (that is, the coding quality of the fourth coding block is higher than the target quality of the second image), and the difference between the quality parameter of the fourth coding block and the target quality parameter of the second image is within the third range, the ΔQP4b corresponding to the fourth coding block is determined to be equal to the QP offset value corresponding to the third range; where ΔQP4b corresponding to the fourth coding block is a positive number. Thus, when the coding quality of the fourth coding block is higher than the target quality of the second image, the encoding device can increase the QP of the fourth coding block, thereby reducing the bitrate of the fourth coding block while meeting the quality requirements.

[0163] When the quality parameter of the fourth coding block is less than the target quality parameter of the second image (that is, the coding quality of the fourth coding block is lower than the target quality of the second image), and the absolute value of the difference between the quality parameter of the fourth coding block and the target quality parameter of the second image is within the fourth range, the absolute value of ΔQP4b corresponding to the fourth coding block is determined to be equal to the QP offset value corresponding to the fourth range; where ΔQP4b corresponding to the fourth coding block is a negative number. Thus, when the coding quality of the fourth coding block is lower than the target quality of the second image, the encoding device can reduce the QP of the fourth coding block, thereby improving the coding quality of the fourth coding block.

[0164] When the predicted quality parameter of the fourth coding block is equal to the target quality parameter of the second image, the encoding device can determine that ΔQP4b corresponding to the fourth coding block is 0.

[0165] Using this method, when the quality of a coded block in the second image is lower than the target quality of the second image, ΔQP4b is negative; thus, the coding quality of that coded block can be improved by reducing QP. When the quality of a coded block in the second image is higher than the target quality of the first image, ΔQP4b is positive; thus, the required bitrate for that coded block can be reduced by increasing QP, and the saved bitrate can be used to improve the coding quality of coded blocks in the second image whose quality is lower than the target quality of the second image; in this way, the overall coding quality of the second image can be improved without increasing the overall bitrate.

[0166] C2: The encoding device determines the third QP corresponding to the fourth coding block based on the second QP offset value corresponding to the fourth coding block.

[0167] The encoding device can obtain the frame-level QP (QP_frame1b) of the second image and the block-level ΔQP (ΔQPb) of the fourth coding block from the code control module 20. Then, the encoding device can determine the third QP corresponding to the fourth coding block as QP_frame1b + ΔQPb + ΔQP4b.

[0168] S312: The encoding device can encode the fourth coding block according to the third QP corresponding to the fourth coding block.

[0169] Encoding devices can adopt Figure 1 The entire encoding process shown encodes the current coding block, outputs the bitstream, and obtains the reconstructed image. For details, please refer to [the documentation / reference needed]. Figure 1 The explanation is simply that the QP of the current coding block is replaced with the third QP, which will not be elaborated here.

[0170] Optionally, the second image can also be replaced with the (n+m)th frame, where m is an integer greater than 1.

[0171] It should be noted that the aforementioned N coded blocks can be all coded blocks in the second image, or only a portion of the coded blocks in the second image. That is, the encoding device can encode all coded blocks in the second image using the method of steps S308-S312, or it can encode only a portion of the coded blocks in the second image using the method of steps S308-S312. When the encoding device encodes only a portion of the coded blocks in the second image using the method of steps S308-S312, for the other coded blocks in the second image, the encoding device can perform at least two encoding operations using the method of steps S302-S305, or it can perform only one encoding operation.

[0172] Using the above method, the encoding device can encode the first image in the video at least twice, thereby improving the encoding quality of the first image. Then, the encoding device can encode the second image in the video once based on the first image with improved encoding quality; specifically, the encoding device predicts the encoding quality of similar coded blocks in subsequent images of the video based on the encoding quality of the target coded block in the first image with improved encoding quality, and adjusts the QP according to the predicted encoding quality, thereby improving the encoding quality of similar coded blocks in subsequent images of the video, and thus improving the encoding quality of the second image.

[0173] Figure 3 The method shown can be applied to application scenarios where encoder performance is redundant and there is a need to improve the quality of the encoder's output image. For example, this method can be applied to the following scenarios:

[0174] Application Scenario 1: Mobile phone camera or video call application scenario.

[0175] In this scenario, the actual image resolution captured by the mobile phone is 1080P@30 frames per second (fps) or 720P@30fps. However, the encoder resolution in most mobile phones is at least 4K@30fps. Therefore, in this scenario, the mobile phone can use the method of this application to encode the image actually captured by the phone at least twice, thereby improving the overall encoding quality of the image output by the encoder.

[0176] Application Scenario 2: Video Surveillance Scenario.

[0177] In this scenario, encoding devices often use low bitrates, resulting in uneven image quality. For example, for static, complex background areas, the encoded image has high clarity; however, for moving areas and areas with weak textures, the encoded image often suffers from local blurring, trailing, and color retention. In this scenario, the encoding device can employ the method described in this application to adjust the QP (Quality Point) based on the encoded image quality by setting appropriate target quality parameters, and then encode the image according to the adjusted QP, thereby improving the overall encoding quality of the image.

[0178] The following are combined with Figures 4-12 introduce Figure 3 The implementation method shown is as follows. Among them, Figures 4-9 This section mainly introduces one possible scenario: the encoding device encodes the image at least twice, adjusts the QP of the corresponding encoding block based on the quality parameters of each encoding block obtained in the previous encoding, and then encodes the image based on the adjusted QP. Figures 10-12 This section mainly introduces the second possible scenario, in which the encoding device encodes the first image in the video at least twice, and predicts the QP of the encoding block in the second image in the video based on the encoding quality of the associated encoding block in the first image, and then encodes the second image in the video once.

[0179] The following is combined Figures 4-9 This section introduces the implementation method of the first possible scenario mentioned above.

[0180] like Figure 4 As shown, the encoding device may include: a first encoder 31, a second encoder 32, a QP adjustment module 33, and a code control module 20.

[0181] The code control module 20 can provide the first encoder 31 and the second encoder 32 with the frame-level QP (i.e., QP_frame1a) of the first image and the block-level ΔQP (i.e., ΔQPa) of the current coding block in the first image. That is, the first encoder 31 and the second encoder 32 share a code control module 20. In this way, the first encoder 31 and the second encoder 32 can use the same frame-level QP and block-level ΔQP when encoding each coding block in the first image.

[0182] The first encoder 31 can be Figure 1The encoder 10 shown may be an encoder of other architectures (e.g., a Joint Photographic Experts Group (JPEG) image encoder or a video encoder such as H.264 / H.265). The first encoder 31 may encode each coded block in the first image by performing steps S301-S303 and output reconstructed data with quantization distortion. Optionally, this reconstructed data may not be written to double datarate (DDR) memory as reference data for the next frame image.

[0183] QP adjustment module 33 can determine the QP offset value corresponding to each coding block in the first image by executing step S304 (i.e., ... Figure 3 ΔQP4a in the method shown).

[0184] The following is for reference. Figure 5 The QP adjustment module 33 is explained below. Figure 5 As shown, the QP adjustment module 33 can determine the QP offset value corresponding to any coded block in the first image by performing the D1-D3 operations.

[0185] D1: The QP adjustment module 33 can calculate the quality parameter (also known as the image quality metric) T1 of the first coding block after encoding the first coding block in the first image by the first encoder 31 by comparing the first image (i.e., the original image) and the reconstructed data output by the first encoder 31. Here, the first coding block is any coding block in the first image; the quality parameter can be objective metrics such as PSNR, SSIM, MS-SSIM, or other custom metrics (e.g., the change in frequency domain (e.g., DCT transform) energy of each coding block before and after encoding (e.g., represented by the sum of the absolute values ​​of the transform coefficients)).

[0186] D2: The QP adjustment module 33 can calculate the coding parameters that need to be adjusted for the first coding block based on the difference between the quality parameter T1 of the first coding block and the target quality parameter T of the first image, for example, ΔQP4a.

[0187] Here, ΔQP4a can be either positive or negative. For example, if a larger mass parameter is better, ΔQP4a is positive when T1 is greater than T, and negative when T1 is less than T. Conversely, if a smaller mass parameter is better, ΔQP4a is negative when T1 is greater than T, and positive when T1 is less than T.

[0188] Optionally, the QP adjustment module 33 can determine ΔQP4a using the following code.

[0189]

[0190] Wherein, Diff is the difference between the quality parameter T1 of the first coding block and the target quality parameter T of the first image; abs(Diff) is the absolute value of Diff; QualityThr[8] is the threshold used to determine the interval in which the difference between the quality parameter T1 of the first coding block and the target quality parameter T of the first image lies. In this code, eight thresholds, a1, a2, a3, a4, a4, a6, a7, a8, are used as examples for illustration. It should be understood that in actual use, other numbers of thresholds (e.g., 4, 5, or 6) can also be used.

[0191] D3: The QP adjustment module 33 can output the encoding parameters that need to be adjusted corresponding to the first encoding block to the second encoder 32.

[0192] Optionally, after D2, the QP adjustment module 33 can also save the encoding parameters that need to be adjusted corresponding to the first encoding block.

[0193] The second encoder 32 can be Figure 1 The encoder shown is an encoder of other architectures (e.g., image JPEG or H.264 / H.265 video encoders). The second encoder 32 can determine the second QP corresponding to each coding block in the first image as QP_frame1a+ΔQPa+ΔQP4a based on the frame-level QP (e.g., QP_frame1a) and block-level QP (e.g., ΔQPa) of the first image output by the code control module 20, and the block-level QP (e.g., ΔQP4a) of each coding block output by the QP adjustment module 33 (see S304 for details), and encode each coding block in the first image according to the second QP corresponding to each coding block, outputting the final video or image bitstream (see S305 for details).

[0194] Specifically, the size of the encoding block used by the second encoder 32 when encoding the first image is the same as the size of the encoding block used by the first encoder 31 when encoding the first image; the size of the first image used in both encodings is also the same. Thus, by adjusting the QP corresponding to the encoding block of the second encoder 32 based on the encoding quality of the encoding block after encoding by the first encoder 31, the encoding quality of the encoding block can be effectively improved.

[0195] Optionally, when the second encoder 32 is a video encoder, the second encoder 32 may also output a reconstructed image of the first image, so as to serve as a reference image for the next frame in the video. For details, please refer to S305, which will not be repeated here.

[0196] Optionally, the first encoder 31 may also output intermediate results of encoding the first image (e.g., Figure 3The first information in the method shown); in this way, the second encoder 32 can use these intermediate results to encode the first image (see method 2 in S305 for details), thereby reducing the amount of computation for the second encoder 32 to encode the first image and thus improving the encoding efficiency.

[0197] The first encoder 31 and the second encoder 32 can be different encoders with the same architecture; they can also be the same encoder; or they can be encoders with different architectures (e.g., ...). Figure 7 (As shown). When the first encoder 31 and the second encoder 32 are the same encoder, the encoding device can call the same encoder in a time-division multiplexing manner to encode each encoding block in the first image. For example, the encoder can be called first to execute steps S301-S303, and then the encoder can be called to execute step S305.

[0198] In some possible implementations, the QP adjustment module 33 can determine the QP corresponding to each coding block in the first image and output the QP corresponding to each coding block in the first image to the second encoder 32; the second encoder 32 can encode each coding block in the first image according to the QP determined by the QP adjustment module 33 and output the final video or image bitstream (see S305 for details). Figure 6 This illustrates how the QP adjustment module 33 determines the QP corresponding to each coded block in the first image. For example... Figure 6 As shown, in Figure 4 Based on this, after determining the QP offset value corresponding to each coding block in the first image, the QP adjustment module 33 can also determine the QP corresponding to each coding block as QP = QP_frame1a + ΔQPa + ΔQP4a (i.e. the second QP in step S304, the details of which can be found in step S304), and output the determined QP to the second encoder 32.

[0199] In this embodiment, the encoding device can encode an image at least twice. Specifically, after encoding each coded block in the first image by the first encoder 31, the encoding device can adjust the corresponding encoding parameters (e.g., adjust the QP) based on the encoding quality of each coded block, and then use the adjusted QP to encode the corresponding coded block in the first image by the second encoder 32. In this way, the encoding device can adjust the encoding parameters QP for the current encoding based on the quality of the previous actual encoding, thereby ensuring the quality of the encoded image.

[0200] Figure 7 It shows Figure 4 The diagram shows one possible structure of the encoding device. The following section combines... Figure 7 Please provide a detailed explanation.

[0201] The first encoder 31 may include an intra-frame prediction module 102, an inter-frame prediction module 104, a mode decision and residual calculation module 106, a transform and quantization module 108-1, and an inverse quantization and inverse transform module 110-1.

[0202] The second encoder 32 may include a prediction coding module 41, a filtering module 112, and an entropy coding module 114.

[0203] Each module in the first encoder 31 can encode each coding block in the first image to obtain the first reconstructed data (i.e., the first image data in step S303), and output the first reconstructed data to the QP adjustment module 33.

[0204] In addition, the pattern decision and residual calculation module 106 can output the determined intermediate results to the prediction coding module 41 and the entropy coding module 114. The intermediate results may include: the predicted pattern and / or the MV.

[0205] The specific contents of each module in the first encoder 31 can be found in the following reference: Figure 1 and Figure 3 The explanation will not be repeated here.

[0206] QP adjustment module 33 can determine the QP corresponding to each coding block in the first image, and output the determined QP corresponding to each coding block to prediction coding module 41. For details of QP adjustment module 33, please refer to [the relevant documentation / reference]. Figures 4-6 The explanation will not be repeated here.

[0207] The predictive coding module 41 can use intermediate results and the QP corresponding to each coding block to encode each coding block in the first image separately, thereby outputting the quantized data corresponding to each coding block to the entropy coding module 114, and outputting the second reconstructed data corresponding to each coding block to the filtering module 112. For details on the predictive coding module 41, please refer to the following description. Figure 8 Explanation.

[0208] The filtering module 112 can filter the reconstructed data corresponding to each coding block to obtain the reconstructed data corresponding to each coding block in the first image. Additionally, the filtering module 112 can output filtering information (e.g., SAO mode information and compensation information) to the entropy coding module 114. For details on the filtering module 112, please refer to the... Figure 1 The explanation will not be repeated here.

[0209] The entropy coding module 114 can apply an entropy coding scheme to one or more of the quantized data, prediction data, SAO mode information, and compensation information to obtain an encoded bitstream. For details on the entropy coding module 114, please refer to [the relevant documentation / reference]. Figure 1 The explanation will not be repeated here.

[0210] The following is combined Figure 8 Taking the first coded block in the first image as an example, the processing procedure of the predictive coding module 41 will be explained. Here, the first coded block can be any coded block in the first image.

[0211] like Figure 8 As shown, the prediction coding module 41 includes: a prediction unit 412, a residual calculation unit 414, a transformation and quantization module 108-2, an inverse quantization and inverse transformation module 110-2, and a data calculation unit 416.

[0212] The prediction unit 412 can use intermediate results from the mode decision and residual calculation module 106 to predict the first coding block, generate prediction data for the first coding block, and output the prediction data to the residual calculation unit 414 and the data calculation unit 416. The intermediate results may include: prediction mode, adjacent reference data, and temporal compensation data (e.g., MV). The method by which the prediction unit 412 generates prediction data can be referred to the description of the intra-frame prediction module 102 or the inter-frame prediction module 104, and will not be repeated here.

[0213] The residual calculation unit 414 can generate the residual of the first coding block based on the original data and predicted data of the first coding block in the first image, and output the residual of the first coding block to the transform and quantization module 108-2. The specific process of the residual calculation unit 414 generating the residual of the first coding block can be found in the... Figure 1 The explanation will not be repeated here.

[0214] The transform and quantization module 108-2 can use the QP from the first coding block of the first coding block from the QP adjustment module 33 to process the residual of the first coding block, obtain the quantized data of the first coding block, and output the quantized data of the first coding block to the entropy coding module 114 and the inverse quantization and inverse transform module 110-2. The specific process by which the transform and quantization module 108-2 obtains the quantized data can be found in the... Figure 1 The explanation will not be repeated here.

[0215] After processing the quantized data of the first coded block, the inverse quantization and inverse transform module 110-2 obtains the inverse transform residual (also called the reconstructed residual) of the first coded block, and outputs the reconstructed residual of the first coded block to the data calculation unit 416. The specific process by which the inverse quantization and inverse transform module 110-2 obtains the inverse transform residual can be found in the... Figure 1The explanation will not be repeated here.

[0216] Data calculation unit 416 obtains the reconstructed data of the first coded block (i.e., based on the predicted data of the first coded block and the residual after the inverse transform of the first coded block) Figure 7 The second reconstructed data is obtained from the predicted data and the residual after inverse transformation, and the reconstructed data of the first coded block is output to the filtering module 112. The reconstructed data is the result of adding the predicted data and the residual after inverse transformation.

[0217] It should be understood that this embodiment is illustrated using the encoding of a coding block as an example. The encoding device can also encode at a smaller prediction granularity. For example, in some video coding standards, such as H.265 or Versatile Video Coding (VVC), a block may contain multiple coding units, different coding units may employ different coding modes, and the encoding of adjacent coding units may have a certain spatial dependency. Therefore, the encoding device in this embodiment can be used for a smaller predictive coding granularity (e.g., CU).

[0218] Figure 9 It shows the use of Figure 4 or Figure 7 The diagram shown illustrates the encoding process performed by the encoding device, as follows: Figure 9 As shown, the first encoder 31 uses the frame-level QP of the first image and the block-level QP (i.e., ΔQP) corresponding to each coded block in the first image to encode each coded block in the first image, thereby obtaining the first reconstructed image of the first image (i.e., the first reconstructed image of the first image). Figure 3 The first image data in the method shown). The quality parameter T1 of each coded block in the first image data is as follows: Figure 9 As shown. When the target quality parameter T is 5, the encoding device can adjust the QP corresponding to each encoding block in the first image according to the difference between T1 and T for each encoding block. For example, the encoding device can determine the QP offset value ΔQP4a corresponding to each encoding block in the first image; and then determine the QP corresponding to each encoding block in the first image according to ΔQP4a. The second encoder 32 can use the QP corresponding to each encoding block to encode each encoding block in the first image to obtain the second reconstructed image of the first image (i.e., Figure 3 The second image data in the method shown). The quality parameter T2 of each coded block in the second image data is as follows: Figure 9 As shown. See also Figure 9 It can be seen that, compared with the quality parameter T1 of each coding block in the first image data, the quality parameter T2 of each coding block in the second image data is closer to the target quality parameter T. The difference between the quality parameters of different coding blocks in the second image data is also smaller, and the quality is more uniform.

[0219] In this embodiment, the encoding device can encode an image at least twice. Based on the quality parameters of each coded block obtained from the previous encoding, it adjusts the QP corresponding to each coded block in the image, and then encodes the image again based on the adjusted QP. In this way, the encoding device can adjust the encoding parameters QP for the current encoding based on the quality of the previous encoding, thereby ensuring the quality of the encoded image. Furthermore, during the current encoding, the encoding device uses the intermediate results from the previous encoding, simplifying the encoder structure and effectively reducing the performance consumption of the encoding device.

[0220] The following is combined Figures 10 to 12 This section introduces the implementation method of the second possible scenario mentioned above.

[0221] like Figure 10 As shown, the encoding device may include: encoder 10 and code control module 20.

[0222] The encoder 10 may include: an intra-frame prediction module 102, an inter-frame prediction module 104, a mode decision and residual calculation module 106, a transform and quantization module 108, an inverse quantization and inverse transform module 110, a filtering module 112, an entropy coding module 114, a QP calculation module 116, and a reconstruction quality calculation module 118.

[0223] In this embodiment, for a portion of the images in the video (e.g., the nth frame of the video, i.e.) Figure 3 In the first image shown in the method, the encoding device can encode the image at least twice. For example, the encoding device can call encoder 10 at least twice to encode each coding block in the image using time-division multiplexing, and adjust the QP corresponding to each coding block in the image during the current encoding based on the coding quality of the coding blocks in the image after the previous encoding. At this time, the encoding device can only call the following modules in encoder 10 to encode the image: intra-frame prediction module 102, inter-frame prediction module 104, mode decision and residual calculation module 106, transform and quantization module 108, inverse quantization and inverse transform module 110, filtering module 112, and entropy coding module 114. For the specific encoding process, please refer to the... Figures 3-6 The explanation will not be repeated here.

[0224] For other images in the video (e.g., the (n+1)th frame image in the video, i.e. Figure 3 In the method shown (using the second image), the encoding device can predict the encoding quality of similar coding blocks in subsequent images of the video based on the encoding quality of the target coding block in the nth frame of the video, and adjust the QP corresponding to each similar coding block according to the predicted encoding quality. The following explanation uses the image to be encoded as the second image and the reference image as the first image as an example.

[0225] The code control module 20 can output the frame-level QP (QP_frame1b) of the second image and the block-level ΔQP (ΔQPb) of the current coding block to the QP calculation module 116. The current coding block can be any coding block in the second image.

[0226] QP calculation module 116 can determine the QP corresponding to the current coding block in the second image by executing S308-S311 (i.e., ... Figure 3 The method shown includes a third QP, and the determined QP is output to the intra-frame prediction module 102 and the inter-frame prediction module 104; then, the encoder 10 can refer to the... Figure 1 and Figure 3 The instructions are to use the third QP to encode the current coding block in the second image.

[0227] The reconstruction quality calculation module 118 can determine a quality matrix representing the coding quality of each coding block in the second image based on the second image and the reconstructed image from the second image from the filtering module 112.

[0228] The following is combined Figure 11 This describes the process by which the QP calculation module 116 determines the QP corresponding to the current coding block in the second image. For example... Figure 11 As shown, the QP calculation module 116 can determine the QP corresponding to the current coding block in the second image by performing the E1-E3 operations.

[0229] E1: QP calculation module 116 predicts the quality parameter T3 of each coding block in the second image based on the first image and the quality matrix of the first image.

[0230] Specifically, the QP calculation module 116 can find at least one target coding block in the first image that is closest to the current coding block through motion estimation. This at least one target coding block can also be referred to as the target coding block associated with the current coding block. Then, the QP calculation module 116 can determine the quality parameters of the at least one target coding block based on the quality matrix of the first image. This quality matrix can be a two-dimensional quality matrix. The QP calculation module 116 can predict the quality parameters of the current coding block based on the quality parameters of the at least one target coding block.

[0231] When the target coding blocks associated with the current coding block can include multiple target coding blocks, the encoding device can predict the quality parameters of the current coding block as a weighted average of the quality parameters of the multiple target coding blocks. For example, Figure 12As shown, the current coded block in the second image is coded block A. The coded blocks associated with coded block A in the first image (i.e., the reference image) include BLK7, BLK8, BLK11, and BLK12. That is, the block in the first image that matches coded block A (hereinafter referred to as the reference block) is located within BLK7, BLK8, BLK11, and BLK12. Assuming the quality parameters of BLK7, BLK8, BLK11, and BLK12 are Q7, Q8, Q11, and Q12 respectively, then the QP calculation module 116 can predict the quality parameters of coded block A as follows:

[0232] QA=w1*Q7+w2*Q8+w3*Q11+w4*Q12;

[0233] Among them, w1, w2, w3, and w4 are the weights corresponding to BLK7, BLK8, BLK11, and BLK12, respectively. The weight corresponding to each block can be the ratio of the number of pixels in the reference block to the total number of pixels in the reference block.

[0234] E2: The QP calculation module 116 determines the QP offset value (i.e., ...) of the QP corresponding to each coding block in the second image based on the predicted quality parameter T3 of each coding block in the second image. Figure 3 The method shown is for ΔQP4b). The method by which the QP calculation module 116 determines ΔQP4b can be referenced from the method by which the QP adjustment module 33 determines ΔQP4a, and will not be repeated here.

[0235] E3: The QP calculation module 116 determines the QP corresponding to each coding block in the second image as QP = QP_frame1b + ΔQPb + ΔQP4b based on ΔQP4b for each coding block (i.e., ...). Figure 3 The third QP in the method shown.

[0236] For details on E1-E3, please refer to [link / reference]. Figure 3 The method shown will not be elaborated here.

[0237] In this embodiment, the encoding device can encode a portion of the images in the video at least twice, and encode the other images in the video once. For example, when the frame rate of the video to be encoded is 25fps, the encoding device can select 5 frames per second for at least two encodings, and encode the other frames per second once.

[0238] The encoding device can flexibly choose between images that require at least two encodings and images that require only one encoding. Optionally, before encoding a frame in the video, the encoding device can pre-determine whether to use at least two encodings or single encoding. The principle of pre-determination is as follows: in a video sequence, a scene (shot) can correspond to multiple consecutive frames; the encoding results of these images are relatively similar; in this case, the encoding quality of the previous frame can be used to predict the encoding quality of similar coded blocks in the current frame. Based on this principle, when multiple similar frames exist, the encoding device can select some images from the multiple similar frames for two encodings and the other images for single encoding.

[0239] In this embodiment, the encoding device can encode the first image in the video at least twice, thereby improving the encoding quality of the first image. Then, the encoding device can encode the second image in the video once based on the first image with improved encoding quality; specifically, the encoding device predicts the encoding quality of similar coding blocks in subsequent images of the video based on the encoding quality of the target coding block in the first image with improved encoding quality, and adjusts the QP corresponding to each similar coding block according to the predicted encoding quality, thereby improving the encoding quality of similar coding blocks in subsequent images of the video, and thus improving the encoding quality of the second image.

[0240] In addition, with Figure 4-9 Compared to the embodiments shown, this embodiment makes fewer changes to the encoder and reduces the number of encoders, thereby simplifying the architecture of the encoding device.

[0241] Optionally, the encoding device may also encode all images in the video once using the method described in this embodiment. In this way, the encoding device predicts the encoding quality of similar coding blocks in subsequent images of the video based on the encoding quality of the target coding block in the already encoded image, and adjusts the QP corresponding to each similar coding block according to the predicted encoding quality, thereby improving the encoding quality of similar coding blocks in subsequent images of the video, and further improving the encoding quality of subsequent images.

[0242] Based on and Figures 3 to 12 The embodiments shown have the same inventive concept, and the embodiments of this application are implemented through... Figure 13 An image encoding apparatus is provided, which can be used to perform the functions of the relevant steps in the above embodiments. The functions can be implemented in hardware, or in software, or in hardware executing corresponding software. The hardware or software includes one or more modules corresponding to the above functions. For example... Figure 13 As shown, the image encoding device 1300 may include an acquisition unit 1301 and a processing unit 1302.

[0243] The acquisition unit 1301 is configured to: acquire a first image, the first image containing at least one coded block; and acquire a first quantization parameter QP corresponding to each coded block in the at least one coded block.

[0244] The processing unit 1302 is configured to: encode each coding block in the at least one coding block according to the first QP corresponding to each coding block to obtain first image data; determine the second QP corresponding to each coding block according to the quality parameters of each coding block in the first image data; and encode each coding block in the at least one coding block according to the second QP corresponding to each coding block to obtain second image data.

[0245] Optionally, the processing unit 1302 is specifically configured to: determine a first QP offset value corresponding to the first coding block based on the target quality parameters of the first image and the quality parameters of the first coding block in the first image data; wherein the first coding block is any one of the at least one coding block; and determine a second QP corresponding to the first coding block based on the first QP corresponding to the first coding block and the first QP offset value corresponding to the first coding block.

[0246] Optionally, the processing unit 1302 is specifically used for:

[0247] When the quality parameter of the first coding block is greater than the target quality parameter of the first image, and the difference between the quality parameter of the first coding block and the target quality parameter of the first image is within a first range, the first QP offset value corresponding to the first coding block is determined to be equal to the QP offset value corresponding to the first range; wherein, the first QP offset value corresponding to the first coding block is a positive number; or

[0248] When the quality parameter of the first coding block is less than the target quality parameter of the first image, and the absolute value of the difference between the quality parameter of the first coding block and the target quality parameter of the first image is within a second range, the absolute value of the first QP offset value corresponding to the first coding block is determined to be equal to the QP offset value corresponding to the second range; wherein, the first QP offset value corresponding to the first coding block is negative; or

[0249] When the quality parameter of the first coding block is equal to the target quality parameter of the first image, the first QP offset value corresponding to the first coding block is determined to be 0.

[0250] Optionally, the processing unit 1302 is specifically configured to: after encoding each coding block in the at least one coding block according to the first QP corresponding to each coding block, compare the first image data and the first image to obtain the quality parameter of each coding block in the first image data.

[0251] Optionally, the processing unit 1302 is specifically configured to: quantize the second coding block according to the first QP corresponding to the second coding block to obtain quantized data; wherein the second coding block is any one of the at least one coding blocks; perform inverse quantization and inverse transform processing on the quantized data according to the first QP corresponding to the second coding block to obtain inverse transform residual data; obtain reconstructed data of the second coding block according to the prediction data and residual data of the second coding block; and filter the reconstructed data to obtain image data in the first image data corresponding to the second coding block.

[0252] Optionally, the processing unit 1302 is specifically configured to: encode the third coding block according to the first information and the second QP corresponding to the third coding block; wherein the third coding block is any one of the at least one coding blocks; wherein the first information includes at least one of the following: the prediction mode of the third coding block determined when encoding the third coding block according to the first QP corresponding to the third coding block; and the motion vector of the third coding block determined when encoding the third coding block according to the first QP corresponding to the third coding block.

[0253] Optionally, the processing unit 1302 is specifically used to: after encoding each coding block in the at least one coding block according to the second QP corresponding to each coding block, save the second information; wherein the second information is used to represent the quality parameters of each coding block in the second image data.

[0254] Optionally, the second information is a matrix containing quality parameters for each coded block in the second image data.

[0255] Optionally, the acquisition unit 1301 is specifically used for: when the first image is the nth frame image in the video, acquiring the second image after saving the second information; wherein the second image is the (n+1)th frame image in the video, and the second image contains N coded blocks, where N is a positive integer; the processing unit 1302 is specifically used for: determining at least one target coded block associated with a fourth coded block in the second image from among the at least one coded block; wherein the fourth coded block is any one of the N coded blocks, and the content of the fourth coded block is included in the at least one target coded block; determining the quality parameters of the at least one target coded block in the second image data according to the second information; predicting the quality parameters of the encoded fourth coded block according to the quality parameters of the at least one target coded block; determining the third QP corresponding to the fourth coded block according to the predicted quality parameters of the encoded fourth coded block; and encoding the fourth coded block according to the third QP corresponding to the fourth coded block, where n is a positive integer.

[0256] Optionally, the processing unit 1302 is specifically configured to: determine a second QP offset value corresponding to the fourth coding block based on the target quality parameters of the second image and the predicted quality parameters of the fourth coding block; and determine a third QP corresponding to the fourth coding block based on the second QP offset value corresponding to the fourth coding block.

[0257] Optionally, the processing unit 1302 is specifically used for:

[0258] When the quality parameter of the fourth coding block is greater than the target quality parameter of the second image, and the difference between the quality parameter of the fourth coding block and the target quality parameter of the second image is within a third range, the second QP offset value corresponding to the fourth coding block is determined to be equal to the QP offset value corresponding to the third range; wherein, the second QP offset value corresponding to the fourth coding block is a positive number; or

[0259] When the quality parameter of the fourth coding block is less than the target quality parameter of the second image, and the absolute value of the difference between the quality parameter of the fourth coding block and the target quality parameter of the second image is within a fourth range, the absolute value of the second QP offset value corresponding to the fourth coding block is determined to be equal to the QP offset value corresponding to the fourth range; wherein, the second QP offset value corresponding to the fourth coding block is negative; or

[0260] When the quality parameter of the fourth coding block after prediction is equal to the target quality parameter of the second image, the second QP offset value corresponding to the fourth coding block is determined to be 0.

[0261] Optionally, the quality parameters of any coded block include at least one of the following:

[0262] Peak signal-to-noise ratio, structural similarity, and multi-scale structural similarity.

[0263] Figure 14 This is a schematic block diagram of an image encoding device 1400 according to an embodiment of this application. It should be understood that the image encoding device 1400 is capable of performing the above-described... Figures 3 to 12 The illustrated embodiment shows the various steps performed by the encoding device. The image encoding device 1400 includes a processor 1401 and a memory 1402 coupled to the processor 1401. The memory 1402 can be used to store program code; the processor 1401 can call the program code stored in the memory to execute the image encoding method described above.

[0264] The processor 1401 may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, transistor logic devices, hardware components, or any combination thereof. The general-purpose processor may be a microprocessor or any conventional processor.

[0265] The memory 1401 can be volatile memory or non-volatile memory, or may include both. The non-volatile memory can be read-only memory (ROM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM), or flash memory. The volatile memory can be RAM, which is used as an external cache. By way of example, but not limitation, many forms of RAM are available, such as Static Random Access Memory (SRAM), Dynamic Random Access Memory (DRAM), Synchronous DRAM (SDRAM), Double Data Rate SDRAM (DDR SDRAM), Enhanced Synchronous DRAM (ESDRAM), Synchlink DRAM (SLDRAM), and Direct Rambus RAM (DR RAM). It should be noted that the memory used in the systems and methods described herein is intended to include, but is not limited to, these and any other suitable types of memory.

[0266] Optionally, the processor 1401 and the memory 1402 can be interconnected via a bus 1403. The bus 1403 can be a peripheral component interconnect (PCI) bus or an extended industry standard architecture (EISA) bus, etc. The bus 1403 can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 14 The bus is represented by a single thick line, but this does not mean that there is only one bus or one type of bus.

[0267] Based on the above embodiments, this application also provides a computer program that, when run on a computer, causes the computer to execute the methods provided in the above embodiments.

[0268] Based on the above embodiments, this application also provides a computer-readable storage medium storing a computer program, which, when executed by a computer, causes the computer to perform the methods provided in the above embodiments.

[0269] The storage medium can be any available medium that a computer can access. For example, but not limited to, a computer-readable medium can include RAM, ROM, EEPROM or other optical disk storage, magnetic disk storage media or other magnetic storage devices, or any other medium that can be used to carry or store desired program code in the form of instructions or data structures and that can be accessed by a computer.

[0270] Based on the above embodiments, this application also provides a chip for reading a computer program stored in a memory to implement the method provided in the above embodiments.

[0271] Based on the above embodiments, this application provides a chip system including a processor for supporting a computer device in implementing the functions involved in the devices in the above embodiments. In one possible design, the chip system further includes a memory for storing necessary programs and data of the computer device. This chip system may be composed of chips or may include chips and other discrete components.

[0272] In summary, this application provides an image encoding method, apparatus, and device. In this method, after acquiring a first image, the encoding device can acquire a first QP corresponding to each coded block in at least one coded block of the first image. Then, based on the first QP corresponding to each coded block, each coded block in the at least one coded block is encoded to obtain first image data. The encoding device can determine a second QP corresponding to each coded block based on the quality parameters of each coded block in the first image data; and based on the second QP corresponding to each coded block, each coded block in the at least one coded block is encoded to obtain second image data. Through this method, the encoding device can adjust the encoding parameters QP of the current encoding based on the quality of the previous actual encoding, thereby ensuring the quality of the encoded image.

[0273] In the various embodiments of this application, unless otherwise specified or in case of logical conflict, the terminology and / or descriptions between different embodiments are consistent and can be referenced by each other. Technical features in different embodiments can be combined to form new embodiments based on their inherent logical relationships.

[0274] Those skilled in the art will understand that embodiments of this application can be provided as methods, systems, or computer program products. Therefore, this application can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, this application can take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, optical storage, etc.) containing computer-usable program code.

[0275] This application is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to this application. 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 program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart illustrations. Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.

[0276] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.

[0277] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.

[0278] Obviously, those skilled in the art can make various modifications and variations to this application without departing from the scope of this application. Therefore, if such modifications and variations fall within the scope of the claims of this application and their equivalents, this application also intends to include such modifications and variations.

Claims

1. An image encoding method, characterized in that, include: Acquire a first image, wherein the first image contains at least one coded block; Obtain the first quantization parameter QP corresponding to each coding block in the at least one coding block; Based on the first QP corresponding to each coding block, each coding block in the at least one coding block is encoded to obtain the first image data; Based on the quality parameters of each coding block in the first image data, determine the second QP corresponding to each coding block; Based on the second QP corresponding to each coding block, each coding block in the at least one coding block is encoded to obtain the second image data; After encoding each of the at least one coding blocks according to the second QP corresponding to each coding block, the method further includes: Save the second information; wherein the second information is used to represent the quality parameters of each coded block in the second image data; The first image is the nth frame of the video, where n is a positive integer; after saving the second information, the method further includes: Obtain the second image; wherein the second image is the (n+1)th frame image in the video, and the second image contains N coded blocks, where N is a positive integer; In the at least one coding block, at least one target coding block is determined that is associated with the fourth coding block in the second image; wherein the fourth coding block is any one of the N coding blocks, and the content of the fourth coding block is contained in the at least one target coding block; Based on the second information, determine the quality parameters of at least one target coding block in the second image data; Based on the quality parameters of the at least one target coding block, predict the quality parameters of the encoded fourth coding block; Based on the predicted quality parameters of the fourth coding block after encoding, determine the third QP corresponding to the fourth coding block; The fourth coding block is encoded according to the third QP corresponding to the fourth coding block.

2. The method as described in claim 1, characterized in that, Based on the quality parameters of each coding block in the first image data, a second QP corresponding to each coding block is determined, including: Based on the target quality parameters of the first image and the quality parameters of the first coded block in the first image data, a first QP offset value corresponding to the first coded block is determined; wherein, the first coded block is any one of the at least one coded blocks; The second QP corresponding to the first coding block is determined based on the first QP corresponding to the first coding block and the offset value of the first QP corresponding to the first coding block.

3. The method as described in claim 2, characterized in that, Based on the target quality parameters of the first image and the quality parameters of the first coded block in the first image data, a first QP offset value corresponding to the first coded block is determined, including: When the quality parameter of the first coding block is greater than the target quality parameter of the first image, and the difference between the quality parameter of the first coding block and the target quality parameter of the first image is within a first range, the first QP offset value corresponding to the first coding block is determined to be equal to the QP offset value corresponding to the first range; wherein, the first QP offset value corresponding to the first coding block is a positive number; or When the quality parameter of the first coding block is less than the target quality parameter of the first image, and the absolute value of the difference between the quality parameter of the first coding block and the target quality parameter of the first image is within a second range, the absolute value of the first QP offset value corresponding to the first coding block is determined to be equal to the QP offset value corresponding to the second range; wherein, the first QP offset value corresponding to the first coding block is negative; or When the quality parameter of the first coding block is equal to the target quality parameter of the first image, the first QP offset value corresponding to the first coding block is determined to be 0.

4. The method according to any one of claims 1 to 3, characterized in that, After encoding each coding block in the at least one coding block according to the first QP corresponding to each coding block, the method further includes: By comparing the first image data with the first image, the quality parameters of each coded block in the first image data are obtained.

5. The method according to any one of claims 1 to 4, characterized in that, Based on the first QP corresponding to each coding block, each coding block in the at least one coding block is encoded to obtain first image data, including: The second coding block is quantized according to the first QP corresponding to the second coding block to obtain quantized data; wherein the second coding block is any one of the at least one coding blocks; Based on the first QP corresponding to the second coding block, the quantized data is dequantized and inversely transformed to obtain the inversely transformed residual data. Based on the prediction data and residual data of the second coding block, the reconstructed data of the second coding block is obtained; The reconstructed data is filtered to obtain the image data corresponding to the second coding block in the first image data.

6. The method according to any one of claims 1 to 5, characterized in that, Encoding is performed on each of the at least one coding blocks according to the second QP corresponding to each coding block, including: The third coding block is encoded according to the first information and the second QP corresponding to the third coding block; wherein the third coding block is any one of the at least one coding blocks; The first information includes at least one of the following: The prediction mode of the third coding block is determined when the third coding block is encoded according to the first QP corresponding to the third coding block; The motion vector of the third coding block is determined when the third coding block is encoded according to the first QP corresponding to the third coding block.

7. The method according to any one of claims 1 to 6, characterized in that, The second information is a matrix containing the quality parameters of each coded block in the second image data.

8. The method according to any one of claims 1 to 7, characterized in that, Based on the predicted quality parameters of the fourth coded block, determine the third QP corresponding to the fourth coded block, including: Based on the target quality parameters of the second image and the predicted quality parameters of the fourth coding block after encoding, a second QP offset value corresponding to the fourth coding block is determined; The third QP corresponding to the fourth coding block is determined based on the second QP offset value corresponding to the fourth coding block.

9. The method as described in claim 8, characterized in that, Based on the target quality parameters of the second image and the predicted quality parameters of the fourth coded block, a second QP offset value corresponding to the fourth coded block is determined, including: When the quality parameter of the fourth coding block is greater than the target quality parameter of the second image, and the difference between the quality parameter of the fourth coding block and the target quality parameter of the second image is within a third range, the second QP offset value corresponding to the fourth coding block is determined to be equal to the QP offset value corresponding to the third range; wherein, the second QP offset value corresponding to the fourth coding block is a positive number; or When the quality parameter of the fourth coding block is less than the target quality parameter of the second image, and the absolute value of the difference between the quality parameter of the fourth coding block and the target quality parameter of the second image is within a fourth range, the absolute value of the second QP offset value corresponding to the fourth coding block is determined to be equal to the QP offset value corresponding to the fourth range; wherein, the second QP offset value corresponding to the fourth coding block is negative; or When the quality parameter of the fourth coding block after prediction is equal to the target quality parameter of the second image, the second QP offset value corresponding to the fourth coding block is determined to be 0.

10. The method according to any one of claims 1 to 9, characterized in that, The quality parameters of any coded block include at least one of the following: Peak signal-to-noise ratio and structural similarity.

11. An image encoding device, characterized in that, include: A processor and a memory coupled to the processor, the processor invoking program code stored in the memory to perform the method as claimed in any one of claims 1-10.

12. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that, when run on a computer, causes the computer to perform the method described in any one of claims 1-10.

13. A chip, characterized in that, The chip is coupled to a memory, and the chip reads a computer program stored in the memory to execute the method described in any one of claims 1-10.