]> git.sesse.net Git - mlt/blob - src/modules/vid.stab/filter_vidstab.cpp
Added a fourth filter, that combines both detect and transform passes.
[mlt] / src / modules / vid.stab / filter_vidstab.cpp
1 /*
2  * filter_deshake.cpp
3  * Copyright (C) 2013
4  * Marco Gittler <g.marco@freenet.de>
5  * Jakub Ksiezniak <j.ksiezniak@gmail.com>
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software Foundation,
19  * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20  */
21
22 extern "C"
23 {
24 #include <vid.stab/libvidstab.h>
25 #include <framework/mlt.h>
26 }
27
28 #include <string.h>
29 #include <assert.h>
30 #include "common.h"
31
32 static mlt_frame process_filter(mlt_filter filter, mlt_frame frame)
33 {
34         mlt_properties properties = MLT_FILTER_PROPERTIES(filter);
35         mlt_get_image vidstab_get_image = (mlt_get_image) mlt_properties_get_data( properties, "_vidstab_get_image", NULL );
36
37 #if 1
38         mlt_position pos = mlt_filter_get_position(filter, frame);
39         mlt_position length = mlt_filter_get_length2(filter, frame) - 1;
40         if(pos >= length)
41         {
42                 mlt_properties_set_data(properties, "_vidstab_get_image", NULL, 0, NULL, NULL);
43         }
44 #endif
45
46         if(vidstab_get_image == NULL)
47         {
48                 if(mlt_properties_get(properties, "vectors") == NULL)
49                 {
50                         // vectors are NULL, so use a detect filter
51                         vidstab_get_image = get_image_and_detect;
52                 } else {
53                         // found vectors, so use a transform filter
54                         vidstab_get_image = get_image_and_transform;
55                 }
56
57                 mlt_properties_set_data( properties, "_vidstab_get_image", (void*)vidstab_get_image, 0, NULL, NULL );
58         }
59
60         mlt_frame_push_service(frame, filter);
61         mlt_frame_push_get_image(frame, vidstab_get_image);
62         return frame;
63 }
64
65 extern "C"
66 {
67
68 mlt_filter filter_vidstab_init(mlt_profile profile, mlt_service_type type,
69                 const char *id, char *arg)
70 {
71         mlt_filter filter = NULL;
72
73         if ((filter = mlt_filter_new()))
74         {
75                 filter->process = process_filter;
76
77                 mlt_properties properties = MLT_FILTER_PROPERTIES(filter);
78
79                 //properties for stabilize
80                 mlt_properties_set(properties, "shakiness", "4");
81                 mlt_properties_set(properties, "accuracy", "4");
82                 mlt_properties_set(properties, "stepsize", "6");
83                 mlt_properties_set(properties, "algo", "1");
84                 mlt_properties_set(properties, "mincontrast", "0.3");
85                 mlt_properties_set(properties, "show", "0");
86                 mlt_properties_set(properties, "tripod", "0");
87
88                 // properties for transform
89                 mlt_properties_set(properties, "smoothing", "15");
90                 mlt_properties_set(properties, "maxshift", "-1");
91                 mlt_properties_set(properties, "maxangle", "-1");
92                 mlt_properties_set(properties, "crop", "0");
93                 mlt_properties_set(properties, "invert", "0");
94                 mlt_properties_set(properties, "relative", "1");
95                 mlt_properties_set(properties, "zoom", "0");
96                 mlt_properties_set(properties, "optzoom", "1");
97                 mlt_properties_set(properties, "zoomspeed", "0.25");
98
99                 mlt_properties_set(properties, "vid.stab.version", LIBVIDSTAB_VERSION);
100
101                 return filter;
102         }
103
104         return NULL;
105 }
106
107 }