Fixing of Shaky Video Parts with FFmpeg

Some parts of the video taken without a tripod or from a vehicle usually include shaking, so in this tutorial, we will see how to fix shaky video parts using FFmpeg filter.

Small changes in a horizontal and vertical shift that can be in certain cases corrected with a deshake filter:

Filter syntax
deshake=x:y:w:h:rx:ry:edge:blocksize:contrast:search:filename
x, y, w, hcoordinates and size of a rectangular area where to search for motion vectors, x and y are top left corner coordinates, w is width and h is height. These parameters can be used to visualize the position of the bounding box.
rx, ryspecify the maximum extent of movement in x and y directions in the range 0 - 64 pixels, the default value is 16
edgeSpecifies how to generate pixels to fill blanks at the edge of the frame, the value is an integer from 0 to 3:
0 - fill zeros at blank locations
1 - original image at blank locations
2 - extruded edge value at blank locations
3 - mirrored edge at blank locations, the default value
blocksizespecifies the blocksize to use for motion search, the value is from range 4 - 128 pixels, the default value is 8
contrastspecifies the contrast threshold for blocks with more than the specified contrast will be considered. The value is from range 1 - 255, the default value is 125.
searchspecifies the search strategy:
0 - exhaustive search, the default value
1 - less exhaustive search
filenameif included, a detailed log of motion search is written to the specified file
FILTER USAGE
ffmpeg -i shaky_video.avi -vf deshake fixed_video.avi

Parameters can be entered sequentially in the default sequence or specified with their name in any order:

ffmpeg -i shaky_video.avi -vf deshake=contrast=160 fixed_video.avi
ffmpeg -i shaky_video.avi -vf deshake=blocksize=4:filename=log.txt fixed_video.avi

 

Published by

qoraiche

Codecs Lover

Leave a Reply