使用 ffmpeg 实现视频稳定

Written by

in

如果您想稳定视频并消除相机抖动,“ffmpeg”工具提供了强大的解决方案。借助内置过滤器“vidstabdetect”和“vidstabtransform”,您无需使用复杂的视频编辑器即可获得专业的效果。

准备工作

在开始之前,请确保您的“ffmpeg”支持“vidstab”库。在 Linux 上,您可以使用以下命令进行检查:

bash  
ffmpeg -filters | grep vidstab  

如果未安装该库,您可以添加它:

sudo apt install ffmpeg libvidstab-dev  

通过brew安装macOS:

brew install libvidstab
brew install ffmpeg

现在让我们继续该过程。

第 1 步:运动分析

首先,您需要分析视频的运动并创建带有稳定参数的文件。

ffmpeg -i input.mp4 -vf vidstabdetect=shakiness=10:accuracy=15 transfile=transforms.trf -f null -  

参数:

抖动:视频抖动级别(默认为 5,对于更复杂的情况可以增加到 10)。
精度:分析精度(默认15)。
transfile:保存运动参数的文件名。

第 2 步:应用稳定化

现在您可以使用转换文件应用稳定性:

ffmpeg -i input.mp4 -vf vidstabtransform=input=transforms.trf:zoom=5 output.mp4

参数:

input:指向带有转换参数的文件(在第一步中创建)。
缩放:用于消除黑边的缩放系数(例如 5 – 自动缩放直至消除伪像)。

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

DemensDeum
Privacy Overview

This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.