Provided in the present application are a coding method, which can be applied to scenarios, such as video coding and decoding. The method comprises: acquiring two image frames, which has a succession association relationship in terms of timing, wherein the two image frames comprise a
reference frame and a current frame; obtaining a predicted frame of the current frame according to the
reference frame and motion information, wherein the motion information is used for describing a transformation difference between the
reference frame and the current frame; acquiring
mask information on the basis of the current frame and the predicted frame, wherein the
mask information is used for indicating
code rate allocation information of the current frame; and coding the current frame on the basis of the
code rate allocation information, so as to obtain a code
stream. The
mask information is acquired according to the predicted frame and the current frame, and therefore the mask information can better present areas, which have a relatively poor or good reconstruction effect, in the predicted frame, such that
code rate allocation can be performed on corresponding areas in the current frame. For example, a higher code rate is allocated to an area, of which the quality is predicted to be relatively poor, such that the
coding quality of an area, in which irregular motion is present, or a blocked area is improved.