Stabilize shaky video footage on Linux Mint by installing FFmpeg, converting your clip to an uncompressed format for processing, applying the vidstabdetect filter to generate motion data, and then using transform to apply the correction. This method produces smooth results without third-party GUI tools.
Installing FFmpeg on Linux Mint
Before stabilizing any video, you must ensure that the necessary software is present on your system. Linux Mint relies on the Debian package manager, making installation straightforward through the terminal. Open a terminal window and update your package lists to ensure you are pulling from the most recent repositories.sudo apt update
Once the update completes, install FFmpeg along with its associated utilities. The following command installs the core tool and several helper packages that may be useful for subsequent encoding tasks.
sudo apt install ffmpeg ffmpeg-doc libavcodec-extra
Verify the installation by checking the version. Running ffmpeg -version should return output indicating the installed build number and configuration options. If the command fails, ensure that the multiverse repository is enabled in your Software Sources settings, as some codec libraries reside there.
Preparing the Video File
The stabilization process involves two distinct passes: detection and transformation. To achieve high-quality results, it is crucial to work with a lossless or minimally compressed intermediate file during the analysis phase. Compressed formats like MP4 or MKV can introduce artifacts that confuse the motion detection algorithm, leading to jittery corrections. First, convert your source video into an uncompressed AVI container using the rawvideo pixel format. This step ensures that every frame is preserved exactly as captured, providing the cleanest possible data for the detector. Replaceinput.mp4 with your actual filename.
ffmpeg -i input.mp4 -c:v rawvideo -pix_fmt yuv420p output_uncompressed.avi
This conversion may take time depending on the resolution and length of the clip. Once complete, you will have a large file ready for analysis. While this file is large, it is only temporary. You will delete it after the final export, so do not worry about disk space constraints for long-term storage.
Detecting Camera Motion
The first technical pass uses thevidstabdetect filter to analyze the movement between frames. This filter calculates how much the camera shifted horizontally, vertically, and rotationally. It generates a text file containing the transformation matrices required for stabilization.
Run the following command to perform the detection. The traj.txt file is the critical output here; do not lose it.
ffmpeg -i output_uncompressed.avi -vf vidstabdetect=shakiness=5:accuracy=15 result.traj
Adjust the parameters based on your specific needs. The shakiness value determines sensitivity. A value of 1 is very conservative, while 10 is highly aggressive. For typical handheld footage, 5 is a good starting point. The accuracy parameter controls the precision of the subpixel estimation. Higher values (up to 15) yield more accurate results but increase processing time significantly.
If the resulting trajectory file seems incomplete or the video still shakes heavily, you may need to adjust these parameters. For extremely shaky footage, consider increasing shakiness to 7 or 8. For subtle handheld drift, reduce it to 3.
Applying the Stabilization Transform
With the motion data extracted, the second pass applies the inverse movements to smooth out the video. This step uses thevidstabtransform filter, which reads the previously generated trajectory file and warps each frame accordingly.
Use the following command to create the stabilized video. Ensure you reference the correct trajectory file path.
ffmpeg -i output_uncompressed.avi -vf vidstabtransform=input=result.traj:smoothing=10:optfilter=deblurr stabilized_output.avi
The smoothing parameter is vital. It applies a moving average to the transformation data, reducing residual micro-jitters. Values typically range from 0 to 30. Start with 10 for standard videos. Increase this value if the video still feels "bumpy" after initial processing.
You may notice black borders appearing around the edges of the video because the image has been cropped to maintain aspect ratio during the warping process. To fill these areas, you can add a blur effect or simply accept the cropping. If you prefer cropping over blurring, add :crop=black to the filter chain. However, note that aggressive cropping reduces the final resolution.
Final Encoding and Optimization
The output from the previous step is still an uncompressed AVI file. To make it usable for sharing or playback, encode it into a modern format like MP4 with H.264 compression. This reduces file size dramatically while maintaining visual quality.ffmpeg -i stabilized_output.avi -c:v libx264 -crf 23 -preset medium final_stabilized.mp4
The -crf (Constant Rate Factor) value controls quality. A value of 23 is default and offers a good balance. Lower values (e.g., 18) produce higher quality but larger files. Higher values (e.g., 28) reduce file size at the cost of visible artifacts. The -preset option affects encoding speed versus compression efficiency. Use medium for a balanced approach, or slow if you want smaller files and have time to wait.
For further optimization of large files, consider reviewing How to Stabilize Large Video Using Linux Mint and ffmpeg Software, which discusses performance tuning for longer clips. If you intend to view the stabilized footage on mobile devices, check How to Convert Videos to Play on iPhone Using FFmpeg on Linux for compatibility tips.
Frequently Asked Questions
Why does my stabilized video have black bars?
Black bars appear because the stabilization algorithm crops the frame to remove shaking edges. The video content moves within the frame, leaving empty pixels behind. You can minimize this by reducing the smoothing parameter or accepting slight quality loss from upscaling later.
Can I stabilize multiple videos in one command?
No, FFmpeg processes one file at a time per invocation. You must run the detection and transform steps for each individual video. You can automate this process using a bash loop script to iterate through a directory of files efficiently.
What if the video becomes too blurry after stabilization?
Blur often results from excessive smoothing or aggressive crop-and-expand techniques. Reduce the smoothing value in the vidstabtransform filter. Additionally, ensure you are using a high enough resolution source file, as interpolation errors become more visible when scaling down.
Does this method work for GoPro or action camera footage?
Yes, but action cameras often have wide-angle distortion that complicates stabilization. You may need to apply lens correction filters before running vidstabdetect. Standard hand-held camera footage yields the best results with this workflow.
How do I fix audio sync issues after stabilization?
If you split audio and video streams during processing, resync them during the final encoding step. FFmpeg automatically handles synchronization if you provide both inputs in the final command. Avoid manual timestamp adjustments unless necessary.