21 #define DEFAULT_INPUT_NAME "transforms.trf"
23 #include <vid.stab/libvidstab.h>
45 #define OFFSET(x) offsetof(TransformContext, x)
46 #define OFFSETC(x) (offsetof(TransformContext, conf)+offsetof(VSTransformConfig, x))
47 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
50 {
"input",
"set path to the file storing the transforms",
OFFSET(input),
52 {
"smoothing",
"set number of frames*2 + 1 used for lowpass filtering",
OFFSETC(smoothing),
55 {
"optalgo",
"set camera path optimization algo",
OFFSETC(camPathAlgo),
57 {
"opt",
"global optimization", 0,
59 {
"gauss",
"gaussian kernel", 0,
61 {
"avg",
"simple averaging on motion", 0,
64 {
"maxshift",
"set maximal number of pixels to translate image",
OFFSETC(maxShift),
66 {
"maxangle",
"set maximal angle in rad to rotate image",
OFFSETC(maxAngle),
69 {
"crop",
"set cropping mode",
OFFSETC(crop),
71 {
"keep",
"keep border", 0,
73 {
"black",
"black border", 0,
76 {
"invert",
"invert transforms",
OFFSETC(invert),
78 {
"relative",
"consider transforms as relative",
OFFSETC(relative),
80 {
"zoom",
"set percentage to zoom (>0: zoom in, <0: zoom out",
OFFSETC(zoom),
82 {
"optzoom",
"set optimal zoom (0: nothing, 1: optimal static zoom, 2: optimal dynamic zoom)",
OFFSETC(optZoom),
84 {
"zoomspeed",
"for adative zoom: percent to zoom maximally each frame",
OFFSETC(zoomSpeed),
87 {
"interpol",
"set type of interpolation",
OFFSETC(interpolType),
89 {
"no",
"no interpolation", 0,
91 {
"linear",
"linear (horizontal)", 0,
93 {
"bilinear",
"bi-linear", 0,
95 {
"bicubic",
"bi-cubic", 0,
98 {
"tripod",
"enable virtual tripod mode (same as relative=0:smoothing=0)",
OFFSET(tripod),
100 {
"debug",
"enable debug mode and writer global motions information to file",
OFFSET(debug),
111 tc->
class = &vidstabtransform_class;
120 vsTransformDataCleanup(&tc->
td);
121 vsTransformationsCleanup(&tc->
trans);
148 VSTransformData *
td = &(tc->
td);
153 if (!vsFrameInfoInit(&fi_src, inlink->
w, inlink->
h,
155 !vsFrameInfoInit(&fi_dest, inlink->
w, inlink->
h,
174 tc->
conf.modName =
"vidstabtransform";
178 tc->
conf.relative = 0;
179 tc->
conf.smoothing = 0;
181 tc->
conf.simpleMotionCalculation = 0;
183 tc->
conf.smoothZoom = 0;
185 if (vsTransformDataInit(td, &tc->
conf, &fi_src, &fi_dest) != VS_OK) {
186 av_log(ctx,
AV_LOG_ERROR,
"initialization of vid.stab transform failed, please report a BUG\n");
190 vsTransformGetConfig(&tc->
conf, td);
191 av_log(ctx,
AV_LOG_INFO,
"Video transformation/stabilization settings (pass 2/2):\n");
195 tc->
conf.camPathAlgo == VSOptimalL1 ?
"opt" :
196 (tc->
conf.camPathAlgo == VSGaussian ?
"gauss" :
"avg"));
204 tc->
conf.optZoom == 1 ?
"Static (1)" : (tc->
conf.optZoom == 2 ?
"Dynamic (2)" :
"Off (0)"));
205 if (tc->
conf.optZoom == 2)
209 f = fopen(tc->
input,
"r");
214 VSManyLocalMotions mlms;
215 if (vsReadLocalMotionsFile(f, &mlms) == VS_OK) {
217 if (vsLocalmotions2Transforms(td, &mlms, &tc->
trans) != VS_OK) {
222 if (!vsReadOldTransforms(td, f, &tc->
trans)) {
230 if (vsPreprocessTransforms(td, &tc->
trans) != VS_OK) {
244 VSTransformData*
td = &(tc->
td);
264 for (plane = 0; plane < vsTransformGetSrcFrameInfo(td)->planes; plane++) {
265 inframe.data[plane] = in->
data[plane];
266 inframe.linesize[plane] = in->
linesize[plane];
269 vsTransformPrepare(td, &inframe, &inframe);
272 for (plane = 0; plane < vsTransformGetDestFrameInfo(td)->planes; plane++) {
273 outframe.data[plane] = out->
data[plane];
274 outframe.linesize[plane] = out->
linesize[plane];
276 vsTransformPrepare(td, &inframe, &outframe);
279 vsDoTransform(td, vsGetNextTransform(td, &tc->
trans));
281 vsTransformFinish(td);
308 .
name =
"vidstabtransform",
310 "pass 2 of 2 for stabilization "
311 "(see vidstabdetect for pass 1)."),
316 .
inputs = avfilter_vf_vidstabtransform_inputs,
317 .
outputs = avfilter_vf_vidstabtransform_outputs,
318 .priv_class = &vidstabtransform_class,