A method of optimizing an encoded video stream comprising one or more video frames, each video frame comprising a plurality of macroblocks, each macroblock comprising a plurality of pixels, the method comprising: receiving an encoded macroblock; decoding the encoded macroblock; extracting a first quantization parameter, wherein the first quantization parameter corresponds to quantization settings originally used for compressing the encoded macroblock; computing a second quantization parameter based at least in part on the first quantization parameter; re-encoding the decoded macroblock based on the second quantization parameter; and providing the re-encoded macroblock wherein computing the second quantization parameter comprises defining a first threshold and a second threshold as a function of past input quantization parameters, wherein the past input quantization parameters correspond to quantization settings originally used for compressing a plurality of previously received encoded macroblocks, setting the second quantization parameter to be equal or lower than the first quantization parameter when the first quantization parameter is higher than the first threshold, and setting the second quantization parameter to be higher than the first quantization parameter when the first quantization parameter is lower than the second threshold, wherein computing the second quantization parameter is further based in part on a number of bits occupied by the encoded macroblock, wherein if the first quantization parameter is lower than the second threshold and it is determined that the number of bits occupied by the encoded macroblock is lower than a third threshold setting the second quantization parameter to be equal or lower than the first quantization parameter, and if the first quantization parameter is higher than the first threshold and it is determined that the number of bits occupied by the encoded macroblock is higher than a fourth threshold setting the second quantization parameter to be higher than the first quantization parameter. receiving an encoded macroblock; decoding the encoded macroblock; extracting a first quantization parameter, wherein the first quantization parameter corresponds to quantization settings originally used for compressing the encoded macroblock; computing a second quantization parameter based at least in part on the first quantization parameter; re-encoding the decoded macroblock based on the second quantization parameter; and providing the re-encoded macroblock wherein computing the second quantization parameter comprises defining a first threshold and a second threshold as a function of past input quantization parameters, wherein the past input quantization parameters correspond to quantization settings originally used for compressing a plurality of previously received encoded macroblocks, setting the second quantization parameter to be equal or lower than the first quantization parameter when the first quantization parameter is higher than the first threshold, and setting the second quantization parameter to be higher than the first quantization parameter when the first quantization parameter is lower than the second threshold, wherein computing the second quantization parameter is further based in part on a number of bits occupied by the encoded macroblock, wherein if the first quantization parameter is lower than the second threshold and it is determined that the number of bits occupied by the encoded macroblock is lower than a third threshold setting the second quantization parameter to be equal or lower than the first quantization parameter, and if the first quantization parameter is higher than the first threshold and it is determined that the number of bits occupied by the encoded macroblock is higher than a fourth threshold setting the second quantization parameter to be higher than the first quantization parameter. <EOS>