├── README.md ├── stringer-transition-module.c ├── CMakeLists.txt ├── obs-ffmpeg-compat.h ├── stinger_transition.effect ├── obs-ffmpeg-formats.h ├── LICENSE └── transition_stinger.c /README.md: -------------------------------------------------------------------------------- 1 | # Video-Transition 2 | Allows to use videos as transitions in OBS Studio 3 | -------------------------------------------------------------------------------- /stringer-transition-module.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | OBS_DECLARE_MODULE() 5 | 6 | OBS_MODULE_USE_DEFAULT_LOCALE("obs-transitions", "en-US") //might be useful in future but not used right now 7 | 8 | extern struct obs_source_info stinger_transition; 9 | 10 | bool obs_module_load(void) 11 | { 12 | obs_register_source(&stinger_transition); 13 | return true; 14 | } 15 | 16 | bool obs_module_unload() 17 | { 18 | return true; 19 | } -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(stinger-transition) 2 | 3 | if(DISABLE_STINGER) 4 | message(STATUS "Stinger transition support disabled") 5 | return() 6 | endif() 7 | 8 | find_package(FFmpeg REQUIRED 9 | COMPONENTS avcodec avfilter avdevice avutil swscale avformat swresample) 10 | include_directories(${FFMPEG_INCLUDE_DIRS}) 11 | 12 | include_directories( 13 | SYSTEM "${CMAKE_SOURCE_DIR}/libobs" 14 | ) 15 | 16 | set(stinger-transition_config_HEADERS 17 | obs-ffmpeg-compat.h 18 | obs-ffmpeg-formats.h 19 | ) 20 | 21 | set(stinger-transition_SOURCES 22 | transition_stinger.c 23 | stringer-transition-module.c 24 | 25 | ) 26 | 27 | add_library(stinger-transition MODULE 28 | ${stinger-transition_config_HEADERS} 29 | ${stinger-transition_SOURCES} 30 | ) 31 | target_link_libraries(stinger-transition 32 | libobs 33 | libff 34 | ${FFMPEG_LIBRARIES} 35 | ) 36 | 37 | install_obs_plugin_with_data(stinger-transition data) 38 | -------------------------------------------------------------------------------- /obs-ffmpeg-compat.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | /* LIBAVCODEC_VERSION_CHECK checks for the right version of libav and FFmpeg 6 | * a is the major version 7 | * b and c the minor and micro versions of libav 8 | * d and e the minor and micro versions of FFmpeg */ 9 | #define LIBAVCODEC_VERSION_CHECK( a, b, c, d, e ) \ 10 | ( (LIBAVCODEC_VERSION_MICRO < 100 && LIBAVCODEC_VERSION_INT >= AV_VERSION_INT( a, b, c ) ) || \ 11 | (LIBAVCODEC_VERSION_MICRO >= 100 && LIBAVCODEC_VERSION_INT >= AV_VERSION_INT( a, d, e ) ) ) 12 | 13 | #if !LIBAVCODEC_VERSION_CHECK(54, 28, 0, 59, 100) 14 | # define avcodec_free_frame av_freep 15 | #endif 16 | 17 | #if LIBAVCODEC_VERSION_INT < 0x371c01 18 | # define av_frame_alloc avcodec_alloc_frame 19 | # define av_frame_unref avcodec_get_frame_defaults 20 | # define av_frame_free avcodec_free_frame 21 | #endif 22 | 23 | #if LIBAVCODEC_VERSION_MAJOR >= 57 24 | #define av_free_packet av_packet_unref 25 | #endif 26 | -------------------------------------------------------------------------------- /stinger_transition.effect: -------------------------------------------------------------------------------- 1 | uniform float4x4 ViewProj; 2 | uniform texture2d a_tex; 3 | uniform texture2d b_tex; 4 | 5 | sampler_state textureSampler { 6 | Filter = Linear; 7 | AddressU = Clamp; 8 | AddressV = Clamp; 9 | }; 10 | 11 | struct VertData { 12 | float4 pos : POSITION; 13 | float2 uv : TEXCOORD0; 14 | }; 15 | 16 | VertData VSDefault(VertData v_in) 17 | { 18 | VertData vert_out; 19 | vert_out.pos = mul(float4(v_in.pos.xyz, 1.0), ViewProj); 20 | vert_out.uv = v_in.uv; 21 | return vert_out; 22 | } 23 | 24 | //Overlay "Top" on "Base" 25 | float4 Overlay(float4 Base, float4 Top) 26 | { 27 | float4 Res; 28 | half3 BaseVisible = Base.rgb * (1 - Top.a); 29 | half3 TopVisible = Top.rgb * (Top.a); 30 | 31 | float3 finalColor = (BaseVisible + TopVisible); 32 | Res.rgb = finalColor; 33 | Res.a = 1.0f; 34 | return Res; 35 | } 36 | 37 | float4 PSStinger(VertData v_in) : TARGET 38 | { 39 | float2 uv = v_in.uv; 40 | float4 a_color = a_tex.Sample(textureSampler, uv); 41 | float4 b_color = b_tex.Sample(textureSampler, uv); 42 | 43 | return Overlay(a_color, b_color); 44 | } 45 | 46 | technique Stinger 47 | { 48 | pass 49 | { 50 | vertex_shader = VSDefault(v_in); 51 | pixel_shader = PSStinger(v_in); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /obs-ffmpeg-formats.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | static inline int64_t rescale_ts(int64_t val, AVCodecContext *context, 4 | AVRational new_base) 5 | { 6 | return av_rescale_q_rnd(val, context->time_base, new_base, 7 | AV_ROUND_NEAR_INF | AV_ROUND_PASS_MINMAX); 8 | } 9 | 10 | static inline enum AVPixelFormat obs_to_ffmpeg_video_format( 11 | enum video_format format) 12 | { 13 | switch (format) { 14 | case VIDEO_FORMAT_NONE: return AV_PIX_FMT_NONE; 15 | case VIDEO_FORMAT_I444: return AV_PIX_FMT_YUV444P; 16 | case VIDEO_FORMAT_I420: return AV_PIX_FMT_YUV420P; 17 | case VIDEO_FORMAT_NV12: return AV_PIX_FMT_NV12; 18 | case VIDEO_FORMAT_YVYU: return AV_PIX_FMT_NONE; 19 | case VIDEO_FORMAT_YUY2: return AV_PIX_FMT_YUYV422; 20 | case VIDEO_FORMAT_UYVY: return AV_PIX_FMT_UYVY422; 21 | case VIDEO_FORMAT_RGBA: return AV_PIX_FMT_RGBA; 22 | case VIDEO_FORMAT_BGRA: return AV_PIX_FMT_BGRA; 23 | case VIDEO_FORMAT_BGRX: return AV_PIX_FMT_BGRA; 24 | case VIDEO_FORMAT_Y800: return AV_PIX_FMT_GRAY8; 25 | } 26 | 27 | return AV_PIX_FMT_NONE; 28 | } 29 | 30 | static inline enum video_format ffmpeg_to_obs_video_format( 31 | enum AVPixelFormat format) 32 | { 33 | switch (format) { 34 | case AV_PIX_FMT_YUV444P: return VIDEO_FORMAT_I444; 35 | case AV_PIX_FMT_YUV420P: return VIDEO_FORMAT_I420; 36 | case AV_PIX_FMT_NV12: return VIDEO_FORMAT_NV12; 37 | case AV_PIX_FMT_YUYV422: return VIDEO_FORMAT_YUY2; 38 | case AV_PIX_FMT_UYVY422: return VIDEO_FORMAT_UYVY; 39 | case AV_PIX_FMT_RGBA: return VIDEO_FORMAT_RGBA; 40 | case AV_PIX_FMT_BGRA: return VIDEO_FORMAT_BGRA; 41 | case AV_PIX_FMT_GRAY8: return VIDEO_FORMAT_Y800; 42 | case AV_PIX_FMT_NONE: 43 | default: return VIDEO_FORMAT_NONE; 44 | } 45 | } 46 | 47 | static inline enum audio_format convert_ffmpeg_sample_format( 48 | enum AVSampleFormat format) 49 | { 50 | switch ((uint32_t)format) { 51 | case AV_SAMPLE_FMT_U8: return AUDIO_FORMAT_U8BIT; 52 | case AV_SAMPLE_FMT_S16: return AUDIO_FORMAT_16BIT; 53 | case AV_SAMPLE_FMT_S32: return AUDIO_FORMAT_32BIT; 54 | case AV_SAMPLE_FMT_FLT: return AUDIO_FORMAT_FLOAT; 55 | case AV_SAMPLE_FMT_U8P: return AUDIO_FORMAT_U8BIT_PLANAR; 56 | case AV_SAMPLE_FMT_S16P: return AUDIO_FORMAT_16BIT_PLANAR; 57 | case AV_SAMPLE_FMT_S32P: return AUDIO_FORMAT_32BIT_PLANAR; 58 | case AV_SAMPLE_FMT_FLTP: return AUDIO_FORMAT_FLOAT_PLANAR; 59 | } 60 | 61 | /* shouldn't get here */ 62 | return AUDIO_FORMAT_16BIT; 63 | } 64 | -------------------------------------------------------------------------------- /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 | {description} 294 | Copyright (C) {year} {fullname} 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 | {signature of Ty Coon}, 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 | -------------------------------------------------------------------------------- /transition_stinger.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include "obs-ffmpeg-compat.h" 9 | #include "obs-ffmpeg-formats.h" 10 | 11 | #include 12 | 13 | //#include 14 | // 15 | // 16 | //void my_log_callback(void *ptr, int level, const char *fmt, va_list vargs) 17 | //{ 18 | // char szBuff[2048]; 19 | // int i = _vsnprintf(szBuff, sizeof(szBuff), fmt, vargs); 20 | // 21 | // OutputDebugStringA(szBuff); 22 | //} 23 | 24 | //av_log_set_callback(my_log_callback); 25 | //av_log_set_level(AV_LOG_VERBOSE); 26 | 27 | 28 | 29 | struct stinger_info { 30 | obs_source_t *source; 31 | 32 | gs_effect_t *effect; 33 | gs_eparam_t *ep_a_tex; 34 | gs_eparam_t *ep_b_tex; 35 | 36 | float lastTime; 37 | 38 | gs_texture_t *stinger_texture; 39 | gs_image_file_t stinger_error_image; 40 | 41 | struct obs_source_audio *audio_data; 42 | 43 | float cutTime; 44 | size_t cutFrame; 45 | bool validInput; 46 | 47 | char *path; 48 | size_t curFrame; 49 | size_t numberOfFrames; 50 | 51 | struct ff_demuxer *demuxer; 52 | struct SwsContext *sws_ctx; 53 | int sws_width; 54 | int sws_height; 55 | enum AVPixelFormat sws_format; 56 | uint8_t *sws_data; 57 | int sws_linesize; 58 | 59 | enum AVDiscard frame_drop; 60 | enum video_range_type range; 61 | int audio_buffer_size; 62 | int video_buffer_size; 63 | bool is_advanced; 64 | bool is_looping; 65 | bool is_forcing_scale; 66 | bool is_hw_decoding; 67 | bool is_clear_on_media_end; 68 | bool restart_on_activate; 69 | 70 | }; 71 | 72 | static const char *stinger_get_name(void *type_data) 73 | { 74 | UNUSED_PARAMETER(type_data); 75 | return obs_module_text("StingerTransition"); 76 | } 77 | 78 | bool update_sws_context(struct stinger_info *s, AVFrame *frame) 79 | { 80 | if (frame->width != s->sws_width 81 | || frame->height != s->sws_height 82 | || frame->format != s->sws_format) { 83 | if (s->sws_ctx != NULL) 84 | sws_freeContext(s->sws_ctx); 85 | 86 | if (frame->width <= 0 || frame->height <= 0) { 87 | blog(LOG_ERROR, "unable to create a sws " 88 | "context that has a width(%d) or " 89 | "height(%d) of zero.", frame->width, 90 | frame->height); 91 | goto fail; 92 | } 93 | 94 | s->sws_ctx = sws_getContext( 95 | frame->width, 96 | frame->height, 97 | frame->format, 98 | frame->width, 99 | frame->height, 100 | AV_PIX_FMT_BGRA, 101 | SWS_BILINEAR, 102 | NULL, NULL, NULL); 103 | 104 | if (s->sws_ctx == NULL) { 105 | blog(LOG_ERROR, "unable to create sws " 106 | "context with src{w:%d,h:%d,f:%d}->" 107 | "dst{w:%d,h:%d,f:%d}", 108 | frame->width, frame->height, 109 | frame->format, frame->width, 110 | frame->height, AV_PIX_FMT_BGRA); 111 | goto fail; 112 | 113 | } 114 | 115 | if (s->sws_data != NULL) 116 | bfree(s->sws_data); 117 | s->sws_data = bzalloc(frame->width * frame->height * 4); 118 | if (s->sws_data == NULL) { 119 | blog(LOG_ERROR, "unable to allocate sws " 120 | "pixel data with size %d", 121 | frame->width * frame->height * 4); 122 | goto fail; 123 | } 124 | 125 | s->sws_linesize = frame->width * 4; 126 | s->sws_width = frame->width; 127 | s->sws_height = frame->height; 128 | s->sws_format = frame->format; 129 | } 130 | 131 | return true; 132 | 133 | fail: 134 | if (s->sws_ctx != NULL) 135 | sws_freeContext(s->sws_ctx); 136 | s->sws_ctx = NULL; 137 | 138 | if (s->sws_data) 139 | bfree(s->sws_data); 140 | s->sws_data = NULL; 141 | 142 | s->sws_linesize = 0; 143 | s->sws_width = 0; 144 | s->sws_height = 0; 145 | s->sws_format = 0; 146 | 147 | return false; 148 | } 149 | 150 | static void setNextFrameTexture(struct stinger_info *stinger, AVFrame *frame) 151 | { 152 | if (!stinger) 153 | return; 154 | 155 | obs_enter_graphics(); 156 | gs_texture_destroy(stinger->stinger_texture); 157 | stinger->stinger_texture = gs_texture_create( 158 | frame->width, frame->height, 5, 1, //5 is AV_PIX_FMT_BGRA 159 | (const uint8_t**)&frame->data, 0); 160 | obs_leave_graphics(); 161 | 162 | stinger->curFrame++; 163 | 164 | av_frame_free(&frame); 165 | } 166 | 167 | 168 | static bool video_frame_scale(struct ff_frame *frame, 169 | struct stinger_info *s, AVFrame *pFrame) 170 | { 171 | if (!update_sws_context(s, frame->frame)) 172 | { 173 | av_frame_free(&pFrame); 174 | return false; 175 | } 176 | 177 | sws_scale( 178 | s->sws_ctx, 179 | (uint8_t const *const *)frame->frame->data, 180 | frame->frame->linesize, 181 | 0, 182 | frame->frame->height, 183 | &s->sws_data, 184 | &s->sws_linesize 185 | ); 186 | 187 | pFrame->data[0] = s->sws_data; 188 | pFrame->linesize[0] = s->sws_linesize; 189 | pFrame->format = AV_PIX_FMT_BGRA; 190 | 191 | setNextFrameTexture(s, pFrame); 192 | 193 | return true; 194 | } 195 | 196 | static bool video_frame_hwaccel(struct ff_frame *frame, 197 | struct stinger_info *s, AVFrame *pFrame) 198 | { 199 | // 4th plane is pixelbuf reference for mac 200 | for (int i = 0; i < 3; i++) { 201 | pFrame->data[i] = frame->frame->data[i]; 202 | pFrame->linesize[i] = frame->frame->linesize[i]; 203 | } 204 | 205 | //if (!set_obs_frame_colorprops(frame, s, obs_frame)) 206 | // return false; 207 | 208 | setNextFrameTexture(s, pFrame); 209 | return true; 210 | } 211 | 212 | static bool video_frame_direct(struct ff_frame *frame, 213 | struct stinger_info *s, AVFrame *pFrame) 214 | { 215 | int i; 216 | 217 | for (i = 0; i < MAX_AV_PLANES; i++) { 218 | pFrame->data[i] = frame->frame->data[i]; 219 | pFrame->linesize[i] = frame->frame->linesize[i]; 220 | } 221 | 222 | //if (!set_obs_frame_colorprops(frame, s, obs_frame)) 223 | // return false; 224 | 225 | setNextFrameTexture(s, pFrame); 226 | return true; 227 | } 228 | 229 | static bool video_frame(struct ff_frame *frame, void *opaque) 230 | { 231 | struct stinger_info *s = opaque; 232 | 233 | // Media ended 234 | if (frame == NULL) { 235 | obs_enter_graphics(); 236 | gs_texture_destroy(s->stinger_texture); 237 | s->stinger_texture = NULL; 238 | obs_leave_graphics(); 239 | return true; 240 | } 241 | AVFrame *pFrame = NULL; 242 | 243 | pFrame = av_frame_alloc(); 244 | if (!pFrame) 245 | return false; 246 | 247 | pFrame->format = AV_PIX_FMT_BGRA; 248 | pFrame->width = frame->frame->width; 249 | pFrame->height = frame->frame->height; 250 | 251 | enum video_format format = 252 | ffmpeg_to_obs_video_format(frame->frame->format); 253 | 254 | if (s->is_forcing_scale || format == VIDEO_FORMAT_NONE) 255 | return video_frame_scale(frame, s, pFrame); 256 | else if (s->is_hw_decoding) 257 | return video_frame_hwaccel(frame, s, pFrame); 258 | else 259 | return video_frame_direct(frame, s, pFrame); 260 | } 261 | 262 | static bool audio_frame(struct ff_frame *frame, void *opaque) 263 | { 264 | struct stinger_info *s = opaque; 265 | 266 | struct obs_source_audio audio_data; 267 | uint64_t pts; 268 | 269 | bfree(s->audio_data); 270 | 271 | // Media ended 272 | if (frame == NULL || frame->frame == NULL){ 273 | s->audio_data = NULL; 274 | return true; 275 | } 276 | 277 | pts = (uint64_t)(frame->pts * 1000000000.0L); 278 | 279 | int channels = av_frame_get_channels(frame->frame); 280 | 281 | for (int i = 0; i < channels; i++) 282 | audio_data.data[i] = frame->frame->data[i]; 283 | 284 | audio_data.samples_per_sec = frame->frame->sample_rate; 285 | audio_data.frames = frame->frame->nb_samples; 286 | audio_data.timestamp = pts; 287 | audio_data.format = 288 | convert_ffmpeg_sample_format(frame->frame->format); 289 | audio_data.speakers = channels; 290 | 291 | s->audio_data = bzalloc(sizeof(audio_data)); 292 | 293 | memcpy(s->audio_data, &audio_data, sizeof audio_data); 294 | 295 | return true; 296 | } 297 | 298 | 299 | 300 | static void ffmpeg_source_start(struct stinger_info *s) 301 | { 302 | if (s->demuxer != NULL) 303 | ff_demuxer_free(s->demuxer); 304 | 305 | s->demuxer = ff_demuxer_init(); 306 | s->demuxer->options.is_hw_decoding = s->is_hw_decoding; 307 | s->demuxer->options.is_looping = false; 308 | 309 | ff_demuxer_set_callbacks(&s->demuxer->video_callbacks, 310 | video_frame, NULL, 311 | NULL, NULL, NULL, s); 312 | 313 | ff_demuxer_set_callbacks(&s->demuxer->audio_callbacks, 314 | audio_frame, NULL, 315 | NULL, NULL, NULL, s); 316 | 317 | ff_demuxer_open(s->demuxer, s->path, NULL); 318 | } 319 | 320 | static inline void load_error_texture(struct stinger_info *stinger) 321 | { 322 | struct dstr path = { 0 }; 323 | 324 | const char* file = obs_module_file(""); 325 | dstr_copy(&path, file); 326 | bfree(file); 327 | dstr_cat(&path, "/NoStingerVideoLoaded.png"); 328 | 329 | obs_enter_graphics(); 330 | gs_image_file_free(&stinger->stinger_error_image); 331 | obs_leave_graphics(); 332 | 333 | gs_image_file_init(&stinger->stinger_error_image, path.array); 334 | 335 | obs_enter_graphics(); 336 | gs_image_file_init_texture(&stinger->stinger_error_image); 337 | obs_leave_graphics(); 338 | stinger->stinger_texture = stinger->stinger_error_image.texture; 339 | dstr_free(&path); 340 | } 341 | 342 | static uint32_t get_duration_ms(struct stinger_info *stinger) 343 | { 344 | AVCodecContext *pCodecCtx = NULL; 345 | AVCodec *pCodec = NULL; 346 | AVFormatContext *pFormatCtx = NULL; 347 | 348 | if (avformat_open_input(&pFormatCtx, stinger->path, NULL, NULL) != 0) 349 | { 350 | stinger->validInput = false; 351 | load_error_texture(stinger); 352 | return 3000; // Couldn't open file 353 | } 354 | 355 | if (avformat_find_stream_info(pFormatCtx, NULL)<0) 356 | { 357 | stinger->validInput = false; 358 | load_error_texture(stinger); 359 | return 3000; // Couldn't find stream information 360 | } 361 | 362 | int videoStream = av_find_best_stream(pFormatCtx, AVMEDIA_TYPE_VIDEO, -1, -1, &pCodec, 0); 363 | 364 | pCodecCtx = pFormatCtx->streams[videoStream]->codec; 365 | 366 | pCodec = avcodec_find_decoder(pCodecCtx->codec_id); 367 | 368 | if (pCodec == NULL) 369 | { 370 | stinger->validInput = false; 371 | load_error_texture(stinger); 372 | return 3000; // Codec not found 373 | } 374 | 375 | double duration = 376 | (double)stinger->numberOfFrames / 377 | (double)pCodecCtx->framerate.num * 378 | (double)pCodecCtx->framerate.den * 379 | 1000.0; 380 | 381 | avcodec_close(pCodecCtx); 382 | avformat_close_input(&pFormatCtx); 383 | 384 | return (uint32_t)duration; 385 | } 386 | 387 | static void stinger_update(void *data, obs_data_t *settings) 388 | { 389 | struct stinger_info *stinger = data; 390 | 391 | bool is_local_file = obs_data_get_bool(settings, "is_local_file"); 392 | bool is_advanced = obs_data_get_bool(settings, "advanced"); 393 | 394 | stinger->is_hw_decoding = obs_data_get_bool(settings, "hw_decode"); 395 | stinger->is_forcing_scale = true; 396 | stinger->lastTime = 1.0f; //to make sure it plays on first scene change 397 | 398 | stinger->path = obs_data_get_string(settings, "stingerPath"); 399 | stinger->cutFrame = obs_data_get_int(settings, "cutFrame"); 400 | stinger->numberOfFrames = obs_data_get_int(settings, "numberOfFrames"); 401 | 402 | if (stinger->numberOfFrames > 1){ 403 | stinger->validInput = true; 404 | //error image not needed if valid input 405 | obs_enter_graphics(); 406 | gs_image_file_free(&stinger->stinger_error_image); 407 | stinger->stinger_texture = NULL; 408 | obs_leave_graphics(); 409 | 410 | obs_transition_enable_fixed(stinger->source, true, 411 | get_duration_ms(stinger)); 412 | } 413 | else 414 | { 415 | stinger->validInput = false; 416 | stinger->cutFrame = 1; 417 | stinger->numberOfFrames = 1; 418 | obs_data_set_int(settings, "numberOfFrames", 1); 419 | obs_data_set_int(settings, "cutFrame", 1); 420 | 421 | load_error_texture(stinger); 422 | 423 | obs_transition_enable_fixed(stinger->source, true, 424 | 3000); 425 | } 426 | } 427 | 428 | static void *stinger_create(obs_data_t *settings, obs_source_t *source) 429 | { 430 | struct stinger_info *stinger; 431 | char *file = obs_module_file("stinger_transition.effect"); 432 | gs_effect_t *effect; 433 | 434 | obs_enter_graphics(); 435 | effect = gs_effect_create_from_file(file, NULL); 436 | obs_leave_graphics(); 437 | 438 | bfree(file); 439 | 440 | if (!effect) { 441 | blog(LOG_ERROR, "Could not find stinger_transition.effect"); 442 | return NULL; 443 | } 444 | 445 | stinger = bzalloc(sizeof(struct stinger_info)); 446 | 447 | stinger->effect = effect; 448 | stinger->ep_a_tex = gs_effect_get_param_by_name(effect, "a_tex"); 449 | stinger->ep_b_tex = gs_effect_get_param_by_name(effect, "b_tex"); 450 | 451 | stinger->source = source; 452 | 453 | stinger_update(stinger, settings); 454 | 455 | return stinger; 456 | } 457 | 458 | static void stinger_destroy(void *data) 459 | { 460 | struct stinger_info *stinger = data; 461 | 462 | if (stinger->demuxer) 463 | ff_demuxer_free(stinger->demuxer); 464 | 465 | if (stinger->sws_ctx != NULL) 466 | sws_freeContext(stinger->sws_ctx); 467 | bfree(stinger->sws_data); 468 | 469 | bfree(stinger->audio_data); 470 | 471 | obs_enter_graphics(); 472 | if (!stinger->validInput) 473 | { 474 | gs_image_file_free(&stinger->stinger_error_image); 475 | stinger->stinger_texture = NULL; 476 | } 477 | if (stinger->stinger_texture != NULL){ 478 | gs_texture_destroy(stinger->stinger_texture); 479 | stinger->stinger_texture = NULL; 480 | } 481 | obs_leave_graphics(); 482 | 483 | bfree(stinger); 484 | } 485 | 486 | static void stinger_callback(void *data, gs_texture_t *a, gs_texture_t *b, 487 | float t, uint32_t cx, uint32_t cy) 488 | { 489 | struct stinger_info *stinger = data; 490 | 491 | if (stinger->validInput && t - stinger->lastTime < 0.0f) //new scene change 492 | { 493 | //clear last frame 494 | obs_enter_graphics(); 495 | gs_texture_destroy(stinger->stinger_texture); 496 | stinger->stinger_texture = NULL; 497 | obs_leave_graphics(); 498 | 499 | stinger->curFrame = 0; 500 | 501 | if (stinger->demuxer != NULL) { 502 | ff_demuxer_free(stinger->demuxer); 503 | stinger->demuxer = NULL; 504 | } 505 | ffmpeg_source_start(stinger); 506 | } 507 | 508 | if (stinger->validInput && stinger->curFrame < stinger->cutFrame) 509 | gs_effect_set_texture(stinger->ep_a_tex, a); 510 | else 511 | gs_effect_set_texture(stinger->ep_a_tex, b); 512 | 513 | gs_effect_set_texture(stinger->ep_b_tex, stinger->stinger_texture); 514 | 515 | 516 | while (gs_effect_loop(stinger->effect, "Stinger")) 517 | gs_draw_sprite(NULL, 0, cx, cy); 518 | 519 | stinger->lastTime = t; 520 | } 521 | 522 | static void stinger_video_render(void *data, gs_effect_t *effect) 523 | { 524 | struct stinger_info *stinger = data; 525 | obs_transition_video_render(stinger->source, stinger_callback); 526 | UNUSED_PARAMETER(effect); 527 | } 528 | 529 | static float mix_a(void *data, float t) 530 | { 531 | UNUSED_PARAMETER(data); 532 | return 1.0f - t; 533 | } 534 | 535 | static float mix_b(void *data, float t) 536 | { 537 | UNUSED_PARAMETER(data); 538 | return t; 539 | } 540 | 541 | bool stinger_audio(obs_source_t *transition, 542 | uint64_t *ts_out, struct obs_source_audio_mix *audio, 543 | uint32_t mixers, size_t channels, size_t sample_rate, 544 | obs_transition_audio_mix_callback_t mix_a, 545 | obs_transition_audio_mix_callback_t mix_b) 546 | { 547 | //transition->source not initialized? 548 | 549 | return false; 550 | } 551 | 552 | static bool stinger_audio_render(void *data, uint64_t *ts_out, 553 | struct obs_source_audio_mix *audio, uint32_t mixers, 554 | size_t channels, size_t sample_rate) 555 | { 556 | struct stinger_info *s = data; 557 | 558 | return stinger_audio(s->source, ts_out, 559 | audio, mixers, channels, sample_rate, mix_a, mix_b); 560 | } 561 | 562 | 563 | static int checkInputFile(const char* file) 564 | { 565 | int numberOfFrames = 0; 566 | 567 | if (!file) 568 | return 0; 569 | 570 | AVFormatContext *pFormatCtx = NULL; 571 | 572 | if (avformat_open_input(&pFormatCtx, file, NULL, NULL) != 0) 573 | { 574 | blog(LOG_WARNING, "Couldn't open stinger video file"); 575 | return -1; 576 | } 577 | 578 | if (avformat_find_stream_info(pFormatCtx, NULL)<0) 579 | { 580 | blog(LOG_WARNING, "Couldn't find stinger video stream information"); 581 | return -1; 582 | } 583 | 584 | AVCodecContext *pCodecCtxOrig = NULL; 585 | AVCodecContext *pCodecCtx = NULL; 586 | AVCodec *pCodec = NULL; 587 | 588 | int videoStream = av_find_best_stream(pFormatCtx, AVMEDIA_TYPE_VIDEO, -1, -1, &pCodec, 0); 589 | 590 | pCodecCtxOrig = pFormatCtx->streams[videoStream]->codec; 591 | 592 | pCodec = avcodec_find_decoder(pCodecCtxOrig->codec_id); 593 | if (pCodec == NULL) { 594 | blog(LOG_WARNING, "Unsupported codec of stinger video"); 595 | return -1; 596 | } 597 | 598 | pCodecCtx = avcodec_alloc_context3(pCodec); 599 | 600 | if (avcodec_copy_context(pCodecCtx, pCodecCtxOrig) != 0) 601 | { 602 | blog(LOG_ERROR, "Couldn't copy codec context of stinger video"); 603 | return -1; 604 | } 605 | 606 | if (avcodec_open2(pCodecCtx, pCodec, NULL) < 0){ 607 | blog(LOG_ERROR, "Couldn't open codec of stinger video"); 608 | return -1; 609 | } 610 | 611 | AVFrame *pFrame = NULL; 612 | pFrame = av_frame_alloc(); 613 | 614 | int frameFinished; 615 | AVPacket packet; 616 | 617 | while (av_read_frame(pFormatCtx, &packet) >= 0) { 618 | if (packet.stream_index == videoStream) { 619 | avcodec_decode_video2(pCodecCtx, pFrame, &frameFinished, &packet); 620 | if (frameFinished) { 621 | numberOfFrames++; 622 | } 623 | } 624 | av_free_packet(&packet); 625 | } 626 | av_free(pFrame); 627 | 628 | avcodec_close(pCodecCtx); 629 | avcodec_close(pCodecCtxOrig); 630 | 631 | avformat_close_input(&pFormatCtx); 632 | 633 | return numberOfFrames; 634 | 635 | } 636 | 637 | 638 | static bool stingerPathModified(obs_properties_t *props, obs_property_t *property, obs_data_t *settings) 639 | { 640 | const char* prevPath = obs_data_get_string(settings, "prevPath"); 641 | const char* file = obs_data_get_string(settings, "stingerPath"); 642 | int numberOfFrames = 0; 643 | 644 | obs_property_t *slider = obs_properties_get(props, "cutFrame"); 645 | if (!slider) 646 | slider = obs_properties_add_int_slider(props, "cutFrame", "Transition at frame", 1, 1, 1); 647 | 648 | if (strcmp(file, prevPath) == 0) 649 | { 650 | numberOfFrames = obs_data_get_int(settings, "numberOfFrames"); 651 | obs_property_int_set_limits(slider, 1, numberOfFrames, 1); 652 | return true; 653 | } 654 | 655 | struct dstr path = { 0 }; 656 | dstr_copy(&path, file); 657 | 658 | numberOfFrames = checkInputFile(path.array); 659 | 660 | if (numberOfFrames > 1){ 661 | obs_property_int_set_limits(slider, 1, numberOfFrames, 1); 662 | //set slider in the middle 663 | obs_data_set_int(settings, "cutFrame", numberOfFrames / 2); 664 | obs_data_set_int(settings, "numberOfFrames", numberOfFrames); 665 | } 666 | else{ 667 | obs_property_int_set_limits(slider, 1, 1, 1); 668 | obs_data_set_int(settings, "numberOfFrames", 1); 669 | } 670 | 671 | obs_data_set_string(settings, "prevPath", path.array); 672 | 673 | dstr_free(&path); 674 | 675 | UNUSED_PARAMETER(property); 676 | return true; 677 | } 678 | 679 | 680 | static obs_properties_t *stinger_properties(void *data) 681 | { 682 | struct stinger_info *stinger = data; 683 | 684 | obs_properties_t *ppts = obs_properties_create(); 685 | 686 | obs_properties_set_flags(ppts, OBS_PROPERTIES_DEFER_UPDATE); 687 | 688 | obs_property_t *pathProp = obs_properties_add_path(ppts, "stingerPath", 689 | "Path to stinger video", OBS_PATH_FILE, "", ""); 690 | obs_property_set_modified_callback(pathProp, stingerPathModified); 691 | obs_properties_add_bool(ppts, "hw_decode", 692 | obs_module_text("HardwareDecode")); 693 | obs_properties_add_int_slider(ppts, "cutFrame", 694 | "Transition at frame", 1, 1, 1); 695 | 696 | return ppts; 697 | } 698 | 699 | static void stinger_defaults(obs_data_t *settings) 700 | { 701 | obs_data_set_default_int(settings, "cutFrame", 1); 702 | obs_data_set_default_int(settings, "numberOfFrames", 1); 703 | obs_data_set_default_string(settings, "stingerPath", ""); 704 | #if defined(_WIN32) 705 | obs_data_set_default_bool(settings, "hw_decode", true); 706 | #endif 707 | } 708 | 709 | static void stinger_activate(void *data) 710 | { 711 | struct stinger_info *s = data; 712 | 713 | if (!s->validInput) 714 | { 715 | load_error_texture(s); 716 | } 717 | } 718 | 719 | static void stinger_deactivate(void *data) 720 | { 721 | struct stinger_info *s = data; 722 | 723 | if (s->demuxer != NULL) { 724 | ff_demuxer_free(s->demuxer); 725 | s->demuxer = NULL; 726 | } 727 | 728 | if (s->sws_ctx != NULL){ 729 | sws_freeContext(s->sws_ctx); 730 | s->sws_ctx = NULL; 731 | } 732 | bfree(s->sws_data); 733 | s->sws_data = NULL; 734 | s->sws_format = 0; 735 | s->sws_height = 0; 736 | s->sws_width = 0; 737 | 738 | bfree(s->audio_data); 739 | 740 | obs_enter_graphics(); 741 | if (!s->validInput) 742 | { 743 | gs_image_file_free(&s->stinger_error_image); 744 | s->stinger_texture = NULL; 745 | } 746 | if (s->stinger_texture != NULL){ 747 | gs_texture_destroy(s->stinger_texture); 748 | s->stinger_texture = NULL; 749 | } 750 | obs_leave_graphics(); 751 | } 752 | 753 | struct obs_source_info stinger_transition = { 754 | .id = "stinger_transition", 755 | .type = OBS_SOURCE_TYPE_TRANSITION, 756 | .get_name = stinger_get_name, 757 | .create = stinger_create, 758 | .destroy = stinger_destroy, 759 | .update = stinger_update, 760 | .video_render = stinger_video_render, 761 | .audio_render = stinger_audio_render, 762 | .get_properties = stinger_properties, 763 | .get_defaults = stinger_defaults, 764 | .deactivate = stinger_deactivate, 765 | .activate = stinger_activate 766 | }; 767 | --------------------------------------------------------------------------------