top | item 22776010

(no title)

iwalton3 | 5 years ago

I used this to stabilize a bunch of vacation videos with great results. It works better than the deshake filter but does require two passes.

   function stabilize {
       tempfile=".temp$RANDOM$RANDOM.trf"
       ffmpeg -nostdin -loglevel error -y -i "$1" -vf vidstabdetect=shakiness=5:show=1:result="$tempfile" -f null -
       ffmpeg -nostdin -loglevel error -y -i "$1" -vf vidstabtransform=input="$tempfile",unsharp=5:5:0.8:3:3:0.4 -movflags +faststart "$2"
       rm "$tempfile"
   }
Usage: stabilize infile outfile.mp4

discuss

order

mehrdadn|5 years ago

Thank you! I'll give it a try.

Update: Just tried it. It seems to do some kind of blurring to smooth the vibrations over several frames instead of trying to cancel the shaking by inverse-transforming the frame with respect to the shake. I think I've tried this in my experiments before -- and I guess it's the difference between "de-shake" and "stabilization"? Sadly it doesn't really seem better to my eyes sadly, but thanks for the help anyway.

pocak|5 years ago

It works by applying a low-pass filter on the camera's motion, so a sudden kick turns into a slow, low amplitude bob.

Perhaps you just need to increase the smoothing parameter. I found the default of 10 way too low, and needed around 50-100 for my very shaky 50 fps home videos.

iwalton3|5 years ago

It does have a mild blur filter which you can remove, but if it isn’t actually stabilizing the video from shakiness, something is wrong.

See here: https://ffmpeg.org/ffmpeg-filters.html#vidstabdetect-1

Maybe your ffmpeg build doesn’t have it? Also try removing the log level parameter.