ENCODING METHOD AND APPARATUS, DECODING METHOD AND APPARATUS, DEVICE, STORAGE MEDIUM AND COMPUTER PROGRAM
Patent Information
- Authority / Receiving Office
- MX · MX
- Patent Type
- Patents
- Current Assignee / Owner
- HUAWEI TECH CO LTD
- Filing Date
- 2023-11-21
- Publication Date
- 2026-06-12
Smart Images

Figure MX434786B0
Abstract
Description
Encoding method and apparatus, decoding method and apparatus, device, storage medium and computer program This application claims priority over Chinese Patent Application No. 202110559102.7, filed on May 21, 2021, entitled ENCODING METHOD AND APPARATUS, DECODING METHOD AND APPARATUS, DEVICE, STORAGE MEDIUM, AND COMPUTER PROGRAM, which is incorporated herein by reference in its entirety. FIELD OF INVENTION The embodiments of this application relate to the field of encoding and decoding technologies and, in particular, to an encoding method and apparatus, a decoding method and apparatus, a device, a storage medium and a computer program. BACKGROUND OF THE INVENTION Encoding and decoding technology is indispensable in media applications such as media communication and broadcasting. Therefore, how to perform encoding and decoding becomes one of the industry's concerns. A related technology proposes a method for encoding and decoding an audio signal. In the method, when encoding an audio signal, modified discrete cosine transform (MDCT) processing is performed on a time-domain audio signal to obtain a frequency-domain audio signal. The frequency-domain audio signal is processed using an encoding neural network model to obtain a latent variable. The latent variable indicates a characteristic of the audio signal in the frequency domain. Quantization processing is performed on the latent variable to obtain a quantized latent variable, entropy coding is performed on the quantized latent variable, and an entropy coding result is written to a bit stream.When the audio signal is decoded, the quantized latent variable is determined based on the bit stream, and dequantization processing is performed on the quantized latent variable to obtain the latent variable. The latent variable is processed using a decoding neural network model to obtain the frequency-domain audio signal, and inverse modified discrete cosine transform (IMDCT) processing is performed on the frequency-domain audio signal to obtain a reconstructed time-domain audio signal. However, entropy coding encodes elements with different probabilities by using different bit counts. Therefore, for two adjacent audio frames, the occurrence probabilities of elements in latent variables corresponding to the two audio frames may be different. As a result, the coding bit counts of the latent variables of the two audio frames are different, and the requirement for a stable coding rate cannot be met. BRIEF DESCRIPTION OF THE INVENTION The embodiments of this application provide an encoding method and apparatus, a decoding method and apparatus, a device, a storage medium, and a computer program, for meeting an encoder's requirement for stable encoding speed. The technical solutions are as follows. According to a first aspect, an encoding method is provided. The method can be applied to a codec that does not include a context model, or it can be applied to a codec that includes a context model. Furthermore, not only can a latent variable generated by using media data to be encoded be scaled based on a scale factor, but also a latent variable determined by using a context model can be scaled based on a scale factor. Therefore, the following explains and describes the method in detail in a plurality of cases. In a first embodiment, the method includes the following steps: processing media data to be encoded using a first encoding neural network model to obtain a first latent variable, the first latent variable indicating a characteristic of the media data to be encoded; determining a first variable scaling factor based on the first latent variable, the first variable scaling factor being used to enable an encoding bit quantity of an entropy encoding result of a second latent variable to meet a preset coding rate condition, and the second latent variable being obtained by scaling the first latent variable based on the first variable scaling factor; obtaining the entropy encoding result of the second latent variable;and writing the entropy encoding result of the second latent variable and an encoding result of the first variable scale factor into a bit stream.; The number of coding bits of the entropy coding result of the second latent variable satisfies the predetermined coding rate condition. This ensures that the number of coding bits of the entropy coding result of a latent variable corresponding to each frame of multimedia data can satisfy the predetermined coding rate condition, that is, the number of coding bits of the entropy coding result of the latent variable corresponding to each frame of multimedia data can be substantially consistent, rather than dynamically changing, thereby satisfying the requirement of an encoder for a stable coding rate.Furthermore, when side information (e.g., a window type ινίΛ / , a temporal noise shaping (TNS) parameter, a frequency-domain noise shaping (FDNS) parameter, and / or a bandwidth extension (BWE) parameter) needs to be transmitted, the number of coding bits of the latent variable entropy coding result corresponding to each frame of media data can be guaranteed to be substantially consistent with a number of coding bits of the side information, thereby meeting the encoder's requirement for stable coding rate. The media data to be encoded is an audio signal, a video signal, an image, or the like. Furthermore, the media data to be encoded can be in any form. This is not limited to this embodiment of this application. An implementation process for processing media data to be encoded using the first encoding neural network model is as follows: inputting the media data to be encoded into the first encoding neural network model, to obtain the first latent variable output by the first encoding neural network model; or preprocessing the media data to be encoded, and inputting the preprocessed media data into the first encoding neural network model, to obtain the first latent variable output by the first encoding neural network model. In other words, the media data to be encoded may be used as an input to the first encoding neural network model to determine the first latent variable, or the media data to be encoded may be preprocessed and then used as an input to the first encoding neural network model to determine the first latent variable. Optionally, when the media data to be encoded is encoded at a constant bit rate, meeting a preset encoding rate condition includes that the number of encoding bits is less than or equal to a target number of encoding bits; meeting a preset encoding rate condition includes that the number of encoding bits is less than or equal to a target number of encoding bits, and a difference between the number of encoding bits and the target number of encoding bits is less than a bit number threshold; or meeting a preset encoding rate condition includes that the number of encoding bits is less than or equal to a maximum number of encoding bits of a target number of encoding bits. Optionally, when the media data to be encoded is encoded at a variable bit rate, satisfying a preset encoding rate condition includes that an absolute value of a difference between the number of encoding bits and a target number of encoding bits is less than a bit number threshold.In other words, satisfying a preset encoding rate condition includes that the number of encoding bits is less than or equal to the target number of encoding bits, and a difference between the target number of encoding bits and the number of encoding bits is less than the bit number threshold, or, satisfying a preset encoding rate condition includes that the number of encoding bits is greater than or equal to the target number of encoding bits, and the difference between the number of encoding bits and the target number of encoding bits is less than the bit number threshold. The target number of coding bits may be preset. Of course, the target number of coding bits can also be determined based on a coding rate, and different coding rates correspond to different target numbers of coding bits. In this embodiment of this application, the media data to be encoded may be encoded at the constant bit rate, or the media data to be encoded may be encoded at a variable bit rate. When the media data to be encoded is encoded at a constant bit rate, a number of bits of the media data to be encoded in a current frame can be determined based on the constant bit rate, and then a number of bits used in the current frame is subtracted to obtain a target number of encoding bits in the current frame. The number of bits used may be a number of bits for encoding side information or the like. Furthermore, the side information of each frame of media data is generally different. Therefore, a target number of encoding bits in each frame of media data is usually different. When media data to be encoded is encoded at a variable bit rate, a bit rate is generally specified, and the actual bit rate fluctuates around the specified bit rate. In this case, a number of bits of media data to be encoded in a current frame can be determined based on the specified bit rate, and then a number of bits used in the current frame is subtracted to obtain a target number of encoding bits in the current frame. The number of bits used may be a number of bits for encoding side information, or the like. In some cases, the side information of different media data frames may be different. Therefore, the target number of encoding bits in different media data frames is usually different. An initial number of encoding bits may be determined based on the first latent variable, and the first variable scale factor may be determined based on the initial number of encoding bits and the target number of encoding bits. ινίΛ / The initial number of coding bits is a number of coding bits of an entropy coding result of the first latent variable; or the initial number of coding bits is a number of coding bits of an entropy coding result of a first latent variable scaled based on a first initial scaling factor. The first initial scaling factor may be a preset first scaling factor. An implementation process for scaling the first latent variable based on the first initial scaling factor is as follows: multiply each element in the first latent variable by a corresponding element in the first initial scaling factor, to obtain the first scaled latent variable. It should be noted that the above implementation process is merely an example, and during actual application, another method may be used for scaling. For example, each element in the first latent variable may be divided by a corresponding element in the first initial scaling factor, to obtain the first scaled latent variable. A scaling method is not limited in this embodiment of this application. There may be a variety of implementations for determining the first variable scale factor based on the initial number of encoding bits and the target number of encoding bits. Three implementations are described below. In a first implementation, when the initial number of encoding bits is equal to the target number of encoding bits, the first initial scaling factor is determined as the first variable scaling factor. When the initial number of encoding bits is not equal to the target number of encoding bits, the first variable scaling factor is determined in a first cyclic manner based on the initial number of encoding bits and the target number of encoding bits. The ith cyclic processing of the first cyclic manner includes the following steps: determining a scaling factor of the ith cyclic processing, where i is a positive integer; scaling the first latent variable based on the scaling factor of the ith cyclic processing, to obtain an ith-first scaled latent variable; determining a number of encoding bits of an entropy coding result of the ith-first scaled latent variable, to obtain an ith number of coding bits; and when the ith number of coding bits meets a continuous scaling condition, performing (i+1)th cyclic processing of the first cyclic manner; or when the ith number of coding bits does not meet a continuous scaling condition, terminating execution of the first cyclic manner, and determining the first variable scaling factor based on the scaling factor of the ith cyclic processing. An implementation process for determining the scale factor of the ith cyclic processing is as follows: determining the scale factor of the ith cyclic processing ινίΛ / based on a scale factor of the (i-i)th cyclic processing in the first cyclic manner, an (i-i)th number of coding bits, and the target number of coding bits. When i=1, the scale factor of the (i-1)th cyclic processing is the first initial scale factor, and the (i-1)th number of coding bits is the initial number of coding bits. In this case, the continuous scaling condition includes that both the (i-1)th number of coding bits and the ith number of coding bits are smaller than the target number of coding bits, or the continuous scaling condition includes that both the (i-1)th number of coding bits and the ith number of coding bits are larger than the target number of coding bits. In other words, the continuous scaling condition includes that the ith number of coding bits does not exceed the target number of coding bits. Herein, does not exceed means that a number of coding bits in the first (i-1) times is always less than the target number of coding bits, and the ith number of coding bits is still less than the target number of coding bits. Alternatively, a number of coding bits in the first (i-1) times is always greater than the target number of coding bits, and the ith number of coding bits is still greater than the target number of coding bits. Conversely, exceeds means that a number of coding bits in the first (i-1) times is always less than the target number of coding bits, and the ith number of coding bits is greater than the target number of coding bits.Alternatively, a number of coding bits in the first (i-1) times is always greater than the target number of coding bits, and the ith number of coding bits is less than the target number of coding bits. An implementation process for determining the first variable scale factor based on the scale factor of the i®5'™ cyclic processing includes: when the ith number of encoding bits is equal to the target number of encoding bits, determining the scale factor of the ith cyclic processing as the first variable scale factor; or when the ith number of encoding bits is not equal to the target number of encoding bits, determining the first variable scale factor based on the scale factor of the ith cyclic processing and a scale factor of the (i-1)th cyclic processing in the first cyclic manner. In other words, the scale factor of the ith cyclic processing is a scale factor obtained for the last time in the first cyclic manner, and the ith number of coding bits is a number of coding bits obtained for the last time. When the number of coding bits obtained for the last time is equal to the target number of coding bits, the scale factor obtained for the last time is determined as the first variable scale factor. When the number of coding bits obtained for the last time is not equal to the target number of coding bits, the first variable scale factor is determined based on the scale factors obtained the last two times. An implementation process for determining the first variable scale factor based on the scale factor of the ith cyclic processing and the scale factor of the (-i)th cyclic processing in the first cyclic manner includes: determining an average value of the scale factor of the ith cyclic processing and the scale factor of the (-i)th cyclic processing, and determining the first variable scale factor based on the average value. The average value can be determined directly as the first variable scale factor, or the average value can be multiplied by a preset constant to obtain the first variable scale factor. Optionally, the constant can be less than 1. Indeed, the implementation process for determining the first variable scale factor based on the scale factor of the ith cyclic processing and the scale factor of the (-1)th cyclic processing of the first cyclic form may further be as follows: determining the first variable scale factor of a second cyclic form based on the scale factor of the ith cyclic processing and the scale factor of the (-1)th cyclic processing. In one example, the jth cyclic processing of the second cyclic manner includes the following steps: determining a third scale factor of the jth cyclic processing based on a first scale factor of the jth cyclic processing and a second scale factor of the jth cyclic processing, where when j is equal to 1, the first scale factor of the jth cyclic processing is one of the scale factor of the ith cyclic processing and the scale factor of the (i-1)th cyclic processing, the second scale factor of the jth cyclic processing is the other of the scale factor of the ith cyclic processing and the scale factor of the (i-1)th cyclic processing, the first scale factor of the jth cyclic processing corresponds to a jth-first number of encoding bits, the second scale factor of the jth cyclic processing corresponds to a jth-second number of encoding bits,the jth-first number of coding bits is a number of coding bits of an entropy coding result of a first latent variable scaled based on the first scaling factor of the jth cyclic processing, the jth-second number of coding bits is a number of coding bits of an entropy coding result of a first latent variable scaled based on the second scaling factor of the jth cyclic processing, and the jth-first number of coding bits is less than the jth-second number of coding bits; obtaining a jth-third number of coding bits,where the jth-third number of encoding bits is a number of encoding bits of an entropy encoding result of a first latent variable scaled based on the third scaling factor of the jth cyclic processing; and if the jth-third number of encoding bits does not satisfy a continuous loop condition, terminate execution, ΜΛ / in the second cyclic manner and determining the third scaling factor of the jth cyclic processing as the first variable scaling factor; if the jth-third number of coding bits satisfies a continuous cycle condition, and is greater than the target number of coding bits and less than the jth-second number of coding bits, performing the (j+1)th cyclic processing in the second cyclic manner using the third scaling factor of the jth cyclic processing as a second scaling factor of the (j+i)th cyclic processing and using the first scaling factor of the jth cyclic processing as a first scaling factor of the (j+i)th cyclic processing;or if the jth-third number of coding bits satisfies a continuous cycle condition, and is less than the target number of coding bits and greater than the jth-first number of coding bits, performing the (j+1)th cyclic processing in the second cyclic manner by using the third scale factor of the jth cyclic processing as a first scale factor of the (j+1)th cyclic processing and using the second scale factor of the jth cyclic processing as a second scale factor of the (j+1)th cyclic processing.; In another example, the jth cyclic processing of the second cyclic manner includes the following steps: determining a third scale factor of the jth cyclic processing based on a first scale factor of the jth cyclic processing and a second scale factor of the jth cyclic processing, where when j is equal to 1, the first scale factor of the jth cyclic processing is one of the scale factor of the ith cyclic processing and the scale factor of the (i-1)th cyclic processing, the second scale factor of the jth cyclic processing is the other of the scale factor of the ith cyclic processing and the scale factor of the (i-1)th cyclic processing, the first scale factor of the jth cyclic processing corresponds to a jth-first number of encoding bits, the second scale factor of the jth cyclic processing corresponds to a jth-second number of encoding bits,the jth-first number of encoding bits is less than the jth-second number of encoding bits, and j is a positive integer; obtaining a jth-third number of encoding bits, where the jth-third number of encoding bits is a number of encoding bits of an entropy encoding result of a first latent variable scaled based on the third scaling factor of the jth cyclic processing; and if the jth-third number of encoding bits does not satisfy a continuous cycle condition, terminating execution of the second cyclic manner, and determining the third scaling factor of the jth cyclic processing as the first variable scaling factor; if j reaches a maximum number of cycles and the jth-third number of encoding bits satisfies a continuous cycle condition, terminating execution of the second cyclic manner,and determining the first variable scale factor based on the first scale factor of the jth cyclic processing; if j does not reach a maximum number of cycles, and the jth third number of encoding bits, ΜΛ / satisfy a continuous cycle condition, and is greater than the target number of coding bits and less than the jth number of coding bits, performing the (j+1)th cyclic processing in the second cyclic manner by using the third scale factor of the jth cyclic processing as a second scale factor of the (j+1 )th cyclic processing and using the first scale factor of the jth cyclic processing as a first scale factor of the (j+i)th cyclic processing;or if j does not reach a maximum number of cycles, and the jth-third number of coding bits satisfies a continuous cycle condition, and is less than the target number of coding bits and greater than the jth-first number of coding bits, performing the (j+i)th cyclic processing in the second cyclic manner using the third scale factor of the jth cyclic processing as a first scale factor of the (j+1)th cyclic processing and using the second scale factor of the jth cyclic processing as a second scale factor of the (j+1)th cyclic processing.; An implementation process for determining the third scale factor of the jth cyclic processing based on the first scale factor of the jth cyclic processing and the second scale factor of the jth cyclic processing includes: determining an average value of the first scale factor of the jth cyclic processing and the second scale factor of the jth cyclic processing, and determining the third scale factor of the jth cyclic processing based on the average value. In one example, the average value may be directly determined as the third scale factor of the jth cyclic processing, or the average value may be multiplied by a preset constant to obtain the third scale factor of the jth cyclic processing. Optionally, the constant may be less than 1. Furthermore, an implementation process for obtaining the jth-third number of coding bits includes: scaling the first latent variable based on the third scaling factor of the jth-th cyclic processing to obtain a scaled first latent variable, and performing quantization processing on the scaled first latent variable to obtain a quantized first latent variable; and performing entropy coding on the first quantized latent variable, and counting a number of coding bits from an entropy coding result, to obtain the jth-third number of coding bits. When the media data to be encoded is encoded at a constant bit rate, an implementation process for determining the first variable scale factor based on the first scale factor of the jth cyclic processing includes: determining the first scale factor of the jth cyclic processing as the first variable scale factor. When the media data to be encoded is encoded at a variable bit rate, an implementation process for determining the first variable scale factor based on the first scale factor of the jth cyclic processing includes: determining a first difference between the target number of encoding bits and the jth-first number of encoding bits, and determining a second difference between the jth-number of encoding bits and the target number of encoding bits;and if the first difference is less than the second difference, determining the first scale factor of the jth cyclic processing as the first variable scale factor; if the second difference is less than the first difference, determining the second scale factor of the jth cyclic processing as the first variable scale factor; or if the first difference is equal to the second difference, determining the first scale factor of the jth cyclic processing as the first variable scale factor, or determining the second scale factor of the jth cyclic processing as the first variable scale factor. When the media data to be encoded is encoded at a constant bit rate, the continuous cycle condition comprises: the jth-third number of encoding bits is greater than the target number of encoding bits, or the continuous cycle condition comprises: the jth-third number of encoding bits is less than the target number of encoding bits, and a difference between the target number of encoding bits and the jth-third number of encoding bits is greater than a threshold number of bits. When the media data to be encoded is encoded at a variable bit rate, the continuous cycle condition includes that an absolute value of a difference between the target number of encoding bits and the jth-third number of encoding bits is greater than a threshold number of bits.In other words, the continuous cycle condition includes that the thirteenth number of coding bits is greater than the target number of coding bits, and a difference between the third number of coding bits and the target number of coding bits is greater than the threshold number of bits, or the continuous cycle condition includes that the third number of coding bits is less than the target number of coding bits, and the difference between the target number of coding bits and the thirteenth number of coding bits is greater than the threshold number of bits. In a second implementation, when the initial number of coding bits is equal to the target number of coding bits, a first initial scaling factor is determined as the first variable scaling factor. When the initial number of coding bits is not equal to the target number of coding bits, the first variable scaling factor is determined according to the first implementation above. However, a difference from the first implementation above is that, when the initial number of coding bits is less than the target number of coding bits, a scaling factor of (i-1)th cyclic processing in the first cyclic manner is scaled based on a first step, to obtain the scaling factor of the ith cyclic processing. In this case, the continuous scaling condition includes that the ith number of coding bits is less than the target number of coding bits.When the initial number of coding bits is greater than the target number of coding bits, a scale factor of the (i-1)th cyclic processing in the first cyclic manner is scaled based on a second stage to obtain the scale factor of the ith cyclic processing. In this case, the continuous scaling condition includes that the ith number of coding bits is greater than the target number of coding bits. That a scale factor of the (i)th cyclic processing of the first cyclic manner is scaled based on a first stage may refer to increasing the scale factor of the (i)th cyclic processing based on the first stage, and that a scale factor of the (-i)th cyclic processing of the first cyclic manner is scaled based on a second stage may refer to decreasing the scale factor of the (-i)th cyclic processing based on the second stage. Incremental processing and decremental processing can be linear or nonlinear. For example, a sum of the scale factor of the (i-1 )th cyclic processing and the first stage can be determined as the scale factor of the (i-1 )th cyclic processing, or a difference between the scale factor of the (i-1 )th cyclic processing and the second stage can be determined as the scale factor of the (i-l)th cyclic processing. It should be noted that the first and second stages can be pre-set, and the first and second stages can be adjusted based on different requirements. Furthermore, the first stage can be the same as or different from the second stage. In a third implementation, when the initial number of encoding bits is less than or equal to the target number of encoding bits, a first initial scaling factor is determined as the first variable scaling factor. When the initial number of encoding bits is greater than the target number of encoding bits, the first variable scaling factor may be determined according to the first implementation above. Alternatively, the first variable scaling factor may be determined when the initial number of encoding bits is greater than the target number of encoding bits in the second implementation above. In a second case, based on the first case, the method further includes the following steps: obtaining an entropy coding result of a third latent variable, where the third latent variable is determined based on the second latent variable by using a context model, and the third latent variable indicates a probability distribution of the second latent variable; and writing the entropy coding result of the third latent variable into the bit stream. A total number of coding bits of the entropy coding result of the second latent variable and coding bits of the entropy coding result of the third latent variable meets the pre-set coding rate condition. Determining a first variable scaling factor based on the first latent variable ινίΛ / includes: determining an initial number of coding bits based on the first latent variable; and determining the first variable scaling factor based on the initial number of coding bits and a target number of coding bits. There are two possible ways to determine the initial number of encoding bits based on the first latent variable. Each method is described separately below. In a first implementation, a corresponding initial number of context coding bits and an initial entropy coding model parameter are determined based on the first latent variable by using a context model, a number of coding bits of an entropy coding result of the first latent variable is determined based on the initial entropy coding model parameter, to obtain a basic initial number of coding bits, and the initial number of coding bits is determined based on the initial number of context coding bits and the basic initial number of coding bits. The context model includes a context encoding neural network model and a context decoding neural network model. An implementation process for determining, based on the first latent variable using the context model, the corresponding initial number of context encoding bits and the initial entropy encoding model parameter includes: processing the first latent variable using the context encoding neural network model to obtain a fifth latent variable, where the fifth latent variable represents a probability distribution of the first latent variable; determining an entropy encoding result of the fifth latent variable, and using a number of encoding bits of the entropy encoding result of the fifth latent variable as the initial number of context coding bits;and reconstructing the fifth latent variable based on the entropy coding result of the fifth latent variable, and processing, by using the context decoding neural network model, the fifth latent variable obtained through the reconstruction, to obtain the initial entropy coding model parameter.; In a second implementation, the first preset scaling factor is used as the first initial scaling factor, the first latent variable is scaled based on the first initial scaling factor, a corresponding initial number of context coding bits and an initial entropy coding model parameter are determined based on a first latent variable scaled using a context model, and a number of coding bits of an entropy coding result of the scaled first latent variable is determined based on the initial entropy coding model parameter, to obtain a basic initial number of coding bits; and the initial number of coding bits is determined based on the initial number of context coding bits and the basic initial number of coding bits. The context model includes a context encoding neural network model and a context decoding neural network model. An implementation process for determining, based on the first latent variable scaled by using the context model, the corresponding initial number of context encoding bits and the initial entropy encoding model parameter includes: processing the first latent variable scaled by using the context encoding neural network model, to obtain a sixth latent variable, where the sixth latent variable indicates a probability distribution of the first scaled latent variable; determining an entropy encoding result of the sixth latent variable, and using a number of encoding bits of the entropy encoding result of the sixth latent variable as the initial number of context coding bits;and reconstructing the sixth latent variable based on the entropy coding result of the sixth latent variable, and processing, by using the context decoding neural network model, the sixth latent variable obtained through the reconstruction, to obtain the initial entropy coding model parameter.; There may be a variety of implementations for determining the first variable scale factor based on the initial number of encoding bits and the target number of encoding bits. Three implementations are described below. In a first implementation, when the initial number of encoding bits is equal to the target number of encoding bits, a first initial scaling factor is determined as the first variable scaling factor. When the initial number of encoding bits is not equal to the target number of encoding bits, the first variable scaling factor is determined in a first cyclic manner based on the initial number of encoding bits and the target number of encoding bits. The ith cyclic processing of the first cyclic form includes the following steps: determining a scale factor of the ith cyclic processing, where i is a positive integer; scaling the first latent variable based on the scale factor of the ith cyclic processing, to obtain an ith-first scaled latent variable;determining, based on the ith-first latent variable scaled by using the context model, a corresponding ith number of context coding bits and an ith entropy coding model parameter, determining a number of coding bits of an entropy coding result of the ith-first latent variable scaled based on the ith entropy coding model parameter, to obtain an ith basic number of coding bits, and determining an ith number of coding bits based on the ith number of context coding bits and the ith basic number of coding bits; and when the ith number of coding bits meets a continuous scaling condition, ML / perform an (i+1)th cyclic processing in the first cyclic manner; or when the ith number of encoding bits does not satisfy a continuous scaling condition, terminate execution of the first cyclic manner and determine the first variable scaling factor based on the scaling factor of the ith cyclic processing. In a second implementation, when the initial number of coding bits is equal to the target number of coding bits, a first initial scaling factor is determined as the first variable scaling factor. When the initial number of coding bits is not equal to the target number of coding bits, the first variable scaling factor is determined according to the first implementation above. However, a difference from the first implementation above is that, when the initial number of coding bits is less than the target number of coding bits, a scaling factor of (i-1)th cyclic processing in the first cyclic manner is scaled based on a first step, to obtain the scaling factor of the ith cyclic processing. In this case, the continuous scaling condition includes that the ith number of coding bits is less than the target number of coding bits.When the initial number of coding bits is larger than the target number of coding bits, a scale factor of the (i)th cyclic processing in the first cyclic manner is scaled based on a second step to obtain the scale factor of the ith cyclic processing. In this case, the continuous scaling condition includes that the ith number of coding bits is larger than the target number of coding bits. That a scale factor of the (i-1)th cyclic processing of the first cyclic manner is scaled based on a first stage may refer to increasing the scale factor of the (i-1)th cyclic processing based on the first stage, and that a scale factor of the (i-1)th cyclic processing of the first cyclic manner is scaled based on a second stage may refer to decreasing the scale factor of the (i-1)th cyclic processing based on the second stage. Incremental processing and decremental processing can be linear or nonlinear. For example, a sum of the scale factor of the (i-1)th cyclic processing and the first stage can be determined as the scale factor of the (i-1)th cyclic processing, or a difference between the scale factor of the (i-1)th cyclic processing and the second stage can be determined as the scale factor of the (i-i)th cyclic processing. It should be noted that the first and second stages can be pre-set, and the first and second stages can be adjusted based on different requirements. Furthermore, the first stage can be the same as or different from the second stage. In a third implementation, when the initial number of encoding bits is less than or equal to the target number of encoding bits, a first initial scale factor ML / is determined as the first variable scale factor. When the initial number of encoding bits is greater than the target number of encoding bits, the first variable scale factor may be determined according to the first implementation above. Alternatively, the first variable scale factor may be determined when the initial number of encoding bits is greater than the target number of encoding bits in the second implementation above. In a third case, based on the first case, the method further includes the following steps: determining a second variable scaling factor based on the first latent variable; obtaining an entropy coding result of a fourth latent variable, where the fourth latent variable is obtained by scaling a third latent variable based on the second variable scaling factor, and the third latent variable is determined based on the second latent variable by using a context model, and the third latent variable indicates a probability distribution of the second latent variable; and writing the entropy coding result of the fourth latent variable and an coding result of the second variable scaling factor into the bit stream.A total amount of encoding bits of the entropy encoding result of the second latent variable and encoding bits of the entropy encoding result of the third latent variable meets the preset encoding rate condition. There are two ways to determine the first variable scale factor and the second variable scale factor based on the first latent variable. These methods are as follows: In a first implementation, a corresponding initial number of context coding bits and an initial entropy coding model parameter are determined based on the first latent variable by using the context model, a number of coding bits of an entropy coding result of the first latent variable is determined based on the initial entropy coding model parameter, to obtain a basic initial number of coding bits, the first variable scaling factor and the second variable scaling factor are determined based on the initial number of context coding bits, the basic initial number of coding bits, and the target number of coding bits. In a second implementation, the first preset scaling factor is used as the first initial scaling factor, and a second preset scaling factor is used as a second initial scaling factor. The first latent variable is scaled based on the first initial scaling factor, a corresponding initial number of context coding bits and an initial entropy coding model parameter are determined based on a scaled first latent variable and the second initial scaling factor by using ινίΛ / of a context model, and a number of coding bits of an entropy coding result of the first latent variable is determined based on the initial entropy coding model parameter, to obtain a basic initial number of coding bits.The first variable scale factor and the second variable scale factor are determined based on the initial number of context coding bits, the initial basic number of coding bits, and a target number of coding bits. The context model includes a context encoding neural network model and a context decoding neural network model. An implementation process for determining, based on the first scaled latent variable and the second initial scaling factor using the context model, the corresponding initial number of context coding bits, the corresponding initial number of context coding bits, and the initial entropy coding model parameter includes: processing the first scaled latent variable using the context coding neural network model to obtain a sixth latent variable, where the sixth latent variable indicates a probability distribution of the first scaled latent variable; scaling the sixth latent variable based on the second initial scaling factor to obtain a seventh latent variable;determining an entropy encoding result of the seventh latent variable and using a number of encoding bits of the entropy encoding result of the seventh latent variable as the initial number of context encoding bits; and reconstructing the seventh latent variable based on the entropy encoding result of the seventh latent variable, and processing, by using the context decoding neural network model, the seventh latent variable obtained through the reconstruction, to obtain the initial entropy coding model parameter. An implementation process for scaling the sixth latent variable based on the second initial scaling factor is as follows: multiply each element in the sixth latent variable by a corresponding element in the second initial scaling factor, to obtain the scaled seventh latent variable. It should be noted that the above implementation process is merely an example, and during actual application, another method may be used for scaling. For example, each element in the sixth latent variable may be divided by a corresponding element in the second initial scaling factor to obtain the seventh latent variable. A scaling method is not limited in this embodiment of this application. There may be two implementation processes for determining the first variable scale factor and the second variable scale factor based on the initial number of context encoding bits, the initial base encoding bit number, and the target encoding bit number. The implementation processes are described separately below. In a first implementation, the second variable scale factor is set to the second initial scale factor, and a target basic number of encoding bits is determined based on the target number of encoding bits and at least one of the initial basic number of encoding bits and the initial number of context encoding bits. The first variable scale factor and an actual basic number of encoding bits are determined based on the second initial scale factor, the target basic number of encoding bits, and the initial basic number of encoding bits, where the actual basic number of encoding bits is a number of encoding bits of an entropy encoding result of a first latent variable scaled based on the first variable scale factor.A target number of context coding bits is determined based on the target number of coding bits and the actual base number of coding bits. The second variable scale factor is determined based on the target number of context coding bits and the initial number of context coding bits. An implementation process for determining the target basic number of coding bits based on the target number of coding bits and at least one of the initial basic number of coding bits and the initial context coding bits includes: subtracting the initial context coding bit number from the target number of coding bits, to obtain the target basic number of coding bits; determining a ratio of the initial basic number of coding bits to the initial context coding bits, and determining the target basic number of coding bits based on the ratio and the target number of coding bits; or determining the target basic number of coding bits based on a ratio of the target number of coding bits to the initial basic number of coding bits.Certainly, it can be further determined by using another implementation process. There are also three implementations for determining the first variable scale factor based on the second initial scale factor, the target base number of encoding bits, and the initial base number of encoding bits. The implementations are described separately below. Form 11: When the initial basic number of coding bits is equal to the target basic number of coding bits, the first initial scaling factor is determined as the first variable scaling factor. When the initial basic number of coding bits is not equal to the target basic number of coding bits, the first variable scaling factor is determined in a first cyclic manner based on the initial basic number of coding bits and the target basic number of coding bits. The 1st cyclic processing of the first cyclic form includes the following stages: ινίΛ / determining a scaling factor of the j-th cyclic processing, where i is a positive integer; scaling the first latent variable based on the scaling factor of the j-th cyclic processing, to obtain a j-th first scaled latent variable; determining, based on the i-th first latent variable scaled by using the context model, an i-th number of coding bits and a j-th entropy coding model parameter, determining a number of coding bits of an entropy coding result of the i-th scaled latent variable based on the i-th entropy coding model parameter, to obtain a i-th basic number of coding bits, and determining an i-th number of coding bits based on the i-th number of context coding bits and the i-th basic number of coding bits;and when the ith encoding bit quantity satisfies a continuous scaling condition, performing an (i+1)th cyclic processing in the first cyclic manner; or when the ¡-th encoding bit quantity does not satisfy a continuous scaling condition, terminating execution of the first cyclic manner and determining the first variable scaling factor based on the scaling factor of the ¡-th cyclic processing; Form 12: When the initial basic coding bit number is equal to the target basic coding bit number, the first initial scaling factor is determined as the first variable scaling factor. When the initial basic coding bit number is not equal to the target basic coding bit number, the first variable scaling factor is determined in Form 11 above. However, one difference from Form 11 above is that when the initial basic coding bit number is smaller than the target basic coding bit number, a scaling factor of (-1) without cyclic processing in the first cyclic form is scaled based on a first step to obtain the ith cyclic processing scaling factor. In this case, the continuous scaling condition includes that the ith coding bit number is smaller than the target basic coding bit number.When the initial basic coding bit count is larger than the target basic coding bit count, a scale factor of the (i)th cyclic processing in the first cyclic manner is scaled based on a second step to obtain the scale factor of the ith cyclic processing. In this case, the continuous scaling condition includes that the ith coding bit count is larger than the target basic coding bit count. Form 13: When the initial basic coding bit number is less than or equal to the target basic coding bit number, the first initial scaling factor is determined as the first variable scaling factor. When the initial coding bit number is greater than the target basic coding bit number, the first variable scaling factor may be determined in the above form 11. Alternatively, the first variable scaling factor ΜΛ / can be determined when the initial basic number of coding bits is greater than the target basic number of coding bits in the above form 12. An implementation process for determining the second variable scaling factor based on the target number of context coding bits and the initial number of context coding bits is similar to the implementation process for determining the first variable scaling factor based on the initial base coding bit number and the target base coding bit number. Three methods are described separately below. Form 21: When the initial number of context coding bits is equal to the target number of context coding bits, the second initial scaling factor is determined as the second variable scaling factor. When the initial number of context coding bits is not equal to the target number of context coding bits, the first latent variable is scaled based on the first variable scaling factor, to obtain the second latent variable. The second variable scaling factor is determined in a first cyclic manner based on the initial number of context coding bits, the target number of context coding bits, and the second latent variable. The ith cyclic processing of the first cyclic manner includes the following steps: determining a scaling factor of the ith cyclic processing, where i is a positive integer; determining, based on the second latent variable and the scaling factor of the ith cyclic processing using the context model, an ith number of context coding bits and an ith entropy coding model parameter; determining a number of coding bits of an entropy coding result of the second latent variable based on the ith entropy coding model parameter, to obtain an ith basic number of coding bits; and determining an ith number of coding bits based on the ith number of context coding bits and the ith basic number of coding bits;and when the ith encoding bit quantity satisfies a continuous scaling condition, performing an (i+1)th cyclic processing in the first cyclic manner; or when the ith encoding bit quantity does not satisfy a continuous scaling condition, terminating execution of the first cyclic manner and determining the second variable scaling factor based on the scaling factor of the ith cyclic processing. An implementation process for determining, based on the second latent variable and the scaling factor of the ith cyclic processing by using the context model, the ith number of context coding bits and the ith entropy coding model parameter includes: processing the second latent variable by using the context coding neural network model, to obtain a third latent variable, where the third latent variable indicates a probability distribution of the second latent variable; scaling the third latent variable ινίΛ / based on the scaling factor of the ith cyclic processing, to obtain a scaled ith third latent variable;determining an entropy coding result of the ith-th scaled latent variable, and using an amount of coding bits of the entropy coding result of the ith-th scaled latent variable as the ith amount of context coding bits; reconstructing the ith-th scaled latent variable based on the entropy coding result of the ith-th scaled latent variable; scaling an ith reconstructed third latent variable based on the scaling factor of the ith cyclic processing, to obtain a reconstructed third latent variable; and processing the reconstructed third latent variable using the context decoding neural network model, to obtain the ith parameter of the entropy coding model. Form 22: When the initial number of context coding bits is equal to the target number of context coding bits, the second initial scaling factor is determined as the second variable scaling factor. When the initial number of context coding bits is not equal to the target number of context coding bits, the second variable scaling factor is determined in the above form 21. However, a difference from the above form 21 is that when the initial number of context coding bits is smaller than the target number of coding bits, a scaling factor of (i-1 )th cyclic processing of the first cyclic form is scaled based on a first step, to obtain the scaling factor of the ith cyclic processing.In this case, the continuous scaling condition includes that the ith number of coding bits is smaller than the target number of context coding bits. When the initial number of context coding bits is larger than the target number of context coding bits, a scale factor of the (i-1)th cyclic processing in the first cyclic manner is scaled based on a second stage, to obtain the scale factor of the ith cyclic processing. In this case, the continuous scaling condition includes that the ith number of coding bits is larger than the target number of context coding bits. Form 23: When the initial number of context coding bits is less than or equal to the target number of context coding bits, the second initial scaling factor is determined as the second variable scaling factor. When the initial number of context coding bits is greater than the target number of context coding bits, the second variable scaling factor may be determined in the above form 21. Alternatively, the second variable scaling factor may be determined when the initial number of context coding bits is greater than the target number of context coding bits in the above form 22. In a second implementation, the target number of encoding bits is divided ινίΛ / into a target basic number of encoding bits and a target number of context encoding bits, and the first variable scaling factor is determined based on the target basic number of encoding bits and the initial basic number of encoding bits. The second variable scaling factor is determined based on the target number of context encoding bits and the initial number of context encoding bits. According to a second aspect, an encoding method is provided. The method is also described in a plurality of embodiments. In a first embodiment, the method includes the following steps: determining a second reconstructed latent variable and a first reconstructed variable scaling factor based on a bit stream; scaling the second reconstructed latent variable based on the first reconstructed variable scaling factor to obtain a first reconstructed latent variable, wherein the first reconstructed latent variable indicates a characteristic of the media data to be decoded; and processing the first reconstructed latent variable using a first decoding neural network model to obtain reconstructed media data. In a second embodiment, the method includes the following steps: determining a third reconstructed latent variable and a first reconstructed variable scaling factor based on a bit stream; determining a second reconstructed latent variable based on the bit stream and the third reconstructed latent variable; scaling the second reconstructed latent variable based on the first reconstructed variable scaling factor to obtain a first reconstructed latent variable, wherein the first reconstructed latent variable indicates a characteristic of the media data to be decoded; and processing the first reconstructed latent variable using a first decoding neural network model to obtain reconstructed media data. Determining a reconstructed second latent variable based on the bit stream and the reconstructed third latent variable includes: processing the reconstructed third latent variable by using a context decoding neural network model to obtain a reconstructed first entropy coding model parameter; and determining the reconstructed second latent variable based on the bit stream and the reconstructed first entropy coding model parameter. In a third embodiment, the method includes the following steps: determining a fourth reconstructed latent variable, a second reconstructed variable scaling factor, and a first reconstructed variable scaling factor based on a bit stream; determining a second reconstructed latent variable based on the bit stream, the fourth reconstructed latent variable, and the second reconstructed variable scaling factor; determining the second reconstructed latent variable based on the bit stream and a third reconstructed latent variable; scaling the second reconstructed latent variable based on the first reconstructed variable scaling factor ινίΛ / to obtain a first reconstructed latent variable, wherein the first reconstructed latent variable indicates a characteristic of the media data to be decoded; and processing the first reconstructed latent variable using a first decoding neural network model to obtain reconstructed media data. Determining a second reconstructed latent variable based on the bit stream, the fourth reconstructed latent variable, and the second reconstructed variable scaling factor includes: scaling the fourth reconstructed latent variable based on the second reconstructed variable scaling factor to obtain a third reconstructed latent variable; processing the third reconstructed latent variable by using the context decoding neural network model to obtain a second reconstructed entropy coding model parameter; and determining the second reconstructed latent variable based on the bit stream and the second reconstructed entropy coding model parameter. Media data is an audio signal, a video signal, or an image. According to a third aspect, an encoding apparatus is provided. The encoding apparatus has the function of implementing the behavior of the encoding method according to the first aspect. The encoding apparatus includes at least one module, and the at least one module is configured to implement the encoding method according to the first aspect. According to a fourth aspect, a decoding apparatus is provided. The decoding apparatus has the function of implementing the behavior of the decoding method according to the second aspect. The decoding apparatus includes at least one module, and the at least one module is configured to implement the decoding method according to the second aspect. According to a fifth aspect, an encoder-side device is provided. The encoder-side device includes a processor and a memory. The memory is configured to store a program for performing the encoding method according to the first aspect. The processor is configured to execute the program stored in the memory, to implement the encoding method according to the first aspect. Optionally, the encoder-side device may further include a communication bus, and the communication bus is configured to establish a connection between the processor and the memory. According to a sixth aspect, a decoder-side device is provided. The decoder-side device includes a processor and a memory. The memory is configured to store a program for performing the decoding method according to the second aspect. The processor is configured to execute the program stored in the memory, to implement the ivia / decoding method according to the second aspect. Optionally, the decoder-side device may further include a communication bus, and the communication bus is configured to establish a connection between the processor and the memory. According to a seventh aspect, a computer-readable storage medium is provided. The storage medium stores instructions. When the instructions are executed on a computer, the computer is enabled to perform the encoding method steps according to the first aspect or the decoding method steps according to the second aspect. According to an eighth aspect, a computer program product is provided including instructions. When the instructions are executed on a computer, the computer is enabled to perform the encoding method steps according to the first aspect or the decoding method steps according to the second aspect. Alternatively, a computer program is provided. When the computer program is executed, the encoding method steps according to the first aspect or the decoding method steps according to the second aspect are implemented. According to a ninth aspect, a computer-readable storage medium is provided. The computer-readable storage medium includes a bit stream obtained by using the encoding method according to the first aspect. The technical effects obtained in the third aspect, fourth aspect, fifth aspect, sixth aspect, seventh aspect, eighth aspect, and ninth aspect are similar to the technical effects obtained through the corresponding technical means in the first aspect or second aspect. Details are not described again here. The technical solutions provided in the modalities of this application can achieve at least the following beneficial effects. The first latent variable is scaled based on the first variable scale factor to obtain the second latent variable, and the number of coding bits of the entropy coding result of the second latent variable satisfies the predetermined coding rate condition. This ensures that the number of coding bits of an entropy coding result of a latent variable corresponding to each frame of multimedia data can meet the predetermined coding rate condition, that is, the number of coding bits of the entropy coding result of the latent variable corresponding to each frame of multimedia data can be substantially consistent, rather than dynamically changing, thereby meeting the requirement of an encoder for a stable coding rate.In addition, when the complementary information (e.g., a window type, a temporal noise shaping parameter (TNS: Temporal ινίΛ / . Noise Shaping), a frequency-domain noise shaping (FDNS) parameter, and / or a bandwidth extension (BWE) parameter, requires to be transmitted, it can be guaranteed that the number of coding bits of the latent variable entropy coding result corresponding to each frame of media data is basically consistent with a number of coding bits of the side information, thereby meeting the encoder's requirement for stable coding rate. BRIEF DESCRIPTION OF THE DRAWINGS FIGURE 1 is a schematic diagram of a deployment environment in accordance with one embodiment of this application. FIGURE 2 is a schematic diagram of a terminal scene implementation environment according to an embodiment of this application. FIGURE 3 is a schematic diagram of a deployment environment of a transcoding scenario of a wireless or backbone network device according to an embodiment of this application. FIGURE 4 is a schematic diagram of an implementation environment of a radio and television scene according to an embodiment of this application. FIGURE 5 is a schematic diagram of an implementation environment of a virtual reality streaming scene according to an embodiment of this application. FIGURE 6 is a flow diagram of a first encoding method according to an embodiment of this application. FIGURE 7 is a schematic diagram of one form of a first latent variable according to one embodiment of this application. FIGURE 8 is a schematic diagram of one form of a second latent variable according to one embodiment of this application. FIGURE 9 is a flow diagram of a first decoding method according to an embodiment of this application. FIGURE 10 is a flow diagram of a second encoding method according to an embodiment of this application. FIGURE 11 is a flow diagram of a second decoding method according to an embodiment of this application. FIGURE 12 is an example block diagram of an encoding method shown in FIGURE 10 in accordance with one embodiment of this application. FIGURE 13 is an example block diagram of a decoding method shown in FIGURE 11 in accordance with one embodiment of this application. ινίΛ / FIGURE 14 is a flow diagram of a third encoding method according to one embodiment of this application. FIGURE 15 is a flow diagram of a third decoding method according to an embodiment of this application. FIGURE 16A and FIGURE 16B are an example block diagram of an encoding method shown in FIGURE 14 in accordance with one embodiment of this application. FIGURE 17 is an example block diagram of a decoding method shown in FIGURE 15 in accordance with one embodiment of this application. FIGURE 18 is a schematic diagram of a structure of an encoding apparatus according to an embodiment of this application. FIGURE 19 is a schematic diagram of a structure of a decoding apparatus according to an embodiment of this application; and FIGURE 20 is a schematic diagram of an encoding and decoding apparatus according to an embodiment of this application. DETAILED DESCRIPTION OF THE INVENTION To clarify the objectives, technical solutions and advantages of the modalities of this application, the following further describes in detail the implementations of this application with reference to the attached drawings. Before explaining and describing in detail the encoding and decoding method provided in the embodiments of this application, the terms and implementation environments in the embodiments of this application are first described. To facilitate understanding, the terms in the modalities of this application are first explained. Encoding is a process of compressing media data to be encoded into a bitstream. The media data to be encoded mainly includes an audio signal, a video signal, and an image. Audio signal encoding is a processing process for compressing a sequence of audio frames included in an audio signal to be encoded into a bitstream; video signal encoding is a processing process for compressing a sequence of images included in a video to be encoded into a bitstream; and image encoding is a processing process for compressing an image to be encoded into a bitstream. It should be noted that after being compressed into the bitstream, media data may be called encoded media data or compressed media data. For example, for an audio signal, after the audio signal is compressed into the bitstream, the audio signal may be called an encoded audio signal or a compressed audio signal; after the video signal is compressed into the bitstream, the video signal may also be called an encoded video signal or a compressed video signal; and after the image is compressed into the bitstream, the image may also be called a coded image or a compressed image. Decoding is a processing process for restoring an encoded bitstream to reconstructed media data according to a specific syntax rule and processing method. Decoding an audio bitstream is a processing process for restoring the audio bitstream to a reconstructed audio signal, decoding a video bitstream is a processing process for restoring the video bitstream to a reconstructed video signal, and decoding an image bitstream is a processing process for restoring the image bitstream to a reconstructed image. Entropy coding is a type of coding in which no information is lost based on the principle of entropy during coding. In other words, it is a lossless data compression method. Entropy coding is performed based on the probability of occurrence of an element, that is, for the same element, when the probabilities of occurrence of the element are different, the number of coding bits of the entropy coding results of the element are different. Entropy coding generally includes arithmetic coding (arithmetic coding), range coding (RC), Huffman coding (Huffman), and the like. A constant bit rate (CBR) means that the encoding bit rate is a constant value. For example, a constant value is a target encoding bit rate. A variable bit rate (VBR) means that an encoding rate can exceed a target encoding bit rate, or can be less than a target encoding bit rate, but a difference between the encoding rate and the target encoding bit rate is small. The implementation environments in the modalities of this request are described below. FIGURE 1 is a schematic diagram of a deployment environment according to one embodiment of this application. The deployment environment includes a source apparatus 10, a destination apparatus 20, a link 30, and a storage apparatus 40. The source apparatus 10 may generate encoded media data. Therefore, the source apparatus 10 may also be referred to as a media data encoding apparatus. The destination apparatus 20 may decode the encoded media data generated by the source apparatus 10. Therefore, the source apparatus 20 may also be referred to as a media data decoding apparatus. The link 30 may receive the encoded media data generated by the source apparatus 10, and may transmit the encoded media data to the destination apparatus 20. The storage apparatus 40 may receive the encoded media data generated by the source apparatus 10, and may store the encoded media data.In this case, the destination apparatus 20 may directly obtain the encoded media data from the storage apparatus 40. Alternatively, the storage apparatus 40 may correspond to a file server or other intermediate storage apparatus that can store the encoded media data generated by the source apparatus 10. In this case, the destination apparatus 20 may perform streaming or download the encoded media data stored in the storage apparatus 40. Both the source apparatus 10 and the destination apparatus 20 may include one or more processors and a memory coupled to the one or more processors. The memory may include random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory, or any other medium that can be used to store the required program code in the form of instructions or a data structure accessible by a computer or the like.For example, both the source apparatus 10 and the destination apparatus 20 may include a desktop computer, a mobile computing apparatus, a portable computer (e.g., a laptop), a tablet computer, a set-top box apparatus, a telephone handset such as a so-called smartphone, a television, a camera, a display apparatus, a digital media player, a video game console, an in-vehicle computer, or the like. The link 30 may include one or more means or apparatus that can transmit the encoded media data from the source apparatus 10 to the destination apparatus 20. In one possible implementation, the link 30 may include one or more communication media that may allow the source apparatus 10 to directly send the encoded media data to the destination apparatus 20 in real time. In this embodiment of this application, the source apparatus 10 may modulate the encoded media data based on a communication standard. The communication standard may be a wireless communication protocol or the like, and may send modulated media data to the destination apparatus 20. The one or more communication media may include a wireless and / or wired communication medium. For example, the one or more communication media may include a radio frequency (RF) frequency spectrum or one or more physical transmission lines.The one or more communication media may be part of a packet-based network, and the packet-based network may be a local area network, a wide area network, a global network (e.g., the Internet), or the like. The one or more communication media may include a router, a switch, a base station, another device that facilitates communication from the source device 10 to the destination device 20, or the like. This is not particularly limited to this embodiment of this application. In one possible implementation, the storage apparatus 40 may store received encoded media data sent by the source apparatus 10, and the destination apparatus 20 may directly obtain the encoded media data from the storage apparatus 40. In such a condition, the storage apparatus 40 may include any of a plurality of distributed or locally accessible data storage media. For example, any of the plurality of distributed or locally accessed data storage media may be a hard disk drive, a Blu-ray disc, a digital versatile disc (DVD), a CD-ROM (compact disc read-only memory, CD-ROM), flash memory, volatile or non-volatile memory, or any other suitable digital storage medium used to store the encoded media data. In one possible implementation, the storage apparatus 40 may correspond to a file server or other intermediate storage apparatus that can store the encoded media data generated by the source apparatus 10, and the destination apparatus 20 may stream or download the media data stored on the storage apparatus 40. The file server may be any type of server that can store the encoded media data and send the encoded media data to the destination apparatus 20. In one possible implementation, the file server may include a network server, a file transfer protocol (FTP) server, a network attached storage (NAS) apparatus, a local disk drive, or the like.The destination apparatus 20 may obtain the encoded media data via any standard data connection (including an Internet connection). Any such standard data connection may include a wireless channel (e.g., a Wi-Fi connection), a wired connection (e.g., a digital subscriber line (DSL) or a cable modem), or a combination of the wireless channel and wired connection suitable for obtaining the encoded media data stored on the file server. Transmission of the encoded media data from the storage apparatus 40 may be streaming, downloading, or a combination thereof. The implementation environment shown in FIG. 1 is merely one possible implementation. Furthermore, the technology in this embodiment of this application is not only applicable to the source apparatus 10 capable of encoding media data and the destination apparatus 20 capable of decoding the encoded media data shown in FIG. 1, but is also applicable to other apparatus capable of encoding the media data and decoding the encoded media data. This is not particularly limited to this embodiment of this application. In the implementation environment shown in FIG. 1, the source apparatus 10 includes a data source 120, an encoder 100, and an output interface 140. In some embodiments, the output interface 140 may include a modulator / demodulator (modem) and / or a sender. The sender may also be referred to as a transmitter. The data source 120 may include an image capture apparatus (e.g., a camera), a file containing previously captured media data, a feed interface for receiving media data from a media data content provider, and / or a computer graphics system for generating media data, or a combination of these media data sources. The data source 120 may send media data to the encoder 100. The encoder 100 may encode the received media data sent by the data source 120 to obtain encoded media data. The encoder may send the encoded media data to the output interface. In some embodiments, the source apparatus 10 directly sends the encoded media data to the destination apparatus 20 through the output interface 140. In another embodiment, the encoded media data may be further stored in the storage apparatus 40, such that the destination apparatus 20 subsequently obtains the encoded media data and uses the encoded media data for decoding and / or display. In the implementation environment shown in FIG. 1, the destination apparatus 20 includes an input interface 240, a decoder 200, and a display apparatus 220. In some embodiments, the input interface 240 includes a receiver and / or a modem. The input interface 240 may receive the encoded media data via the link 30 and / or from the storage apparatus 40, and then send the encoded media data to the decoder 200. The decoder 200 may decode the received encoded media data to obtain decoded media data. The decoder may send the decoded media data to the display apparatus 220. The display apparatus 220 may be integrated with the destination apparatus 20 or may be disposed outside of the destination apparatus 20. Generally, the display apparatus 220 displays the decoded media data.The display apparatus 220 may be any of a plurality of display apparatus. For example, the display apparatus 220 may be a liquid crystal display (LCD), a plasma display, an organic light-emitting diode (OLED) display, or another type of display apparatus. Although not shown in FIG. 1, in some aspects, the encoder 100 and the encoder / decoder 200 may be respectively integrated with an encoder and a decoder, and may include an appropriate multiplexer-demultiplexer (MUX-DEMUX) unit or other hardware and software for encoding both audio and video into a shared data stream or separate data streams. In some embodiments, if applicable, the MUX-DEMUX unit may comply with the ITU H.223 multiplexer protocol or another protocol such as a user datagram protocol (UDP). The encoder 100 and the decoder 200 may each be any of the following circuits: one or more microprocessors, a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA), discrete logic, hardware, or any combination thereof. If the technology in this embodiment of this application is partially implemented in software, the apparatus may store, on an appropriate non-volatile computer-readable storage medium, instructions used for the software, and may use one or more processors to execute the instructions in hardware, to implement the technology in this embodiment of this application.Any of the foregoing (including hardware, software, a combination of hardware and software, and the like) may be considered as one or more processors. The encoder 100 and the decoder 200 may each be included in one or more encoders or decoders. Any of the encoders or decoders may be integrated as part of a combined encoder / decoder (codec) in a corresponding apparatus. In this embodiment of this application, the encoder 100 may generally be referred to as signaling or sending some information to another apparatus, for example, the decoder 200. The term “signaling” or “sending” may generally refer to the transmission of syntax elements and / or other data used to decode compressed media data. Such transmission may occur in real time or near real time. Alternatively, the communication may occur after a period of time, for example, it may occur when a syntax element is stored on a computer-readable storage medium in an encoded bit stream during encoding, and the decoding apparatus may retrieve the syntax element at any time after the syntax element is stored on the medium. The encoding and decoding method provided in the embodiments of this application can be applied to a variety of scenes. Several scenes are described separately below using an example in which the media data to be encoded is an audio signal. FIGURE 2 is a schematic diagram of an implementation environment in which an encoding and decoding method is applied to a terminal scene according to an embodiment of this application. The implementation environment includes a first terminal 101 and a second terminal 201, and the first terminal 101 and the second terminal 201 are in communication connection. The communication connection may be a wireless connection or may be a wired connection. This is not limited in this embodiment of this application. The first terminal 101 may be a transmitting end device, or it may be a receiving end device. Similarly, the second terminal 201 may be a receiving end device, or it may be a transmitting end device. If the first terminal 101 is a transmitting end device, the second terminal 201 is a receiving end device. If the first terminal 101 is a receiving end device, the second terminal 201 is a transmitting end device. Descriptions are provided below by using an example in which the first terminal 101 is a transmitting end device and the second terminal 201 is a receiving end device. The first terminal 101 may be the source apparatus 10 in the implementation environment shown in FIGURE 1. The second terminal 201 may be the destination apparatus 20 in the implementation environment shown in FIGURE 1. Both the first terminal 101 and the second terminal 201 include an audio capture module, an audio playback module, an encoder, a decoder, a channel encoding module, and a channel decoding module. The audio capture module in the first terminal 101 captures an audio signal and transmits the audio signal to the encoder. The encoder encodes the audio signal using the encoding method provided in this embodiment of this application. The encoding may be referred to as source encoding. Then, to transmit the audio signal on a channel, the channel encoding module further needs to perform channel encoding, and then transmit, on a digital channel by using a wireless or wired network communication device, a bit stream obtained through the encoding. The second terminal 201 receives, using a wired or wireless network communication device, the bit stream transmitted on the digital channel. The channel decoding module performs channel decoding on the bit stream. The decoder then obtains the audio signal through decoding using the decoding method provided in this embodiment of this application, and then reproduces the audio signal using the audio playback module. The first terminal 101 and the second terminal 201 may be any electronic product that can perform human-computer interaction with a user in one or more ways, such as a keyboard, a touchpad, a touch screen, a remote control, a touch device, or a computer. M / voice interaction or a handwriting device, for example, a personal computer (PC), a mobile phone, a smartphone, a personal digital assistant (PDA), a handheld device, a pocket PC (PPC), a tablet computer, a smart head unit, a smart TV, or a smart speaker. One skilled in the art should understand that the above terminal is merely an example. If another existing or future terminal is applicable to the embodiments of this application, it should also be within the scope of protection of the embodiments of this application and is included herein by reference. FIGURE 3 is a schematic diagram of a deployment environment in which an encoding and decoding method is applied to a transcoding scenario of a wireless or backbone network device according to an embodiment of this application. The deployment environment includes a channel decoding module, an audio decoder, an audio encoder, and a channel encoding module. The audio decoder may be a decoder that uses the decoding method provided in the embodiments of this application, or it may be a decoder that uses another decoding method. The audio encoder may be an encoder that uses the encoding method provided in the embodiments of this application, or it may be an encoder that uses another encoding method. When the audio decoder is the decoder that uses the decoding method provided in the embodiments of this application, the audio encoder is the encoder that uses another encoding method. When the audio decoder is the decoder that uses the other decoding method, the audio encoder is an encoder that uses the encoding method provided in the embodiments of this application. In a first case, the audio decoder is the decoder that uses the decoding method provided in the embodiments of this application, and the audio encoder is the encoder that uses the other encoding method. In this case, the channel decoding module is configured to perform channel decoding on a received bit stream. The audio decoder is configured to perform source decoding using the decoding method provided in the embodiments of this application. The audio encoder then performs encoding using the other encoding method. Conversion from one format to another, i.e., transcoding, is implemented. The data is then sent after channel encoding. In a second case, the audio decoder is the decoder that uses the other decoding method, the audio encoder is the encoder that uses the other decoding method. ML / coding provided in the modalities of this application. In this case, the channel decoding module is configured to perform channel decoding on a received bit stream. The audio decoder is configured to perform source decoding using another decoding method. The audio encoder then performs encoding using the encoding method provided in the embodiments of this application. Conversion from one format to another, i.e., transcoding, is implemented. The data is then sent after channel encoding. The wireless device may be a wireless access point, a wireless router, a wireless connector, or the like. The backbone device may be a mobility management entity, a gateway, or the like. One skilled in the art should understand that the above wireless device or backbone device is merely an example. If another wireless or backbone network device, existing or future, is applicable to the embodiments of this application, it should also be within the scope of protection of the embodiments of this application, and is included herein by reference. FIG. 4 is a schematic diagram of an implementation environment in which an encoding and decoding method is applied to a radio and television scene according to an embodiment of this application. The radio and television scene includes a live continuous broadcast scene and a post-production scene. For the live broadcast scene, the implementation environment includes a live program three-dimensional sound production module, a three-dimensional sound encoding module, a decoding apparatus, and a speaker group. The decoding apparatus includes a three-dimensional sound decoding module. For the post-production scene, the implementation environment includes a post-program three-dimensional sound production module, a three-dimensional sound encoding module, a network receiver, a mobile terminal, a headset, and the like. In the live broadcast scenario, the three-dimensional sound production module of the live program produces a three-dimensional sound signal. The three-dimensional sound signal is encoded using the encoding method in the embodiments of this application to obtain a bit stream. The bit stream is transmitted to the user side via a radio and television network. A three-dimensional sound decoder in the decoding apparatus decodes the bit stream using the decoding method provided in the embodiments of this application, to reconstruct the three-dimensional sound signal. The speaker array reproduces a reconstructed three-dimensional sound signal. Alternatively, the bit stream is transmitted to the user side via the Internet.A three-dimensional sound decoder in a network receiver decodes the bit stream using the decoding method provided in embodiments of this application to reconstruct the three-dimensional sound signal. The speaker array reproduces a reconstructed three-dimensional sound signal. Alternatively, the bit stream is transmitted to the user via the Internet. A three-dimensional sound decoder in a mobile terminal decodes the bit stream using the decoding method provided in embodiments of this application to reconstruct the three-dimensional sound signal. The handset reproduces a reconstructed three-dimensional sound signal. In the post-production scene, the post-production three-dimensional sound production module produces a three-dimensional sound signal. The three-dimensional sound signal is encoded using the encoding method in the embodiments of this application to obtain a bit stream. The bit stream is transmitted to the user side via a radio and television network. A three-dimensional sound decoder in a decoding apparatus decodes the bit stream using the decoding method provided in the embodiments of this application, to reconstruct the three-dimensional sound signal. The speaker array reproduces a reconstructed three-dimensional sound signal. Alternatively, the bit stream is transmitted to the user side via the Internet.A three-dimensional sound decoder in the network receiver decodes the bit stream using the decoding method provided in the embodiments of this application to reconstruct the three-dimensional sound signal. The speaker array reproduces a reconstructed three-dimensional sound signal. Alternatively, the bit stream is transmitted to the user via the Internet. A three-dimensional sound decoder in the mobile terminal decodes the bit stream using the decoding method provided in the embodiments of this application to reconstruct the three-dimensional sound signal. The handset reproduces a reconstructed three-dimensional sound signal. FIGURE 5 is a schematic diagram of an implementation environment in which an encoding and decoding method is applied to a virtual reality streaming scene according to an embodiment of this application. The implementation environment includes an encoder side and a decoder side. The encoder side includes a capture module, a preprocessing module, an encoding module, an encapsulation module, and a sending module. The decoder side includes a decapsulation module, a decoding module, a rendering module, and a headset. The module captures an audio signal. Then, the preprocessing module performs a preprocessing operation. The preprocessing operation includes filtering a low-frequency portion of the signal, generally with 20 Hz or 50 Hz as the cutoff point, extracting orientation information from the signal, and the like. Then, the encoding module performs encoding processing by using the encoding method provided in the embodiments of this application. After encoding, the encapsulation module performs encapsulation. Then, the sending module sends an encapsulated signal to the decoder side. The decapsulation module on the decoder side first performs decapsulation. The decoding module performs decoding using the decoding method provided in the embodiments of this application. The rendering module then performs binaural rendering processing on a decoded signal. A signal obtained through the rendering processing is assigned to a headphone of a listener. The headphone may be a standalone headphone, or it may be a headphone in a virtual reality-based headset. The encoding and decoding method provided in embodiments of the present application is explained and described in detail below. It should be noted that, with reference to the implementation environment shown in FIG. 1 , any of the following encoding methods may be performed by the encoder 100 on the source apparatus 10. Any of the following decoding methods may be performed by the decoder 200 on the destination apparatus 20. It should be noted that the embodiments of this application may be applied to a codec that does not include a context model, or may be applied to a codec that includes a context model. Furthermore, in embodiments of this application, not only can a latent variable generated by using media data to be encoded be scaled based on a scale factor, but also a latent variable determined by using a context model can be scaled based on a scale factor. Therefore, the following explains and describes in detail the encoding and decoding method provided in embodiments of this application in a plurality of embodiments. Furthermore, the scale factor and a variable scale factor in embodiments of this application may be unquantized values, or they may be quantized values. This is not limited in the embodiments of this application. FIGURE 6 is a flowchart of a first encoding method according to an embodiment of this application. The method does not include a context model, and only a latent variable generated by using media data to be encoded is scaled based on a scale factor. The encoding method is applied to an encoder-side device and includes the following steps. Step 601: Process the media data to be encoded by using a first encoding neural network model, to obtain a first latent variable, where the first latent variable indicates a characteristic of the media data to be encoded. The media data to be encoded is an audio signal, a video signal, an image M / or similar. Furthermore, the media data to be encoded may be in any form. This is not limited to this embodiment of this application. For example, the media data to be encoded may be time-domain media data, or may be frequency-domain media data obtained by performing a time-frequency transform on the time-domain media data, for example, may be frequency-domain media data obtained by performing MDCT on the time-domain media data, or may be frequency-domain media data obtained by performing a fast Fourier transform (FFT) on the time-domain media data.Alternatively, the media data to be encoded may be complex frequency domain media data obtained by filtering time domain media data using a quadrature mirror filter (QMF), the media data to be encoded is a characteristic signal extracted from time domain media data, for example a Mel-Frequency Cepstral Coefficient, or the media data to be encoded may be a residual signal, for example another coded residual signal or a residual signal obtained by linear predictive coding (LPC) filtering. An implementation process for processing media data to be encoded using the first encoding neural network model is as follows: inputting the media data to be encoded into the first encoding neural network model to obtain the first latent variable output by the first encoding neural network model; or preprocessing the media data to be encoded, and inputting the preprocessed media data into the first encoding neural network model to obtain the first latent variable output by the first encoding neural network model. In other words, the media data to be encoded may be used as an input to the first encoding neural network model to determine the first latent variable, or the media data to be encoded may be preprocessed and then used as an input to the first encoding neural network model to determine the first latent variable. The preprocessing operation may be temporal noise shaping (TNS) processing, frequency-domain noise shaping (FDNS) processing, channel downmixing processing, or the like. The first encoding neural network model is trained in advance. A network structure and a training method of the first encoding neural network model are not limited in this embodiment of this application. For example, the network structure of the first encoding neural network model may be a fully connected network or a convolutional neural network (CNN). In addition, a ΜΛ / number of layers included in the network structure of the first coding neural network model and a number of nodes in each layer are also not limited in this embodiment of this application. The output forms of latent variables by encoding neural network models of different network structures may be different. For example, when the network structure of the first encoding neural network model is the fully connected network, the first latent variable is a vector, and M dimensions of the vector are the size of the latent variable (latent size), as shown in FIG. 7. When the network structure of the first encoding neural network model is the CNN network, the first latent variable is an N*M dimensional array, where N is the number of channels of the CNN network, and M is the size of a latent variable (latent size) of each channel of the CNN network, as shown in FIG. 8. It should be noted that FIG. 7 and FIG. 8 only provide a schematic diagram of the latent variable of the fully connected network and a schematic diagram of the latent variable of the CNN network.A channel sequence number can start from 1 or it can start from 0, and the sequence numbers of latent variable elements in all channels are the same. Step 602: Determining a first variable scaling factor based on the first latent variable, where the first variable scaling factor is used to enable an amount of encoding bits of an entropy coding result of a second latent variable to meet a preset coding rate condition, and the second latent variable is obtained by scaling the first latent variable based on the first variable scaling factor. In some embodiments, an initial number of encoding bits may be determined based on the first latent variable, and the first variable scale factor may be determined based on the initial number of encoding bits and a target number of encoding bits. The target number of coding bits may be preset. Of course, the target number of coding bits can also be determined based on a coding rate, and different coding rates correspond to different target numbers of coding bits. In this embodiment of this application, the media data to be encoded may be encoded at a constant bit rate, or the media data to be encoded may be encoded at a variable bit rate. When the media data to be encoded is encoded at the constant bit rate, a number of bits of the media data to be encoded in a current frame can be determined based on the constant bit rate, and then a number of used bits ινίΛ / is subtracted from the current frame, to obtain a target number of encoding bits in the current frame. The number of used bits may be a number of bits for encoding side information or the like. Furthermore, generally, the side information of each frame of media data is different. Therefore, a target number of encoding bits in each frame of media data is usually different. When media data to be encoded is encoded at a variable bit rate, a bit rate is typically specified, and the actual bit rate fluctuates around the specified bit rate. In this case, a bit count of the media data to be encoded in a current frame can be determined based on the specified bit rate, and then a number of bits used in the current frame is subtracted to obtain a target number of encoding bits in the current frame. The number of bits used may be a number of bits for encoding side information or the like. In some cases, the side information of different media data frames may be different. Therefore, the target number of encoding bits in different media data frames is usually different. The processes for determining the initial number of encoding bits and the first variable scale factor are explained and described in detail separately below. Determine the initial number of encoding bits There are two possible ways to determine the initial number of encoding bits based on the first latent variable. Each method is described separately below. In a first implementation, a number of encoding bits is determined from an entropy encoding result of the first latent variable to obtain the initial number of encoding bits. In other words, the initial number of encoding bits is the number of encoding bits of the entropy encoding result of the first latent variable. In one embodiment, quantization processing is performed on the first latent variable to obtain a quantized first latent variable. Entropy coding is performed on the first quantized latent variable to obtain an initial coding result of the first latent variable. A number of coding bits of the initial coding result of the first latent variable is counted to obtain the initial number of coding bits. There may be a plurality of ways to perform quantization processing on the first latent variable. For example, scalar quantization is performed on each element of the first latent variable. A quantization step of scalar quantization may be determined based on different coding rates. In other words, a correspondence between an coding rate and a quantization step is stored ινίΛ / in advance, and a corresponding quantization step may be obtained from the correspondence based on a coding rate used in this embodiment of this application. Additionally, the scalar quantization may further have an offset, that is, after the shift processing is performed on the first latent variable based on the offset, scalar quantization is performed based on the quantization step. When entropy coding is performed on the first quantized latent variable, the entropy coding may be performed based on a scalable entropy coding model, or the entropy coding may be performed using an entropy coding model with a pre-established probability distribution. This is not limited in this embodiment of this application. The entropy coding may use arithmetic coding (arithmetic coding), range coding (RC), or Huffman coding (Huffman). This is not limited in this embodiment of this application. It should be noted that the following quantization processing method and entropy coding method are similar to those of the present invention. For the following quantization processing method and entropy coding method, see the methods in the present invention. Details are not described below in this embodiment of this application. In a second implementation, the first latent variable is scaled based on a first initial scale factor, and a number of encoding bits is determined from an entropy encoding result of a scaled first latent variable to obtain the initial number of encoding bits. In other words, the initial number of encoding bits is the number of encoding bits of the entropy encoding result of the first latent variable scaled based on the first initial scale factor. The first initial scale factor may be a preset first scale factor. In one embodiment, the first latent variable is scaled based on the first initial scale factor to obtain the first scaled latent variable, and quantization processing is performed on the first scaled latent variable to obtain a first quantized latent variable. Entropy coding is performed on the first quantized latent variable to obtain an initial coding result of the first latent variable. A number of coding bits of the initial coding result of the first latent variable is counted to obtain the initial number of coding bits. An implementation process for scaling the first latent variable based on the first initial scaling factor is as follows: multiply each element in the first latent variable by a corresponding element in the first initial scaling factor, to obtain the first scaled latent variable. It should be noted that the above implementation process is simply an example, and In actual implementation, another method may be used for scaling. For example, each element in the first latent variable may be divided by a corresponding element in the first initial scaling factor to obtain the first scaled latent variable. A scaling method is not limited in this embodiment of this application. It should be noted that in this embodiment of this application, an initial value of a scale factor is set for the first latent variable, and the initial value of the scale factor is typically equal to 1. The first preset scale factor may be greater than or equal to the initial value of the scale factor, or it may be less than the initial value of the scale factor. For example, the first preset scale factor is a constant such as 1 or 2. When determining the initial number of encoding bits in the first implementation, the first initial scale factor is the initial value of the scale factor. When determining the initial number of encoding bits in the second implementation, the first initial scale factor is the first preset scale factor. Furthermore, the first initial scaling factor may be a scalar or a vector. For example, the network structure of the first coding neural network model is assumed to be a fully connected network, the first latent variable output by the first coding neural network model is a vector, and the number of dimensions M of the vectors is a size of the first latent variable (latent size). If the first initial scaling factor is a scalar, the scaling factor values corresponding to all elements in the first latent variable, the number of dimensions M and which is a vector, are the same, that is, the first initial scaling factor includes one element.If the first initial scale factor is a vector, the scale factor values corresponding to all elements in the first latent variable vector whose number of dimensions is M and which is a vector are not equal, and a plurality of elements may share a scale factor value, that is, the first initial scale factor includes a plurality of elements, and each element corresponds to one or more elements in the first latent variable. Similarly, the network structure of the first encoding neural network model is assumed to be CNN network, the first latent variable output by the first encoding neural network model is an N*M dimensional array, where N is a number of channels of the CNN network, and M is a size of a latent variable (latent size) of each channel of the CNN network. If the first initial scaling factor is a scalar, the scaling factor values corresponding to all elements in the first N*M dimensional latent variable array are the same, that is, the first initial scaling factor includes one element.If the first initial scale factor is a vector, the scale factor values corresponding to all elements in the first N*M dimensional latent variable array are not the same, and latent variable elements falling within the same channel may ινίΛ / correspond to the same scale factor value, that is, the first initial scale factor includes N elements, and each element corresponds to M elements with the same channel sequence number in the first latent variable. Determine the first variable scale factor The first variable scale factor is a final value of a scale factor of the first latent variable. A second latent variable is obtained by scaling the first latent variable based on the first variable scale factor, and the number of coding bits of the entropy coding result of the second latent variable satisfies the preset coding rate condition. When the media data to be encoded is encoded at the constant bit rate, satisfying a preset coding rate condition includes that the number of coding bits is less than or equal to a target number of coding bits.Alternatively, satisfying a preset encoding rate condition includes that the number of encoding bits is less than or equal to the target number of encoding bits, and a difference between the number of encoding bits and the target number of encoding bits is less than a bit number threshold. When the media data to be encoded is encoded at the variable bit rate, satisfying a preset encoding rate condition includes that an absolute value of a difference between the number of encoding bits and a target number of encoding bits is less than a bit number threshold.In other words, satisfying a pre-set encoding rate condition includes the number of encoding bits being less than or equal to the target number of encoding bits, and a difference between the target number of encoding bits and the number of encoding bits being less than the bit number threshold. Alternatively, satisfying a pre-set encoding rate condition includes the number of encoding bits being greater than or equal to the target number of encoding bits, and the difference between the number of encoding bits and the target number of encoding bits being less than the bit number threshold. It should be noted that the bit count threshold can be preset, and the bit count threshold can be adjusted based on different requirements. There may be a variety of implementations for determining the first variable scale factor based on the initial number of encoding bits and the target number of encoding bits. Three implementations are described below. In a first implementation, when the initial number of encoding bits is equal to the target number of encoding bits, the first initial scaling factor is determined as the first variable scaling factor. When the initial number of encoding bits is not equal to the target number of encoding bits, the first variable scaling factor is determined in a first cyclic manner based on the initial number of encoding bits and the target number of encoding bits. The ith cyclic processing of the first cyclic manner includes the following steps: determining a scaling factor of the ith cyclic processing, where i is a positive integer; scaling the first latent variable based on the scaling factor of the ith cyclic processing, to obtain an ith-first scaled latent variable; determining a number of encoding bits of an entropy coding result of the ith-first scaled latent variable, to obtain an ith number of coding bits; and when the ith number of coding bits meets a continuous scaling condition, performing (i+1)th cyclic processing of the first cyclic manner; or when the ith number of coding bits does not meet a continuous scaling condition, terminating execution of the first cyclic manner, and determining the first variable scaling factor based on the scaling factor of the ith cyclic processing. An implementation process for determining the scale factor of the ith cyclic processing is as follows: determining the scale factor of the ith cyclic processing based on a scale factor of the (i-1)th cyclic processing in the first cyclic manner, an (i-1)th number of coding bits, and the target number of coding bits. When i=1, the scale factor of the (i-1)th cyclic processing is the first initial scale factor, and the (i-1)th number of coding bits is the initial number of coding bits. In this case, the continuous scaling condition includes that both the (i-1)th number of coding bits and the ¡th number of coding bits are smaller than the target number of coding bits, or the continuous scaling condition includes that both the (i-l)th number of coding bits and the ith number of coding bits are larger than the target number of coding bits. In other words, the continuous scaling condition includes that the ith number of coding bits does not exceed the target number of coding bits. Herein, does not exceed means that a number of coding bits in the first (i-1) times is always less than the target number of coding bits, and the ith number of coding bits is still less than the target number of coding bits. Alternatively, a number of coding bits in the first (i-1) times is always greater than the target number of coding bits, and the ith number of coding bits is still greater than the target number of coding bits. Conversely, exceeds means that a number of coding bits in the first (i-1) times is always less than the target number of coding bits, and the ith number of coding bits is greater than the target number of coding bits.Alternatively, a number of coding bits in the first (i-1) times is always greater than the target number of coding bits, and the ith number of ινίΛ / coding bits is less than the target number of coding bits. In one example, when the scale factor is a quantized value, the scale factor of the (i-1)th cyclic processing may be determined based on the scale factor of the (i-1)th cyclic processing in the first cyclic manner, the (i-1)th number of coding bits, and the target number of coding bits according to the following formula (1). scaleíi) = Q |.síz / / <?(7 -1) * [target / curr(i - l)]j (1) In the above formula (1), scale(i) is the scale factor of the ith cyclic processing, scale(iY) is the scale factor of the (-l)th cyclic processing, target is the target number of encoding bits, and curr{iV) is the (i-1)th number of encoding bits, i is a positive integer greater than 0. Q {λ} is to obtain a quantized value of x . It should be noted that when the scale factor is a non-quantized value, when the scale factor of the µ-th cyclic processing is determined according to the above formula (1), the right side of the equation of the above formula (1) cannot be processed by using Q{%}. An implementation process for determining the first variable scale factor based on the scale factor of the ith cyclic processing includes: when the ith number of coding bits is equal to the target number of coding bits, determining the scale factor of the ith cyclic processing as the first variable scale factor; or when the ith number of coding bits is not equal to the target number of coding bits, determining the first variable scale factor based on the scale factor of the rth cyclic processing and the scale factor of the (i)th cyclic processing. In other words, the scale factor of the th cyclic processing is a scale factor obtained for the last time in the first cyclic manner, and the rth number of coding bits is a number of coding bits obtained for the last time. When the number of coding bits obtained for the last time is equal to the target number of coding bits, the scale factor obtained for the last time is determined as the first variable scale factor. When the number of coding bits obtained for the last time is not equal to the target number of coding bits, the first variable scale factor is determined based on the scale factors obtained the last two times. In some embodiments, an implementation process for determining the first variable scale factor based on the scale factor of the ith cyclic processing and the scale factor of the (i-1 )th cyclic processing includes: determining an average value of the scale factor of the ith cyclic processing and the scale factor of the (i-1 )th cyclic processing ινίΛ / and determining the first variable scale factor based on the average value. In one example, the average value can be determined directly as the first variable scale factor, or the average value can be multiplied by a preset constant to obtain the first variable scale factor. Optionally, the constant can be less than 1. In some embodiments, an implementation process for determining the first variable scale factor based on the scale factor of the ith cyclic processing and the scale factor of the (i-1)th cyclic processing includes: determining the first variable scale factor in a second cyclic manner based on the scale factor of the i-th cyclic processing and the scale factor of the (i-1)th cyclic processing. In one example, the jth cyclic processing of the second cyclic manner includes the following steps: determining a third scale factor of the jth cyclic processing based on a first scale factor of the jth cyclic processing and a second scale factor of the jth cyclic processing, where when j is equal to 1, the first scale factor of the jth cyclic processing is one of the scale factor of the i-th cyclic processing and the scale factor of the (i-1)th cyclic processing, the second scale factor of the jth cyclic processing is the other of the scale factor of the i-th cyclic processing and the scale factor of the (i-1)th cyclic processing, the first scale factor of the jth cyclic processing corresponds to a jth-first number of encoding bits, the second scale factor of the jth cyclic corresponds to a jth-second number of encoding bits,the jth-first number of coding bits is a number of coding bits of an entropy coding result of a first latent variable scaled based on the first scaling factor of the jth cyclic processing, the jth-second number of coding bits is a number of coding bits of an entropy coding result of a first latent variable scaled based on the second scaling factor of the jth cyclic processing, and the jth-first number of coding bits is less than the jth-second number of coding bits; obtaining a jth-third number of coding bits,where the jth-third number of coding bits is a number of coding bits of an entropy coding result of a first latent variable scaled based on the third scaling factor of the jth cyclic processing; and if the jth-third number of coding bits does not satisfy a continuous cycle condition, terminating the execution of the second cyclic manner and determining the third scaling factor of the jth cyclic processing as the first variable scaling factor; if the jth-third number of coding bits satisfies a continuous cycle condition, and is greater than the target number of coding bits and less than the jth-second number of coding bits,performing the (j+i)th cyclic processing in the second cyclic manner using the third scaling factor of the jth cyclic processing as a second scaling factor of the (j+i)th cyclic processing and using the first scaling factor of the jth cyclic processing as a first scaling factor of the (j+1)th cyclic processing; or if the jth-third number of coding bits satisfies a continuous cycle condition, and is less than the target number of coding bits and greater than the jth-first number of coding bits, performing the (j+1)th cyclic processing in the second cyclic manner by using the third scale factor of the jth cyclic processing as a first scale factor of the (j+i)th cyclic processing and using the second scale factor of the jth cyclic processing as a second scale factor of the (j+1)th cyclic processing., In another example, the jth cyclic processing of the second cyclic manner includes the following steps: determining a third scale factor of the jth cyclic processing based on a first scale factor of the jth cyclic processing and a second scale factor of the jth cyclic processing, where when j is equal to 1, the first scale factor of the jth cyclic processing is one of the scale factor of the ith cyclic processing and the scale factor of the (i-1)th cyclic processing, the second scale factor of the jth cyclic processing is the other of the scale factor of the i-th cyclic processing and the scale factor of the (i1)th cyclic processing, the first scale factor of the jth cyclic processing corresponds to a jth-first number of encoding bits, the second scale factor of the jth cyclic processing corresponds to a jth-second number of encoding bits,the jth-first number of encoding bits is less than the jth-second number of encoding bits, and j is a positive integer; obtaining a jth-third number of encoding bits, where the jth-third number of encoding bits is a number of encoding bits of an entropy encoding result of a first latent variable scaled based on the third scaling factor of the jth cyclic processing; and if the jth-third number of encoding bits does not satisfy a continuous cycle condition, terminating execution of the second cyclic manner, and determining the third scaling factor of the jth cyclic processing as the first variable scaling factor; if j reaches a maximum number of cycles and the jth-third number of encoding bits satisfies a continuous cycle condition, terminating execution of the second cyclic manner,and determining the first variable scaling factor based on the first scaling factor of the jth cyclic processing; if j does not reach a maximum number of cycles, and the jth-third number of the coding bits satisfy a continuous cycle condition, and is greater than the target number of coding bits and less than the jth-second number of coding bits, performing (j+i)th cyclic processing in the second cyclic manner by using the third scaling factor of the jth cyclic processing as a second scaling factor of the (j+1)th cyclic processing and using the first scaling factor of the jth cyclic processing as a first scaling factor of the (j+i)th cyclic processing; or if j does not reach a maximum number of cycles, and the jth-third number of coding bits satisfy a continuous cycle condition,and is less than the target number of coding bits and greater than the jth-first number of coding bits, performing the (j+i)th cyclic processing in the second cyclic manner using the third scale factor of the jth cyclic processing as a first scale factor of the (j+1)th cyclic processing and using the second scale factor of the jth cyclic processing as a second scale factor of the (j+1)th cyclic processing., An implementation process for determining the third scale factor of the jth cyclic processing based on the first scale factor of the jth cyclic processing and the second scale factor of the jth cyclic processing includes: determining an average value of the first scale factor of the jth cyclic processing and the second scale factor of the jth cyclic processing, and determining the third scale factor of the jth cyclic processing based on the average value. In one example, the average value may be directly determined as the third scale factor of the jth cyclic processing, or the average value may be multiplied by a preset constant to obtain the third scale factor of the jth cyclic processing. Optionally, the constant may be less than 1. Furthermore, an implementation process for obtaining the jth-third number of coding bits includes: scaling the first latent variable based on the third scaling factor of the cyclic processing ¡θ'5'10 to obtain a scaled first latent variable, and performing quantization processing on the scaled first latent variable to obtain a quantized first latent variable; and performing entropy coding on the first quantized latent variable, and counting a number of coding bits from an entropy coding result, to obtain the jth-third number of coding bits. When the media data to be encoded is encoded at a constant bit rate, an implementation process for determining the first variable scale factor based on the first scale factor of the jth cyclic processing includes: determining the first scale factor of the jth cyclic processing as the first variable scale factor.When the media data to be encoded is encoded at a variable bit rate, an implementation process for determining the first variable scaling factor based on the first scaling factor of the ijth cyclic processing includes: determining a first difference between the target number of encoding bits and the ijth-first number of encoding bits, and determining a second difference between the jth-number of encoding bits and the target number of encoding bits; and if the first difference is smaller than the second difference, determining the first scaling factor of the jth cyclic processing as the first variable scaling factor; if the second difference is smaller than the first difference, determining the second scaling factor of the jth cyclic processing as the first variable scaling factor; ινίΛ / or if the first difference is equal to the second difference, determine the first scale factor of the jth cyclic processing as the first variable scale factor, or determine the second scale factor of the jth cyclic processing as the first variable scale factor. When the media data to be encoded is encoded at a constant bit rate, the continuous cycle condition comprises: the jth-third number of encoding bits is greater than the target number of encoding bits, or the continuous cycle condition comprises: the jth-third number of encoding bits is less than the target number of encoding bits, and a difference between the target number of encoding bits and the jth-third number of encoding bits is greater than a threshold number of bits. When the media data to be encoded is encoded at a variable bit rate, the continuous cycle condition includes that an absolute value of a difference between the target number of encoding bits and the jth-third number of encoding bits is greater than a threshold number of bits.In other words, the continuous cycle condition includes that the jth-third number of coding bits is greater than the target number of coding bits, and a difference between the jth-third number of coding bits and the target number of coding bits is greater than the threshold number of bits, or the continuous cycle condition includes that the jth-third number of coding bits is less than the target number of coding bits, and the difference between the target number of coding bits and the jth-third number of coding bits is greater than the threshold number of bits. In other words, when the media data to be encoded is encoded at the constant bit rate, the continuous cycle condition includes: bits_curr > target || (bits_curr < target && (target-bits_curr) > TH), and when the media data to be encoded is encoded at the variable bit rate, the continuous cycle condition includes: bits_curr > target && (bits_curr-target) > TH || (bits_curr < target && (target-bits_curr) > TH). bits_curr is the jth-thirteenth encoding bit count, target is the target encoding bit count, and TH is the bit count threshold. The first scale factor of the jth cyclic processing can be denoted as scalejower, the jth-first number of encoding bits can be denoted as bitsjower, the second scale factor of the jth cyclic processing can be denoted as scale_upper, the jth-second number of encoding bits can be denoted as bits_upper, the third scale factor of the jth cyclic processing can be denoted as scale_curr, and the pseudocode for using the third scale factor of the jth cyclic processing as the first scale factor of the (j+1)th cyclic processing or the second scale factor of the (j+1)th cyclic processing is as follows: if bits_curr > target & bits_curr < bits_upper scale_upper = scale _curr ΜΛ / bits_upper = bits_curr furthermore, if if bits_curr < target & bits_curr >bits_lower scale_lower= scale_curr bitsjower = b¡ts_curr In a second implementation, when the initial number of coding bits is equal to the target number of coding bits, the first initial scaling factor is determined as the first variable scaling factor. When the initial number of coding bits is not equal to the target number of coding bits, the first variable scaling factor is determined according to the first implementation above. However, a difference from the first implementation above is that, when the initial number of coding bits is less than the target number of coding bits, a scaling factor of (i-1)th cyclic processing is scaled based on a first step, to obtain the scaling factor of ith cyclic processing. In this case, the continuous scaling condition includes that the ith number of coding bits is less than the target number of coding bits.When the initial number of coding bits is greater than the target number of coding bits, a scale factor of the (i-1)th cyclic processing is scaled based on a second stage to obtain the scale factor of the ith cyclic processing. In this case, the continuous scaling condition includes that the ith number of coding bits is greater than the target number of coding bits. That a scale factor of the (i-1)th cyclic processing is scaled based on a first stage may refer to increasing the scale factor of the (i-1)th cyclic processing based on the first stage, and that a scale factor of the (i-1)th cyclic processing in the first cyclic manner is scaled based on a second stage may refer to decreasing the scale factor of the (i-1)th cyclic processing based on the second stage. Incremental processing and decremental processing can be linear or nonlinear. For example, a sum of the scale factor of the (i-1 )th cyclic processing and the first stage can be determined as the scale factor of the (i-1 )th cyclic processing, or a difference between the scale factor of the (i-1 )th cyclic processing and the second stage can be determined as the scale factor of the (i-1 )th cyclic processing. It should be noted that the first and second stages can be pre-set, and the first and second stages can be adjusted based on different requirements. Furthermore, the first stage can be the same as or different from the second stage. In a third implementation, when the initial number of encoding bits is less than or equal to the target number of encoding bits, the first initial scale factor is determined as the first variable scale factor. When the initial number of encoding bits is greater than the target number of encoding bits, the first scale factor The variable ML / can be determined according to the first implementation above. Alternatively, the first variable scale factor can be determined when the initial number of encoding bits is greater than the target number of encoding bits in the second implementation above. Step 603: Obtain the entropy encoding result of the second latent variable. In the process of determining the first variable scaling factor in step 602, the first variable scaling factor may be the first initial scaling factor, may be the scaling factor of the 1st cyclic processing, may be the third scaling factor of the jth cyclic processing, or may be determined and obtained based on the first scaling factor of the jth cyclic processing. In either case, a corresponding entropy coding result is determined in the previous cycle process. Therefore, an entropy coding result corresponding to the first variable scaling factor, that is, the entropy coding result of the second latent variable, may be directly obtained from the entropy coding result determined in the previous cycle process. Certainly, the processing can be performed again. In other words, the first latent variable is scaled directly based on the first variable scale factor to obtain the second latent variable. Quantization processing is performed on the second latent variable to obtain a second quantized latent variable. Entropy coding is performed on the second quantized latent variable to obtain the entropy coding result of the second latent variable. Based on the above description, the first initial scale factor can be a scalar or a vector, and the first variable scale factor is determined based on the first initial scale factor. Therefore, the first initial scale factor can be a scalar or a vector. In other words, the first variable scale factor includes one or more items, and when the first variable scale factor includes a plurality of items, one item in the first variable scale factor corresponds to one or more items in the first latent variable. Step 604: Write the entropy encoding result of the second latent variable and an encoding result of the first variable scale factor into a bit stream. Based on the above description, the first variable scale factor may be an unquantized value, or it may be a quantized value. If the first variable scale factor is the unquantized value, an implementation process for determining the encoding result of the first variable scale factor includes: performing quantization and ML / encoding processing on the first variable scale factor, to obtain the encoding result of the first variable scale factor. If the first variable scale factor is the quantized value, an implementation process for determining the encoding result of the first variable scale factor includes: encoding the first variable scale factor, to obtain the encoding result of the first variable scale factor. The first variable scale factor can be encoded in any coding format. This is not limited to this application. Furthermore, for some encoders, a quantization process and an encoding process are performed in one process, that is, a quantization result and an encoding result can be obtained through one process. Therefore, for the first variable scale factor, the encoding result of the first variable scale factor can also be obtained in the previous process of determining the first variable scale factor. Therefore, the encoding result of the first variable scale factor can be obtained directly. In other words, the encoding result of the first variable scale factor can also be obtained directly in the process of determining the first variable scale factor. Optionally, if the first variable scale factor is the unquantized value, in this embodiment of this application, a quantization index corresponding to a quantization step of the first variable scale factor may be further determined to obtain a first quantization index. Optionally, in this embodiment of this application, a quantization index corresponding to a quantization step of the second latent variable may be further determined to obtain a second quantization index. The first quantization index and the second quantization index are encoded in the bit stream. The quantization index indicates a corresponding quantization step, i.e., the first quantization index indicates the quantization step of the first variable scale factor, and the second quantization index indicates the quantization step of the second latent variable. In this embodiment of this application, the first latent variable is scaled based on the first variable scaling factor to obtain the second latent variable, and the number of coding bits of the entropy coding result of the second latent variable satisfies the preset coding rate condition. This ensures that a number of coding bits of an entropy coding result of a latent variable corresponding to each frame of multimedia data can satisfy the preset coding rate condition, that is, the number of coding bits of the entropy coding result of the latent variable corresponding to each frame of multimedia data can be substantially consistent, rather than dynamically changing, thereby meeting an encoder's requirement for a stable coding rate.Furthermore, when side information (e.g., a window type, a temporal noise shaping (TNS) parameter, a frequency-domain noise shaping (FDNS) parameter, and / or a bandwidth extension (BWE) parameter) needs to be transmitted, the number of coding bits of the latent variable entropy coding result corresponding to each frame of media data can be guaranteed to be substantially consistent with a number of coding bits of the side information, thereby meeting the encoder's requirement for stable coding rate. FIGURE 9 is a flowchart of a first decoding method according to an embodiment of this application. The method is applied to one side of the decoder. The method corresponds to the encoding method shown in FIGURE 6. The method includes the following steps. Step 901: Determine a second reconstructed latent variable and a first reconstructed variable scale factor based on a bit stream. In some embodiments, entropy decoding may be performed on an entropy encoding result of a second latent variable in the bit stream, and an encoding result of a first variable scale factor in the bit stream may be decoded to obtain a quantized second latent variable and a first quantized variable scale factor. Dequantization processing is performed on the second quantized latent variable and the first quantized variable scale factor to obtain the reconstructed second latent variable and the reconstructed first variable scale factor. The decoding method at this stage corresponds to the encoding method on one side of the encoder, and the dequantization processing at this stage corresponds to the quantization processing on the encoder side. In other words, the decoding method is the reverse process of the encoding method, and the dequantization processing is the reverse process of the quantization processing. For example, the bit stream may be parsed to obtain a first quantization index and a second quantization index. The first quantization index indicates a quantization step of the first variable scale factor, and the second quantization index indicates a quantization step of the second latent variable. Dequantization processing is performed on the quantized first variable scale factor based on the quantization step indicated by the first quantization index to obtain the reconstructed first variable scale factor. Dequantization processing is performed on the quantized second latent variable based on the quantization step indicated by the second quantization index to obtain the second latent variable. Ml / rebuilt. Step 902: Scale the second reconstructed latent variable based on the first reconstructed variable scale factor, to obtain a first reconstructed latent variable, where the first reconstructed latent variable indicates a characteristic of the media data to be decoded. Because the second latent variable is obtained by scaling a first latent variable based on the first variable scale factor, the reconstructed second latent variable can be scaled based on the reconstructed first variable scale factor, to obtain the first reconstructed latent variable. A scaling process of the reconstructed second latent variable based on the reconstructed first variable scale factor is an inverse process of scaling the first latent variable on the encoder side. For example, when the encoder side multiplies each element in the first latent variable by a corresponding element in the first variable scale factor, each element in the reconstructed second latent variable may be divided by a corresponding element in the first reconstructed variable scale factor, to obtain the reconstructed first latent variable. When the encoder side divides each element in the first latent variable by a corresponding element in the first variable scale factor, each element in the reconstructed second latent variable may be multiplied by a corresponding element in the first reconstructed variable scale factor, to obtain the reconstructed first latent variable. Based on the above description, a first initial scaling factor may be a scaler or a vector. Therefore, the finally obtained first variable scaling factor may be a scaler or a vector. For example, a network structure of a first coding neural network model is assumed to be a fully connected network, the second latent variable is a vector, and the number M of dimensions of the vector is a size of the second latent variable (latent size). If the first variable scaling factor is a scalar, the scale factor values corresponding to all elements in the second latent variable whose number of dimensions is M and which is a vector are the same, that is, the first variable scaling factor includes one element.If the first variable scale factor is a vector, the scale factor values corresponding to all elements in the second latent variable vector whose number of dimensions is M and which is a vector are not equal, and a plurality of elements may share a scale factor value, that is, the second initial scale factor includes a plurality of elements, and each element corresponds to one or more elements in the second latent variable. Similarly, a network structure of the first encoding neural network model is assumed to be a CNN network, the second latent variable is an N*M dimensional array, ινίΛ / where N is a number of channels of the CNN network and M is a size of a latent variable (latent size) of each channel of the CNN network. If the first variable scaling factor is a scalar, the values of the scaling factor corresponding to all elements of the second N*M dimensional latent variable array are the same, that is, the first variable scaling factor includes one element.If the first variable scale factor is a vector, the scale factor values corresponding to all elements in the second N*M dimensional latent variable array are not the same, and latent variable elements falling within the same channel may correspond to the same scale factor value, that is, the second initial scale factor includes N elements, and each element corresponds to M elements with the same channel sequence number in the first latent variable. Step 903: Process the first reconstructed latent variable by using a first decoding neural network model, to obtain reconstructed media data. In some embodiments, the reconstructed first latent variable may be input into the first decoding neural network model to obtain reconstructed media data output by the first decoding neural network model. Alternatively, the reconstructed first latent variable is post-processed, and a post-processed first latent variable is input into the first decoding neural network model to obtain reconstructed media data output by the first decoding neural network model. In other words, the first reconstructed latent variable may be used as an input to the first decoding neural network model to determine the reconstructed media data, or the first reconstructed latent variable may be post-processed and then used as an input to the first decoding neural network model to determine the reconstructed media data. The first decoding neural network model corresponds to the first encoding neural network model, and both are pre-trained. A network structure and a training method of the first decoding neural network model are not limited in this embodiment of this application. For example, the network structure of the first decoding neural network model may be a fully connected network or a CNN network. Furthermore, a number of layers included in the network structure of the first decoding neural network model and a number of nodes in each layer are also not limited in this embodiment of this application. When the media data is an audio signal and a video signal, an output of the first decoding neural network model may be reconstructed time-domain media data, or it may be reconstructed frequency-domain media data. If the output is media data in the frequency domain, a transformation from the frequency domain to the time domain must be performed to obtain media data in the time domain. Alternatively, an output of the first decoding neural network model may be a residual signal. In this case, other corresponding processing must be performed to obtain the audio signal or the video signal. In this embodiment of this application, a number of coding bits of the entropy coding result of the second latent variable satisfies a predetermined coding rate condition. This ensures that a number of coding bits of an entropy coding result of a latent variable corresponding to each frame of multimedia data can satisfy the predetermined coding rate condition, that is, the number of coding bits of the entropy coding result of the latent variable corresponding to each frame of multimedia data can be substantially consistent, rather than dynamically changing, thereby meeting a requirement of an encoder for a stable coding rate.Furthermore, when side information (e.g., a window type, a temporal noise shaping (TNS) parameter, a frequency-domain noise shaping (FDNS) parameter, and / or a bandwidth extension (BWE) parameter) needs to be transmitted, the number of coding bits of the latent variable entropy coding result corresponding to each frame of media data can be guaranteed to be substantially consistent with a number of coding bits of the side information, thereby meeting the encoder's requirement for stable coding rate. FIGURE 10 is a flowchart of a second encoding method according to an embodiment of this application. The method includes a context model, but only a latent variable generated using media data to be encoded is scaled based on a scale factor. The encoding method is applied to an encoder-side device and includes the following steps. Step 1001: Process the media data to be encoded by using a first encoding neural network model, to obtain a first latent variable, where the first latent variable indicates a characteristic of the media data to be encoded. For a stage 1001 implementation process, see the stage 601 implementation process. Details are not described again here. Step 1002: Determine a first variable scale factor based on the first latent variable. In some embodiments, an initial number of coding bits may be determined based on the first latent variable, and the first variable scaling factor may be determined based on the initial number of coding bits and a target number of coding bits. For a related description of the target number of coding bits ινίΛ / , see the contents in step 602. Details are not described again herein. The processes for determining the initial number of coding bits and the first variable scaling factor are explained and described in detail separately below. Determine the initial number of encoding bits There are two possible ways to determine the initial number of encoding bits based on the first latent variable. Each method is described separately below. In a first implementation, a corresponding initial number of context coding bits and an initial entropy coding model parameter are determined based on the first latent variable by using the context model, a number of coding bits of an entropy coding result of the first latent variable is determined based on the initial entropy coding model parameter, to obtain a basic initial number of coding bits, and the initial number of coding bits is determined based on the initial number of context coding bits and the basic initial number of coding bits. The context model includes a context encoding neural network model and a context decoding neural network model. An implementation process for determining, based on the first latent variable using the context model, the corresponding initial number of context encoding bits and the initial entropy encoding model parameter includes: processing the first latent variable using the context encoding neural network model to obtain a fifth latent variable, where the fifth latent variable indicates a probability distribution of the first latent variable; determining an entropy encoding result of the fifth latent variable, and using a number of encoding bits of the entropy encoding result of the fifth latent variable as the initial number of context coding bits;and reconstructing the fifth latent variable based on the entropy coding result of the fifth latent variable, and processing, by using the context decoding neural network model, the fifth latent variable obtained through the reconstruction, to obtain the initial entropy coding model parameter.; In one example, the first latent variable is processed using the context coding neural network model to obtain a fifth latent variable. Quantization processing is performed on the fifth latent variable to obtain a quantized fifth latent variable. Entropy coding is performed on the quantized fifth latent variable, and a number of encoding bits of an entropy coding result are counted to obtain the initial number of context coding bits. Thereafter, entropy decoding is performed on the entropy coding result of the fifth latent variable to obtain the quantized fifth latent variable, and ινίΛ / dequantization processing is performed on the quantized fifth latent variable to obtain a reconstructed fifth latent variable.The reconstructed fifth latent variable is input into the context decoding neural network model, to obtain the initial entropy encoding model parameter output by the context decoding neural network model. An implementation process for processing the first latent variable by using the context coding neural network model is as follows: input the first latent variable into the context coding neural network model, to obtain the fifth latent variable output by the context coding neural network model; or obtain an absolute value of each element in the first latent variable, and then input the absolute value of each element in the first latent variable into the context coding neural network model, to obtain the fifth latent variable output by the context coding neural network model. An implementation process for determining the number of encoding bits of the entropy encoding result of the first latent variable based on the initial entropy coding model parameter, so as to obtain the basic initial number of encoding bits is as follows: determining, from entropy coding models with scalable coding model parameters, an entropy coding model corresponding to the initial entropy coding model parameter; performing quantization processing on the first latent variable, to obtain a quantized first latent variable; performing entropy coding on the first quantized latent variable based on the entropy coding model corresponding to the initial entropy coding model parameter, to obtain an initial coding result of the first latent variable;and counting a number of encoding bits from the initial encoding result of the first latent variable, to obtain the basic initial number of encoding bits.; For a quantization processing manner and an entropy encoding manner in step 1002, see the quantization processing manner and the entropy encoding manner in step 602. Details are not described again here. An implementation process for determining the initial number of encoding bits based on the initial number of context encoding bits and the initial basic number of encoding bits includes: determining a sum of the initial number of context encoding bits and the initial basic number of encoding bits as the initial number of encoding bits. Indeed, it may be further determined in another implementation. In a second implementation, the first latent variable is scaled based on a first initial scaling factor, a corresponding initial number of context coding bits and an initial entropy coding model parameter are determined based on ινίΛ / on a first scaled latent variable using the context model, and a number of coding bits of an entropy coding result of the scaled first latent variable is determined based on the initial entropy coding model parameter, to obtain a basic initial number of coding bits; and the initial number of coding bits is determined based on the initial number of context coding bits and the basic initial number of coding bits. The first initial scaling factor may be a preset first scaling factor. The context model includes a context encoding neural network model and a context decoding neural network model. An implementation process for determining, based on the first latent variable scaled by using the context model, the corresponding initial number of context encoding bits and the initial entropy encoding model parameter includes: processing the first latent variable scaled by using the context encoding neural network model, to obtain a sixth latent variable, where the sixth latent variable indicates a probability distribution of the first scaled latent variable; determining an entropy encoding result of the sixth latent variable, and using a number of encoding bits of the entropy encoding result of the sixth latent variable as the initial number of context coding bits;and reconstructing the sixth latent variable based on the entropy coding result of the sixth latent variable, and processing, by using the context decoding neural network model, the sixth latent variable obtained through the reconstruction, to obtain the initial entropy coding model parameter.; In one example, the first scaled latent variable is processed using the context coding neural network model to obtain a sixth latent variable. Quantization processing is performed on the sixth latent variable to obtain a quantized sixth latent variable. Entropy coding is performed on the sixth quantized latent variable, and a number of encoding bits of an entropy coding result are counted to obtain the initial number of context coding bits. Thereafter, entropy decoding is performed on the entropy coding result of the sixth latent variable to obtain the sixth quantized latent variable, and dequantization processing is performed on the sixth quantized latent variable to obtain a reconstructed sixth latent variable.The reconstructed sixth latent variable is input into the context decoding neural network model, to obtain the initial entropy encoding model parameter output by the context decoding neural network model. It should be noted that for other content in the second implementation, please refer to the previous descriptions of the corresponding stages. Details are not described again here. M / Determine the first variable scale factor The first variable scaling factor is a final value of a scaling factor of the first latent variable. A second latent variable is obtained by scaling the first latent variable based on the first variable scaling factor, a third latent variable is obtained by processing the second latent variable by using the context coding neural network model, and a total number of coding bits of an entropy coding result of the second latent variable and coding bits of an entropy coding result of the third latent variable meets a preset coding rate condition. When the media data to be encoded is encoded at a constant bit rate, meeting a preset coding rate condition includes that the number of coding bits is less than or equal to a target number of coding bits.Alternatively, satisfying a preset encoding rate condition includes that the number of encoding bits is less than or equal to the target number of encoding bits, and a difference between the number of encoding bits and the target number of encoding bits is less than a bit count threshold. When the media data to be encoded is encoded at a variable bit rate, satisfying a preset encoding rate condition includes that an absolute value of a difference between the number of encoding bits and a target number of encoding bits is less than a bit count threshold.In other words, satisfying a pre-set encoding rate condition includes the number of encoding bits being less than or equal to the target number of encoding bits, and a difference between the target number of encoding bits and the number of encoding bits being less than the bit number threshold. Alternatively, satisfying a pre-set encoding rate condition includes the number of encoding bits being greater than or equal to the target number of encoding bits, and the difference between the number of encoding bits and the target number of encoding bits being less than the bit number threshold. It should be noted that the bit count threshold can be preset, and the bit count threshold can be adjusted based on different requirements. There may be a variety of implementations for determining the first variable scale factor based on the initial number of encoding bits and the target number of encoding bits. Three implementations are described below. In a first implementation, when the initial number of encoding bits is equal to the target number of encoding bits, the first initial scale factor is determined as the first variable scale factor. When the initial number of encoding bits is not equal to the target number of encoding bits, the first variable scale factor is ML / is first determined cyclically based on the initial number of encoding bits and the target number of encoding bits. The jth cyclic processing of the first cyclic form includes the following steps: determining a scale factor of the i-th cyclic processing, where i is a positive integer; scaling the first latent variable based on the scale factor of the i-th cyclic processing, to obtain an i-th first scaled latent variable;determining, based on the ith-first latent variable scaled by using the context model, a corresponding ¡-th number of context coding bits and an ¡-th entropy coding model parameter, determining a number of coding bits of an entropy coding result of the j-first scaled latent variable based on the ¡-th entropy coding model parameter, to obtain an ith basic number of coding bits, and determining an ith number of coding bits based on the ith number of context coding bits and the ¡-th basic number of coding bits; and when the ¡-th number of coding bits meets a continuous scaling condition, performing an (i+1)th cyclic processing in the first cyclic manner;or when the ¡-th encoding bit quantity does not satisfy a continuous scaling condition, terminating the execution of the first cyclic manner and determining the first variable scaling factor based on the scaling factor of the ¡-th cyclic processing; For an implementation process for determining the scaling factor of the j-th cyclic processing, see the related description in step 602. Details are not described again here. For an implementation process for determining, based on the j-th latent variable scaled by using the context model, the ith number of context coding bits and the ith entropy coding model parameter, see the above process for determining the initial number of context coding bits and the initial entropy coding model parameter. Details are not described again here.For an implementation process for determining the number of encoding bits of the entropy encoding result of the ith scaled latent variable based on the !-th entropy encoding model parameter, refer to the previous process for determining the basic initial number of encoding bits based on the initial entropy coding model parameter. Details are not described again here. For an implementation process for determining the first variable scale factor based on the scale factor of the 1st cyclic processing, see the description in step 602. Details are not described again here. In a second implementation, when the initial number of encoding bits is equal to the target number of encoding bits, the first initial scale factor is determined ML / as the first variable scaling factor. When the initial number of coding bits is not equal to the target number of coding bits, the first variable scaling factor is determined according to the first implementation above. However, one difference from the first implementation above is that when the initial number of coding bits is smaller than the target number of coding bits, a scaling factor of (i-1)th cyclic processing in the first cyclic manner is scaled based on a first step, to obtain the scaling factor of the ith cyclic processing. In this case, the continuous scaling condition includes that the ith number of coding bits is smaller than the target number of coding bits.When the initial number of coding bits is greater than the target number of coding bits, a scale factor of the (i)th cyclic processing in the first cyclic manner is scaled based on a second step to obtain the scale factor of the ith cyclic processing. In this case, the continuous scaling condition includes that the ith number of coding bits is greater than the target number of coding bits. That a scale factor of the (i-l)th cyclic processing is scaled based on a first stage may refer to increasing the scale factor of the (i-l)th cyclic processing based on the first stage, and that a scale factor of the (i-l)th cyclic processing of the first cyclic form is scaled based on a second stage may refer to decreasing the scale factor of the (i-l)th cyclic processing based on the second stage. Incremental processing and decremental processing can be linear or nonlinear. For example, a sum of the scale factor of the (-l)th cyclic processing and the first stage can be determined as the scale factor of the (-l)th cyclic processing, or a difference between the scale factor of the (-l)th cyclic processing and the second stage can be determined as the scale factor of the (-l)th cyclic processing. It should be noted that the first and second stages can be pre-set, and the first and second stages can be adjusted based on different requirements. Furthermore, the first stage can be the same as or different from the second stage. In a third implementation, when the initial number of encoding bits is less than or equal to the target number of encoding bits, the first initial scaling factor is determined as the first variable scaling factor. When the initial number of encoding bits is greater than the target number of encoding bits, the first variable scaling factor may be determined according to the first implementation above. Alternatively, the first variable scaling factor may be determined when the initial number of encoding bits is greater than the target number of encoding bits in the second implementation above. Step 1003: Obtain the entropy coding result of the second latent variable ivia / and the entropy coding result of the third latent variable, where the second latent variable is obtained by scaling the first latent variable based on the first variable scaling factor, the third latent variable indicates a probability distribution of the second latent variable, and the total number of coding bits of the entropy coding result of the second latent variable and the coding bits of the entropy coding result of the third latent variable meets the preset coding rate condition. In the process of determining the first variable scaling factor in step 1002, the first variable scaling factor may be the first initial scaling factor, may be the scaling factor of the 1st cyclic processing, may be the third scaling factor of the jth cyclic processing, or may be determined based on the first scaling factor of the jth cyclic processing. In either case, a corresponding entropy coding result is determined in the previous cycle process. Therefore, the entropy coding result of the second latent variable and the entropy coding result of the third latent variable can be directly obtained from the entropy coding result determined in the previous cycle process. Certainly, the processing can be performed again. In other words, the first latent variable is directly scaled based on the first variable scale factor to obtain the second latent variable. The entropy coding result of the third latent coding and a first parameter of the entropy coding model are determined based on the second latent variable by using the context model. Quantization processing is performed on the second latent variable to obtain a quantized second latent variable. An entropy coding result of the quantized second latent variable, that is, the entropy coding result of the second latent variable, is determined based on the first parameter of the entropy coding model. The context model includes a context encoding neural network model and a context decoding neural network model. An implementation process for determining, based on the second latent variable using the context model, the entropy encoding result of the third latent encoding and the first parameter of the entropy encoding model includes: processing the second latent variable using the context encoding neural network model to obtain the third latent variable; performing quantization processing on the third latent variable to obtain a quantified third latent variable; performing entropy encoding on the quantified third latent variable to obtain the entropy encoding result of the third latent variable; performing entropy decoding on the entropy encoding result. ΜΛ / of the third latent variable to obtain a quantized third latent variable, and perform dequantization processing on the quantized third latent variable to obtain a reconstructed third latent variable; and process the reconstructed third latent variable by using the context decoding neural network model, to obtain the first parameter of the entropy coding model. An implementation process for determining the entropy encoding result of the second quantified latent variable based on the first entropy encoding model parameter includes: determining, from entropy coding models with scalable coding model parameters, an entropy coding model corresponding to the first entropy coding model parameter; and performing entropy encoding on the second quantified latent variable based on the entropy coding model corresponding to the first entropy coding model parameter, to obtain the entropy coding result of the second latent variable. Step 1004: Write the entropy encoding result of the second latent variable, the entropy encoding result of the third latent variable, and an encoding result of the first variable scale factor into a bit stream. For the related content of the encoding result of the first variable scale factor, see the description in step 604. Details are not described again here. Optionally, if the first variable scale factor is an unquantized value, in this embodiment of this application, a quantization index corresponding to a quantization step of the first variable scale factor may be further determined to obtain a first quantization index. Optionally, in this embodiment of this application, a quantization index corresponding to a quantization step of the second latent variable may be further determined to obtain a second quantization index, and a quantization index corresponding to a quantization step of the third latent variable may be further determined to obtain a third quantization index. The first quantization index, the second quantization index, and the third quantization index are encoded in the bit stream.The quantization index indicates a corresponding quantization stage, that is, the first quantization index indicates the quantization stage of the first variable scale factor, the second quantization index indicates the quantization stage of the second latent variable, and the third quantization index indicates the quantization stage of the third latent variable. In this embodiment of this application, the first latent variable is scaled based on the first variable scaling factor to obtain the second latent variable, the second latent variable is processed by using the context coding neural network model to obtain the third latent variable, and the total number of coding bits of the entropy coding result of the second latent variable and the coding bits of the entropy coding result of the third latent variable meet the pre-set coding rate condition.This ensures that a number of coding bits of an entropy coding result of a latent variable corresponding to each frame of multimedia data can meet the pre-set coding rate condition, that is, the number of coding bits of the entropy coding result of the latent variable corresponding to each frame of multimedia data can be basically consistent, rather than dynamically changing, thereby meeting a requirement of an encoder for a stable coding rate.Furthermore, when side information (e.g., a window type, a temporal noise shaping (TNS) parameter, a frequency-domain noise shaping (FDNS) parameter, and / or a bandwidth extension (BWE) parameter) needs to be transmitted, the number of coding bits of the latent variable entropy coding result corresponding to each frame of media data can be guaranteed to be substantially consistent with a number of coding bits of the side information, thereby meeting the encoder's requirement for stable coding rate. FIGURE 11 is a flowchart of a second decoding method according to an embodiment of this application. The method is applied to one side of the decoder. The method corresponds to the encoding method shown in FIGURE 10. The method includes the following steps. Step 1101: Determine a third reconstructed latent variable and a first reconstructed variable scale factor based on a bit stream. In some embodiments, entropy decoding may be performed on an entropy encoding result of a third latent variable in the bit stream, and an encoding result of a first variable scale factor in the bit stream may be decoded to obtain a quantized third latent variable and a first quantized variable scale factor. Dequantization processing is performed on the quantized third latent variable and the first quantized variable scale factor to obtain the reconstructed third latent variable and the reconstructed first variable scale factor. The decoding method at this stage corresponds to the encoding method on one side of the encoder, and the dequantization processing at this stage corresponds to the quantization processing on the encoder side. In other words, the decoding method is the reverse process of the encoding method, and the dequantization processing is the reverse process of the quantization processing. ινίΛ / For example, the bit stream may be parsed to obtain a first quantization index and a third quantization index. The first quantization index indicates a quantization step of the first variable scale factor, and the third quantization index indicates a quantization step of the third latent variable. Dequantization processing is performed on the quantized first variable scale factor based on the quantization step indicated by the first quantization index, to obtain the reconstructed first variable scale factor. Dequantization processing is performed on the quantized third latent variable based on the quantization step indicated by the third quantization index, to obtain the reconstructed third latent variable. Step 1102: Determine a second reconstructed latent variable based on the bit stream and the third reconstructed latent variable. In some embodiments, the reconstructed third latent variable is processed using a context decoding neural network model to obtain a first reconstructed entropy coding model parameter, and the reconstructed second latent variable is determined based on the bit stream and the first reconstructed entropy coding model parameter. In some embodiments, an entropy decoding model corresponding to the first parameter of the reconstructed entropy coding model may be determined. Entropy decoding is performed on an entropy coding result of a second latent variable in the bit stream based on the entropy decoding model corresponding to the first parameter of the reconstructed entropy coding model, to obtain a second quantized latent variable. Dequantization processing is performed on the second quantized latent variable, to obtain the reconstructed second latent variable. The decoding method at this stage corresponds to the encoding method on one side of the encoder, and the dequantization processing at this stage corresponds to the quantization processing on the encoder side. In other words, the decoding method is the reverse process of the encoding method, and the dequantization processing is the reverse process of the quantization processing. For example, the bit stream may be parsed to obtain a second quantization index, the second quantization index indicating a quantization step of the second latent variable. Dequantization processing is performed on the quantized second latent variable based on the quantization step indicated by the second quantization index, to obtain the reconstructed second latent variable. Step 1103: Scale the second reconstructed latent variable based on the first reconstructed variable scale factor, to obtain a first reconstructed latent variable, where ΜΛ / the first reconstructed latent variable indicates a characteristic of the media data to be decoded. For a step 1103 implementation process, see the step 902 implementation process. Details are not described again here. Step 1104: Process the first reconstructed latent variable by using a first decoding neural network model, to obtain reconstructed media data. For a step 1104 implementation process, see the step 903 implementation process. Details are not described again here. In this embodiment of this application, a total number of coding bits of the entropy coding result of the second latent variable and coding bits of the entropy coding result of the third latent variable satisfy the predetermined coding rate condition. This ensures that a number of coding bits of an entropy coding result of a latent variable corresponding to each frame of multimedia data can satisfy the predetermined coding rate condition, that is, the number of coding bits of the entropy coding result of the latent variable corresponding to each frame of multimedia data can be substantially consistent, rather than dynamically changing, thereby satisfying a requirement of an encoder for a stable coding rate.Furthermore, when side information (e.g., a window type, a temporal noise shaping (TNS) parameter, a frequency-domain noise shaping (FDNS) parameter, and / or a bandwidth extension (BWE) parameter) needs to be transmitted, the number of coding bits of the latent variable entropy coding result corresponding to each frame of media data can be guaranteed to be substantially consistent with a number of coding bits of the side information, thereby meeting the encoder's requirement for stable coding rate. FIGURE 12 is an exemplary block diagram of an encoding method according to an embodiment of this application. FIGURE 12 mainly explains the encoding method shown in FIGURE 10 as an example. In FIGURE 12, an audio signal is used as an example. Windowing processing may be performed on the audio signal to obtain an audio signal of a current frame. MDCT processing is performed on the audio signal of the current frame to obtain a frequency domain signal of the current frame. A first latent variable is generated by performing processing by a first encoding neural network model based on the frequency domain signal of the current frame. The first latent variable is scaled based on a first latent variable scaling factor to obtain a second latent variable.The second latent variable ινίΛ / is processed using a context coding neural network model to obtain a third latent variable. Quantization processing and entropy coding are performed on the third latent variable to obtain an entropy coding result of the third latent variable, and the entropy coding result of the third latent variable is written into a bit stream. Furthermore, entropy decoding is performed on the entropy coding result of the third latent variable to obtain a quantized third latent variable. Dequantization processing is performed on the quantized third latent variable to obtain a reconstructed third latent variable. The reconstructed third latent variable is processed using a context decoding neural network model to obtain a first entropy coding model parameter.An entropy coding model corresponding to the first parameter of the entropy coding model is selected from entropy coding models with scalable parameters. The second latent variable is quantized, entropy coding is performed on a second quantized latent variable based on the selected entropy coding model to obtain an entropy coding result of the second latent variable, and the entropy coding result of the second latent variable is written to the bit stream. Next, an encoding result of the first variable scaling factor is written to the bit stream. FIGURE 13 is an exemplary block diagram of a decoding method according to an embodiment of this application. FIGURE 13 mainly explains the decoding method shown in FIGURE 11 as an example. In FIGURE 13, an audio signal is used as an example. Entropy decoding is performed on an entropy coding result of a third latent variable in a bit stream by using an entropy decoding model, to obtain a quantized third latent variable. Dequantization processing is performed on the quantized third latent variable, to obtain a reconstructed third latent variable. The reconstructed third variable is processed by using a context decoding neural network model, to obtain a reconstructed first entropy coding model parameter.A corresponding entropy decoding model is selected based on the first parameter of the reconstructed entropy coding model from entropy decoding models with scalable parameters. Entropy decoding is performed on an entropy coding result of a second latent variable in the bit stream based on the selected entropy decoding model to obtain a quantized second latent variable. Dequantization processing is performed on the quantized second latent variable to obtain a reconstructed second latent variable. An coding result of a first variable scaling factor in the bit stream is decoded to obtain a reconstructed first variable scaling factor. The reconstructed second latent variable is scaled based on the reconstructed first variable scaling factor to obtain a reconstructed first latent variable.The first reconstructed latent variable is processed using a first decoding neural network model to obtain a reconstructed frequency-domain signal of a current frame. IMDCT processing and window removal processing are performed on the reconstructed frequency-domain signal of the current frame to obtain a reconstructed audio signal. FIGURE 14 is a flowchart of a third encoding method according to an embodiment of this application. The method includes a context model, and not only a latent variable generated by using media data to be encoded is scaled based on a scale factor, but also a latent variable determined by using the context model is scaled based on a scale factor. The encoding method is applied to an encoder-side device and includes the following steps. Step 1401: Process the media data to be encoded by using a first encoding neural network model, to obtain a first latent variable, where the first latent variable indicates a characteristic of the media data to be encoded. For a step 1401 implementation process, see the step 601 implementation process. Details are not described again here. Step 1402: Determine a first variable scale factor and a second variable scale factor based on the first latent variable. In some embodiments, a corresponding initial number of context coding bits and an initial entropy coding model parameter may be determined based on the first latent variable by using the context model, a number of coding bits of an entropy coding result of the first latent variable is determined based on the initial entropy coding model parameter, to obtain a basic initial number of coding bits, the first variable scaling factor and the second variable scaling factor are determined based on the initial number of context coding bits, the basic initial number of coding bits, and a target number of coding bits. For an implementation process for determining, based on the first latent variable by using the context model, the corresponding initial number of context coding bits and the initial entropy coding model parameter, and an implementation process for determining the number of coding bits of the entropy coding result of the first latent variable based on the initial entropy coding model parameter, to obtain the basic initial number of coding bits, see the related descriptions in step 1002. Details are not described again herein. In some other embodiments, a first preset scaling factor may be used as a first initial scaling factor, and a second preset scaling factor may be used as a second initial scaling factor. The first latent variable is scaled based on the first initial scaling factor, a corresponding initial number of context coding bits and an initial entropy coding model parameter are determined based on the scaled first latent variable and the second initial scaling factor by using the context model, and a number of coding bits of an entropy coding result of the first latent variable is determined based on the initial entropy coding model parameter, to obtain a basic initial number of coding bits.The first variable scale factor and the second variable scale factor are determined based on the initial number of context coding bits, the initial basic number of coding bits, and a target number of coding bits. For a process of implementing scaling of the first latent variable based on the first initial scaling factor, see the related description in step 1002. Details are not described again here. The context model includes a context encoding neural network model and a context decoding neural network model. An implementation process for determining, based on the first scaled latent variable and the second initial scaling factor using the context model, the corresponding initial number of context coding bits, the corresponding initial number of context coding bits, and the initial entropy coding model parameter includes: processing the first scaled latent variable using the context coding neural network model to obtain a sixth latent variable, where the sixth latent variable indicates a probability distribution of the first scaled latent variable; scaling the sixth latent variable based on the second initial scaling factor to obtain a seventh latent variable;determining an entropy encoding result of the seventh latent variable and using a number of encoding bits of the entropy encoding result of the seventh latent variable as the initial number of context encoding bits; and reconstructing the seventh latent variable based on the entropy encoding result of the seventh latent variable, and processing, by using the context decoding neural network model, the seventh latent variable obtained through the reconstruction, to obtain the initial entropy coding model parameter. In one example, the first scaled latent variable is processed using the context coding neural network model to obtain a sixth latent variable. The sixth latent variable is scaled based on the second initial scaling factor to obtain a seventh latent variable ινίΛ / . Quantization processing is performed on the seventh latent variable to obtain a quantized seventh latent variable. Entropy coding is performed on the seventh quantized latent variable, and a number of encoding bits of an entropy coding result are counted to obtain the initial number of context coding bits.Next, entropy decoding is performed on the entropy encoding result of the seventh latent variable to obtain the quantized seventh latent variable, and dequantization processing is performed on the quantized seventh latent variable to obtain a reconstructed seventh latent variable. The reconstructed seventh latent variable is input into the context decoding neural network model to obtain the initial entropy encoding model parameter output by the context decoding neural network model. An implementation process for scaling the sixth latent variable based on the second initial scaling factor is as follows: multiply each element in the sixth latent variable by a corresponding element in the second initial scaling factor, to obtain the scaled seventh latent variable. It should be noted that the above implementation process is merely an example, and during actual application, another method may be used for scaling. For example, each element in the sixth latent variable may be divided by a corresponding element in the second initial scaling factor to obtain the seventh latent variable. A scaling method is not limited in this embodiment of this application. For the specific implementation processes for the remaining stages, please refer to the previous descriptions of the corresponding stages. Details are not described again here. It should be noted that in this embodiment of this application, an initial value of a scale factor is set for a third latent variable, and the initial value of the scale factor is typically equal to 1. The second preset scale factor may be greater than or equal to the initial value of the scale factor, or it may be less than the initial value of the scale factor. For example, the second preset scale factor is a constant such as 1 or 2. When the first variable scale factor and the second variable scale factor are determined in the first implementation, the second initial scale factor is the initial value of the scale factor. When the first variable scale factor and the second variable scale factor are determined in the second implementation, the second initial scale factor is the second preset scale factor. Additionally, the second initial scale factor can be a scalar or a vector. For a specific description, see the related description of the first initial scale factor. ινίΛ / There may be two implementation processes for determining the first variable scaling factor and the second variable scaling factor based on the initial number of context coding bits, the initial base coding bit number, and the target coding bit number. The implementation processes are described separately below. In a first implementation, the second variable scale factor is set to the second initial scale factor, and a target basic number of encoding bits is determined based on the target number of encoding bits and at least one of the initial basic number of encoding bits and the initial number of context encoding bits. The first variable scale factor and an actual basic number of encoding bits are determined based on the second initial scale factor, the target basic number of encoding bits, and the initial basic number of encoding bits, where the actual basic number of encoding bits is a number of encoding bits of an entropy encoding result of a first latent variable scaled based on the first variable scale factor.A target number of context coding bits is determined based on the target number of coding bits and the actual base number of coding bits. The second variable scale factor is determined based on the target number of context coding bits and the initial number of context coding bits. An implementation process for determining the target basic number of coding bits based on the target number of coding bits and at least one of the initial basic number of coding bits and the initial context coding bits includes: subtracting the initial context coding bit number from the target number of coding bits, to obtain the target basic number of coding bits; determining a ratio of the initial basic number of coding bits to the initial context coding bits, and determining the target basic number of coding bits based on the ratio and the target number of coding bits; or determining the target basic number of coding bits based on a ratio of the target number of coding bits to the initial basic number of coding bits.Certainly, it can be further determined by using another implementation process. For example, the ratio of the initial base coding bit count to the initial context coding bit count is determined to be 5:3. In this case, the target coding bit count can be multiplied by 5 / 8 to obtain the target base coding bit count. For another example, the ratio of the target number of coding bits to the basic initial number of coding bits is determined. If the ratio of the target number of coding bits to the basic initial number of coding bits is greater than ML / a first ratio threshold, a sum of the initial basic number of coding bits and a first preset ratio scaling step is determined as the target basic number of coding bits. If the ratio of the target number of coding bits to the initial basic number of coding bits is less than a second ratio threshold, a difference between the initial basic number of coding bits and a second preset ratio scaling step is determined as the target basic number of coding bits. The first ratio threshold is greater than the second ratio threshold.If the ratio of the target number of coding bits to the basic initial number of coding bits is greater than or equal to a second ratio threshold and less than or equal to a first ratio threshold, the basic initial number of coding bits is determined as the target basic number of coding bits. It should be noted that the first ratio scaling stage may be greater than the second ratio scaling stage, or it may be less than the second ratio scaling stage, or indeed, it may be equal to the second ratio scaling stage. A value relationship between the first ratio scaling stage and the second ratio scaling stage is not limited in this embodiment of this application. There are also three implementations for determining the first variable scale factor based on the second initial scale factor, the target base number of encoding bits, and the initial base number of encoding bits. The implementations are described separately below. Form 11: When the initial basic number of coding bits is equal to the target basic number of coding bits, the first initial scaling factor is determined as the first variable scaling factor. When the initial basic number of coding bits is not equal to the target basic number of coding bits, the first variable scaling factor is determined in a first cyclic manner based on the initial basic number of coding bits and the target basic number of coding bits. The ¡-th cyclic processing of the first cyclic manner includes the following steps: determining a scaling factor of the ¡-th cyclic processing, where i is a positive integer; scaling the first latent variable based on the scaling factor of the ¡-th cyclic processing, to obtain an ith first scaled latent variable; determining, based on the ith first scaled latent variable by using the context model, an ¡-th number of encoding bits and an ¡-th entropy coding model parameter, determining a number of encoding bits of an entropy coding result of the ¡.th first latent variable scaled based on the ¡-th entropy coding model parameter, to obtain an ¡-th basic number of coding bits, and determine an ¡-th number of coding bits based on the ¡-th number of context coding bits and the ith basic number of coding bits; and when the ith number of coding bits meets a continuous scaling condition, performing a (+1)th cyclic processing in the first cyclic manner; or when the jth number of coding bits does not meet a continuous scaling condition, ending execution of the first cyclic manner and determining the first variable scaling factor based on the scaling factor of the ith cyclic processing. The content in form 11 of determining the first variable scaling factor is similar to the content in the first implementation of determining the first variable scaling factor in step 1002. One difference is that, in this step, the ith number of context coding bits and the rth entropy coding model parameter are determined based on the ith first scaled latent variable and the second initial scaling factor by using the context model. For an implementation process of determining, based on the ith scaled latent variable and the second initial scaling factor by using the context model, the ith number of context coding bits and e|th parameter of the entropy coding model, refer to the previous implementation process to determine, based on the first scaled latent variable and the second initial scaling factor using the context model, the corresponding initial number of context coding bits and the initial entropy coding model parameter. Details are not described again here. Form 12: When the initial basic coding bit amount is equal to the target basic coding bit amount, the first initial scaling factor is determined as the first variable scaling factor. When the initial basic coding bit amount is not equal to the target basic coding bit amount, the first variable scaling factor is determined in Form 11 above. However, a difference from Form 11 above is that when the initial basic coding bit amount is smaller than the target basic coding bit amount, a scaling factor of (i-1)th cyclic processing of the first cyclic manner is scaled based on a first step to obtain the scaling factor of ith cyclic processing. In this case, the continuous scaling condition includes that the ith coding bit amount is smaller than the target basic coding bit amount.When the initial basic coding bit count is larger than the target basic coding bit count, a scaling factor of the (i)th cyclic processing in the first cyclic manner is scaled based on a second step to obtain the scaling factor of the ith cyclic processing. In this case, the continuous scaling condition includes that the ith coding bit count is larger than the target basic coding bit count. For the related content of form 12, please refer to the content in the second ινίΛ / implementation at step 1002. Details are not described again here. Form 13: When the initial basic number of coding bits is less than or equal to the target basic number of coding bits, the first initial scaling factor is determined as the first variable scaling factor. When the initial number of coding bits is greater than the target basic number of coding bits, the first variable scaling factor may be determined in Form 11 above. Alternatively, the first variable scaling factor may be determined when the initial basic number of coding bits is greater than the target basic number of coding bits in Form 12 above. An implementation process for determining the target number of context coding bits based on the target number of coding bits and the basic actual number of coding bits includes: subtracting the basic actual number of coding bits from the target number of coding bits, to obtain the target number of context coding bits. An implementation process for determining the second variable scaling factor based on the target number of context coding bits and the initial number of context coding bits is similar to the implementation process for determining the first variable scaling factor based on the initial base coding bit number and the target base coding bit number. Three methods are described separately below. Form 21: When the initial number of context coding bits is equal to the target number of context coding bits, the second initial scaling factor is determined as the second variable scaling factor. When the initial number of context coding bits is not equal to the target number of context coding bits, the first latent variable is scaled based on the first variable scaling factor, to obtain the second latent variable. The second variable scaling factor is determined in a first cyclic manner based on the initial number of context coding bits, the target number of context coding bits, and the second latent variable. The ith cyclic processing of the first cyclic manner includes the following steps: determining a scaling factor of the ith cyclic processing, where i is a positive integer; determining, based on the second latent variable and the scaling factor of the ith cyclic processing using the context model, an ith number of context coding bits and an ith entropy coding model parameter; determining a number of coding bits of an entropy coding result of the second latent variable based on the ith entropy coding model parameter, to obtain an ith basic number of coding bits; and determining an ith number of coding bits based on the ith number of context coding bits and the ith basic number of coding bits;and when the ith number of coding bits meets a continuous scaling condition, performing a (+i)th cyclic processing in the first cyclic manner; or when the ith number of coding bits does not meet a continuous scaling condition, terminating execution of the first cyclic manner and determining the second variable scaling factor based on the scaling factor of the ith cyclic processing.; An implementation process for determining, based on the second latent variable and the scaling factor of the ith cyclic processing by using the context model, the ith number of context coding bits and the ith entropy coding model parameter includes: processing the second latent variable by using the context coding neural network model, to obtain a third latent variable, where the third latent variable indicates a probability distribution of the second latent variable; scaling the third latent variable based on the scaling factor of the ith cyclic processing, to obtain an ith scaled third latent variable;determining an entropy coding result of the ith-th scaled latent variable, and using an amount of coding bits of the entropy coding result of the ith-th scaled latent variable as the ¡®th amount of context coding bits; reconstructing the ¡®th scaled latent variable based on the entropy coding result of the ith-th scaled latent variable; scaling an ith reconstructed third latent variable based on the scaling factor of the ¡-th cyclic processing, to obtain a reconstructed third latent variable; and processing the reconstructed third latent variable using the context decoding neural network model, to obtain the ith parameter of the entropy coding model. For other steps, please refer to the corresponding content descriptions above. Details are not described again here. Form 22: When the initial number of context coding bits is equal to the target number of context coding bits, the second initial scaling factor is determined as the second variable scaling factor. When the initial number of context coding bits is not equal to the target number of context coding bits, the second variable scaling factor is determined in the above form 21. However, a difference from the above form 21 is that when the initial number of context coding bits is smaller than the target number of coding bits, a scaling factor of (i-1 )th cyclic processing of the first cyclic form is scaled based on a first step, to obtain the scaling factor of the ith cyclic processing.In this case, the continuous scaling condition includes that the ith number of coding bits is smaller than the target number of context coding bits. When the initial number of context coding bits is greater than the target number of context coding bits, via a scale factor of the (-i)th cyclic processing in the first cyclic manner is scaled based on a second stage, to obtain the scale factor of the ith cyclic processing. In this case, the continuous scaling condition includes that the ith number of coding bits is greater than the target number of context coding bits. Form 23: When the initial number of context coding bits is less than or equal to the target number of context coding bits, the second initial scaling factor is determined as the second variable scaling factor. When the initial number of context coding bits is greater than the target number of context coding bits, the second variable scaling factor may be determined in the above form 21. Alternatively, the second variable scaling factor may be determined when the initial number of context coding bits is greater than the target number of context coding bits in the above form 22. In a second implementation, the target number of encoding bits is divided into a target base number of encoding bits and a target number of context encoding bits, and the first variable scaling factor is determined based on the target base number of encoding bits and the initial base number of encoding bits. The second variable scaling factor is determined based on the target number of context encoding bits and the initial number of context encoding bits. When the first variable scale factor is determined based on the target basic number of coding bits and the initial basic number of coding bits, the second variable scale factor may be set as the second initial scale factor, and the first variable scale factor is determined based on the second initial scale factor, the target basic number of coding bits, and the initial basic number of coding bits. For a specific implementation process, see the previous description. Furthermore, when the second variable scaling factor is determined based on the target number of context coding bits and the initial number of context coding bits, the first variable scaling factor is already determined. In this case, the second variable scaling factor can be determined directly based on the first variable scaling factor, the target number of context coding bits, and the initial number of context coding bits. For a specific implementation process, see the previous description. Step 1403: Obtaining the entropy coding result of the second latent variable and an entropy coding result of a fourth latent variable, where the second latent variable is obtained by scaling the first latent variable based on the first variable scaling factor, the fourth latent variable is obtained by scaling the third latent variable based on the second variable scaling factor, the third latent variable is determined based on the second latent variable using the context model, and the third latent variable indicates a probability distribution of the second latent variable, and a total number of coding bits of the entropy coding result of the second latent variable and the coding bits of the entropy coding result of the fourth latent variable meet a preset coding rate condition. In the process of determining the first variable scaling factor and the second variable scaling factor in step 1402, an entropy coding result corresponding to a scaling factor of each cyclic processing in the previous cycle process is determined. Therefore, the entropy coding result of the second latent variable and the entropy coding result of the fourth latent variable can be directly obtained from the entropy coding result determined in the previous cycle process. Certainly, the processing can be performed again. In other words, the first latent variable is directly scaled based on the first variable scale factor to obtain the second latent variable. The entropy coding result of the fourth latent coding and a second parameter of the entropy coding model are determined based on the second latent variable by using the context model. Quantization processing is performed on the second latent variable to obtain a quantized second latent variable. An entropy coding result of the second quantized latent variable, that is, the entropy coding result of the second latent variable, is determined based on the second parameter of the entropy coding model. The context model includes a context encoding neural network model and a context decoding neural network model. An implementation process for determining, based on the second latent variable using the context model, the entropy encoding result of the fourth latent encoding and the second parameter of the entropy encoding model includes: processing the second latent variable using the context encoding neural network model to obtain the third latent variable; scaling the third latent variable based on the second variable scaling factor to obtain the fourth latent variable; performing quantization processing on the fourth latent variable to obtain a quantized fourth latent variable; performing entropy encoding on the quantized fourth latent variable to obtain the entropy encoding result of the fourth latent variable;performing entropy decoding on the entropy encoding result of the fourth latent variable to obtain a quantized fourth latent variable, and performing dequantization processing on the quantized fourth latent variable to obtain a reconstructed fourth latent variable; scaling the reconstructed fourth latent variable based on the second variable scaling factor, to obtain a reconstructed third latent variable; processing the reconstructed third latent variable by using context decoding of the neural network model, to obtain the second parameter of the entropy coding model. An implementation process for determining the entropy encoding result of the second quantified latent variable based on the second entropy encoding model parameter includes: determining, from entropy coding models with scalable coding model parameters, an entropy coding model corresponding to the second entropy coding model parameter; and performing entropy encoding on the second quantified latent variable based on the entropy coding model corresponding to the second entropy coding model parameter, to obtain an initial encoding result of the second latent variable. Step 1404: Write the entropy encoding result of the second latent variable, the entropy encoding result of the fourth latent variable, an encoding result of the first variable scale factor, and an encoding result of the second variable scale factor into a bit stream. For the related content of the encoding result of the first variable scale factor, see the description in step 604. Details are not described again here. Based on the above description, the second variable scale factor may be a non-quantized value, or it may be a quantized value. If the second variable scale factor is the non-quantized value, an implementation process for determining the encoding result of the second variable scale factor includes: performing quantization and encoding processing on the second variable scale factor, to obtain the encoding result of the second variable scale factor. If the second variable scale factor is the quantized value, an implementation process for determining the encoding result of the second variable scale factor includes: encoding the second variable scale factor, to obtain the encoding result of the second variable scale factor. The second variable scale factor may be encoded in any encoding manner. This is not limited in this embodiment of this application. In addition, for some encoders, a quantization process and an encoding process are performed in one processing, that is, a quantization result and an encoding result can be obtained through one processing. Therefore, for the second variable scale factor, the encoding result of the second variable scale factor can also be obtained in the previous process of determining the second variable scale factor. Therefore, the encoding result of the second scale factor ML / variable can be obtained directly. In other words, the coding result of the second variable scale factor can also be obtained directly in the process of determining the second variable scale factor. Optionally, if the first variable scale factor and the second variable scale factor are non-quantized values, in this embodiment of this application, a quantization index corresponding to a quantization step of the first variable scale factor may be further determined to obtain a first quantization index, and a quantization step of the second variable scale factor may be determined to obtain a fifth quantization index.Optionally, in this embodiment of this application, a quantization index corresponding to a quantization step of the second latent variable may be further determined to obtain a second quantization index, a quantization index corresponding to a quantization step of the fourth latent variable may be determined to obtain a fourth quantization index, and the first quantization index, the second quantization index, the fourth quantization index, and the fifth quantization index are encoded in the bit stream.The quantization index indicates a corresponding quantization stage, that is, the first quantization index indicates the quantization stage of the first variable scale factor, the second quantization index indicates the quantization stage of the second latent variable, the fourth quantization index indicates the quantization stage of the fourth latent variable, and the fifth quantization index indicates the quantization stage of the second variable scale factor. In this embodiment of this application, the first latent variable is scaled based on the first variable scaling factor to obtain the second latent variable, and the second latent variable is processed using the context coding neural network model to obtain the third latent variable. The third latent variable is scaled based on the second variable scaling factor to obtain the fourth latent variable. In addition, the total number of coding bits of the entropy coding result of the second latent variable and coding bits of the entropy coding result of the fourth latent variable meets the predetermined coding rate condition.This ensures that a number of coding bits of an entropy coding result of a latent variable corresponding to each frame of multimedia data can meet the pre-set coding rate condition, that is, the number of coding bits of the entropy coding result of the latent variable corresponding to each frame of multimedia data can be basically consistent, rather than dynamically changing, thereby meeting a requirement of an encoder for a stable coding rate. In addition, when side information (e.g., a window type, a temporal noise shaping (TNS) parameter), a noise shaping parameter in. ML / the frequency-domain noise shaping (FDNS) and / or a bandwidth extension (BWE) parameter, needs to be transmitted, it can be guaranteed that the number of coding bits of the latent variable entropy coding result corresponding to each frame of media data is basically consistent with a number of coding bits of the side information, thereby meeting the encoder's requirement for stable coding rate. FIGURE 15 is a flowchart of a third decoding method according to an embodiment of this application. The method is applied to one side of the decoder. The method corresponds to the encoding method shown in FIGURE 14. The method includes the following steps. Step 1501: Determine a fourth reconstructed latent variable, a first reconstructed variable scale factor, and a second reconstructed variable scale factor based on a bit stream. In some embodiments, entropy decoding may be performed on an entropy encoding result of a fourth latent variable in a bit stream, and the encoding results of a first variable scale factor and a second variable scale factor in the bit stream may be decoded, to obtain a quantized fourth latent variable, a first quantized variable scale factor, and a second quantized variable scale factor. Dequantization processing is performed on the quantized fourth latent variable, the first quantized variable scale factor, and the second quantized variable scale factor, to obtain the reconstructed fourth latent variable, the first reconstructed variable scale factor, and the second reconstructed variable scale factor. The decoding method at this stage corresponds to the encoding method on one side of the encoder, and the dequantization processing at this stage corresponds to the quantization processing on the encoder side. In other words, the decoding method is the reverse process of the encoding method, and the dequantization processing is the reverse process of the quantization processing. For example, the bit stream may be parsed to obtain a first quantization index, a fourth quantization index, and a fifth quantization index, where the first quantization index indicates a quantization step of the first variable scale factor, the fourth quantization index indicates a quantization step of the fourth latent variable, and the fifth quantization index indicates a quantization step of the second variable scale factor. Dequantization processing is performed on the quantized first variable scale factor based on the quantization step indicated by the first quantization index to obtain the reconstructed first variable scale factor. Dequantization processing is performed on the quantized fourth latent variable with ινίΛ / based on the quantization step indicated by the fourth quantization index to obtain the reconstructed latent variable.Dequantization processing is performed on the second quantized variable scale factor based on the quantization step indicated by the fifth quantization index, to obtain the reconstructed second variable scale factor. Step 1502: Determine a second reconstructed latent variable based on the bit stream, the fourth reconstructed latent variable, and the second reconstructed variable scale factor. In some embodiments, the reconstructed fourth latent variable is scaled based on the reconstructed second variable scale factor to obtain a reconstructed third latent variable. The reconstructed third latent variable is processed using a context decoding neural network model to obtain a reconstructed second entropy coding model parameter, and the reconstructed second latent variable is determined based on the bit stream and the reconstructed second entropy coding model parameter. In some embodiments, an entropy decoding model corresponding to the second parameter of the reconstructed entropy coding model may be determined. Entropy decoding is performed on an entropy coding result of a second latent variable in the bit stream based on the entropy decoding model corresponding to the second parameter of the entropy coding model, to obtain a quantized second latent variable. Dequantization processing is performed on the quantized second latent variable, to obtain the reconstructed second latent variable. The decoding method at this stage corresponds to the encoding method on one side of the encoder, and the dequantization processing at this stage corresponds to the quantization processing on the encoder side. In other words, the decoding method is the reverse process of the encoding method, and the dequantization processing is the reverse process of the quantization processing. For example, the bit stream may be parsed to obtain a second quantization index, the second quantization index indicating a quantization step of the second latent variable. Dequantization processing is performed on the quantized second latent variable based on the quantization step indicated by the second quantization index, to obtain the reconstructed second latent variable. Step 1503: Scale the second reconstructed latent variable based on the first reconstructed variable scale factor, to obtain a first reconstructed latent variable. For a step 1503 implementation process, see the step 902 implementation process. Details are not described again here. Step 1504: Process the first reconstructed latent variable by using a first decoding neural network model, to obtain reconstructed media data. ινίΛ / For a step 1504 implementation process, see the step 903 implementation process. Details are not described again here. In this embodiment of this application, a total number of coding bits of the entropy coding result of the second latent variable and coding bits of the entropy coding result of the fourth latent variable satisfy a preset coding rate condition. This ensures that a number of coding bits of an entropy coding result of a latent variable corresponding to each frame of multimedia data can satisfy the preset coding rate condition, that is, the number of coding bits of the entropy coding result of the latent variable corresponding to each frame of multimedia data can be substantially consistent, rather than dynamically changing, thereby satisfying a requirement of an encoder for a stable coding rate.Furthermore, when side information (e.g., a window type, a temporal noise shaping (TNS) parameter, a frequency-domain noise shaping (FDNS) parameter, and / or a bandwidth extension (BWE) parameter) needs to be transmitted, the number of coding bits of the latent variable entropy coding result corresponding to each frame of media data can be guaranteed to be substantially consistent with a number of coding bits of the side information, thereby meeting the encoder's requirement for stable coding rate. FIGURE 16A and FIGURE 16B are an exemplary block diagram of an encoding method according to an embodiment of this application. FIGURE 16A and FIGURE 16B mainly explain the encoding method shown in FIGURE 14 as an example. In FIGURE 16A and FIGURE 16B, an audio signal is used as an example. Windowing processing may be performed on the audio signal to obtain an audio signal of a current frame. MDCT processing is performed on the audio signal of the current frame to obtain a frequency domain signal of the current frame. A first latent variable is generated by performing processing by a first encoding neural network model based on the frequency domain signal of the current frame. The first latent variable is scaled based on a first latent variable scaling factor to obtain a second latent variable.The second latent variable is processed using a context coding neural network model to obtain a third latent variable. The third latent variable is scaled based on the second variable scaling factor to obtain a fourth latent variable. Quantization processing and entropy coding are performed on the fourth latent variable to obtain an entropy coding result of the fourth latent variable, and the entropy coding result of the fourth latent variable ινίΛ / is written into a bit stream. Furthermore, entropy decoding is performed on the entropy coding result of the fourth latent variable to obtain a quantized fourth latent variable. Dequantization processing is performed on the quantized fourth latent variable to obtain a reconstructed fourth latent variable.The reconstructed fourth latent variable is scaled based on the reconstructed second variable scale factor to obtain a third reconstructed latent variable. The reconstructed third latent variable is processed using a context decoding neural network model to obtain a second entropy coding model parameter. An entropy coding model corresponding to the second entropy coding model parameter is selected from entropy coding models with scalable parameters. The second latent variable is quantized, entropy coding is performed on a quantized second latent variable based on the selected entropy coding model to obtain an entropy coding result of the second latent variable, and the entropy coding result of the second latent variable is written to the bit stream.An encoding result of the first variable scale factor is then written to the bitstream. FIGURE 17 is an exemplary block diagram of a decoding method according to an embodiment of this application. FIGURE 17 mainly explains the decoding method shown in FIGURE 15 as an example. In FIGURE 17, an audio signal is used as an example. Entropy decoding is performed on an entropy coding result of a fourth latent variable in a bit stream by using an entropy decoding model, to obtain a quantized fourth latent variable. Dequantization processing is performed on the quantized fourth latent variable, to obtain a reconstructed fourth latent variable. A coding result of a second variable scale factor in the bit stream is decoded, to obtain a quantized second variable scale factor.Dequantization processing is performed on the second quantized variable scale factor to obtain a second reconstructed variable scale factor. The fourth reconstructed latent variable is scaled based on the second reconstructed variable scale factor to obtain a third reconstructed latent variable. The third reconstructed variable is processed using a context decoding neural network model to obtain a second reconstructed entropy coding model parameter. A corresponding entropy decoding model is selected, based on the second reconstructed entropy coding model parameter, from entropy decoding models with scalable parameters.Entropy decoding is performed on an entropy encoding result of a second latent variable in the bit stream based on the selected entropy decoding model, to obtain a quantized second latent variable. Dequantization processing is performed on the second quantized latent variable, to obtain a reconstructed second latent variable. An encoding result of a first variable scale factor in the bit stream is decoded, to obtain a reconstructed first variable scale factor. The reconstructed second latent variable is scaled based on the reconstructed first variable scale factor, to obtain a reconstructed first latent variable. The reconstructed first latent variable is processed by using a first decoding neural network model, to obtain a reconstructed frequency domain signal of a current frame.IMDCT processing and window removal processing are performed on the reconstructed frequency domain signal of the current frame, to obtain a reconstructed audio signal. FIGURE 18 is a schematic diagram of a structure of an encoding apparatus according to an embodiment of this application. The encoding apparatus may be implemented as part or all of an encoder-side device by using software, hardware, or a combination thereof. The encoder-side device may be the source apparatus shown in FIGURE 1. As shown in FIGURE 18, the apparatus includes: a data processing module 1801, a scale factor determining module 1802, a first encoding result obtaining module 1803, and a first encoding result writing module 1804. The data processing module 1801 is configured to process media data to be encoded using a first encoding neural network model to obtain a first latent variable, where the first latent variable indicates a characteristic of the media data to be encoded. For a detailed implementation process, see the corresponding section in the preceding embodiments. Details are not described again here. The scaling factor determining module 1802 is configured to determine a first variable scaling factor based on the first latent variable, where the first variable scaling factor is used to enable an encoding bit quantity of an entropy coding result of a second latent variable to meet a preset coding rate condition, and the second latent variable is obtained by scaling the first latent variable based on the first variable scaling factor. For a detailed implementation process, refer to the corresponding contents in the previous embodiments. Details are not described again herein. The first encoding result obtaining module 1803 is configured to obtain the entropy encoding result of the second latent variable. For a detailed implementation process, please refer to the corresponding content in the previous embodiments. Details are not described again here. The first encoding result writing module 1804 is configured to write the entropy encoding result of the second latent variable and an encoding result of the first variable scale factor into a bit stream. For a detailed implementation process, see the corresponding content in the previous embodiments. Details are not described again here. Optionally, when the media data to be encoded is encoded at a constant bit rate, satisfying a preset encoding rate condition includes that the number of encoding bits is less than or equal to a target number of encoding bits; or satisfying a preset encoding rate condition includes that the number of encoding bits is less than or equal to a target number of encoding bits, and a difference between the number of encoding bits and the target number of encoding bits is less than a bit number threshold. Optionally, when the media data to be encoded is encoded at a variable bit rate, satisfying a preset encoding rate condition includes that an absolute value of a difference between the number of encoding bits and a target number of encoding bits is less than a bit number threshold. Optionally, the scale factor determining module 1802 includes: a bit-count determining submodule, configured to determine an initial number of encoding bits based on the first latent variable; and a first factor determining submodule, configured to determine the first variable scale factor based on the initial number of encoding bits and a target number of encoding bits. Optionally, the initial number of encoding bits is a number of encoding bits of an entropy encoding result of the first latent variable; or the initial number of encoding bits is a number of encoding bits of an entropy encoding result of a first latent variable scaled based on a first initial scaling factor. Optionally, when the initial number of encoding bits is not equal to the target number of encoding bits, the first factor determining submodule is specifically configured to: determining the first variable scaling factor of a first cyclic manner based on the initial number of encoding bits and the target number of encoding bits; and the ith cyclic processing of the first cyclic manner includes the following steps: determining a scaling factor of the ith cyclic processing, where i is a positive integer; ινίΛ / scale the first latent variable based on the scale factor of the ith cyclic processing, to obtain an ith-first scaled latent variable; determining an encoding bit count of an entropy encoding result of the ith-first scaled latent variable, to obtain an ith encoding bit count; and if the ith encoding bit count satisfies a continuous scaling condition, performing the (i + i)th cyclic processing in the first cyclic manner; or if the ith encoding bit count does not satisfy a continuous scaling condition, terminating execution of the first cyclic manner and determining the first variable scaling factor based on the scaling factor of the ith cyclic processing. Optionally, the device also includes: a second encoding result obtaining module, configured to obtain an entropy encoding result of a third latent variable, where the third latent variable is determined based on the second latent variable by using a context model; and a second encoding result writing module, configured to write the entropy encoding result of the third latent variable into the bit stream. A total amount of encoding bits of the entropy encoding result of the second latent variable and encoding bits of the entropy encoding result of the third latent variable meets the preset encoding rate condition. Optionally, the scale factor determining module 1802 includes: a bit-count determining submodule, configured to determine an initial number of encoding bits based on the first latent variable; and a first factor determining submodule, configured to determine the first variable scale factor based on the initial number of encoding bits and a target number of encoding bits. Optionally, the bit quantity determining submodule is specifically configured to: determining, based on the first latent variable by using the context model, a corresponding initial amount of context coding bits and an initial entropy coding model parameter; determining a number of encoding bits of an entropy encoding result of the first latent variable based on the initial entropy encoding model parameter, to obtain a basic initial number of encoding bits; and determining the initial number of encoding bits based on the initial number of context encoding bits and the basic initial number of encoding bits. ινίΛ / Optionally, when the initial number of encoding bits is not equal to the target number of encoding bits, the first factor determining submodule is specifically configured to: determining the first variable scale factor of a first cyclic form based on the initial number of coding bits and the target number of coding bits; and the ith cyclic processing of the first cyclic form includes the following steps: determine a scaling factor of the ith cyclic processing, where i is a positive integer; scale the first latent variable based on the scale factor of the ith cyclic processing, to obtain an ith-first scaled latent variable; determining, based on the first ith latent variable scaled by using the context model, an ith number of context coding bits and an ith entropy coding model parameter; determining an amount of encoding bits of an entropy encoding result of the ith first scaled latent variable based on the ith parameter of the entropy encoding model, to obtain an ith basic amount of encoding bits; determining an ith number of coding bits based on the ith number of context coding bits and the ith number of basic coding bits; and if the ith number of coding bits meets a continuous scaling condition, performing the (i + i)th cyclic processing in the first cyclic manner; or if the ith number of coding bits does not meet a continuous scaling condition, terminating the execution of the first cyclic manner and determining the first variable scaling factor based on the scaling factor of the ith cyclic processing. Optionally, the first factor determining submodule is specifically configured to: determining the scaling factor of the ith cyclic processing based on a scaling factor of the (i-1 )th cyclic processing in the first cyclic manner, an (i-1 )th number of encoding bits, and the target number of encoding bits. When i=1, the scale factor of the (-l)th cyclic processing is a first initial scale factor, and the (-l)th number of encoding bits is the initial number of encoding bits. The continuous scaling condition includes that both the (il)th number of coding bits and the ith number of coding bits are smaller than the target number of coding bits, or the continuous scaling condition includes that both the (il)th number of coding bits and the ith number of coding bits are larger than the target number of coding bits. M / Optionally, when the initial number of encoding bits is less than the target number of encoding bits, the first factor determining submodule is specifically configured to: scale a scale factor of the (il)th cyclic processing in the first cyclic manner based on a first step, to obtain the scale factor of the ith cyclic processing. When i=1, the scaling factor of the (i-1)th cyclic processing is a first initial scaling factor. The continuous scaling condition includes that the ith number of coding bits is less than the target number of coding bits. Optionally, when the initial number of encoding bits is greater than the target number of encoding bits, the first factor determining submodule is specifically configured to: scale a scale factor of the (i-1 )th cyclic processing of the first cyclic form based on a second stage, to obtain the scale factor of the ith cyclic processing. When i=1, the scaling factor of the (i-1)th cyclic processing is a first initial scaling factor. The continuous scaling condition includes that the ith number of coding bits is greater than the target number of coding bits. Optionally, the first factor determining submodule is specifically configured to: When the initial number of encoding bits is smaller than the target number of encoding bits, they determined the first initial scale factor as the first variable scale factor. Optionally, the first factor determining submodule is specifically configured to: when the ith number of coding bits is equal to the target number of coding bits, determining the scale factor of the ith cyclic processing as the first variable scale factor; or when the ith number of coding bits is not equal to the target number of coding bits, determining the first variable scale factor based on the scale factor of the ith cyclic processing and a scale factor of the (i-1)th cyclic processing in the first cyclic manner. Optionally, the first factor determining submodule is specifically configured to: determining an average value of the scale factor of the ith cyclic processing and the scale factor of the (i-1)th cyclic processing; and ινίΛ / determining the first variable scale factor based on the average value. Optionally, the first factor determining submodule is specifically configured to: determining the first variable scale factor of a second cyclic form based on the scale factor of the ith cyclic processing and the scale factor of the (i)th cyclic processing. the ith cyclic processing of the second cyclic manner includes the following steps: determining a third scaling factor of the jth cyclic processing based on a first scaling factor of the jth cyclic processing and a second scaling factor of the jth cyclic processing, where when j is equal to 1, the first scaling factor of the jth cyclic processing is one of the scaling factor of the ith cyclic processing and the scaling factor of the (i-l)th cyclic processing, the second scaling factor of the jth cyclic processing is the other of the scaling factor of the ith cyclic processing and the scaling factor of the (i1)th cyclic processing, the first scaling factor of the jth cyclic processing corresponds to a jth-first number of encoding bits, the second scaling factor of the jth cyclic processing corresponds to a jth-second number of bits of coding,The jth-first number of coding bits is less than the jth-second number of coding bits, and j is a positive integer; obtaining a jth-third number of coding bits, where the jth-third number of coding bits is a number of coding bits of an entropy coding result of a first latent variable scaled based on the third scaling factor of the jth cyclic processing; and if the jth-third number of coding bits does not satisfy a continuous cycle condition, ending execution of the second cyclic manner and determining the third scaling factor of the jth cyclic processing as the first variable scaling factor; if the jth-third number of coding bits satisfies a continuous cycle condition, and is greater than the target number of coding bits and less than the jth-second number of coding bits, performing (j+1)th cyclic processing in the second cyclic manner using the third scale factor of the jth cyclic processing as a second scale factor of the (j+i)th cyclic processing and using the first scale factor of the jth cyclic processing as a first scale factor of the (j+i)th cyclic processing;or if the jth-third number of coding bits satisfies a continuous cycle condition, and is less than the target number of coding bits and greater than the jth-first number of coding bits, performing cyclic processing (j+i)th |second cyclically using the third scale factor of the jth cyclic processing as the first scale factor of the (j+i)th cyclic processing and using the second scale factor of the (j+i)th; ΜΛ / cyclic processing as the second scaling factor of the (j+i)th cyclic processing. Optionally, the first factor determining submodule is specifically configured to: determining the first variable scale factor of a second cyclic form based on the scale factor of the ith cyclic processing and the scale factor of the (i)th cyclic processing. the ith cyclic processing of the second cyclic manner includes the following steps: determining a third scaling factor of the jth cyclic processing based on a first scaling factor of the jth cyclic processing and a second scaling factor of the jth cyclic processing, where when j is equal to 1, the first scaling factor of the jth cyclic processing is one of the scaling factor of the ith cyclic processing and the scaling factor of the (i-l)th cyclic processing, the second scaling factor of the jth cyclic processing is the other of the scaling factor of the ith cyclic processing and the scaling factor of the (i1)th cyclic processing, the first scaling factor of the jth cyclic processing corresponds to a jth-first number of encoding bits, the second scaling factor of the jth cyclic processing corresponds to a jth-second number of bits of coding,The jth-first number of coding bits is less than the jth-second number of coding bits, and j is a positive integer; obtaining a jth-third number of coding bits, where the jth-third number of coding bits is a number of coding bits of an entropy coding result of a first latent variable scaled based on the third scaling factor of the jth cyclic processing; and if the jth-third number of coding bits does not satisfy a continuous cycle condition, ending execution of the second cyclic manner and determining the third scaling factor of the jth cyclic processing as the first variable scaling factor; if j reaches a maximum number of cycles and the jth-third number of encoding bits meets a continuous cycle condition, terminate execution of the second cyclic form and determine the first variable scale factor based on the first scale factor of the jth cyclic processing; if j does not reach a maximum number of cycles, and the jth-third number of coding bits satisfies a continuous cycle condition, and is greater than the target number of coding bits and less than the jth-second number of coding bits, performing the (j+i)th cyclic processing in the second cyclic manner using the third scaling factor of the jth cyclic processing as a second scaling factor of the (j+i)th cyclic processing and using the first scaling factor of the jth cyclic processing as a first scaling factor of the (j+1)th cyclic processing;or ινίΛ / if j does not reach a maximum number of cycles, and the jth-third number of coding bits satisfies a continuous cycle condition, and is less than the target number of coding bits and greater than the jth-first number of coding bits, performing a (j+i)th cyclic processing in the second cyclic manner using the third scale factor of the jth cyclic processing as the first scale factor of the (j+i)th cyclic processing and using the second scale factor of the (j+i)th cyclic processing as the second scale factor of the (j+i)th cyclic processing.; Optionally, the first factor determining submodule is specifically configured to: When the media data to be encoded is encoded at a constant bit rate, determine the first scale factor of the jth cyclic processing as the first variable scale factor. Optionally, the first factor determining submodule is specifically configured to: when the media data to be encoded is encoded at a variable bit rate, determining a first difference between the target number of encoding bits and the jth-first number of encoding bits, and determining a second difference between the jth-second number of encoding bits and the target number of encoding bits; and if the first difference is smaller than the second difference, determining the first scaling factor of the jth cyclic processing as the first variable scaling factor; If the second difference is less than the first difference, determine the second scale factor of the jth cyclic processing as the first variable scale factor; or if the first difference is equal to the second difference, determine the first scale factor of the jth cyclic processing as the first variable scale factor, or determine the second scale factor of the jth cyclic processing as the first variable scale factor. Optionally, when the media data to be encoded encodes at a constant bit rate, the continuous cycle condition comprises: the jth-third number of encoding bits is greater than the target number of encoding bits, or the continuous cycle condition comprises: the jth-third number of encoding bits is less than the target number of encoding bits, and a difference between the target number of encoding bits and the jth-thirteenth number of encoding bits is greater than a threshold number of bits. Optionally, when the media data to be encoded is encoded at a variable bit rate, the continuous cycle condition includes that an absolute value of a difference between the target number of encoding bits and the jth-third number of encoding bits is greater than a threshold number of bits. Optionally, the first factor-determining submodule is configured specifically for: When the initial number of encoding bits is equal to the target number of encoding bits, determining a first initial scale factor as the first variable scale factor. Optionally, the device also includes: the scale factor determining module 1802, further configured to: determine a second variable scale factor based on the first latent variable; a third encoding result obtaining module, configured to obtain an entropy encoding result of a fourth latent variable, where the fourth latent variable is obtained by scaling a third latent variable based on the second variable scaling factor, and the third latent variable is determined based on the second latent variable by using a context model; and a third encoding result writing module, configured to write the entropy encoding result of the fourth latent variable and an encoding result of the second variable scaling factor into the bit stream. A total amount of encoding bits of the entropy encoding result of the second latent variable and encoding bits of the entropy encoding result of the third latent variable meets the preset encoding rate condition. Optionally, the scale factor determining module 1802 includes: a first determining submodule, configured to determine, based on the first latent variable by using the context model, a corresponding initial amount of context coding bits and an initial entropy coding model parameter; a second determining submodule, configured to determine a number of encoding bits of an entropy encoding result of the first latent variable based on the initial entropy encoding model parameter, to obtain a basic initial number of encoding bits; and a second factor determining submodule, configured to determine the first variable scaling factor and the second variable scaling factor based on the initial number of context encoding bits, the basic initial number of encoding bits, and a target number of encoding bits. Optionally, the second factor determining submodule is specifically configured to: determining a target basic number of encoding bits based on the target number of encoding bits and at least one of the initial basic number of encoding bits and the initial number of context encoding bits; determining the first variable scale factor and a basic actual number of coding bits ινίΛ / based on a second initial scale factor, the target basic number of coding bits, and the initial basic number of coding bits, where the basic actual number of coding bits is a number of coding bits of an entropy coding result of a first latent variable scaled based on the first variable scale factor; determining a target number of context coding bits based on the target number of coding bits and the actual base number of coding bits; and determining the second variable scaling factor based on the target number of context coding bits and the initial number of context coding bits. Optionally, the second factor determining submodule is specifically configured to: dividing the target number of encoding bits into a target basic number of encoding bits and a target context number of encoding bits; determining the first variable scaling factor based on the target base number of coding bits and the initial base number of coding bits; and determining the second variable scaling factor based on the target number of context coding bits and the initial number of context coding bits. Optionally, the media data is an audio signal, a video signal, or an image. The number of coding bits of the entropy coding result of the second latent variable satisfies the predetermined coding rate condition. This ensures that the number of coding bits of the entropy coding result of a latent variable corresponding to each frame of multimedia data can satisfy the predetermined coding rate condition, that is, the number of coding bits of the entropy coding result of the latent variable corresponding to each frame of multimedia data can be substantially consistent, rather than dynamically changing, thereby satisfying the requirement of an encoder for a stable coding rate.Furthermore, when side information (e.g., a window type, a temporal noise shaping (TNS) parameter, a frequency-domain noise shaping (FDNS) parameter, and / or a bandwidth extension (BWE) parameter) needs to be transmitted, the number of coding bits of the latent variable entropy coding result corresponding to each frame of media data can be guaranteed to be substantially consistent with a number of coding bits of the side information, thereby meeting the encoder's requirement for stable coding rate. It should be noted that when the coding apparatus provided in the above embodiment performs coding, the above division of functional modules is merely used as an example for the description. In actual application, the above functions may be assigned to different functional modules for implementation based on a requirement, that is, an internal structure of the apparatus is divided into different functional modules to complete all or some of the functions described above. Furthermore, the coding apparatus provided in the above embodiment belongs to the same concept as the coding method embodiment. For a specific implementation process of the coding apparatus, refer to the method embodiment. Details are not described again here. FIGURE 19 is a schematic diagram of a structure of a decoding apparatus according to an embodiment of this application. The decoding apparatus may be implemented as part or all of a decoder-side device by using software, hardware, or a combination thereof. The decoder-side device may be the destination apparatus shown in FIGURE 1. As shown in FIGURE 19, the apparatus includes: a first determining module 1901, a variable scaling module 1902, and a variable processing module 1903. The first determining module 1901 is configured to determine a second reconstructed latent variable and a first reconstructed variable scale factor based on a bit stream. For a detailed implementation process, see the corresponding section in the previous embodiments. Details are not described again here. The variable scaling module 1902 is configured to scale the reconstructed second latent variable based on the reconstructed first variable scaling factor to obtain a reconstructed first latent variable, where the reconstructed first latent variable indicates a characteristic of the media data to be decoded. For a detailed implementation process, see the corresponding section in the previous embodiments. Details are not described again here. The variable processing module 1903 is configured to process the reconstructed first latent variable using a first decoding neural network model to obtain reconstructed media data. For a detailed implementation process, see the corresponding section in the preceding embodiments. Details are not described again here. Optionally, the first determining module 1901 includes: a first determining submodule, configured to determine a third reconstructed latent variable based on the bit stream; and a second determining submodule, configured to determine the second reconstructed latent variable based on the bit stream and the third reconstructed latent variable. Optionally, the second determining submodule is specifically configured to: processing the reconstructed third latent variable using a context decoding neural network model to obtain a first reconstructed entropy coding model parameter; and determining the reconstructed second latent variable based on the bit stream and the first reconstructed entropy coding model parameter. Optionally, the first determining module 1901 includes: a third determining submodule, configured to determine a fourth reconstructed latent variable and a second reconstructed variable scale factor based on the bit stream; and a fourth determining submodule, configured to determine the second reconstructed latent variable based on the bit stream, the fourth reconstructed latent variable, and the second reconstructed variable scale factor. Optionally, the fourth determining submodule is specifically configured to: scale the fourth reconstructed latent variable based on the second reconstructed variable scale factor, to obtain a third reconstructed latent variable; processing the reconstructed third latent variable using a context decoding neural network model to obtain a second reconstructed entropy coding model parameter; and determining the reconstructed second latent variable based on the bit stream and the second reconstructed entropy coding model parameter. Optionally, the media data is an audio signal, a video signal, or an image. In this embodiment of this application, a number of coding bits of the entropy coding result of the second latent variable satisfies a predetermined coding rate condition. This ensures that a number of coding bits of an entropy coding result of a latent variable corresponding to each frame of multimedia data can satisfy the predetermined coding rate condition, that is, the number of coding bits of the entropy coding result of the latent variable corresponding to each frame of multimedia data can be substantially consistent, rather than dynamically changing, thereby meeting a requirement of an encoder for a stable coding rate.Furthermore, when complementary information (e.g., a window type, a temporal noise shaping (TNS) parameter, a frequency-domain noise shaping (FDNS) parameter, and / or a bandwidth extension (BWE) parameter) is required to be transmitted, the number of coding bits of the latent variable entropy coding result corresponding to each frame of media data can be guaranteed to be substantially consistent with a number of coding bits of the complementary information, thereby meeting the encoder's requirement for stable coding rate. It should be noted that when the decoding apparatus provided in the above embodiment performs decoding, the above division of functional modules is merely used as an example for the description. In actual application, the above functions may be assigned to different functional modules for implementation based on a requirement, that is, an internal structure of the apparatus is divided into different functional modules to complete all or some of the functions described above. Furthermore, the decoding apparatus provided in the above embodiment belongs to the same concept as the decoding method embodiment. For a specific implementation process of the encoding apparatus, refer to the method embodiment. Details are not described again here. FIGURE 20 is a schematic block diagram of an encoding and decoding apparatus 2000 according to one embodiment of this application. The encoding and decoding apparatus 2000 may include a processor 2001, a memory 2002, and a bus system 2003. The processor 2001 and memory 2002 are connected via the bus system 2003. The memory 2002 is configured to store instructions. The processor 2001 is configured to execute instructions stored in the memory 2002 to perform various encoding or decoding methods described in embodiments of this application. To avoid repetition, details are not described again herein. In this embodiment of this application, the processor 2001 may be a central processing unit (CPU), or the processor 2001 may be another general-purpose processor, a DSP, an ASIC, an FPGA or other programmable logic device, a discrete gate or transistor logic device, a discrete hardware component, or the like. The general-purpose processor may be a microprocessor, or the processor may be any conventional processor or the like. Memory 2002 may include a ROM device or a RAM device. Any other suitable type of storage device may also be used as memory 2002. Memory 2002 may include code and data 20021 that are accessed by processor 2001 via bus 2003. Memory 2002 may further include an operating system 20023 and an application program 20022. Application program 20022 includes at least one program that enables processor 2001 to perform the encoding or decoding method described in embodiments of this application. For example, application program 20022 may include applications 1 through N, and further include an encoding or decoding application (referred to as an encoding and decoding application for short) that performs the encoding or decoding method described in embodiments of this application. In addition to a data bus, the bus system 2003 may also include a power bus, a control bus, a status signal bus, and the like. However, for clarity, the various types of buses in the figure are labeled as the bus system 2003. Optionally, the encoding and decoding apparatus 2000 may further include one or more output devices, for example, a display 2004. In one example, the display 2004 may be a touch screen that combines a display and a touch unit that operatively detects a touch input. The display 2004 may be connected to the processor 2001 via the bus 2003. It should be noted that the encoding and decoding apparatus 2000 may perform the encoding method in embodiments of this application and may also perform the decoding method in embodiments of this application. One skilled in the art can appreciate that the functions described with reference to various illustrative logic blocks, modules, and algorithm steps disclosed and described herein may be implemented by hardware, software, firmware, or any combination thereof. If implemented by software, the functions described with reference to the illustrative logic blocks, modules, and steps may be stored or transmitted via a computer-readable medium as one or more instructions or code and executed by a hardware-based processing unit. Computer-readable media may include computer-readable storage media, corresponding to a tangible medium, such as a data storage medium, or any communication medium that facilitates the transfer of a computer program from one location to another (e.g., in accordance with a communication protocol).Thus, the computer-readable medium may generally correspond to (1) a non-transitory, tangible computer-readable storage medium, or (2) a communication medium such as a signal or a carrier. The data storage medium may be any usable medium that can be accessed by one or more computers or one or more processors to retrieve instructions, codes, and / or data structures for implementing the techniques described in this application. A computer program product may include a computer-readable medium. By way of example and not limitation, such computer-readable storage media may comprise RAM, ROM, EEPROM, CD-ROM or other optical disk storage device, magnetic disk storage device or other magnetic storage devices, flash memory, or any other medium capable of storing the desired programming code in the form of instructions or data structures and accessible by a computer. Furthermore, any connection to a computer-readable medium may be appropriately referred to.For example, if instructions are transmitted from a website, server, or other remote source using coaxial cable, optical fiber, twisted pair, digital subscriber line (DSL), or wireless technologies such as infrared, radio, or microwave, the coaxial cable, optical fiber, twisted pair, DSL, or wireless technologies such as infrared, radio, or microwave are included in the definition of medium. However, it should be understood that computer-readable storage medium and data storage medium do not include connections, carriers, signals, or other transient media, but actually mean tangible, non-transitory storage media.A disc and an optical disc used in this specification include a compact disc (CD), a laser disc, an optical disc, a DVD, and a Blu-ray disc, where the disc typically reproduces data magnetically and the optical disc reproduces data optically by using a laser. Combinations of the above should also be included within the scope of computer-readable media. The instructions may be executed by one or more processors, such as one or more digital signal processors (DSPs), general-purpose microprocessors, application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other equivalent integrated or discrete logic circuitry. Thus, the term "processor" as used in this specification may refer to the above structure or any other structure that may be applicable to the implementation of the technologies described in this specification. Furthermore, in some aspects, the functions described with reference to the illustrative logic blocks, modules, and stages described in this specification may be provided within dedicated hardware and / or software modules configured for encoding and decoding or may be incorporated into a combined codec.Also, the techniques may be implemented entirely in one or more circuits or logic elements. In one example, various illustrative logic blocks, units, and modules in the encoder 100 and decoder 200 may be understood as corresponding circuit devices or logic elements. The technologies in the embodiments of this application may be implemented in various apparatus or devices, including a wireless telephone, an integrated circuit (IC), or a ML / IC assembly (e.g., a chipset). Various components, modules, or units are described in this application to emphasize the functional aspects of devices configured to perform the disclosed techniques, but do not necessarily require their implementation by different hardware units. Indeed, as described above, multiple units may be combined into a codec hardware unit in combination with appropriate software and / or firmware, or may be provided by interoperable hardware units (including the one or more processors described above). In other words, all or some of the foregoing embodiments may be implemented using software, hardware, firmware, or any combination thereof. When software is used to implement the embodiments, all or some of the embodiments may be implemented in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, procedures or functions according to the embodiments of this application are generated in whole or in part. The computer may be a general-purpose computer, a dedicated computer, a computer network, or other programmable apparatus. The computer instructions may be stored on a computer-readable storage medium or may be transmitted from a computer-readable storage medium to another computer-readable storage medium.For example, computer instructions may be transmitted from one website, computer, server, or data center to another website, computer, server, or data center in a wired (e.g., coaxial cable, optical fiber, or digital subscriber line (DSL)) or wireless (e.g., infrared, radio, or microwave) manner. The computer-readable storage medium may be any medium usable and accessible by a computer or data storage device, such as a server or data center, that integrates one or more usable media. The usable medium may be a magnetic medium (e.g., a floppy disk, a hard disk, or magnetic tape), an optical medium (e.g., a digital versatile disc (DVD)), a semiconductor medium (e.g., a solid state disk (SSD)), or the like.It should be noted that the computer-readable storage medium mentioned in the embodiments of this application may be a non-volatile storage medium or, in other words, it may be a non-transitory storage medium. A plurality of in this specification should be understood to mean two or more. In the descriptions of the embodiments of this application, / means or unless otherwise specified. For example, A / B may represent either A or B. The term and / or in this specification describes only one association relationship for describing associated objects ινίΛ / and represents that three relationships may exist. For example, A and / or B may represent the following three cases: Only A exists, both A and B exist, and only B exists. Furthermore, in order to clearly describe the technical solutions in the embodiments of the present application, terms such as first and second are used in the embodiments of the present application to distinguish between the same or similar elements that provide substantially the same functions or purposes.One skilled in the art can understand that terms such as first and second do not limit an amount or sequence of execution, and terms such as first and second do not indicate a definitive difference. The above descriptions are merely modalities of this application, but are not intended to limit it. Any modification, equivalent replacement, or improvement made without departing from the spirit and principle of this application must be included within the scope of protection of this application.
Claims
1. An encoding method, the method comprising: processing media data to be encoded to obtain a first latent variable, wherein the first latent variable indicates a characteristic of the media data to be encoded; determining a first variable scaling factor based on the first latent variable, wherein the first variable scaling factor is used to enable an encoding bit amount of an encoding result of a second latent variable to meet a preset coding rate condition, and the second latent variable is obtained by scaling the first latent variable based on the first variable scaling factor; obtaining the encoding result of the second latent variable; and writing the encoding result of the second latent variable and an encoding result of the first variable scaling factor into a bit stream.
2. The method according to claim 1, characterized in that when the media data to be encoded is encoded at a constant bit rate, satisfying a preset encoding rate condition comprises: the number of encoding bits is less than or equal to a target number of encoding bits; or satisfying a preset encoding rate condition comprises: the number of encoding bits is less than or equal to a target number of encoding bits, and a difference between the number of encoding bits and the target number of encoding bits is less than a bit number threshold.
3. The method according to claim 1, characterized in that when the media data to be encoded is encoded at a variable bit rate, the fulfillment of a preset encoding rate condition comprises: an absolute value of a difference between the number of encoding bits and a target number of encoding bits is less than a threshold number of bits.
4. The method of claim 1, wherein determining a first variable scaling factor based on the first latent variable comprises: determining an initial number of coding bits based on the first latent variable; and determining the first variable scaling factor based on the initial number of coding bits and a target number of coding bits.
5. The method according to claim 4, characterized in that the initial number of coding bits is a number of coding bits of an entropy coding result of the first latent variable; or ινίΛ / 101 the initial number of coding bits is a number of coding bits of an entropy coding result of a first latent variable scaled based on a first initial scaling factor.
6. The method of claim 4, wherein when the initial number of coding bits is not equal to the target number of coding bits, determining the first variable scaling factor based on the initial number of coding bits and a target number of coding bits comprises: determining the first variable scaling factor in a first cyclic manner based on the initial number of coding bits and the target number of coding bits; and performing cyclic processing in the first cyclic manner comprises the steps of: determining a scaling factor of the ith cyclic processing, wherein i is a positive integer; scaling the first latent variable based on the scaling factor of the ith cyclic processing, to obtain an ith first scaled latent variable;determining an amount of encoding bits from an entropy encoding result of the ¡®th first scaled latent variable, to obtain an ith amount of encoding bits; and if the ¡th amount of encoding bits satisfies a continuous scaling condition, performing the (i + i)th cyclic processing in the first cyclic manner; or if the ¡th amount of encoding bits does not satisfy a continuous scaling condition, terminating the execution of the first cyclic manner and determining the first variable scaling factor based on the scaling factor of the ith cyclic processing; 7. The method according to claim 1, characterized in that the method further comprises: obtaining an entropy coding result of a third latent variable, wherein the third latent variable is determined based on the second latent variable by using a context model; and writing the entropy coding result of the third latent variable into the bit stream, wherein a total amount of coding bits of the entropy coding result of the second latent variable and coding bits of the entropy coding result of the third latent variable meets the pre-set coding rate condition.
8. The method of claim 7, wherein determining a first variable scaling factor based on the first latent variable comprises: ivia / 102 determining an initial number of coding bits based on the first latent variable; and determining the first variable scaling factor based on the initial number of coding bits and a target number of coding bits.
9. The method according to claim 8, characterized in that the determining an initial number of coding bits based on the first latent variable comprises: determining, based on the first latent variable by using the context model, a corresponding initial number of context coding bits and an initial entropy coding model parameter; determining a number of coding bits of an entropy coding result of the first latent variable based on the initial entropy coding model parameter, to obtain a basic initial number of coding bits; and determining the initial number of coding bits based on the initial number of context coding bits and the basic initial number of coding bits.
10. The method of claim 8, wherein when the initial number of coding bits is not equal to the target number of coding bits, determining the first variable scaling factor based on the initial number of coding bits and a target number of coding bits comprises: determining the first variable scaling factor in a first cyclic manner based on the initial number of coding bits and the target number of coding bits; and performing cyclic processing in the first cyclic manner comprises the steps of: determining a scaling factor of the ith cyclic processing, wherein i is a positive integer; scaling the first latent variable based on the scaling factor of the ith cyclic processing, to obtain an ith first scaled latent variable;determining, based on the first ith latent variable scaled by using the context model, an ith number of context coding bits and an ith entropy coding model parameter; determining a number of coding bits of an entropy coding result of the ith first scaled latent variable based on the ith entropy coding model parameter, to obtain an ith basic number of coding bits; determining an ith number of coding bits based on the ith number of context coding bits and the ith basic number of coding bits; and if the ith number of coding bits meets a continuous scaling condition ινίΛ / 103, performing the (i + i)th cyclic processing in the first cyclic manner;or if the ith number of encoding bits does not satisfy a continuous scaling condition, terminate execution of the first cyclic manner and determine the first variable scale factor based on the scale factor of the ith cyclic processing; 11. The method according to claim 6 or 10, characterized in that the determining a scaling factor of the ith cyclic processing comprises: determining the scaling factor of the ith cyclic processing based on a scaling factor of the (i-1)th cyclic processing in the first cyclic manner, an (i-1)th number of coding bits and the target number of coding bits, wherein when i=1, the scaling factor of the (i-i)th cyclic processing is a first initial scaling factor, and the (ii)th number of coding bits is the initial number of coding bits;and the continuous scaling condition comprises: both the (-l)th number of encoding bits and the i)th number of encoding bits are less than the target number of encoding bits, or the continuous scaling condition comprises: both the (-l)th number of encoding bits and the (i)th number of encoding bits are greater than the target number of encoding bits.; 12. The method according to claim 6 or 10, characterized in that when the initial number of coding bits is smaller than the target number of coding bits, determining a scaling factor of the ith cyclic processing comprises: scaling a scaling factor of the (i-1)th cyclic processing in the first cyclic manner based on a first step, to obtain the scaling factor of the (i-1)th cyclic processing, wherein when i=1, the scaling factor of the (i-1)th cyclic processing is a first initial scaling factor; and the continuous scaling condition comprises: the ith number of coding bits is smaller than the target number of coding bits.
13. The method according to claim 6 or 10, characterized in that when the initial number of coding bits is greater than the target number of coding bits, determining a scaling factor of the ith cyclic processing comprises: scaling a scaling factor of the (i-l)th cyclic processing in the first cyclic manner based on a second step, to obtain the scaling factor of the ith cyclic processing, wherein when i=1, the scaling factor of the (i-l)th cyclic processing is a first initial scaling factor; and the continuous scaling condition comprises: the ith number of coding bits is greater than the target number of coding bits.
14. The method according to claim 4 or 8, characterized in that the determining the first variable scale factor based on the initial number of encoding bits and a target number of encoding bits comprises: when the initial number of encoding bits is less than the target number of encoding bits, determining the first initial scale factor as the first variable scale factor.
15. The method according to claim 6 or 10, characterized in that the determining the first variable scale factor based on the scale factor of the ith cyclic processing comprises: when the ith number of coding bits is equal to the target number of coding bits, determining the scale factor of the ith cyclic processing as the first variable scale factor; or when the ith number of coding bits is not equal to the target number of coding bits, determining the first variable scale factor based on the scale factor of the ith cyclic processing and a scale factor of the (i-1)th cyclic processing in the first cyclic manner.
16. The method according to claim 15, characterized in that the determining the first variable scale factor based on the scale factor of the ith cyclic processing and a scale factor of the (i-l)th cyclic processing of the first cyclic manner comprises: determining an average value of the scale factor of the (i-l)th cyclic processing and the scale factor of the (i-l)th cyclic processing; and determining the first variable scale factor based on the average value.
17. The method of claim 15, wherein determining the first variable scaling factor based on the scaling factor of the ith cyclic processing and a scaling factor of the (-l)th cyclic processing of the first cyclic manner comprises: determining the first variable scaling factor of a second cyclic manner based on the scaling factor of the ith cyclic processing and the scaling factor of the (-l)th cyclic processing; and the jth cyclic processing of the second cyclic manner comprises the following steps: determining a third scaling factor of the jth cyclic processing based on a first scaling factor of the jth cyclic processing and a second scaling factor of the jth ινίΛ / 105 cyclic processing, wherein when j is equal to 1,the first scale factor of the jth cyclic processing is one of the scale factor of the ith cyclic processing and the scale factor of the (-i)th cyclic processing, the second scale factor of the jth cyclic processing is the other of the scale factor of the ith cyclic processing and the scale factor of the (i1)th cyclic processing, the first scale factor of the jth cyclic processing corresponds to a jth-first number of coding bits, the second scale factor of the jth cyclic processing corresponds to a jth-second number of coding bits, the jth-first number of coding bits is less than the jth-second number of coding bits, and j is a positive integer; obtaining a jth-third number of coding bits,wherein the jth-third number of coding bits is a number of coding bits of an entropy coding result of a first latent variable scaled based on the third scaling factor of the jth cyclic processing; and if the jth-third number of coding bits does not satisfy a continuous cycle condition, terminating execution in the second cyclic manner and determining the third scaling factor of the jth cyclic processing as the first variable scaling factor; if the jth-third number of coding bits satisfies a continuous cycle condition, and is greater than the target number of coding bits and less than the jth-second number of coding bits,performing the (j+1)th cyclic processing in the second cyclic manner using the third scale factor of the jth cyclic processing as a second scale factor of the (j+1)th cyclic processing and using the first scale factor of the jth cyclic processing as a first scale factor of the (j+1)th cyclic processing; or if the jth-third number of coding bits satisfies a continuous cycle condition, and is less than the target number of coding bits and greater than the jth-first number of coding bits, performing the (j+i)th cyclic processing in the second cyclic manner using the third scale factor of the jth cyclic processing as a first scale factor of the (j+i)th cyclic processing and using the second scale factor of the jth cyclic processing as a second scale factor of the (j+i)th cyclic processing.
18. The method of claim 15, wherein determining the first variable scale factor based on the scale factor of the ith cyclic processing and a scale factor of the (-l)th cyclic processing of the first cyclic manner comprises: determining the first variable scale factor of a second cyclic manner based on the scale factor of the ith cyclic processing and the scale factor of the (-l)th cyclic processing; and ML / 106 the jth cyclic processing of the second cyclic manner comprises the following steps: determining a third scale factor of the jth cyclic processing based on a first scale factor of the jth cyclic processing and a second scale factor of the jth cyclic processing, wherein when j is equal to 1,the first scale factor of the jth cyclic processing is one of the scale factor of the ith cyclic processing and the scale factor of the (-i)th cyclic processing, the second scale factor of the jth cyclic processing is the other of the scale factor of the ith cyclic processing and the scale factor of the (i1)th cyclic processing, the first scale factor of the jth cyclic processing corresponds to a jth-first number of coding bits, the second scale factor of the jth cyclic processing corresponds to a jth-second number of coding bits, the jth-first number of coding bits is less than the jth-second number of coding bits, and j is a positive integer; obtaining a jth-third number of coding bits,wherein the jth-third number of coding bits is a number of coding bits of an entropy coding result of a first latent variable scaled based on the third scaling factor of the jth cyclic processing; and if the jth-third number of coding bits does not satisfy a continuous cycle condition, terminating execution of the second cyclic manner and determining the third scaling factor of the jth cyclic processing as the first variable scaling factor; if j reaches a maximum number of cycles and the jth-third number of coding bits satisfies a continuous cycle condition, terminating execution of the second cyclic manner and determining the first variable scaling factor based on the first scaling factor of the jth cyclic processing; if j does not reach a maximum number of cycles, and the jth-third number of coding bits satisfies a continuous cycle condition,and is greater than the target number of coding bits and less than the jth-second number of coding bits, performing the (j+1)th cyclic processing in the second cyclic manner using the third scale factor of the jth cyclic processing as a second scale factor of the (j+1)th cyclic processing and using the first scale factor of the jth cyclic processing as a first scale factor of the (j+1)th cyclic processing; or if j does not reach a maximum number of cycles, and the jth-third number of coding bits satisfies a continuous cycle condition, and is less than the target number of coding bits and greater than the jth-first number of coding bits,performing a (j+i)th cyclic processing in the second cyclic manner using the third scale factor of the jth cyclic processing as the first scale factor of the (j+i)th cyclic processing and ινίΛ / 107 using the second scale factor of the (j+i)th cyclic processing as the second scale factor of the (j+1 )th cyclic processing., 19. The method according to claim 18, characterized in that the determining the first variable scale factor based on the first scale factor of the jth cyclic processing comprises: when the media data to be encoded is encoded at a constant bit rate, determining the first scale factor of the jth cyclic processing as the first variable scale factor.
20. The method of claim 18, wherein determining the first variable scaling factor based on the first scaling factor of the jth cyclic processing comprises: when the media data to be encoded is encoded at a variable bit rate, determining a first difference between the target number of encoding bits and the jth-first number of encoding bits, and determining a second difference between the jth-second number of encoding bits and the target number of encoding bits; and if the first difference is less than the second difference, determining the first scaling factor of the jth cyclic processing as the first variable scaling factor; if the second difference is less than the first difference, determining the second scaling factor of the jth cyclic processing as the first variable scaling factor;or if the first difference is equal to the second difference, determining the first scale factor of the jth cyclic processing as the first variable scale factor, or determining the second scale factor of the jth cyclic processing as the first variable scale factor.; 21. The method according to claim 17 or 18, characterized in that: when the media data to be encoded is encoded at a constant bit rate, the continuous cycle condition comprises: the jth-third number of encoding bits is greater than the target number of encoding bits, or the continuous cycle condition comprises: the jth-third number of encoding bits is less than the target number of encoding bits, and a difference between the target number of encoding bits and the jth-third number of encoding bits is greater than a threshold number of bits.
22. The method according to claim 17 or 18, characterized in that: when the media data to be encoded encodes at a variable bit rate, the continuous cycle condition comprises: an absolute value of a difference between the target number of encoding bits and the jth-third number of encoding bits is greater than a threshold number of bits.
23. The method according to claim 4 or 8, characterized in that the determining the first variable scale factor based on the initial number of 108 encoding bits and a target number of encoding bits comprises: when the initial number of encoding bits is equal to the target number of encoding bits, determining a first initial scale factor as the first variable scale factor.
24. The method of claim 1, wherein the method further comprises: determining a second variable scaling factor based on the first latent variable; obtaining an entropy coding result of a fourth latent variable, wherein the fourth latent variable is obtained by scaling a third latent variable based on the second variable scaling factor, and the third latent variable is determined based on the second latent variable by using a context model; and writing the entropy coding result of the fourth latent variable and an coding result of the second variable scaling factor into the bit stream; wherein a total amount of coding bits of the entropy coding result of the second latent variable and coding bits of the entropy coding result of the fourth latent variable meets the preset coding rate condition.
25. The method of claim 24, wherein determining a first variable scaling factor and a second variable scaling factor based on the first latent variable comprises: determining, based on the first latent variable by using the context model, a corresponding initial number of context coding bits and an initial entropy coding model parameter; determining a number of coding bits of an entropy coding result of the first latent variable based on the initial entropy coding model parameter, to obtain a basic initial number of coding bits; and determining the first variable scaling factor and the second variable scaling factor based on the initial number of context coding bits, the basic initial number of coding bits, and a target number of coding bits.
26. The method of claim 25, wherein determining the first variable scaling factor and the second variable scaling factor based on the initial number of context coding bits, the initial basic number of coding bits, and a target number of coding bits comprises: determining a target basic number of coding bits based on the target number of coding bits and at least one of the initial basic number of coding bits and the initial number of context coding bits;determining the first variable scale factor and a basic actual number of coding bits ινίΛ / 109 based on a second initial scale factor, the target basic number of coding bits, and the initial basic number of coding bits, wherein the basic actual number of coding bits is a number of coding bits of an entropy coding result of a first latent variable scaled based on the first variable scale factor; determining a target number of context coding bits based on the target number of coding bits and the basic actual number of coding bits; and determining the second variable scale factor based on the target number of context coding bits and the initial number of context coding bits.; 27. The method of claim 25, wherein determining the first variable scaling factor and the second variable scaling factor based on the initial number of context coding bits, the basic initial number of coding bits, and a target number of coding bits comprises: dividing the target number of coding bits into a target basic number of coding bits and a target number of context coding bits; determining the first variable scaling factor based on the target basic number of coding bits and the basic initial number of coding bits; and determining the second variable scaling factor based on the target number of context coding bits and the initial number of context coding bits.
28. The method according to any one of claims 1 to 27, characterized in that the media data is an audio signal, a video signal or an image.
29. A decoding method, the method comprising: determining a second reconstructed latent variable and a first reconstructed variable scaling factor based on a bit stream; scaling the second reconstructed latent variable based on the first reconstructed variable scaling factor to obtain a first reconstructed latent variable, wherein the first reconstructed latent variable indicates a characteristic of the media data to be decoded; and processing the first reconstructed latent variable using a first decoding neural network model to obtain reconstructed media data.
30. The method of claim 29, wherein determining a second reconstructed latent variable based on a bit stream comprises: determining a third reconstructed latent variable based on the bit stream; and determining the second reconstructed latent variable based on the bit stream and the third reconstructed latent variable.
31. The method of claim 30, wherein determining the reconstructed second latent variable based on the bit stream and the reconstructed third latent variable comprises: processing the reconstructed third latent variable using a context decoding neural network model to obtain a first reconstructed entropy coding model parameter; and determining the reconstructed second latent variable based on the bit stream and the first reconstructed entropy coding model parameter.
32. The method of claim 29, wherein determining a second reconstructed latent variable based on a bit stream comprises: determining a fourth reconstructed latent variable and a second reconstructed variable scale factor based on the bit stream; and determining the second reconstructed latent variable based on the bit stream, the fourth reconstructed latent variable, and the second reconstructed variable scale factor.
33. The method of claim 32, wherein determining the reconstructed second latent variable based on the bit stream, the reconstructed fourth latent variable, and the reconstructed second variable scaling factor comprises: scaling the reconstructed fourth latent variable based on the reconstructed second variable scaling factor to obtain a reconstructed third latent variable; processing the reconstructed third latent variable using a context decoding neural network model to obtain a reconstructed second entropy coding model parameter; and determining the reconstructed second latent variable based on the bit stream and the reconstructed second entropy coding model parameter.
34. The method according to any one of claims 29 to 33, characterized in that the media data is an audio signal, a video signal or an image.
35. An encoding apparatus, characterized in that the apparatus comprises: a data processing module, configured to process media data to be encoded to obtain a first latent variable, wherein the first latent variable indicates a characteristic of the media data to be encoded; a scaling factor determining module, configured to determine a first variable scaling factor based on the first latent variable, wherein the first variable scaling factor is used to enable an amount of coding bits of an coding result ινίΛ / 111 of a second latent variable to meet a preset coding rate condition, and the second latent variable is obtained by scaling the first latent variable based on the first variable scaling factor; a first coding result obtaining module, configured to obtain the coding result of the second latent variable;and a first encoding result writing module, configured to write the encoding result of the second latent variable and an encoding result of the first variable scale factor into a bit stream.; 36. The apparatus according to claim 35, characterized in that when the media data to be encoded is encoded at a constant bit rate, the fulfillment of a preset encoding rate condition comprises: the number of encoding bits is less than or equal to a target number of encoding bits; or the fulfillment of a preset encoding rate condition comprises: the number of encoding bits is less than or equal to a target number of encoding bits, and a difference between the number of encoding bits and the target number of encoding bits is less than a threshold number of bits.
37. The apparatus according to claim 35, characterized in that when the media data to be encoded is encoded at a variable bit rate, the fulfillment of a preset encoding rate condition comprises: an absolute value of a difference between the number of encoding bits and a target number of encoding bits is less than a threshold number of bits.
38. The apparatus of claim 35, wherein the scale factor determining module comprises: a bit number determining submodule configured to determine an initial number of encoding bits based on the first latent variable; and a first factor determining submodule configured to determine the first variable scale factor based on the initial number of encoding bits and a target number of encoding bits.
39. The apparatus of claim 38, wherein the initial number of coding bits is a number of coding bits of an entropy coding result of the first latent variable; or the initial number of coding bits is a number of coding bits of an entropy coding result of a first latent variable scaled based on a first initial scaling factor.
40. The apparatus according to claim 38, characterized in that when the initial number of coding bits is not equal to the target number of coding bits, ινίΛ / 112 the first factor determining submodule is specifically configured to: determine the first variable scaling factor in a first cyclic manner based on the initial number of coding bits and the target number of coding bits; and the ith cyclic processing of the first cyclic manner comprises the following steps: determining a scaling factor of the ith cyclic processing, wherein i is a positive integer; scaling the first latent variable based on the scaling factor of the ith cyclic processing, to obtain an ith first scaled latent variable;determining an amount of encoding bits from an entropy encoding result of the ith first scaled latent variable, to obtain ith amount of encoding bits; and if the ith amount of encoding bits satisfies a continuous scaling condition, performing the (i + i)th cyclic processing in the first cyclic manner; or if the ith amount of encoding bits does not satisfy a continuous scaling condition, terminating the execution of the first cyclic manner and determining the first variable scaling factor based on the scaling factor of the ith cyclic processing.
41. The apparatus according to claim 35, characterized in that the apparatus further comprises: a second encoding result obtaining module, configured to obtain an entropy encoding result of a third latent variable, wherein the third latent variable is determined based on the second latent variable by using a context model; and a second encoding result writing module, configured to write the entropy encoding result of the third latent variable into the bit stream, wherein a total amount of encoding bits of the entropy encoding result of the second latent variable and encoding bits of the entropy encoding result of the third latent variable meets the condition of a preset encoding rate.
42. The apparatus of claim 41, wherein the scale factor determining module comprises: a bit number determining submodule configured to determine an initial number of encoding bits based on the first latent variable; and a first factor determining submodule configured to determine the first variable scale factor based on the initial number of encoding bits and a target number of encoding bits.
43. The apparatus according to claim 42, characterized in that the bit amount determining submodule is specifically configured to: determine, based on the first latent variable by using the context model, a corresponding initial number of context coding bits and an initial entropy coding model parameter; determine a number of coding bits of an entropy coding result of the first latent variable based on the initial entropy coding model parameter, to obtain a basic initial number of coding bits; and determine the initial number of coding bits based on the initial number of context coding bits and the basic initial number of coding bits.
44. The apparatus of claim 42, wherein when the initial number of coding bits is not equal to the target number of coding bits, the first factor determining submodule is specifically configured to: determine the first variable scaling factor in a first cyclic manner based on the initial number of coding bits and the target number of coding bits; and the ith cyclic processing of the first cyclic manner comprises the following steps: determining a scaling factor of the ith cyclic processing, wherein i is a positive integer; scaling the first latent variable based on the scaling factor of the ith cyclic processing, to obtain an ith first scaled latent variable;determining, based on the first ith latent variable scaled by using the context model, an !th number of context coding bits and an ith entropy coding model parameter; determining a number of coding bits of an entropy coding result of the ith first scaled latent variable based on the ith entropy coding model parameter, to obtain an ith basic number of coding bits; determining an ith number of coding bits based on the ith number of context coding bits and the ith basic number of coding bits; and if the ith number of coding bits meets a continuous scaling condition, performing the (i + 1)th cyclic processing in the first cyclic manner;or if the ith number of encoding bits does not satisfy a continuous scaling condition, terminate execution of the first cyclic manner and determine the first variable scale factor based on the scale factor of the ith cyclic processing; 45. The apparatus according to claim 40 or 44, characterized in that the first factor determining submodule is specifically configured to: ML / 114 determine the scale factor of the ith cyclic processing based on a scale factor of the (i)th cyclic processing in the first cyclic manner, an (i)th number of coding bits and the target number of coding bits, wherein when i=1, the scale factor of the (i)th cyclic processing is a first initial scale factor, and the (ji)th number of coding bits is the initial number of coding bits;and the continuous scaling condition comprises: both the (i)th number of encoding bits and the ith number of encoding bits are less than the target number of encoding bits, or the continuous scaling condition comprises: both the (ii)th number of encoding bits and the ith number of encoding bits are greater than the target number of encoding bits.; 46. The apparatus according to claim 40 or 44, characterized in that when the initial number of coding bits is smaller than the target number of coding bits, the first factor determining submodule is specifically configured to: scale a scale factor of the (i-1)th cyclic processing in the first cyclic manner based on a first step, to obtain the scale factor of the (i-1)th cyclic processing, where when i=1, the scale factor of the (i-1)th cyclic processing is a first initial scale factor; and the continuous scaling condition comprises: the ith number of coding bits is smaller than the target number of coding bits.
47. The apparatus according to claim 40 or 44, characterized in that when the initial number of coding bits is greater than the target number of coding bits, the first factor determining submodule is specifically configured to: scale a scale factor of the (i-1)th cyclic processing in the first cyclic manner based on a second step, to obtain the scale factor of the ith cyclic processing, wherein when i=1, the scale factor of the (i-1)th cyclic processing is a first initial scale factor; and the continuous scaling condition comprises: the ith number of coding bits is greater than the target number of coding bits.
48. The apparatus according to claim 38 or 42, characterized in that the first factor determining submodule is specifically configured to: when the initial number of coding bits is less than the target number of ινίΛ / 115 coding bits, determine a first initial scale factor as the first variable scale factor.
49. The apparatus according to claim 40 or 44, characterized in that the first factor determining submodule is specifically configured to: when the ith number of coding bits is equal to the target number of coding bits, determine the scale factor of the ith cyclic processing as the first variable scale factor; or when the ith number of coding bits is not equal to the target number of coding bits, determine the first variable scale factor based on the scale factor of the ith cyclic processing and a scale factor of the (i-1)th cyclic processing in the first cyclic manner.
50. The apparatus of claim 49, wherein the first factor determining submodule is specifically configured to: determine an average value of the scale factor of the (i)th first cyclic form and the scale factor of the (ii)th first cyclic form; and determine the first variable scale factor based on the average value.
51. The apparatus of claim 49, wherein the first factor determining submodule is specifically configured to: determine the first variable scaling factor of a second cyclic form based on the scaling factor of the ith first cyclic form and the scaling factor of the (i-1)th first cyclic form; and the jth cyclic processing of the second cyclic form comprises the following steps: determining a third scaling factor of the jth cyclic processing based on a first scaling factor of the jth cyclic processing and a second scaling factor of the jth cyclic processing, wherein when j is equal to 1, the first scaling factor of the jth cyclic processing is one of the scaling factor of the ith cyclic processing and the scaling factor of the (i-1)th cyclic processing,the second scaling factor of the jth cyclic processing is the other of the scaling factor of the ith cyclic processing and the scaling factor of the (i1 )th cyclic processing, the first scaling factor of the jth cyclic processing corresponds to a jth-first number of coding bits, the second scaling factor of the jth cyclic processing corresponds to a jth-second number of coding bits, the jth-first number of coding bits is less than the jth-second number of coding bits, and j is a positive integer; obtaining a jth-third number of coding bits,wherein the jth-third number of coding bits is a number of coding bits of a result of ινίΛ / 116 entropy coding of a first latent variable scaled based on the third scaling factor of the jth cyclic processing; and if the jth-third number of coding bits does not satisfy a continuous cycle condition, ending execution in the second cyclic manner and determining the third scaling factor of the jth cyclic processing as the first variable scaling factor; if the jth-third number of coding bits satisfies a continuous cycle condition, and is greater than the target number of coding bits and less than the jth-second number of coding bits,performing (j+i)th cyclic processing in the second cyclic manner using the third scale factor of the jth cyclic processing as a second scale factor of the (j+1)th cyclic processing and using the first scale factor of the jth cyclic processing as a first scale factor of the (j+i)th cyclic processing. 0 s¡ The jth-third number of coding bits satisfies a continuous cycle condition, and is less than the target number of coding bits and greater than the jth-first number of coding bits, performing (j+1)th cyclic processing in the second cyclic manner using the third scale factor of the jth cyclic processing as a first scale factor of the (j+1)th cyclic processing and using the second scale factor of the jth cyclic processing as a second scale factor of the (j+i)th cyclic processing., 52. The apparatus according to claim 49, characterized in that the first factor determining submodule is specifically configured to: determine the first variable scaling factor of a second cyclic manner based on the scaling factor of the ith cyclic processing and the scaling factor of the (i-i)th cyclic processing; and the jth cyclic processing of the second cyclic manner comprises the following steps: determining a third scaling factor of the jth cyclic processing based on a first scaling factor of the jth cyclic processing and a second scaling factor of the jth cyclic processing, wherein when j is equal to 1, the first scaling factor of the jth cyclic processing is one of the scaling factor of the ith cyclic processing and the scaling factor of the (i-1)th cyclic processing,the second scaling factor of the jth cyclic processing is the other of the scaling factor of the ith cyclic processing and the scaling factor of the (i1 )th cyclic processing, the first scaling factor of the jth cyclic processing corresponds to a jth-first number of coding bits, the second scaling factor of the jth cyclic processing corresponds to a jth-second number of coding bits, the jth-first number of coding bits is less than the jth-second number of coding bits, and j is a positive integer; ML / 117 obtaining a jth-third number of coding bits,wherein the jth-third number of coding bits is a number of coding bits of an entropy coding result of a first latent variable scaled based on the third scaling factor of the jth cyclic processing; and if the jth-third number of coding bits does not satisfy a continuous cycle condition, terminating execution of the second cyclic manner and determining the third scaling factor of the jth cyclic processing as the first variable scaling factor; if j reaches a maximum number of cycles and the jth-third number of coding bits satisfies a continuous cycle condition, terminating execution of the second cyclic manner and determining the first variable scaling factor based on the first scaling factor of the jth cyclic processing; if j does not reach a maximum number of cycles, and the jth-third number of coding bits satisfies a continuous cycle condition,and is greater than the target number of coding bits and less than the jth-second number of coding bits, performing the (j+i)th cyclic processing in the second cyclic manner using the third scale factor of the jth cyclic processing as a second scale factor of the (j+i)th cyclic processing and using the first scale factor of the jth cyclic processing as a first scale factor of the (j+l)th cyclic processing; or if j does not reach a maximum number of cycles, and the jth-third number of coding bits satisfies a continuous cycle condition, and is less than the target number of coding bits and greater than the jth-first number of coding bits,performing a (j+i)th cyclic processing in the second cyclic manner using the third scale factor of the jth cyclic processing as the first scale factor of the (j+i)th cyclic processing and using the second scale factor of the (j+i)th cyclic processing as the second scale factor of the (j+1)th cyclic processing., 53. The apparatus according to claim 52, characterized in that the first factor determining submodule is specifically configured to: when the media data to be encoded is encoded at a constant bit rate, determine the first scale factor of the jth cyclic processing as the first variable scale factor.
54. The apparatus of claim 52, wherein the first factor determining submodule is specifically configured to: when media data to be encoded is encoded at a variable bit rate, determine a first difference between the target number of encoding bits and the jth-first number of encoding bits, and determine a second difference between the jth-second number of encoding bits and the target number of encoding bits; and if the first difference is less than the second difference, determine the first scaling factor of the jth cyclic processing as the first variable scaling factor; if the second difference is less than the first difference, determine the second scaling factor of the jth cyclic processing as the first variable scaling factor;or if the first difference is equal to the second difference, determining the first scale factor of the jth cyclic processing as the first variable scale factor, or determining the second scale factor of the jth cyclic processing as the first variable scale factor.; 55. The apparatus according to claim 51 or 52, characterized in that when the media data to be encoded is encoded at a constant bit rate, the continuous cycle condition comprises: the jth-third number of encoding bits is greater than the target number of encoding bits, or the continuous cycle condition comprises: the jth-third number of encoding bits is less than the target number of encoding bits, and a difference between the target number of encoding bits and the jth-third number of encoding bits is greater than a threshold number of bits.
56. The apparatus according to claim 51 or 52, characterized in that when the media data to be encoded is encoded at a variable bit rate, the continuous cycle condition comprises: an absolute value of a difference between the target number of encoding bits and the jth-third number of encoding bits is greater than a threshold number of bits.
57. The apparatus according to claim 38 or 42, characterized in that the first factor determining submodule is specifically configured to: when the initial number of coding bits is equal to the target number of coding bits, determine a first initial scale factor as the first variable scale factor.
58. The apparatus of claim 35, wherein the apparatus further comprises: a scaling factor determining module, further configured to: determine a second variable scaling factor based on the first latent variable; a third encoding result obtaining module, configured to obtain an entropy encoding result of a fourth latent variable, wherein the fourth latent variable is obtained by scaling a third latent variable based on the second variable scaling factor, and the third latent variable is determined based on the second latent variable by using a context model;and a third encoding result writing module, configured to write the entropy encoding result of the fourth latent variable and an encoding result of the second variable scale factor into the bit stream, wherein ινίΛ / 119 a total amount of encoding bits of the entropy encoding result of the second latent variable and encoding bits of the entropy encoding result of the fourth latent variable meets the preset encoding rate condition.; 59. The apparatus of claim 58, wherein the scale factor determining module comprises: a first determining sub-module configured to determine, based on the first latent variable using the context model, a corresponding initial number of context coding bits and an initial entropy coding model parameter; a second determining sub-module configured to determine a number of coding bits of an entropy coding result of the first latent variable based on the initial entropy coding model parameter, to obtain a basic initial number of coding bits;and a second factor determining submodule, configured to determine the first variable scale factor and the second variable scale factor based on the initial number of context coding bits, the initial basic number of coding bits, and a target number of coding bits.; 60. The apparatus of claim 59, wherein the second factor determining submodule is specifically configured to: determine a target basic number of coding bits based on the target number of coding bits and at least one of the initial basic number of coding bits and the initial context coding bit number; determine the first variable scale factor and an actual basic number of coding bits based on a second initial scale factor, the target basic number of coding bits, and the initial basic number of coding bits, wherein the actual basic number of coding bits is a number of coding bits of an entropy coding result of a first latent variable scaled based on the first variable scale factor;determining a target number of context coding bits based on the target number of coding bits and the basic actual number of coding bits; and determining the second variable scale factor based on the target number of context coding bits and the initial number of context coding bits.
61. The apparatus of claim 59, wherein the second factor determining submodule is specifically configured to: divide the target number of coding bits into a target basic number of coding bits and a target number of context coding bits; determine the first variable scaling factor based on the target basic number of ML / 120 coding bits and the initial basic number of coding bits; and determine the second variable scaling factor based on the target number of context coding bits and the initial number of context coding bits.
62. The apparatus according to any one of claims 35 to 61, characterized in that the media data is an audio signal, a video signal or an image.
63. A decoding apparatus, characterized in that the apparatus comprises: a first determining module, configured to determine a reconstructed second latent variable and a reconstructed first variable scaling factor based on a bit stream; a variable scaling module, configured to scale the reconstructed second latent variable based on the reconstructed first variable scaling factor, to obtain a first reconstructed latent variable, wherein the reconstructed first latent variable indicates a characteristic of the media data to be decoded; and a variable processing module, configured to process the reconstructed first latent variable to obtain reconstructed media data.
64. The apparatus of claim 63, wherein the first determining module comprises: a first determining submodule configured to determine a reconstructed third latent variable based on the bit stream; and a second determining submodule configured to determine the reconstructed second latent variable based on the bit stream and the reconstructed third latent variable.
65. The apparatus of claim 64, wherein the second submodule is specifically configured to: process the reconstructed third latent variable using a context decoding neural network model to obtain a first reconstructed entropy coding model parameter; and determine the reconstructed second latent variable based on the bit stream and the first reconstructed entropy coding model parameter.
66. The apparatus of claim 63, wherein the first determining module comprises: a third determining submodule configured to determine a fourth reconstructed latent variable and a second reconstructed variable scale factor based on the bit stream; and a fourth determining submodule configured to determine the second reconstructed latent variable based on the bit stream, the fourth reconstructed latent variable, and the second reconstructed variable scale factor.
67. The apparatus of claim 66, wherein the fourth determining submodule is specifically configured to: scale the reconstructed fourth latent variable based on the reconstructed second variable scaling factor to obtain a reconstructed third latent variable; process the reconstructed third latent variable using a context decoding neural network model to obtain a reconstructed second entropy coding model parameter; and determine the reconstructed second latent variable based on the bit stream and the reconstructed second entropy coding model parameter.
68. The apparatus according to any one of claims 63 to 67, characterized in that the media data is an audio signal, a video signal or an image.
69. An encoder-side device, characterized in that the encoder-side device comprises a memory and a processor; and the memory is configured to store a computer program, and the processor is configured to execute the computer program stored in the memory, for implementing the encoding method according to any one of claims 1 to 28.
70. A decoder-side device, characterized in that the decoder-side device comprises a memory and a processor; and the memory is configured to store a computer program, and the processor is configured to execute the computer program stored in the memory, to implement the decoding method according to any one of claims 29 to 34.
71. A computer-readable storage medium, characterized in that the storage medium stores instructions, and when the instructions are executed on a computer, the computer is enabled to perform the step of the method according to any one of claims 1 to 34.
72. A computer program, characterized in that when the computer program product is carried out on a computer, the method according to any one of claims 1 to 34 is implemented.
73. A computer-readable storage medium, characterized in that it comprises the bit stream obtained by using the encoding method according to any of claims 1 to 28.