Skip to content

Instantly share code, notes, and snippets.

@kowalcj0
Created September 8, 2018 22:40
Show Gist options
  • Save kowalcj0/bd88621e4be9951fbc6de8d2cb564fae to your computer and use it in GitHub Desktop.
Save kowalcj0/bd88621e4be9951fbc6de8d2cb564fae to your computer and use it in GitHub Desktop.
Stabilise shaky video with ffmpeg and vid.stab
alias stabilize=stabilize
function stabilize() {
type ffmpeg >/dev/null 2>&1 || { echo >&2 "ffmpeg is required but it's not installed."; return 1; }
video="${1}"
filename="${1%.*}"
extension="${1##*.}"
output="${filename}-stabilized.${extension}"
# calculate transformation vectors
ffmpeg -nostdin -hide_banner -i "${video}" -vf vidstabdetect=stepsize=6:shakiness=8:accuracy=15:result=transform_vectors.trf -f null -
# stabilise video using transformation vectors from previous step
ffmpeg -nostdin -hide_banner -i "${video}" -vf vidstabtransform=input=transform_vectors.trf:zoom=1:smoothing=30,unsharp=5:5:0.8:3:3:0.4 -vcodec libx264 -preset slow -tune film -crf 18 -acodec copy "${output}"
rm -fr transform_vectors.trf
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment