Method for encoding video, comprising: receiving information (S02; S102) representative of pixels in a current digital image frame (1; 1a-f) of a video to be encoded, calculating (S03; S103) a group value for each group of neighboring pixels based on said received information for groups of neighboring pixels in said current digital image frame, accumulating (S04; S104) group values of corresponding groups of neighboring pixels in a first sequence of digital image frames comprising said current frame and a first number of preceding image frames to form a first accumulation of accumulated group values, accumulating (S05; S106) group values of corresponding groups of neighboring pixels in a second sequence of digital image frames comprising said current digital image frame and a second number of preceding digital image frames to form a second accumulation of accumulated group values, wherein said second sequence of digital image frames includes digital image frames captured over a longer period of time than the image frames of said first sequence, comparing (S06; S106) accumulated group values of said first accumulation with accumulated group values of corresponding groups of neighboring pixels in said second accumulation, calculating (S07; S108) a global change value based on the comparison of the first and second accumulations (AS, AL) of group values, setting (S08; S109) a GOP length as a number of frames to be encoded in a group of pictures based on said global change value, including making a choice between increasing, decreasing and leaving unaltered a current GOP length; and encoding (S09; S110) said current image frame as an intra-frame or inter-frame based on said GOP length. receiving information (S02; S102) representative of pixels in a current digital image frame (1; 1a-f) of a video to be encoded, calculating (S03; S103) a group value for each group of neighboring pixels based on said received information for groups of neighboring pixels in said current digital image frame, accumulating (S04; S104) group values of corresponding groups of neighboring pixels in a first sequence of digital image frames comprising said current frame and a first number of preceding image frames to form a first accumulation of accumulated group values, accumulating (S05; S106) group values of corresponding groups of neighboring pixels in a second sequence of digital image frames comprising said current digital image frame and a second number of preceding digital image frames to form a second accumulation of accumulated group values, wherein said second sequence of digital image frames includes digital image frames captured over a longer period of time than the image frames of said first sequence, comparing (S06; S106) accumulated group values of said first accumulation with accumulated group values of corresponding groups of neighboring pixels in said second accumulation, calculating (S07; S108) a global change value based on the comparison of the first and second accumulations (AS, AL) of group values, setting (S08; S109) a GOP length as a number of frames to be encoded in a group of pictures based on said global change value, including making a choice between increasing, decreasing and leaving unaltered a current GOP length; and encoding (S09; S110) said current image frame as an intra-frame or inter-frame based on said GOP length.