A method in a video encoder, comprising: receiving a current frame to be encoded and dividing the current frame into blocks of pixels, calculating a spatial variability of a block of pixels of the current frame, matching the block of pixels of the current frame with a plurality of blocks of pixels of a reference frame, wherein, for each of the plurality of blocks of pixels in the reference frame, a motion vector and a sum of absolute differences, SAD, between the block of pixels of the current frame and the block of pixels in the reference frame are calculated, and a cost for encoding the block of pixels of the current frame as an inter-coded block with reference to the block of pixels in the reference frame is evaluated according to a cost function which is a weighted sum of a cost of encoding the motion vector and the SAD calculated with respect to the block of pixels in the reference frame, wherein the cost function is set to be dependent on the spatial variability of the block of pixels in the current frame, such that a ratio of a weight associated with the cost of encoding the motion vector and a weight associated with the SAD is lower if the spatial variability of the block of pixels in the current frame is below a first threshold compared to if the spatial variability is equal to or above the first threshold, determining that the cost for encoding the block of pixels of the current frame as an inter-coded block is equal to the lowest evaluated cost, adjusting a predefined value as a cost for encoding the block of pixels in the current frame as an intra-coded block based on the spatial variability of the block of pixels in the current frame, such that the cost for encoding the block of pixels in the current frame as an intra-coded block is higher if the spatial variability is equal to or above the first threshold compared to if the spatial variability is below the first threshold, comparing the cost for encoding the block of pixels in the current frame as an inter-coded block to the cost for encoding the block of pixels in the current frame as an intra-coded block, encoding the block of pixels of the current frame as an inter-coded block if the cost for encoding the block of pixels in the current frame as an inter-coded block is lower than the cost for encoding the block of pixels in the current frame as an intra-coded block, wherein the block of pixels of the current frame is encoded with reference to the block of pixels in the reference frame having the lowest evaluated cost, and encoding the block of pixels in the current frame as an intra-coded block if the cost for encoding the block of pixels in the current frame as an inter-coded block is greater than or equal to the cost for encoding the block of pixels in the current frame as an intra-coded block. receiving a current frame to be encoded and dividing the current frame into blocks of pixels, calculating a spatial variability of a block of pixels of the current frame, matching the block of pixels of the current frame with a plurality of blocks of pixels of a reference frame, wherein, for each of the plurality of blocks of pixels in the reference frame, a motion vector and a sum of absolute differences, SAD, between the block of pixels of the current frame and the block of pixels in the reference frame are calculated, and a cost for encoding the block of pixels of the current frame as an inter-coded block with reference to the block of pixels in the reference frame is evaluated according to a cost function which is a weighted sum of a cost of encoding the motion vector and the SAD calculated with respect to the block of pixels in the reference frame, wherein the cost function is set to be dependent on the spatial variability of the block of pixels in the current frame, such that a ratio of a weight associated with the cost of encoding the motion vector and a weight associated with the SAD is lower if the spatial variability of the block of pixels in the current frame is below a first threshold compared to if the spatial variability is equal to or above the first threshold, determining that the cost for encoding the block of pixels of the current frame as an inter-coded block is equal to the lowest evaluated cost, adjusting a predefined value as a cost for encoding the block of pixels in the current frame as an intra-coded block based on the spatial variability of the block of pixels in the current frame, such that the cost for encoding the block of pixels in the current frame as an intra-coded block is higher if the spatial variability is equal to or above the first threshold compared to if the spatial variability is below the first threshold, comparing the cost for encoding the block of pixels in the current frame as an inter-coded block to the cost for encoding the block of pixels in the current frame as an intra-coded block, encoding the block of pixels of the current frame as an inter-coded block if the cost for encoding the block of pixels in the current frame as an inter-coded block is lower than the cost for encoding the block of pixels in the current frame as an intra-coded block, wherein the block of pixels of the current frame is encoded with reference to the block of pixels in the reference frame having the lowest evaluated cost, and encoding the block of pixels in the current frame as an intra-coded block if the cost for encoding the block of pixels in the current frame as an inter-coded block is greater than or equal to the cost for encoding the block of pixels in the current frame as an intra-coded block.