Skip to content

Instantly share code, notes, and snippets.

@parsapoorsh
Last active November 26, 2025 15:45
Show Gist options
  • Select an option

  • Save parsapoorsh/5562371ce28f760a092cce2e36b9e476 to your computer and use it in GitHub Desktop.

Select an option

Save parsapoorsh/5562371ce28f760a092cce2e36b9e476 to your computer and use it in GitHub Desktop.
ffmpeg video stabilization

ffmpeg video stabilization

for finding encoder info use: $ ffprobe -i original.mp4

for next commands, encoder settings MUST BE the same or better then original video to don't lose significant quality and color during re-encoding


shake detection and stabilization:

$ ENCODER_CMD="-c:v libx265 -preset medium -crf 28 -pix_fmt yuv420p" # example encoder
$ ffmpeg -i original.mp4 -vf 'vidstabdetect=shakiness=5:accuracy=15:stepsize=3:show=1:result=original.trf' -f null - # detection
$ ffmpeg -i original.mp4 -vf 'vidstabtransform=smoothing=10:input=original.trf' -c:a copy $ENCODER_CMD stabilized.mp4 # stabilization

to compare side by side

$ ffmpeg -i original.mp4 -i stabilized.mp4 -filter_complex hstack=inputs=2 -c:a copy $ENCODER_CMD sidebyside.mp4

sources:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment