a lot of hand held videos are shaky, youtube used to have great stabilization filter… but Alphabet Google removed it (too CPU intense or what?)

most smart phones and camera apps actually should apply some anti shake stabilization during recording … but sometimes it’s not enough

luckily UNIX style combining multiple nice tools it’s possible with some bash magic to offline stabilize (anti shake) a video BUT BE WARNED: the quality is not great and it will introduce a lot of artefacts, especially when there are a lot of details moving fast 🙁

hostnamectl; # tested on
Static hostname: workstation
Operating System: Debian GNU/Linux 13 (trixie) 
Kernel: Linux 6.12.48+deb13-amd64
Architecture: x86-64
Hardware Vendor: Gigabyte Technology Co., Ltd.
Hardware Model: B550 AORUS ELITE AX V2

su - root; # become root
apt-get install ffmpeg libavfilter-extra libvidstab1.1; # install required tools
vim /scripts/mp4stabilize_anti_shake.sh; # create a script for better reusability

#!/bin/bash
# anti shake video stabilize bash script by dwaves.de + AI https://duck.ai/
# v2.0
ffmpeg -i $1 -vf vidstabdetect=shakiness=5:result=$1_stabilized.trf -f null -
ffmpeg -i $1 -vf "vidstabtransform=smoothing=30:input=$1_stabilized.trf:zoom=1.05,hqdn3d=1.5:1.5:6:6" -c:v libx264 -crf 18 -preset slow -c:a copy $1_stabilized.mp4

# v1.0 works but loss of quality is signifant and also aretefacts are introduced
# echo "analyzing video ..."
# ffmpeg -i $1 -vf vidstabdetect=shakiness=5:accuracy=15:result=$1_transforms.trf -f null -
# echo "applying stabilize anti shake... "
# ffmpeg -i $1 -vf vidstabtransform=smoothing=30:input=$1_transforms.trf -c:v libx264 -crf 23 -preset medium $1_stabilized.mp4

chmod +x /scripts/*.sh
cd /home/where/video/is
/scripts/mp4stabilize_anti_shake.sh shaky_video_file.mp4; # run it, all output will be in the same folder

if the output still sucks… test other methods:

2. HandBrake (GUI)

Install: sudo apt-get install handbrake
Open HandBrake → Source → select video.
In the Filters tab, set Deinterlace to Off and Detelecine to Off (these are unrelated).
In the Video tab, enable Stabilization (requires the libvidstab plugin).
Choose output settings and click Start Encode.

3. Shotcut (cross‑platform GUI)

Install: sudo snap install shotcut –classic

# BUT sure first user has to install snap: please DO NOT install snap on productive work PC or laptop, rather install it inside a Debian or Ubuntu vm where snap is native and the user does not care how much it messes with the rest of the system

Drag the video onto the timeline.
Select the clip → Filters → + → Stabilize.
Click Analyze; after processing, the clip will play stabilized.

Tips for Better Results

Trim first: Remove unnecessary start/end sections before stabilizing; it speeds up analysis.
Crop after: Stabilization can introduce black borders. Use ffmpeg -vf “crop=iw-2*crop_w:ih-2*crop_h” or Shotcut’s Crop filter to cut them out.
Avoid extreme shakiness: If the original footage is very jittery, increase shakiness (up to 10) and smoothing (up to 70) but expect some loss of detail.
Preserve audio: The commands above keep the original audio stream (-c:a copy can be added if you don’t want re‑encoding).

liked this article?

  • only together we can create a truly free world
  • plz support dwaves to keep it up & running!
  • (yes the info on the internet is (mostly) free but beer is still not free (still have to work on that))
  • really really hate advertisement
  • contribute: whenever a solution was found, blog about it for others to find!
  • talk about, recommend & link to this blog and articles
  • thanks to all who contribute!
admin