├── .gitignore ├── CMakeLists.txt ├── LICENSE ├── README.md ├── data ├── motion-filter │ ├── en-US.ini │ └── zh-TW.ini └── motion-transition │ ├── en-US.ini │ └── zh-TW.ini ├── external └── FindLibObs.cmake ├── img ├── motion.gif ├── motion2.gif ├── motion3.gif └── transition.gif └── src ├── helper.c ├── helper.h ├── motion-filter ├── CMakeLists.txt └── motion-filter.c └── motion-transition ├── CMakeLists.txt └── motion-transition.c /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | # .gitignore 3 | build/ -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.5) 2 | project(motion-effect) 3 | 4 | set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/") 5 | add_subdirectory(src/motion-filter) 6 | add_subdirectory(src/motion-transition) 7 | 8 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc., 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Lesser General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | 294 | Copyright (C) 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License along 307 | with this program; if not, write to the Free Software Foundation, Inc., 308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 309 | 310 | Also add information on how to contact you by electronic and paper mail. 311 | 312 | If the program is interactive, make it output a short notice like this 313 | when it starts in an interactive mode: 314 | 315 | Gnomovision version 69, Copyright (C) year name of author 316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 317 | This is free software, and you are welcome to redistribute it 318 | under certain conditions; type `show c' for details. 319 | 320 | The hypothetical commands `show w' and `show c' should show the appropriate 321 | parts of the General Public License. Of course, the commands you use may 322 | be called something other than `show w' and `show c'; they could even be 323 | mouse-clicks or menu items--whatever suits your program. 324 | 325 | You should also get your employer (if you work as a programmer) or your 326 | school, if any, to sign a "copyright disclaimer" for the program, if 327 | necessary. Here is a sample; alter the names: 328 | 329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 330 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 331 | 332 | , 1 April 1989 333 | Ty Coon, President of Vice 334 | 335 | This General Public License does not permit incorporating your program into 336 | proprietary programs. If your program is a subroutine library, you may 337 | consider it more useful to permit linking proprietary applications with the 338 | library. If this is what you want to do, use the GNU Lesser General 339 | Public License instead of this License. 340 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # motion-effect 2 | Motion-effect is an obs-studio plugin for source item animation by updating transform settings. 3 | 4 | ## Features 5 | ### motion-filter (animate one source in the scene) 6 | - Source animation (linear or bezier curve) and scaling. 7 | - One way (just forward) or Round trip (forward and backward) movement. 8 | - Trigger by hotkey or scene switch. 9 | ### motion-transition (animate all sources between scene switch) 10 | - Source in both scene : linear transform animation 11 | - Source only in previous scene : zoom out 12 | - Source only in next scene : zoom in 13 | 14 | ## Download 15 | See [Release Page](https://github.com/CatxFish/motion-effect/releases) 16 | 17 | ## Screenshots 18 | ![Transition](https://github.com/CatxFish/motion-effect/blob/master/img/transition.gif) 19 | 20 | ## Usage 21 | ### motion-filter 22 | - Add a motion filter to a **scene** (this filter won't work if applied directly to a source). If you want two-way movement, make sure you choose the _Motion-filter (Round trip)_ variant of the filter. 23 | - On the filter property page, choose the source you wish to animate and provide the control points for the animation. 24 | - Use the Forward (and Backward) toggle button to check the results. 25 | - Go to hotkeys page in OBS settings and set hotkey(s) for the motion(s) within the scene. 26 | - That's everything! 27 | ### motion-transition 28 | - Add to your transition list then switch scene, just this one. 29 | 30 | ## Build 31 | ### Windows 32 | First follow build procedures for [obs-studio](https://github.com/obsproject/obs-studio/wiki/install-instructions#windows-build-directions). 33 | 34 | - Building obs-studio will produce an `obs.lib` file, generated inside the build directories - e.g. `obs-studio/build/libobs/debug/obs.lib` 35 | 36 | - Assuming you have cmake, prior to first configure, add the following entries: 37 | 38 | | Entry name | Type | Value (e.g.) | 39 | |--------------------|----------|------------------------------------------------------| 40 | | LIBOBS_LIB | FILEPATH | /obs-studio/path/to/obs.lib | 41 | | LIBOBS_INCLUDE_DIR | PATH | /obs-studio/libobs | 42 | | OBS_FRONTEND_LIB | FILEPATH | /obs-studio/UI/obs-frontend-api/obs-frontend-api.lib | 43 | 44 | - Click 'Configure', which will run 45 | - Click 'Generate' 46 | 47 | This should produce the desired development environment, which after building, shall produce the plugin dll file. 48 | 49 | ### Linux (Test on Ubuntu) 50 | You have to download obs-studio source code first and make sure you have installed cmake. 51 | ``` 52 | git clone https://github.com/CatxFish/motion-filter.git 53 | cd motion-filter 54 | mkdir build && cd build 55 | cmake -DLIBOBS_INCLUDE_DIR="" -DCMAKE_INSTALL_PREFIX=/usr .. 56 | make -j4 57 | sudo make install 58 | ``` 59 | -------------------------------------------------------------------------------- /data/motion-filter/en-US.ini: -------------------------------------------------------------------------------- 1 | Motion="Motion" 2 | Behavior="Trigger Behavior" 3 | Behavior.OneWay="Hotkey (One way)" 4 | Behavior.RoundTrip="Hotkey (Round trip)" 5 | Behavior.SceneSwitch="Scene switch" 6 | VariationType="Variation Type" 7 | VariationType.Position="Position" 8 | VariationType.Size="Size" 9 | VariationType.PositionAndSize="Position & Size" 10 | Start.Setting="Custom starting setting" 11 | Start.X="Starting X" 12 | Start.Y="Starting Y" 13 | Start.W="Starting Width" 14 | Start.H="Starting Height" 15 | PathType="Motion Path" 16 | PathType.Linear="Linear" 17 | PathType.Quadratic="Quadratic Bezier curve" 18 | PathType.Cubic="Cubic Bezier curve" 19 | ControlPoint.X="Control Point X" 20 | ControlPoint.Y="Control Point Y" 21 | ControlPoint2.X="Control Point #2 X" 22 | ControlPoint2.Y="Control Point #2 Y" 23 | DestinationGrabPosition="Populate destination with current source position" 24 | Destination.X="Destination X" 25 | Destination.Y="Destination Y" 26 | Destination.W="Width" 27 | Destination.H="Height" 28 | Duration="Duration" 29 | Acceleration="Acceleration" 30 | SourceName="Source" 31 | Forward="Forward" 32 | Backward="Backward" 33 | Disabled="Disabled" -------------------------------------------------------------------------------- /data/motion-filter/zh-TW.ini: -------------------------------------------------------------------------------- 1 | Motion="動畫" 2 | Behavior="觸發方式" 3 | Behavior.OneWay="熱鍵 (單向動畫)" 4 | Behavior.RoundTrip="熱鍵 (往返動畫)" 5 | Behavior.SceneSwitch="場景切換" 6 | VariationType="變化方式" 7 | VariationType.Position="位置" 8 | VariationType.Size="大小" 9 | VariationType.PositionAndSize="位置與大小" 10 | Start.Setting="使用起始資訊" 11 | Start.X="起始座標X" 12 | Start.Y="起始座標Y" 13 | Start.H="起始高度" 14 | Start.W="起始寬度" 15 | PathType="移動路徑" 16 | PathType.Linear="直線" 17 | PathType.Quadratic="二次貝茲曲線" 18 | PathType.Cubic="三次貝茲曲線" 19 | ControlPoint.X="控制點座標X" 20 | ControlPoint.Y="控制點座標Y" 21 | ControlPoint2.X="控制點2座標X" 22 | ControlPoint2.Y="控制點2座標Y" 23 | DestinationGrabPosition="套用目前座標至目標" 24 | Destination.X="目標座標X" 25 | Destination.Y="目標座標Y" 26 | ChangeScale="變更目標大小" 27 | Destination.W="目標寬度" 28 | Destination.H="目標高度" 29 | Duration="持續時間" 30 | Acceleration="加速" 31 | SourceName="來源" 32 | Forward="播放" 33 | Backward="回放" 34 | Disabled="停用" -------------------------------------------------------------------------------- /data/motion-transition/en-US.ini: -------------------------------------------------------------------------------- 1 | Motion="Motion" 2 | Acceleration.X="Acceleration (x-axis)" 3 | Acceleration.Y="Acceleration (y-axis)" 4 | -------------------------------------------------------------------------------- /data/motion-transition/zh-TW.ini: -------------------------------------------------------------------------------- 1 | Motion="動畫" 2 | Acceleration.X="X軸加速度" 3 | Acceleration.Y="Y軸加速度" 4 | -------------------------------------------------------------------------------- /external/FindLibObs.cmake: -------------------------------------------------------------------------------- 1 | # This module can be copied and used by external plugins for OBS 2 | # 3 | # Once done these will be defined: 4 | # 5 | # LIBOBS_FOUND 6 | # LIBOBS_INCLUDE_DIRS 7 | # LIBOBS_LIBRARIES 8 | 9 | find_package(PkgConfig QUIET) 10 | if (PKG_CONFIG_FOUND) 11 | pkg_check_modules(_OBS QUIET obs libobs) 12 | endif() 13 | 14 | if(CMAKE_SIZEOF_VOID_P EQUAL 8) 15 | set(_lib_suffix 64) 16 | else() 17 | set(_lib_suffix 32) 18 | endif() 19 | 20 | if(DEFINED CMAKE_BUILD_TYPE) 21 | if(CMAKE_BUILD_TYPE STREQUAL "Debug") 22 | set(_build_type_base "debug") 23 | else() 24 | set(_build_type_base "release") 25 | endif() 26 | endif() 27 | 28 | find_path(LIBOBS_INCLUDE_DIR 29 | NAMES obs.h 30 | HINTS 31 | ENV obsPath${_lib_suffix} 32 | ENV obsPath 33 | ${obsPath} 34 | PATHS 35 | /usr/include /usr/local/include /opt/local/include /sw/include 36 | PATH_SUFFIXES 37 | libobs 38 | ) 39 | 40 | function(find_obs_lib base_name repo_build_path lib_name) 41 | string(TOUPPER "${base_name}" base_name_u) 42 | 43 | if(DEFINED _build_type_base) 44 | set(_build_type_${repo_build_path} "${_build_type_base}/${repo_build_path}") 45 | set(_build_type_${repo_build_path}${_lib_suffix} "${_build_type_base}${_lib_suffix}/${repo_build_path}") 46 | endif() 47 | 48 | find_library(${base_name_u}_LIB 49 | NAMES ${_${base_name_u}_LIBRARIES} ${lib_name} lib${lib_name} 50 | HINTS 51 | ENV obsPath${_lib_suffix} 52 | ENV obsPath 53 | ${obsPath} 54 | ${_${base_name_u}_LIBRARY_DIRS} 55 | PATHS 56 | /usr/lib /usr/local/lib /opt/local/lib /sw/lib 57 | PATH_SUFFIXES 58 | lib${_lib_suffix} lib 59 | libs${_lib_suffix} libs 60 | bin${_lib_suffix} bin 61 | ../lib${_lib_suffix} ../lib 62 | ../libs${_lib_suffix} ../libs 63 | ../bin${_lib_suffix} ../bin 64 | # base repo non-msvc-specific search paths 65 | ${_build_type_${repo_build_path}} 66 | ${_build_type_${repo_build_path}${_lib_suffix}} 67 | build/${repo_build_path} 68 | build${_lib_suffix}/${repo_build_path} 69 | # base repo msvc-specific search paths on windows 70 | build${_lib_suffix}/${repo_build_path}/Debug 71 | build${_lib_suffix}/${repo_build_path}/RelWithDebInfo 72 | build/${repo_build_path}/Debug 73 | build/${repo_build_path}/RelWithDebInfo 74 | ) 75 | endfunction() 76 | 77 | find_obs_lib(LIBOBS libobs obs) 78 | 79 | if(MSVC) 80 | find_obs_lib(W32_PTHREADS deps/w32-pthreads w32-pthreads) 81 | endif() 82 | 83 | include(FindPackageHandleStandardArgs) 84 | find_package_handle_standard_args(Libobs DEFAULT_MSG LIBOBS_LIB LIBOBS_INCLUDE_DIR) 85 | mark_as_advanced(LIBOBS_INCLUDE_DIR LIBOBS_LIB) 86 | 87 | if(LIBOBS_FOUND) 88 | if(MSVC) 89 | if (NOT DEFINED W32_PTHREADS_LIB) 90 | message(FATAL_ERROR "Could not find the w32-pthreads library" ) 91 | endif() 92 | 93 | set(W32_PTHREADS_INCLUDE_DIR ${LIBOBS_INCLUDE_DIR}/../deps/w32-pthreads) 94 | endif() 95 | 96 | set(LIBOBS_INCLUDE_DIRS ${LIBOBS_INCLUDE_DIR} ${W32_PTHREADS_INCLUDE_DIR}) 97 | set(LIBOBS_LIBRARIES ${LIBOBS_LIB} ${W32_PTHREADS_LIB}) 98 | include(${LIBOBS_INCLUDE_DIR}/../cmake/external/ObsPluginHelpers.cmake) 99 | 100 | # allows external plugins to easily use/share common dependencies that are often included with libobs (such as FFmpeg) 101 | if(NOT DEFINED INCLUDED_LIBOBS_CMAKE_MODULES) 102 | set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${LIBOBS_INCLUDE_DIR}/../cmake/Modules/") 103 | set(INCLUDED_LIBOBS_CMAKE_MODULES true) 104 | endif() 105 | else() 106 | message(FATAL_ERROR "Could not find the libobs library" ) 107 | endif() 108 | -------------------------------------------------------------------------------- /img/motion.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CatxFish/motion-effect/567c8a229babf82adaf4067a78a55a3155a854f2/img/motion.gif -------------------------------------------------------------------------------- /img/motion2.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CatxFish/motion-effect/567c8a229babf82adaf4067a78a55a3155a854f2/img/motion2.gif -------------------------------------------------------------------------------- /img/motion3.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CatxFish/motion-effect/567c8a229babf82adaf4067a78a55a3155a854f2/img/motion3.gif -------------------------------------------------------------------------------- /img/transition.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CatxFish/motion-effect/567c8a229babf82adaf4067a78a55a3155a854f2/img/transition.gif -------------------------------------------------------------------------------- /src/helper.c: -------------------------------------------------------------------------------- 1 | /* 2 | * motion-effect, an OBS-Studio plugin for animating sources using 3 | * transform manipulation on the scene. 4 | * Copyright(C) <2018> 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License along 17 | * with this program; if not, write to the Free Software Foundation, Inc., 18 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110 - 1301 USA. 19 | */ 20 | 21 | #include "helper.h" 22 | #include 23 | #include 24 | 25 | 26 | obs_sceneitem_t *get_item(obs_source_t *context, 27 | const char *name) 28 | { 29 | obs_source_t *source = obs_filter_get_parent(context); 30 | obs_scene_t *scene = obs_scene_from_source(source); 31 | return obs_scene_find_source(scene, name); 32 | } 33 | 34 | obs_sceneitem_t *get_item_by_id(obs_source_t* context, 35 | int64_t id) 36 | { 37 | obs_source_t *source = obs_filter_get_parent(context); 38 | obs_scene_t *scene = obs_scene_from_source(source); 39 | obs_sceneitem_t* item = obs_scene_find_sceneitem_by_id(scene, id); 40 | return item; 41 | } 42 | 43 | int64_t get_item_id(obs_source_t* context, const char* name) 44 | { 45 | obs_sceneitem_t *item = get_item(context, name); 46 | return item ? obs_sceneitem_get_id(item) : -1; 47 | } 48 | 49 | bool cal_size(obs_sceneitem_t* item, float sx, float sy, 50 | int* width, int* height) 51 | { 52 | obs_source_t *item_source = obs_sceneitem_get_source(item); 53 | int base_width = obs_source_get_base_width(item_source); 54 | int base_height = obs_source_get_base_height(item_source); 55 | 56 | *width = (int)(base_width * sx); 57 | *height = (int)(base_height * sy); 58 | 59 | return true; 60 | } 61 | 62 | bool check_item_basesize(obs_sceneitem_t* item) 63 | { 64 | obs_source_t *item_source = obs_sceneitem_get_source(item); 65 | int base_width = obs_source_get_width(item_source); 66 | int base_height = obs_source_get_height(item_source); 67 | return base_width != 0 && base_height != 0; 68 | } 69 | 70 | bool cal_scale(obs_sceneitem_t* item, float* sx, float*sy, 71 | int width, int height) 72 | { 73 | obs_source_t *item_source = obs_sceneitem_get_source(item); 74 | int base_width = obs_source_get_width(item_source); 75 | int base_height = obs_source_get_height(item_source); 76 | 77 | if (base_width == 0 || base_height == 0) 78 | return false; 79 | 80 | *sx = (float)width / base_width; 81 | *sy = (float)height / base_height; 82 | 83 | return true; 84 | } 85 | 86 | void set_item_scale(obs_sceneitem_t *item, int width, int height) 87 | { 88 | struct vec2 scale; 89 | if (cal_scale(item, &scale.x, &scale.y, width, height)) 90 | obs_sceneitem_set_scale(item, &scale); 91 | } 92 | 93 | /* 94 | * Workaround way to judge if is a program scene. 95 | * A program scene is a private source without name. 96 | */ 97 | 98 | bool is_program_scene(obs_source_t *scene) 99 | { 100 | if (!obs_scene_from_source(scene)) 101 | return false; 102 | 103 | if (!scene->context.private) 104 | return false; 105 | 106 | if (obs_source_get_name(scene)) 107 | return false; 108 | 109 | return true; 110 | } 111 | 112 | obs_hotkey_id register_hotkey(obs_source_t *context, obs_source_t *scene, 113 | const char *name, const char *text, obs_hotkey_func func, void *data) 114 | { 115 | const char *source_name = obs_source_get_name(context); 116 | const char *description; 117 | obs_data_t *settings = obs_source_get_settings(context); 118 | obs_data_array_t *save_array; 119 | struct dstr str = { 0 }; 120 | obs_hotkey_id id; 121 | 122 | 123 | dstr_copy(&str, text); 124 | dstr_cat(&str, " [ %1 ] "); 125 | dstr_replace(&str, "%1", source_name); 126 | description = str.array; 127 | 128 | if (is_program_scene(scene)) { 129 | id = obs_hotkey_register_frontend(description, description, func, 130 | data); 131 | } else { 132 | id = obs_hotkey_register_source(scene, description, description, 133 | func, data); 134 | } 135 | 136 | save_array = obs_data_get_array(settings, name); 137 | obs_hotkey_load(id, save_array); 138 | obs_data_array_release(save_array); 139 | dstr_free(&str); 140 | obs_data_release(settings); 141 | 142 | return id; 143 | } 144 | 145 | void unregister_hotkey(obs_hotkey_id id) 146 | { 147 | if (id != OBS_INVALID_HOTKEY_ID) 148 | obs_hotkey_unregister(id); 149 | 150 | } 151 | 152 | void save_hotkey_config(obs_hotkey_id id, obs_data_t *settings, 153 | const char *name) 154 | { 155 | obs_data_array_t* save_array = obs_hotkey_save(id); 156 | obs_data_set_array(settings, name, save_array); 157 | obs_data_array_release(save_array); 158 | } 159 | 160 | bool same_transform_type(struct obs_transform_info *info_a, 161 | struct obs_transform_info *info_b) 162 | { 163 | if (!info_a || !info_b) 164 | return false; 165 | 166 | return info_a->alignment == info_b->alignment && 167 | info_a->bounds_type == info_b->bounds_type && 168 | info_a->bounds_alignment == info_b->bounds_alignment; 169 | } 170 | 171 | float bezier(float point[], float coefficient, int order) 172 | { 173 | float p = 1.0f - coefficient; 174 | float t = coefficient; 175 | 176 | if (order < 1) 177 | return point[0]; 178 | else if (order == 1) 179 | return p * point[0] + t * point[1]; 180 | else 181 | return p * bezier(point, t, order - 1) + 182 | t * bezier(&point[1], t, order - 1); 183 | } 184 | 185 | void vec_linear(struct vec2 a, struct vec2 b, struct vec2 *result ,float t) 186 | { 187 | float x[2] = { a.x, b.x }; 188 | float y[2] = { a.y, b.y }; 189 | result->x = bezier(x, t, 1); 190 | result->y = bezier(y, t, 1); 191 | } 192 | 193 | void vec_bezier(struct vec2 a, struct vec2 b, struct vec2 c , 194 | struct vec2 *result, float t) 195 | { 196 | float x[3] = { a.x,b.x,c.x }; 197 | float y[3] = { a.y,b.y,c.y }; 198 | result->x = bezier(x, t, 2); 199 | result->y = bezier(y, t, 2); 200 | } 201 | 202 | void crop_linear(struct obs_sceneitem_crop a, struct obs_sceneitem_crop b, 203 | struct obs_sceneitem_crop* result, float t) 204 | { 205 | result->bottom = (1.0f - t) * a.bottom + t * b.bottom; 206 | result->left = (1.0f - t) * a.left + t * b.left; 207 | result->top = (1.0f - t) * a.top + t * b.top; 208 | result->right = (1.0f - t) * a.right + t * b.right; 209 | } 210 | -------------------------------------------------------------------------------- /src/helper.h: -------------------------------------------------------------------------------- 1 | /* 2 | * motion-effect, an OBS-Studio filter plugin for animating sources using 3 | * transform manipulation on the scene. 4 | * Copyright(C) <2018> 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License along 17 | * with this program; if not, write to the Free Software Foundation, Inc., 18 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110 - 1301 USA. 19 | */ 20 | 21 | #pragma once 22 | 23 | #include 24 | 25 | obs_sceneitem_t* get_item(obs_source_t *context,const char *name); 26 | obs_sceneitem_t* get_item_by_id(obs_source_t *context,int64_t id); 27 | int64_t get_item_id(obs_source_t *context, const char *name); 28 | 29 | bool cal_size(obs_sceneitem_t* item, float sx, float sy, int *width, 30 | int *height); 31 | 32 | bool check_item_basesize(obs_sceneitem_t *item); 33 | 34 | bool cal_scale(obs_sceneitem_t *item, float *sx, float *sy, int width, 35 | int height); 36 | 37 | void set_item_scale(obs_sceneitem_t *item, int width, int height); 38 | 39 | bool is_program_scene(obs_source_t *scene); 40 | 41 | obs_hotkey_id register_hotkey(obs_source_t *context, obs_source_t *scene, 42 | const char *name, const char *text, obs_hotkey_func func, void *data); 43 | 44 | void unregister_hotkey(obs_hotkey_id id); 45 | 46 | bool same_transform_type(struct obs_transform_info *info_a, 47 | struct obs_transform_info *info_b); 48 | 49 | void save_hotkey_config(obs_hotkey_id id, obs_data_t *settings, 50 | const char *name); 51 | 52 | float bezier(float point[], float percent, int order); 53 | 54 | void vec_linear(struct vec2 a, struct vec2 b, struct vec2 *result, float t); 55 | 56 | void vec_bezier(struct vec2 a, struct vec2 b, struct vec2 c, 57 | struct vec2 *result, float t); 58 | 59 | void crop_linear(struct obs_sceneitem_crop a, struct obs_sceneitem_crop b, 60 | struct obs_sceneitem_crop* result, float t); -------------------------------------------------------------------------------- /src/motion-filter/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.5) 2 | project(motion-filter) 3 | 4 | include(${CMAKE_SOURCE_DIR}/external/FindLibObs.cmake) 5 | find_package(LibObs REQUIRED) 6 | set(motion-filter_SOURCES 7 | ../helper.c 8 | motion-filter.c 9 | ) 10 | 11 | set(motion-filter_HEADERS 12 | ../helper.h 13 | ) 14 | 15 | include_directories( 16 | "${LIBOBS_INCLUDE_DIR}/../UI/obs-frontend-api") 17 | 18 | add_library(motion-filter MODULE 19 | ${motion-filter_SOURCES} 20 | ${motion-filter_HEADERS}) 21 | 22 | target_link_libraries(motion-filter 23 | libobs) 24 | 25 | if(UNIX AND NOT APPLE) 26 | 27 | if(ARCH EQUAL 64) 28 | set(ARCH_NAME "x86_64") 29 | else() 30 | set(ARCH_NAME "i686") 31 | endif() 32 | 33 | set_target_properties(motion-filter PROPERTIES PREFIX "") 34 | 35 | install(TARGETS motion-filter 36 | LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/obs-plugins) 37 | install(DIRECTORY ${CMAKE_SOURCE_DIR}/data/motion-filter/ 38 | DESTINATION "${CMAKE_INSTALL_PREFIX}/share/obs/obs-plugins/motion-filter/") 39 | endif() 40 | 41 | 42 | if(WIN32) 43 | set(OBS_FRONTEND_LIB "OBS_FRONTEND_LIB-NOTFOUND" CACHE FILEPATH "OBS frontend library") 44 | if(OBS_FRONTEND_LIB EQUAL "OBS_FRONTEND_LIB-NOTFOUND") 45 | message(FATAL_ERROR "OBS_FRONTEND_LIB NOTFOUND") 46 | endif() 47 | 48 | target_link_libraries(motion-filter 49 | "${OBS_FRONTEND_LIB}") 50 | 51 | endif() 52 | 53 | -------------------------------------------------------------------------------- /src/motion-filter/motion-filter.c: -------------------------------------------------------------------------------- 1 | /* 2 | * motion-filter, an OBS-Studio filter plugin for animating sources using 3 | * transform manipulation on the scene. 4 | * Copyright(C) <2018> 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License along 17 | * with this program; if not, write to the Free Software Foundation, Inc., 18 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110 - 1301 USA. 19 | */ 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include "../helper.h" 27 | 28 | // Define property keys 29 | 30 | enum { 31 | PATH_LINEAR = 0, 32 | PATH_QUADRATIC = 1, 33 | PATH_CUBIC = 2 34 | }; 35 | 36 | enum { 37 | BEHAVIOR_NONE = 0, 38 | BEHAVIOR_ONE_WAY = 1, 39 | BEHAVIOR_ROUND_TRIP = 2, 40 | BEHAVIOR_SCENE_SWITCH =3 41 | }; 42 | 43 | #define VARIATION_POSITION (1<<0) 44 | #define VARIATION_SIZE (1<<1) 45 | 46 | #define S_MOTION_END "motion_end" 47 | #define S_ORG_X "org_x" 48 | #define S_ORG_Y "org_y" 49 | #define S_ORG_W "org_w" 50 | #define S_ORG_H "org_h" 51 | #define S_START_X "start_x" 52 | #define S_START_Y "start_y" 53 | #define S_START_W "start_w" 54 | #define S_START_H "start_h" 55 | #define S_PATH_TYPE "path_type" 56 | #define S_START_SETTING "start_setting" 57 | #define S_CTRL_X "ctrl_x" 58 | #define S_CTRL_Y "ctrl_y" 59 | #define S_CTRL2_X "ctrl2_x" 60 | #define S_CTRL2_Y "ctrl2_y" 61 | #define S_DST_X "dst_x" 62 | #define S_DST_Y "dst_y" 63 | #define S_DST_W "dst_w" 64 | #define S_DST_H "dst_h" 65 | #define S_USE_DST_SCALE "dst_use_scale" 66 | #define S_DURATION "duration" 67 | #define S_ACCELERATION "acceleration" 68 | #define S_SOURCE "source_id" 69 | #define S_FORWARD "forward" 70 | #define S_BACKWARD "backward" 71 | #define S_DEST_GRAB_POS "use_cur_src_pos" 72 | #define S_MOTION_BEHAVIOR "motion_behavior" 73 | #define S_VARIATION_TYPE "variation_type" 74 | #define S_SCENE_NAME "scene_name" 75 | 76 | // Define property localisation tags 77 | #define T_(v) obs_module_text(v) 78 | #define T_PATH_TYPE T_("PathType") 79 | #define T_PATH_LINEAR T_("PathType.Linear") 80 | #define T_PATH_QUADRATIC T_("PathType.Quadratic") 81 | #define T_PATH_CUBIC T_("PathType.Cubic") 82 | #define T_START_SETTING T_("Start.Setting") 83 | #define T_START_X T_("Start.X") 84 | #define T_START_Y T_("Start.Y") 85 | #define T_START_W T_("Start.W") 86 | #define T_START_H T_("Start.H") 87 | #define T_CTRL_X T_("ControlPoint.X") 88 | #define T_CTRL_Y T_("ControlPoint.Y") 89 | #define T_CTRL2_X T_("ControlPoint2.X") 90 | #define T_CTRL2_Y T_("ControlPoint2.Y") 91 | #define T_DST_X T_("Destination.X") 92 | #define T_DST_Y T_("Destination.Y") 93 | #define T_DST_W T_("Destination.W") 94 | #define T_DST_H T_("Destination.H") 95 | #define T_DURATION T_("Duration") 96 | #define T_ACCELERATION T_("Acceleration") 97 | #define T_SOURCE T_("SourceName") 98 | #define T_FORWARD T_("Forward") 99 | #define T_BACKWARD T_("Backward") 100 | #define T_DISABLED T_("Disabled") 101 | #define T_VARIATION_TYPE T_("VariationType") 102 | #define T_VARIATION_POS T_("VariationType.Position") 103 | #define T_VARIATION_SIZE T_("VariationType.Size") 104 | #define T_VARIATION_BOTH T_("VariationType.PositionAndSize") 105 | #define T_DEST_GRAB_POS T_("DestinationGrabPosition") 106 | #define T_MOTION_BEHAVIOR T_("Behavior") 107 | #define T_HOTKEY_ONE_WAY T_("Behavior.OneWay") 108 | #define T_HOTKEY_ROUND_TRIP T_("Behavior.RoundTrip") 109 | #define T_SCENE_SWITCH T_("Behavior.SceneSwitch") 110 | 111 | typedef struct variation_data variation_data_t; 112 | typedef struct motion_filter_data motion_filter_data_t; 113 | 114 | struct variation_data { 115 | float point_x[4]; 116 | float point_y[4]; 117 | float scale_x[2]; 118 | float scale_y[2]; 119 | float coeff[3]; 120 | struct vec2 scale; 121 | struct vec2 position; 122 | float elapsed_time; 123 | bool coeff_varaite; 124 | }; 125 | 126 | struct motion_filter_data { 127 | obs_source_t *context; 128 | obs_scene_t *scene; 129 | obs_sceneitem_t *item; 130 | obs_hotkey_id hotkey_id_f; 131 | obs_hotkey_id hotkey_id_b; 132 | variation_data_t variation; 133 | bool initialize; 134 | bool restart_backward; 135 | bool motion_start; 136 | bool motion_end; 137 | bool use_start_position; 138 | bool use_start_scale; 139 | bool change_position; 140 | bool change_size; 141 | int motion_behavior; 142 | int path_type; 143 | int org_width; 144 | int org_height; 145 | int dst_width; 146 | int dst_height; 147 | struct vec2 org_pos; 148 | struct vec2 ctrl_pos; 149 | struct vec2 ctrl2_pos; 150 | struct vec2 dst_pos; 151 | float duration; 152 | float acceleration; 153 | char *item_name; 154 | int64_t item_id; 155 | }; 156 | 157 | static inline bool is_reverse(motion_filter_data_t *filter) 158 | { 159 | return filter->motion_end && 160 | filter->motion_behavior == BEHAVIOR_ROUND_TRIP; 161 | } 162 | 163 | static inline const char* get_scene_name(motion_filter_data_t *filter) 164 | { 165 | obs_source_t* scene = obs_filter_get_parent(filter->context); 166 | return obs_source_get_name(scene); 167 | } 168 | 169 | static void update_variation_data(motion_filter_data_t *filter) 170 | { 171 | variation_data_t *var = &filter->variation; 172 | 173 | if (!check_item_basesize(filter->item)) 174 | return ; 175 | 176 | if (!is_reverse(filter)) { 177 | struct obs_transform_info info; 178 | obs_sceneitem_get_info(filter->item, &info); 179 | if (!filter->use_start_position) { 180 | var->point_x[0] = info.pos.x; 181 | var->point_y[0] = info.pos.y; 182 | } 183 | if (!filter->use_start_scale) { 184 | var->scale_x[0] = info.scale.x; 185 | var->scale_y[0] = info.scale.y; 186 | } 187 | 188 | } 189 | 190 | if (filter->use_start_position){ 191 | var->point_x[0] = filter->org_pos.x; 192 | var->point_y[0] = filter->org_pos.y; 193 | } 194 | 195 | if (filter->path_type >= PATH_QUADRATIC) { 196 | var->point_x[1] = filter->ctrl_pos.x; 197 | var->point_y[1] = filter->ctrl_pos.y; 198 | } 199 | 200 | if (filter->path_type == PATH_CUBIC) { 201 | var->point_x[2] = filter->ctrl2_pos.x; 202 | var->point_y[2] = filter->ctrl2_pos.y; 203 | } 204 | 205 | var->point_x[filter->path_type + 1] = filter->dst_pos.x; 206 | var->point_y[filter->path_type + 1] = filter->dst_pos.y; 207 | 208 | if(filter->use_start_scale) { 209 | cal_scale(filter->item, &var->scale_x[0], 210 | &var->scale_y[0], filter->org_width, filter->org_height); 211 | } 212 | 213 | cal_scale(filter->item, &var->scale_x[1], 214 | &var->scale_y[1], filter->dst_width, filter->dst_height); 215 | 216 | if (filter->acceleration != 0) { 217 | var->coeff_varaite = true; 218 | var->coeff[0] = 0.0f; 219 | var->coeff[1] = (-(filter->acceleration) + 1.0f) / 2; 220 | var->coeff[2] = 1.0f; 221 | } else 222 | var->coeff_varaite = false; 223 | 224 | var->elapsed_time = 0.0f; 225 | return ; 226 | } 227 | 228 | static void reset_source_name(void *data, obs_sceneitem_t *item) 229 | { 230 | motion_filter_data_t *filter = data; 231 | if (item) { 232 | obs_data_t *settings = obs_source_get_settings(filter->context); 233 | obs_source_t *item_source = obs_sceneitem_get_source(item); 234 | const char *name = obs_source_get_name(item_source); 235 | obs_data_set_string(settings, S_SOURCE, name); 236 | bfree(filter->item_name); 237 | filter->item_name = bstrdup(name); 238 | obs_data_release(settings); 239 | } 240 | } 241 | 242 | static void recover_source(motion_filter_data_t *filter) 243 | { 244 | struct vec2 pos; 245 | struct vec2 scale; 246 | obs_data_t *settings; 247 | variation_data_t *var = &filter->variation; 248 | 249 | if (!filter->motion_end) 250 | return; 251 | 252 | pos.x = var->point_x[0]; 253 | pos.y = var->point_y[0]; 254 | scale.x = var->scale_x[0]; 255 | scale.y = var->scale_y[0]; 256 | 257 | obs_sceneitem_set_pos(filter->item, &pos); 258 | obs_sceneitem_set_scale(filter->item, &scale); 259 | filter->motion_end = false; 260 | settings = obs_source_get_settings(filter->context); 261 | obs_data_set_bool(settings, S_MOTION_END, false); 262 | obs_data_release(settings); 263 | } 264 | 265 | static bool motion_init(void *data, bool forward) 266 | { 267 | motion_filter_data_t *filter = data; 268 | 269 | if (filter->motion_start || is_reverse(filter) == forward) 270 | return false; 271 | 272 | filter->item = get_item(filter->context, filter->item_name); 273 | 274 | if (!filter->item) { 275 | filter->item = get_item_by_id(filter->context, filter->item_id); 276 | reset_source_name(data, filter->item); 277 | } 278 | 279 | if (filter->item) { 280 | update_variation_data(filter); 281 | obs_sceneitem_addref(filter->item); 282 | filter->motion_start = true; 283 | return true; 284 | } 285 | return false; 286 | } 287 | 288 | static void hotkey_forward(void *data, obs_hotkey_pair_id id, 289 | obs_hotkey_t *hotkey, bool pressed) 290 | { 291 | UNUSED_PARAMETER(id); 292 | UNUSED_PARAMETER(hotkey); 293 | UNUSED_PARAMETER(pressed); 294 | motion_init(data, true); 295 | } 296 | 297 | static void hotkey_backward(void *data, obs_hotkey_pair_id id, 298 | obs_hotkey_t *hotkey, bool pressed) 299 | { 300 | UNUSED_PARAMETER(id); 301 | UNUSED_PARAMETER(hotkey); 302 | UNUSED_PARAMETER(pressed); 303 | motion_init(data, false); 304 | } 305 | 306 | static void scene_change(enum obs_frontend_event event, void *data) 307 | { 308 | motion_filter_data_t *filter = data; 309 | obs_data_t *settings; 310 | obs_source_t *cur_scene; 311 | obs_source_t *self_scene; 312 | const char* cur_name; 313 | const char* self_name; 314 | 315 | if (event != OBS_FRONTEND_EVENT_SCENE_CHANGED) 316 | return; 317 | 318 | cur_scene = obs_frontend_get_current_scene(); 319 | self_scene = obs_filter_get_parent(filter->context); 320 | 321 | if (cur_scene == self_scene) { 322 | motion_init(data, true); 323 | } else if (is_program_scene(self_scene)) { 324 | settings = obs_source_get_settings(filter->context); 325 | self_name = obs_data_get_string(settings, S_SCENE_NAME); 326 | cur_name = obs_source_get_name(cur_scene); 327 | if (self_name && cur_name && strcmp(self_name, cur_name)==0) { 328 | motion_init(data, true); 329 | } 330 | obs_data_release(settings); 331 | } else { 332 | filter->motion_start = false; 333 | filter->motion_end = true; 334 | recover_source(filter); 335 | } 336 | obs_source_release(cur_scene); 337 | } 338 | 339 | static void set_reverse_info(struct motion_filter_data *filter) 340 | { 341 | variation_data_t *var = &filter->variation; 342 | obs_data_t *settings = obs_source_get_settings(filter->context); 343 | obs_data_set_bool(settings, S_MOTION_END, filter->motion_end); 344 | obs_data_set_double(settings, S_ORG_X, var->point_x[0]); 345 | obs_data_set_double(settings, S_ORG_Y, var->point_y[0]); 346 | obs_data_set_double(settings, S_ORG_W, var->scale_x[0]); 347 | obs_data_set_double(settings, S_ORG_H, var->scale_y[0]); 348 | obs_data_release(settings); 349 | } 350 | 351 | static void get_reverse_info(struct motion_filter_data *filter) 352 | { 353 | variation_data_t *var = &filter->variation; 354 | obs_data_t *settings = obs_source_get_settings(filter->context); 355 | filter->motion_end = obs_data_get_bool(settings, S_MOTION_END); 356 | var->point_x[0] = (float)obs_data_get_double(settings, S_ORG_X); 357 | var->point_y[0] = (float)obs_data_get_double(settings, S_ORG_Y); 358 | var->scale_x[0] = (float)obs_data_get_double(settings, S_ORG_W); 359 | var->scale_y[0] = (float)obs_data_get_double(settings, S_ORG_H); 360 | obs_data_release(settings); 361 | } 362 | 363 | static void motion_filter_save(void *data, obs_data_t *settings) 364 | { 365 | motion_filter_data_t *filter = data; 366 | const char *name = get_scene_name(filter); 367 | 368 | if (name) 369 | obs_data_set_string(settings, S_SCENE_NAME, name); 370 | 371 | save_hotkey_config(filter->hotkey_id_f, settings, S_FORWARD); 372 | save_hotkey_config(filter->hotkey_id_b, settings, S_BACKWARD); 373 | } 374 | 375 | static void motion_filter_update(void *data, obs_data_t *settings) 376 | { 377 | motion_filter_data_t *filter = data; 378 | bool use_start, change_pos, change_size, scene_switch; 379 | int var_type; 380 | int64_t item_id; 381 | const char *item_name; 382 | 383 | filter->motion_behavior = (int)obs_data_get_int(settings, S_MOTION_BEHAVIOR); 384 | filter->path_type = (int)obs_data_get_int(settings, S_PATH_TYPE); 385 | filter->org_pos.x = (float)obs_data_get_int(settings, S_START_X); 386 | filter->org_pos.y = (float)obs_data_get_int(settings, S_START_Y); 387 | filter->org_width = (int)obs_data_get_int(settings, S_START_W); 388 | filter->org_height = (int)obs_data_get_int(settings, S_START_H); 389 | filter->ctrl_pos.x = (float)obs_data_get_int(settings, S_CTRL_X); 390 | filter->ctrl_pos.y = (float)obs_data_get_int(settings, S_CTRL_Y); 391 | filter->ctrl2_pos.x = (float)obs_data_get_int(settings, S_CTRL2_X); 392 | filter->ctrl2_pos.y = (float)obs_data_get_int(settings, S_CTRL2_Y); 393 | filter->duration = (float)obs_data_get_double(settings, S_DURATION); 394 | filter->dst_pos.x = (float)obs_data_get_int(settings, S_DST_X); 395 | filter->dst_pos.y = (float)obs_data_get_int(settings, S_DST_Y); 396 | filter->dst_width = (int)obs_data_get_int(settings, S_DST_W); 397 | filter->dst_height = (int)obs_data_get_int(settings, S_DST_H); 398 | filter->acceleration = (float)obs_data_get_double(settings, S_ACCELERATION); 399 | use_start = obs_data_get_bool(settings, S_START_SETTING); 400 | var_type = (int)obs_data_get_int(settings, S_VARIATION_TYPE); 401 | item_name = obs_data_get_string(settings, S_SOURCE); 402 | item_id = get_item_id(filter->context, item_name); 403 | 404 | change_pos = (var_type & VARIATION_POSITION) != 0; 405 | change_size = (var_type & VARIATION_SIZE) != 0; 406 | scene_switch = filter->motion_behavior == BEHAVIOR_SCENE_SWITCH; 407 | 408 | 409 | filter->use_start_position = (scene_switch || use_start) && change_pos; 410 | filter->use_start_scale = (scene_switch || use_start) && change_size; 411 | filter->change_position = change_pos; 412 | filter->change_size = change_size; 413 | 414 | 415 | bfree(filter->item_name); 416 | filter->item_name = bstrdup(item_name); 417 | filter->item_id = item_id; 418 | } 419 | 420 | static bool register_trigger_event(void *data) 421 | { 422 | motion_filter_data_t *filter = data; 423 | obs_source_t *source = obs_filter_get_parent(filter->context); 424 | obs_scene_t *scene = obs_scene_from_source(source); 425 | 426 | if (!scene) 427 | return false; 428 | 429 | if (filter->motion_behavior == BEHAVIOR_SCENE_SWITCH) { 430 | obs_frontend_add_event_callback(scene_change, data); 431 | return true; 432 | } 433 | 434 | 435 | filter->hotkey_id_f = register_hotkey(filter->context, source, S_FORWARD, 436 | T_FORWARD, hotkey_forward, data); 437 | 438 | if (filter->motion_behavior == BEHAVIOR_ROUND_TRIP) { 439 | filter->hotkey_id_b = register_hotkey(filter->context, source, 440 | S_BACKWARD, T_BACKWARD, hotkey_backward, data); 441 | } 442 | 443 | return true; 444 | } 445 | 446 | static void unregister_trigger_event(void *data) 447 | { 448 | motion_filter_data_t *filter = data; 449 | obs_data_t *settings; 450 | 451 | 452 | if (filter->motion_behavior == BEHAVIOR_SCENE_SWITCH) { 453 | obs_frontend_remove_event_callback(scene_change, data); 454 | return ; 455 | } 456 | 457 | settings = obs_source_get_settings(filter->context); 458 | motion_filter_save(data, settings); 459 | obs_data_release(settings); 460 | 461 | 462 | unregister_hotkey(filter->hotkey_id_f); 463 | unregister_hotkey(filter->hotkey_id_b); 464 | filter->hotkey_id_f = OBS_INVALID_HOTKEY_ID; 465 | filter->hotkey_id_b = OBS_INVALID_HOTKEY_ID; 466 | } 467 | 468 | static bool motion_set_button(obs_properties_t *props, obs_property_t *p, 469 | bool reversed) 470 | { 471 | obs_property_t *f = obs_properties_get(props, S_FORWARD); 472 | obs_property_t *b = obs_properties_get(props, S_BACKWARD); 473 | obs_property_set_visible(f, !reversed); 474 | obs_property_set_visible(b, reversed); 475 | UNUSED_PARAMETER(p); 476 | return true; 477 | } 478 | 479 | static bool forward_clicked(obs_properties_t *props, obs_property_t *p, 480 | void *data) 481 | { 482 | motion_filter_data_t *filter = data; 483 | if (motion_init(data, true) && filter->motion_behavior == BEHAVIOR_ROUND_TRIP) 484 | return motion_set_button(props, p, true); 485 | else 486 | return false; 487 | } 488 | 489 | static bool backward_clicked(obs_properties_t *props, obs_property_t *p, 490 | void *data) 491 | { 492 | if (motion_init(data, false)) 493 | return motion_set_button(props, p, false); 494 | else 495 | return false; 496 | } 497 | 498 | static bool source_changed(void *data, obs_properties_t *props, 499 | obs_property_t *p, obs_data_t *s) 500 | { 501 | motion_filter_data_t* filter = data; 502 | const char* name = obs_data_get_string(s, S_SOURCE); 503 | 504 | if (!filter->item_name ||!name) 505 | return false; 506 | else if (strcmp(filter->item_name, name) == 0) 507 | return false; 508 | else 509 | recover_source(filter); 510 | 511 | return motion_set_button(props, p, false); 512 | } 513 | 514 | static bool motion_list_source(obs_scene_t* scene, 515 | obs_sceneitem_t* item, void* p) 516 | { 517 | obs_source_t *source = obs_sceneitem_get_source(item); 518 | const char *name = obs_source_get_name(source); 519 | obs_property_list_add_string((obs_property_t*)p, name, name); 520 | UNUSED_PARAMETER(scene); 521 | return true; 522 | } 523 | 524 | /** 525 | * Macro: set_visibility 526 | * --------------------- 527 | * Sets the visibility of a property field in the config. 528 | * key: the property key - e.g. S_EXAMPLE 529 | * vis: a bool for whether the property should be shown (true) or hidden (false) 530 | */ 531 | #define set_visibility(key, vis) \ 532 | do { \ 533 | p = obs_properties_get(props, key); \ 534 | obs_property_set_visible(p, vis);\ 535 | } while (false) 536 | 537 | 538 | static bool properties_set_vis(void *data, obs_properties_t *props, 539 | obs_property_t *p, obs_data_t *s) 540 | { 541 | int trigger_type = (int)obs_data_get_int(s, S_MOTION_BEHAVIOR); 542 | int var_type = (int)obs_data_get_int(s, S_VARIATION_TYPE); 543 | int path_type = (int)obs_data_get_int(s, S_PATH_TYPE); 544 | bool use_start = obs_data_get_bool(s, S_START_SETTING); 545 | bool change_pos = (var_type & VARIATION_POSITION) != 0; 546 | bool change_size = (var_type & VARIATION_SIZE) != 0; 547 | bool scene_switch = trigger_type == BEHAVIOR_SCENE_SWITCH; 548 | 549 | set_visibility(S_START_SETTING, !scene_switch); 550 | set_visibility(S_START_X, change_pos && (use_start || scene_switch)); 551 | set_visibility(S_START_Y, change_pos && (use_start || scene_switch)); 552 | set_visibility(S_DST_X, change_pos); 553 | set_visibility(S_DST_Y, change_pos); 554 | set_visibility(S_PATH_TYPE, change_pos); 555 | set_visibility(S_CTRL_X, change_pos && path_type >= PATH_QUADRATIC); 556 | set_visibility(S_CTRL_Y, change_pos && path_type >= PATH_QUADRATIC); 557 | set_visibility(S_CTRL2_X, change_pos && path_type >= PATH_CUBIC); 558 | set_visibility(S_CTRL2_Y, change_pos && path_type >= PATH_CUBIC); 559 | set_visibility(S_START_W, change_size && (use_start || scene_switch)); 560 | set_visibility(S_START_H, change_size && (use_start || scene_switch)); 561 | set_visibility(S_DST_W, change_size); 562 | set_visibility(S_DST_H, change_size); 563 | 564 | UNUSED_PARAMETER(p); 565 | return true; 566 | } 567 | 568 | static bool motion_behavior_changed(void *data, obs_properties_t *props, 569 | obs_property_t *p, obs_data_t *s) 570 | { 571 | motion_filter_data_t *filter = data; 572 | int behavior = (int)obs_data_get_int(s, S_MOTION_BEHAVIOR); 573 | if (behavior != filter->motion_behavior) { 574 | recover_source(filter); 575 | unregister_trigger_event(data); 576 | filter->motion_behavior = behavior; 577 | register_trigger_event(data); 578 | properties_set_vis(data, props, p, s); 579 | return motion_set_button(props, p, false); 580 | } 581 | return false; 582 | } 583 | 584 | static bool dest_grab_current_position_clicked(obs_properties_t *props, 585 | obs_property_t *p, void *data) 586 | { 587 | struct motion_filter_data *filter = data; 588 | obs_sceneitem_t *item = get_item(filter->context, filter->item_name); 589 | // Find the targetted source item within the scene 590 | if (!filter->item) { 591 | item = get_item_by_id(filter->context, filter->item_id); 592 | reset_source_name(data, filter->item); 593 | } 594 | 595 | if (item) { 596 | struct obs_transform_info info; 597 | int width, height; 598 | obs_sceneitem_get_info(item, &info); 599 | cal_size(item, info.scale.x, info.scale.y, &width, &height); 600 | // Set setting property values to match the source's current position 601 | obs_data_t *settings = obs_source_get_settings(filter->context); 602 | obs_data_set_int(settings, S_DST_X, (int)info.pos.x); 603 | obs_data_set_int(settings, S_DST_Y, (int)info.pos.y); 604 | obs_data_set_int(settings, S_DST_W, width); 605 | obs_data_set_int(settings, S_DST_H, height); 606 | obs_data_release(settings); 607 | return true; 608 | } 609 | 610 | return false; 611 | } 612 | 613 | #undef set_visibility 614 | #undef set_visibility_bool 615 | 616 | /* 617 | * Filter property layout. 618 | */ 619 | static obs_properties_t *motion_filter_properties(void *data) 620 | { 621 | motion_filter_data_t *filter = data; 622 | obs_properties_t *props = obs_properties_create(); 623 | obs_property_t *p; 624 | struct dstr disable_str = { 0 }; 625 | 626 | obs_source_t *source = obs_filter_get_parent(filter->context); 627 | obs_scene_t *scene = obs_scene_from_source(source); 628 | 629 | if (!scene) 630 | return props; 631 | 632 | p = obs_properties_add_list(props, S_SOURCE, T_SOURCE, 633 | OBS_COMBO_TYPE_LIST, OBS_COMBO_FORMAT_STRING); 634 | 635 | dstr_copy(&disable_str, "--- "); 636 | dstr_cat(&disable_str, T_DISABLED); 637 | dstr_cat(&disable_str, " ---"); 638 | obs_property_list_add_string(p, disable_str.array, disable_str.array); 639 | dstr_free(&disable_str); 640 | 641 | // A list of sources 642 | obs_scene_enum_items(scene, motion_list_source, (void*)p); 643 | obs_property_set_modified_callback2(p, source_changed, filter); 644 | 645 | // Various motion behaviour types 646 | p = obs_properties_add_list(props, S_MOTION_BEHAVIOR, T_MOTION_BEHAVIOR, 647 | OBS_COMBO_TYPE_LIST, OBS_COMBO_FORMAT_INT); 648 | obs_property_list_add_int(p, T_HOTKEY_ONE_WAY, BEHAVIOR_ONE_WAY); 649 | obs_property_list_add_int(p, T_HOTKEY_ROUND_TRIP, BEHAVIOR_ROUND_TRIP); 650 | obs_property_list_add_int(p, T_SCENE_SWITCH, BEHAVIOR_SCENE_SWITCH); 651 | // Using modified_callback2 enables us to send along data into the callback 652 | obs_property_set_modified_callback2(p, motion_behavior_changed, filter); 653 | 654 | 655 | //Variation of position or size 656 | p = obs_properties_add_list(props, S_VARIATION_TYPE, T_VARIATION_TYPE, 657 | OBS_COMBO_TYPE_LIST, OBS_COMBO_FORMAT_INT); 658 | obs_property_list_add_int(p, T_VARIATION_POS, VARIATION_POSITION); 659 | obs_property_list_add_int(p, T_VARIATION_SIZE, VARIATION_SIZE); 660 | obs_property_list_add_int(p, T_VARIATION_BOTH, 661 | VARIATION_POSITION | VARIATION_SIZE); 662 | obs_property_set_modified_callback2(p, properties_set_vis, filter); 663 | 664 | p = obs_properties_add_bool(props, S_START_SETTING, T_START_SETTING); 665 | obs_property_set_modified_callback2(p, properties_set_vis,filter); 666 | 667 | // Custom starting X and Y values 668 | obs_properties_add_int(props, S_START_X, T_START_X, -8192, 8192, 1); 669 | obs_properties_add_int(props, S_START_Y, T_START_Y, -8192, 8192, 1); 670 | 671 | 672 | // Custom width and height 673 | obs_properties_add_int(props, S_START_W, T_START_W, 0, 8192, 1); 674 | obs_properties_add_int(props, S_START_H, T_START_H, 0, 8192, 1); 675 | 676 | // Various animation types 677 | p = obs_properties_add_list(props, S_PATH_TYPE, T_PATH_TYPE, 678 | OBS_COMBO_TYPE_LIST, OBS_COMBO_FORMAT_INT); 679 | obs_property_list_add_int(p, T_PATH_LINEAR, PATH_LINEAR); 680 | obs_property_list_add_int(p, T_PATH_QUADRATIC, PATH_QUADRATIC); 681 | obs_property_list_add_int(p, T_PATH_CUBIC, PATH_CUBIC); 682 | obs_property_set_modified_callback2(p, properties_set_vis,filter); 683 | 684 | // Button that pre-populates destination position with the source's current position 685 | obs_properties_add_button(props, S_DEST_GRAB_POS, T_DEST_GRAB_POS, 686 | dest_grab_current_position_clicked); 687 | 688 | // Destination X and Y values 689 | obs_properties_add_int(props, S_DST_X, T_DST_X, -8192, 8192, 1); 690 | obs_properties_add_int(props, S_DST_Y, T_DST_Y, -8192, 8192, 1); 691 | 692 | 693 | // Other control point fields for other types 694 | obs_properties_add_int(props, S_CTRL_X, T_CTRL_X, -8192, 8192, 1); 695 | obs_properties_add_int(props, S_CTRL_Y, T_CTRL_Y, -8192, 8192, 1); 696 | obs_properties_add_int(props, S_CTRL2_X, T_CTRL2_X, -8192, 8192, 1); 697 | obs_properties_add_int(props, S_CTRL2_Y, T_CTRL2_Y, -8192, 8192, 1); 698 | 699 | // Custom width and height 700 | obs_properties_add_int(props, S_DST_W, T_DST_W, 0, 8192, 1); 701 | obs_properties_add_int(props, S_DST_H, T_DST_H, 0, 8192, 1); 702 | 703 | // Animation duration slider 704 | obs_properties_add_float_slider(props, S_DURATION, T_DURATION, 0, 5, 705 | 0.1); 706 | 707 | // Animation acceleration slider 708 | obs_properties_add_float_slider(props, S_ACCELERATION, T_ACCELERATION, -1, 709 | 1, 0.01); 710 | 711 | // Forwards / Backwards button(s) 712 | p = obs_properties_add_button(props, S_FORWARD, T_FORWARD, forward_clicked); 713 | obs_property_set_visible(p, !is_reverse(filter)); 714 | p =obs_properties_add_button(props, S_BACKWARD, T_BACKWARD, backward_clicked); 715 | obs_property_set_visible(p, is_reverse(filter)); 716 | 717 | return props; 718 | } 719 | 720 | static void cal_variation(motion_filter_data_t *filter) 721 | { 722 | variation_data_t *var = &filter->variation; 723 | 724 | float elapsed_time = fmin(filter->duration, var->elapsed_time); 725 | float coeff; 726 | int order; 727 | 728 | if (filter->duration <= 0) 729 | coeff = 1.0f; 730 | else if (is_reverse(filter)) 731 | coeff = 1.0f - (elapsed_time / filter->duration); 732 | else 733 | coeff = elapsed_time / filter->duration; 734 | 735 | if (var->coeff_varaite) 736 | coeff = bezier(var->coeff, coeff, 2); 737 | 738 | order = filter->change_size ? 1 : 0; 739 | 740 | var->scale.x = bezier(var->scale_x, coeff, order); 741 | var->scale.y = bezier(var->scale_y, coeff, order); 742 | 743 | 744 | if (!filter->change_position) 745 | order = 0; 746 | else if (filter->path_type == PATH_QUADRATIC) 747 | order = 2; 748 | else if (filter->path_type == PATH_CUBIC) 749 | order = 3; 750 | else 751 | order = 1; 752 | 753 | var->position.x = bezier(var->point_x, coeff, order); 754 | var->position.y = bezier(var->point_y, coeff, order); 755 | } 756 | 757 | static void motion_filter_tick(void *data, float seconds) 758 | { 759 | motion_filter_data_t *filter = data; 760 | variation_data_t *var = &filter->variation; 761 | 762 | if (filter->motion_start) { 763 | 764 | cal_variation(filter); 765 | obs_sceneitem_set_pos(filter->item, &var->position); 766 | obs_sceneitem_set_scale(filter->item, &var->scale); 767 | 768 | if (var->elapsed_time >= filter->duration) { 769 | filter->motion_start = false; 770 | var->elapsed_time = 0.0f; 771 | obs_sceneitem_release(filter->item); 772 | filter->motion_end = !filter->motion_end; 773 | set_reverse_info(filter); 774 | } else 775 | var->elapsed_time += seconds; 776 | } 777 | 778 | 779 | //Some APIs are not valid during creation , do initlize in tick loop 780 | if (!filter->initialize) { 781 | register_trigger_event(data); 782 | obs_data_t* settings = obs_source_get_settings(filter->context); 783 | motion_filter_save(data, settings); 784 | obs_data_release(settings); 785 | filter->initialize = true; 786 | } 787 | } 788 | 789 | static void *motion_filter_create(obs_data_t *settings, obs_source_t *context) 790 | { 791 | motion_filter_data_t *filter = bzalloc(sizeof(*filter)); 792 | 793 | filter->context = context; 794 | filter->motion_start = false; 795 | filter->initialize = false; 796 | filter->motion_behavior = BEHAVIOR_ROUND_TRIP; 797 | filter->path_type = PATH_LINEAR; 798 | filter->hotkey_id_f = OBS_INVALID_HOTKEY_ID; 799 | filter->hotkey_id_b = OBS_INVALID_HOTKEY_ID; 800 | get_reverse_info(filter); 801 | obs_source_update(context, settings); 802 | return filter; 803 | } 804 | 805 | static void motion_filter_remove(void *data, obs_source_t *source) 806 | { 807 | motion_filter_data_t *filter = data; 808 | unregister_trigger_event(data); 809 | recover_source(filter); 810 | UNUSED_PARAMETER(source); 811 | } 812 | 813 | static void motion_filter_destroy(void *data) 814 | { 815 | motion_filter_data_t *filter = data; 816 | bfree(filter->item_name); 817 | bfree(filter); 818 | } 819 | 820 | static void motion_filter_defaults(obs_data_t *settings) 821 | { 822 | obs_data_set_default_bool(settings, S_MOTION_END, false); 823 | obs_data_set_default_int(settings, S_MOTION_BEHAVIOR, BEHAVIOR_ROUND_TRIP); 824 | obs_data_set_default_double(settings, S_DURATION, 1.0); 825 | } 826 | 827 | static const char *motion_filter_get_name(void *unused) 828 | { 829 | UNUSED_PARAMETER(unused); 830 | return T_("Motion"); 831 | } 832 | 833 | OBS_DECLARE_MODULE() 834 | OBS_MODULE_USE_DEFAULT_LOCALE("motion-filter", "en-US") 835 | 836 | struct obs_source_info motion_filter = { 837 | .id = "motion-filter", 838 | .type = OBS_SOURCE_TYPE_FILTER, 839 | .output_flags = OBS_SOURCE_VIDEO, 840 | .get_name = motion_filter_get_name, 841 | .create = motion_filter_create, 842 | .destroy = motion_filter_destroy, 843 | .update = motion_filter_update, 844 | .get_properties = motion_filter_properties, 845 | .get_defaults = motion_filter_defaults, 846 | .video_tick = motion_filter_tick, 847 | .save = motion_filter_save, 848 | .filter_remove = motion_filter_remove 849 | }; 850 | 851 | bool obs_module_load(void) { 852 | obs_register_source(&motion_filter); 853 | return true; 854 | } 855 | 856 | -------------------------------------------------------------------------------- /src/motion-transition/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.5) 2 | project(motion-transition) 3 | 4 | include(${CMAKE_SOURCE_DIR}/external/FindLibObs.cmake) 5 | find_package(LibObs REQUIRED) 6 | set(motion-transition_SOURCES 7 | ../helper.c 8 | motion-transition.c 9 | ) 10 | 11 | set(motion-transition_HEADERS 12 | ../helper.h 13 | ) 14 | 15 | add_library(motion-transition MODULE 16 | ${motion-transition_SOURCES} 17 | ${motion-transition_HEADERS}) 18 | 19 | target_link_libraries(motion-transition 20 | libobs) 21 | 22 | if(UNIX AND NOT APPLE) 23 | 24 | if(ARCH EQUAL 64) 25 | set(ARCH_NAME "x86_64") 26 | else() 27 | set(ARCH_NAME "i686") 28 | endif() 29 | 30 | set_target_properties(motion-transition PROPERTIES PREFIX "") 31 | 32 | install(TARGETS motion-transition 33 | LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/obs-plugins) 34 | install(DIRECTORY ${CMAKE_SOURCE_DIR}/data/motion-transition/ 35 | DESTINATION "${CMAKE_INSTALL_PREFIX}/share/obs/obs-plugins/motion-transition/") 36 | endif() -------------------------------------------------------------------------------- /src/motion-transition/motion-transition.c: -------------------------------------------------------------------------------- 1 | /* 2 | * motion-effect, an OBS-Studio plugin for animating sources 3 | * Copyright(C) <2018> 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License along 16 | * with this program; if not, write to the Free Software Foundation, Inc., 17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110 - 1301 USA. 18 | */ 19 | 20 | 21 | #include "obs-module.h" 22 | #include "../helper.h" 23 | #include 24 | 25 | enum variation_type { 26 | VARIATION_MOTION = 0, 27 | VARIATION_ZOOMOUT = 1, 28 | VARIATION_ZOOMIN = 2 29 | }; 30 | 31 | 32 | #define S_BEZIER_X "bezier_x" 33 | #define S_BEZIER_Y "bezier_y" 34 | 35 | #define T_(v) obs_module_text(v) 36 | #define T_BEZIER_X T_("Acceleration.X") 37 | #define T_BEZIER_Y T_("Acceleration.Y") 38 | 39 | 40 | typedef struct moving_item moving_item_t; 41 | typedef struct list_info list_info_t; 42 | typedef struct transition_data transition_data_t; 43 | 44 | struct moving_item { 45 | obs_sceneitem_t *item; 46 | enum variation_type type; 47 | struct obs_transform_info start_info; 48 | struct obs_transform_info end_info; 49 | struct obs_sceneitem_crop start_crop; 50 | struct obs_sceneitem_crop end_crop; 51 | struct vec2 control_pos; 52 | moving_item_t *next; 53 | }; 54 | 55 | struct list_info { 56 | obs_scene_t *scene; 57 | obs_source_t *source; 58 | moving_item_t *last_item; 59 | moving_item_t *first_item; 60 | }; 61 | 62 | struct transition_data { 63 | obs_source_t *context; 64 | list_info_t out_list; 65 | list_info_t in_list; 66 | float acc_x; 67 | float acc_y; 68 | bool start_init; 69 | bool scene_transition; 70 | bool transitioning; 71 | }; 72 | 73 | static bool append_item_list(obs_scene_t *scene, obs_sceneitem_t *item_a, void *data) 74 | { 75 | transition_data_t *tr = data; 76 | bool transition_out = tr->out_list.scene == scene; 77 | bool transform_variation = false; 78 | list_info_t *list, *list_cmp; 79 | struct obs_transform_info *info_a, *info_b; 80 | struct obs_sceneitem_crop *crop_a, *crop_b; 81 | obs_source_t *source_a = obs_sceneitem_get_source(item_a); 82 | obs_sceneitem_t *item_b; 83 | moving_item_t *next = bzalloc(sizeof(*next)); 84 | 85 | if (transition_out) { 86 | list = &tr->out_list; 87 | list_cmp = &tr->in_list; 88 | info_a = &next->start_info; 89 | info_b = &next->end_info; 90 | crop_a = &next->start_crop; 91 | crop_b = &next->end_crop; 92 | } else { 93 | list = &tr->in_list; 94 | list_cmp = &tr->out_list; 95 | info_a = &next->end_info; 96 | info_b = &next->start_info; 97 | crop_a = &next->end_crop; 98 | crop_b = &next->start_crop; 99 | } 100 | 101 | obs_sceneitem_get_info(item_a, info_a); 102 | obs_sceneitem_get_crop(item_a, crop_a); 103 | item_b = obs_scene_find_source(list_cmp->scene, 104 | obs_source_get_name(source_a)); 105 | 106 | 107 | if (item_b) { 108 | obs_sceneitem_get_info(item_b, info_b); 109 | obs_sceneitem_get_crop(item_b, crop_b); 110 | transform_variation = same_transform_type(info_a, info_b) && (item_a->user_visible==item_b->user_visible); 111 | } 112 | 113 | if (transform_variation) { 114 | float t = transition_out ? tr->acc_x : 1 - tr->acc_x; 115 | float f = transition_out ? tr->acc_y : 1 - tr->acc_y; 116 | next->control_pos.x = (1 - t) * info_a->pos.x + t * info_b->pos.x; 117 | next->control_pos.y = (1 - f) * info_a->pos.y + f * info_b->pos.y; 118 | next->type = VARIATION_MOTION; 119 | } else { 120 | float w = obs_source_get_base_width(source_a) * info_a->scale.x; 121 | float h = obs_source_get_base_height(source_a) * info_a->scale.y; 122 | info_b->pos.x = info_a->pos.x + w / 2; 123 | info_b->pos.y = info_a->pos.y + h / 2; 124 | info_b->scale.x = 0; 125 | info_b->scale.y = 0; 126 | next->type = transition_out ? VARIATION_ZOOMOUT : VARIATION_ZOOMIN; 127 | } 128 | 129 | next->item = item_a; 130 | 131 | if (list->last_item) 132 | list->last_item->next = next; 133 | else 134 | list->first_item = next; 135 | 136 | list->last_item = next; 137 | 138 | return true; 139 | } 140 | 141 | static void create_item_list(transition_data_t* tr) 142 | { 143 | obs_scene_enum_items(tr->out_list.scene, append_item_list, tr); 144 | obs_scene_enum_items(tr->in_list.scene, append_item_list, tr); 145 | } 146 | 147 | static void release_item_list(list_info_t *list) 148 | { 149 | moving_item_t *mv = list->first_item; 150 | moving_item_t *next; 151 | while (mv) { 152 | next = mv->next; 153 | bfree(mv); 154 | mv = next; 155 | } 156 | 157 | memset(list, 0, sizeof(list_info_t)); 158 | } 159 | 160 | static void update_item_information(moving_item_t *mv, float time) 161 | { 162 | struct vec2 pos; 163 | struct vec2 scale; 164 | struct vec2 bounds; 165 | struct obs_sceneitem_crop crop; 166 | float rot; 167 | float t; 168 | 169 | while(mv) { 170 | 171 | if (mv->type == VARIATION_MOTION) { 172 | t = time; 173 | vec_bezier(mv->start_info.pos, mv->control_pos, mv->end_info.pos, 174 | &pos, t); 175 | vec_linear(mv->start_info.bounds, mv->end_info.bounds, &bounds, t); 176 | crop_linear(mv->start_crop, mv->end_crop, &crop, t); 177 | rot = (1.0f - t) * mv->start_info.rot + t * mv->end_info.rot; 178 | obs_sceneitem_set_bounds(mv->item, &bounds); 179 | obs_sceneitem_set_crop(mv->item, &crop); 180 | obs_sceneitem_set_rot(mv->item, rot); 181 | 182 | } else if (mv->type == VARIATION_ZOOMIN) { 183 | t = time * 2 - 1.0f; 184 | vec_linear(mv->start_info.pos, mv->end_info.pos, &pos, t); 185 | } else { 186 | t = time * 2; 187 | vec_linear(mv->start_info.pos, mv->end_info.pos, &pos, t); 188 | } 189 | 190 | vec_linear(mv->start_info.scale, mv->end_info.scale, &scale, t); 191 | 192 | obs_sceneitem_set_pos(mv->item, &pos); 193 | obs_sceneitem_set_scale(mv->item, &scale); 194 | mv = mv->next; 195 | } 196 | } 197 | 198 | static void motion_transition_update(void *data, obs_data_t *settings) 199 | { 200 | transition_data_t *tr = data; 201 | float x = (float)obs_data_get_double(settings, S_BEZIER_X); 202 | float y = (float)obs_data_get_double(settings, S_BEZIER_Y); 203 | 204 | tr->acc_x = - x + 0.5f; 205 | tr->acc_y = - y + 0.5f; 206 | } 207 | 208 | static void motion_transition_start(void *data) 209 | { 210 | transition_data_t *tr = data; 211 | tr->start_init = true; 212 | } 213 | 214 | static void motion_transition_stop(void *data) 215 | { 216 | transition_data_t *tr = data; 217 | 218 | obs_source_remove_active_child(tr->context, tr->in_list.source); 219 | obs_source_remove_active_child(tr->context, tr->out_list.source); 220 | obs_scene_release(tr->in_list.scene); 221 | obs_scene_release(tr->out_list.scene); 222 | release_item_list(&tr->in_list); 223 | release_item_list(&tr->out_list); 224 | tr->transitioning = false; 225 | } 226 | 227 | static obs_properties_t *motion_transition_properties(void *data) 228 | { 229 | obs_properties_t *props = obs_properties_create(); 230 | obs_properties_add_float_slider(props, S_BEZIER_X, T_BEZIER_X, -0.5, 0.5, 231 | 0.01); 232 | obs_properties_add_float_slider(props, S_BEZIER_Y, T_BEZIER_Y, -0.5, 0.5, 233 | 0.01); 234 | return props; 235 | } 236 | 237 | static void motion_transition_video_render(void *data, gs_effect_t *effect) 238 | { 239 | transition_data_t *tr = data; 240 | 241 | float t = obs_transition_get_time(tr->context); 242 | 243 | if (tr->start_init) { 244 | 245 | if (tr->transitioning) 246 | motion_transition_stop(tr); 247 | 248 | obs_source_t *source_a = obs_transition_get_source(tr->context, 249 | OBS_TRANSITION_SOURCE_A); 250 | obs_scene_t *scene_a = obs_scene_from_source(source_a); 251 | 252 | obs_source_t *source_b = obs_transition_get_source(tr->context, 253 | OBS_TRANSITION_SOURCE_B); 254 | obs_scene_t *scene_b = obs_scene_from_source(source_b); 255 | tr->scene_transition = scene_a && scene_b; 256 | 257 | if (tr->scene_transition) { 258 | 259 | tr->out_list.scene = obs_scene_duplicate(scene_a, 260 | "motion-transition-a", OBS_SCENE_DUP_PRIVATE_REFS); 261 | tr->out_list.source = obs_scene_get_source(tr->out_list.scene); 262 | obs_source_add_active_child(tr->context, tr->out_list.source); 263 | 264 | tr->in_list.scene = obs_scene_duplicate(scene_b, 265 | "motion-transition-b", OBS_SCENE_DUP_PRIVATE_REFS); 266 | tr->in_list.source = obs_scene_get_source(tr->in_list.scene); 267 | obs_source_add_active_child(tr->context, tr->in_list.source); 268 | 269 | create_item_list(tr); 270 | tr->transitioning = true; 271 | } 272 | obs_source_release(source_a); 273 | obs_source_release(source_b); 274 | tr->start_init = false; 275 | } 276 | 277 | if (t > 0.0f && t < 1.0f && tr->scene_transition) { 278 | if (t <= 0.5) { 279 | update_item_information(tr->out_list.first_item, t); 280 | obs_source_video_render(tr->out_list.source); 281 | } else { 282 | update_item_information(tr->in_list.first_item, t); 283 | obs_source_video_render(tr->in_list.source); 284 | } 285 | } else if (t <= 0.5f ) { 286 | obs_transition_video_render_direct(tr->context, 287 | OBS_TRANSITION_SOURCE_A); 288 | } else { 289 | obs_transition_video_render_direct(tr->context, 290 | OBS_TRANSITION_SOURCE_B); 291 | } 292 | 293 | } 294 | 295 | static float mix_a(void *data, float t) 296 | { 297 | UNUSED_PARAMETER(data); 298 | return 1.0f - t; 299 | } 300 | 301 | static float mix_b(void *data, float t) 302 | { 303 | UNUSED_PARAMETER(data); 304 | return t; 305 | } 306 | 307 | 308 | static bool motion_transition_audio_render(void *data, uint64_t *ts_out, 309 | struct obs_source_audio_mix *audio, uint32_t mixers, 310 | size_t channels, size_t sample_rate) 311 | { 312 | transition_data_t *tr = data; 313 | return obs_transition_audio_render(tr->context, ts_out, 314 | audio, mixers, channels, sample_rate, mix_a, mix_b); 315 | } 316 | 317 | static void motion_enum_all_sources(void *data, 318 | obs_source_enum_proc_t enum_callback, void *param) 319 | { 320 | transition_data_t* tr = data; 321 | if (tr->out_list.source) 322 | enum_callback(tr->context, tr->out_list.source, param); 323 | 324 | if (tr->in_list.source) 325 | enum_callback(tr->context, tr->in_list.source, param); 326 | 327 | } 328 | 329 | 330 | static void motion_enum_active_sources(void *data, 331 | obs_source_enum_proc_t enum_callback, void *param) 332 | { 333 | transition_data_t* tr = data; 334 | if (tr->out_list.source && tr->transitioning) 335 | enum_callback(tr->context, tr->out_list.source, param); 336 | 337 | if (tr->in_list.source && tr->transitioning) 338 | enum_callback(tr->context, tr->in_list.source, param); 339 | } 340 | 341 | static void *motion_transition_create(obs_data_t *settings, obs_source_t *context) 342 | { 343 | transition_data_t *tr = bzalloc(sizeof(*tr)); 344 | tr->context = context; 345 | UNUSED_PARAMETER(settings); 346 | return tr; 347 | } 348 | 349 | 350 | static void motion_transition_destroy(void *data) 351 | { 352 | transition_data_t *tr = data; 353 | bfree(tr); 354 | } 355 | 356 | 357 | static const char *motion_transition_get_name(void *unused) 358 | { 359 | UNUSED_PARAMETER(unused); 360 | return obs_module_text("Motion"); 361 | } 362 | 363 | OBS_DECLARE_MODULE() 364 | OBS_MODULE_USE_DEFAULT_LOCALE("motion-transition", "en-US") 365 | 366 | struct obs_source_info motion_transition = { 367 | .id = "motion-transition", 368 | .type = OBS_SOURCE_TYPE_TRANSITION, 369 | .get_name = motion_transition_get_name, 370 | .create = motion_transition_create, 371 | .destroy = motion_transition_destroy, 372 | .update = motion_transition_update, 373 | .video_render = motion_transition_video_render, 374 | .audio_render = motion_transition_audio_render, 375 | .get_properties = motion_transition_properties, 376 | .enum_active_sources = motion_enum_active_sources, 377 | .enum_all_sources = motion_enum_all_sources, 378 | .transition_start = motion_transition_start, 379 | .transition_stop = motion_transition_stop 380 | }; 381 | 382 | bool obs_module_load(void) { 383 | obs_register_source(&motion_transition); 384 | return true; 385 | } --------------------------------------------------------------------------------