Skip to content

Instantly share code, notes, and snippets.

@wbhinton
Last active March 16, 2023 14:02
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wbhinton/69f6466ba641a43774ed9f5fae5e3c92 to your computer and use it in GitHub Desktop.
Save wbhinton/69f6466ba641a43774ed9f5fae5e3c92 to your computer and use it in GitHub Desktop.
Video Stabilization

Default

ffmpeg -i shaky-input.mp4 -vf vidstabdetect=shakiness=5:accuracy=15:stepsize=6:mincontrast=0.3:show=2 -y dummy.mp4
ffmpeg -i shaky-input.mp4 -vf scale=trunc((iw*1.15)/2)*2:trunc(ow/a/2)*2 -y scaled.mp4
ffmpeg -i scaled.mp4 -vf vidstabtransform=smoothing=30:input="transforms.trf":interpol=linear:crop=black:zoom=-15:optzoom=0,unsharp=5:5:0.8:3:3:0.4 -y stabilized-output.mp4

Crop

ffmpeg -i shaky-input.mp4 -vf vidstabdetect=shakiness=5:accuracy=15:stepsize=6:mincontrast=0.3:show=2 dummy_crop.mp4
ffmpeg -i shaky-input.mp4 -vf scale=trunc((iw*0.90)/2)*2:trunc(ow/a/2)*2 scaled_crop.mp4
ffmpeg -i scaled_crop.mp4 -vf vidstabtransform=smoothing=30:input="transforms.trf":interpol=linear:zoom=-10:optzoom=2,unsharp=5:5:0.8:3:3:0.4 stabilized_crop-output.mp4

Tripod

ffmpeg -i shaky-input.mp4 -vf vidstabdetect=shakiness=5:accuracy=15:stepsize=6:mincontrast=0.3:show=2 dummy_tripod.mp4
ffmpeg -i shaky-input.mp4 -vf scale=trunc((iw*1.15)/2)*2:trunc(ow/a/2)*2 scaled_tripod.mp4
ffmpeg -i scaled_tripod.mp4 -vf vidstabtransform=tripod=1:interpol=linear:crop=black:zoom=-35 stabilized_tripod-output.mp4

2step

ffmpeg -i input.mp4 -vf vidstabdetect=stepsize=32:shakiness=10:accuracy=10:result=transforms.trf -f null -
ffmpeg -y -i input.mp4 -vf vidstabtransform=input=transforms.trf:zoom=0:smoothing=10,unsharp=5:5:0.8:3:3:0.4 -vcodec libx264 -tune film -acodec copy -preset slow output.mp4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment