A method for prediction refinement with optical flow, PROF, for an affine coded block in video encoding or video decoding, the method is performed by an encoding apparatus or a decoding apparatus, comprising: performing a PROF process for a current sub-block of the affine coded block to obtain refined prediction sample values of the current sub-block of the affine coded block, wherein all of a plurality of constraint conditions for applying PROF are not fulfilled for the affine coded block; wherein the performing a PROF process for a current sub-block of the affine coded block comprises: performing an optical flow processing for the current sub-block to obtain a delta prediction value of a current sample of the current sub-block; and obtaining a refined prediction sample value of the current sample based on the delta prediction value of the current sample and a prediction sample value of the current sample of the current sub-block; wherein the plurality of constraint conditions for applying PROF comprises: first indication information indicates that PROF is disabled for a picture containing the affine coded block; and second indication information indicates no partition of the affine coded block; and wherein the performing an optical flow processing for the current sub-block to obtain a delta prediction value of a current sample of the current sub-block comprises: obtaining a second prediction matrix, wherein the second prediction matrix is generated based on motion information of the current sub-block; generating a horizontal prediction gradient matrix and a vertical prediction gradient matrix based on the second prediction matrix, wherein the horizontal prediction gradient matrix and the vertical prediction gradient matrix have a same size and a size of the second prediction matrix is greater than or equal to the size of the horizontal prediction gradient matrix and the vertical prediction gradient matrix; and calculating a delta prediction value of the current sample of the current sub-block based on a horizontal prediction gradient value of the current sample in the horizontal prediction gradient matrix, a vertical prediction gradient value of the current sample in the vertical prediction gradient matrix, and a difference between a motion vector of the current sample of the current sub-block and a motion vector of a center sample of the current sub-block. performing a PROF process for a current sub-block of the affine coded block to obtain refined prediction sample values of the current sub-block of the affine coded block, wherein all of a plurality of constraint conditions for applying PROF are not fulfilled for the affine coded block; wherein the performing a PROF process for a current sub-block of the affine coded block comprises: performing an optical flow processing for the current sub-block to obtain a delta prediction value of a current sample of the current sub-block; and obtaining a refined prediction sample value of the current sample based on the delta prediction value of the current sample and a prediction sample value of the current sample of the current sub-block; performing an optical flow processing for the current sub-block to obtain a delta prediction value of a current sample of the current sub-block; and obtaining a refined prediction sample value of the current sample based on the delta prediction value of the current sample and a prediction sample value of the current sample of the current sub-block; wherein the plurality of constraint conditions for applying PROF comprises: first indication information indicates that PROF is disabled for a picture containing the affine coded block; and second indication information indicates no partition of the affine coded block; and wherein the performing an optical flow processing for the current sub-block to obtain a delta prediction value of a current sample of the current sub-block comprises: first indication information indicates that PROF is disabled for a picture containing the affine coded block; and second indication information indicates no partition of the affine coded block; and wherein the performing an optical flow processing for the current sub-block to obtain a delta prediction value of a current sample of the current sub-block comprises: obtaining a second prediction matrix, wherein the second prediction matrix is generated based on motion information of the current sub-block; generating a horizontal prediction gradient matrix and a vertical prediction gradient matrix based on the second prediction matrix, wherein the horizontal prediction gradient matrix and the vertical prediction gradient matrix have a same size and a size of the second prediction matrix is greater than or equal to the size of the horizontal prediction gradient matrix and the vertical prediction gradient matrix; and calculating a delta prediction value of the current sample of the current sub-block based on a horizontal prediction gradient value of the current sample in the horizontal prediction gradient matrix, a vertical prediction gradient value of the current sample in the vertical prediction gradient matrix, and a difference between a motion vector of the current sample of the current sub-block and a motion vector of a center sample of the current sub-block.