Using ffmpeg in Ubuntu 18.04 to stabilize video shake.There are a number of internet resources, but they did not make life easier. So here are few simple comments and instructions about the basics. I do assume a simple knowledge of installing software and the command line.
Get the right ffmpeg.The stabilization is done by filters in ffmpeg - not my idea of what a filter is, but that is just an aside. Some versions of ffmpeg do not contain these filters and then you have to add them (how, I have given up to find out).
One way of getting the relevant ffmpeg version is to add a PPA link to the repositories and then to update the software on your pc. If you use Synaptic, the process is quite simple as you are prompted to update your software, search then for ffmpeg, mark it for installation and apply it.
In any event, here is a more complete explanation doing it entirely via the command line in the terminal.
The next step is to get hold of the video to be stabilized and its location on your pc.
1. Navigate to the folder in the terminalNavigate with the command line terminal to the relevant folder.
2. Convert to mp4 format (optional, but recommended to get the feel for the process) In my case, I first converted my video to mp4 format, using the following command line instruction, after having navigated to the folder where my video is. Perhaps it is not necessary but I got the impression that ffmpeg did not like the .MOV file extension. In any event, just to get the feel for the process, keep to the names I used and do a similar conversion where your target video is used in the place of my MVI_0103.MOV video.
ffmpeg -i MVI_0103.MOV shaky.mp4The converted video will now be found under shaky.mp4 in the same folder.
3.The two core command line instructions Next run the following command in the terminal, in the folder where the video is (ie the folder you already have navigated to).
ffmpeg -i shaky.mp4 -vf vidstabdetect=shakiness=10:accuracy=15:result="mytransforms.trf":show=1 dummy.avi
This creates two extra files:
dummy.avi and
mytransforms.trf The dummy.avi apparently shows the stabilization process . The mytransformations.trf file contains instruction the next command line instruction operates on.
So then, in the terminal, in the same folder, you run the following command:
ffmpeg -i shaky.mp4 -vf vidstabtransform=smoothing=25:zoom=1:input="mytransforms.trf",unsharp=13:13:1.4:9:9:1.4 inp_stabilized.mp4This creates the stabilized video in a file called
inp_stabilized.mp4Run this in a video editor (eg SM Player, VLC ) and you should see a much improved video.
It will be seen from the following documentation that numerous changes can be made to the stabilization process by changing parameters in the commands.
With reference to the documentation, the first core command above we can call vidstabdetect and the second one, vidstabtransform.
4. Odds and EndsSome video editors (eg Blender, Kendenlive) provide built-in stabilization options. Perhaps that makes it easier, but Blender is a nightmare whatever one does. Stabilization in ffmpeg cries out for a GUI to make life simpler as the insertion of various parameters in the course of experimenting with the best results is time consuming and mind numbing.