Adjust vidstabdetect Accuracy in FFmpeg
This article provides a quick guide on how to adjust the shaking
detection accuracy in FFmpeg using the vidstabdetect
filter. By fine-tuning parameters such as accuracy, shakiness, and step
size, you can significantly improve how the filter analyzes camera
movement, leading to much smoother video stabilization in the subsequent
rendering step.
The vidstabdetect filter is the first step in the
two-pass stabilization process of the vid.stab library in
FFmpeg. It analyzes the video and writes motion data to a file
(typically transforms.trf). To adjust how precisely this
filter detects shaking, you need to modify three key parameters:
accuracy, shakiness, and
stepsize.
Key Parameters for Adjusting Accuracy
accuracy(Integer, 1 to 15): This parameter directly controls the accuracy of the detection process. A value of 1 represents the lowest accuracy (fastest processing), while 15 represents the highest accuracy (slowest processing). The default value is 15. If you are experiencing poor stabilization, ensure this is kept at a high value.shakiness(Integer, 1 to 10): This parameter defines how shaky the input video is. A value of 1 means minimal shaking, while 10 means extremely shaky. Setting this correctly helps the algorithm optimize its search grid. The default is 4. For very shaky, fast-moving footage, increase this value to 7 or 8.stepsize(Integer, 1 or greater): This controls the step size of the search process in pixels. A smaller step size results in more precise motion detection but increases processing time. The default is 6. Lowering this to 4 or 2 can improve accuracy on fine, high-frequency vibrations.
Example Commands
To apply these adjustments, run the detection pass with your custom parameters.
For Highly Precise Detection (Slowest, Best Quality):
ffmpeg -i input.mp4 -vf vidstabdetect=accuracy=15:shakiness=8:stepsize=2:result=transforms.trf -f null -For Standard/Default Detection (Balanced):
ffmpeg -i input.mp4 -vf vidstabdetect=accuracy=10:shakiness=4:stepsize=6:result=transforms.trf -f null -The Second Pass (Applying the Stabilization)
Once the motion data is generated with your desired accuracy
settings, apply the stabilization using the
vidstabtransform filter in the second pass:
ffmpeg -i input.mp4 -vf vidstabtransform=input=transforms.trf output.mp4