The problem consist of creating a timelapse made of photos which have been taken with a camera which has been removed and attached to a tripod during a few months thus creating a lot of shaking. Solution, use hugin to align photos:

<pre lang="bash">
#!/bin/bash

align_image_stack -v -a$1 -s 2 *.jpg

mkdir base
for i in $(find . -maxdepth 1 -name "*.tif"); do n=".$(echo $i | cut -f2 -d".").jpg"; convert $i $n && mv $n base; done
rm *.tif
cd base && mencoder -nosound -ovc lavc -lavcopts vcodec=mpeg4:mbd=2:trell:autoaspect:vqscale=3 -mf type=jpeg:fps=5 mf://*.jpg -o $1.avi && cd .. && mv base/$1.avi .