OBS VLC (or any Item) in the Same Scene Fade in Fade Out Script

Thayonn

New Member
Just been working on some scripting and decided to post this snippet.
I wanted a fade object, could not find one, so I decided to mess with the Opacity on the filters and emulate a fade in/out
I am using this on 4 objects in the same scene, this code snippet is just for 1 VLC Control

Setup:
You must have a VLC object in the scene and the Following Filter Setup
Filter Setup:
Capture.JPG

You can copy the filters, makes life easier to add more items

This is a Python script, you can use the same method in LUA i suppose.

Code:
import obspython as obs
import time

sourcev1 = ""
fadeinterval = 0.05
fadetrans = False

def script_update(settings):
    sourcev1 = obs.obs_data_get_string(settings, "sourcev1")
    fadetrans = obs.obs_data_get_bool(settings,"fadetrans")
    fadeinterval = (obs.obs_data_get_int(settings, "fadeinterval")*0.01)


def script_properties():
    props = obs.obs_properties_create()
    obs.obs_properties_add_int(props, "fadeinterval", "Fade Interval (Frames ms 0.0x)", 5, 100, 1)
    obs.obs_properties_add_bool(props, "fadetrans", "Enable Fade")
    p = obs.obs_properties_add_list(props, "sourcev1", "Video Source 1", obs.OBS_COMBO_TYPE_EDITABLE, obs.OBS_COMBO_FORMAT_STRING)
    sources = obs.obs_enum_sources()
    if sources is not None:
        for source in sources:
            source_id = obs.obs_source_get_id(source)
            if source_id == "ffmpeg_source" or source_id == "vlc_source":
                name = obs.obs_source_get_name(source)
                obs.obs_property_list_add_string(p, name, name)
               
def dofadeOut()              
    source = obs.obs_get_source_by_name(sourcev1)
    if fadetrans == True:
        for x in range(10):
            obs.obs_source_set_enabled(obs.obs_source_get_filter_by_name(source,str(x*10)),True)
            obs.obs_source_set_enabled(obs.obs_source_get_filter_by_name(source,str((x-1)*10)),False)
            time.sleep(fadeinterval*10)
   
    else:
        obs.obs_source_set_enabled(obs.obs_source_get_filter_by_name(source,'100'),False)
        obs.obs_source_set_enabled(obs.obs_source_get_filter_by_name(source,'0'),True)
   
def dofadeIn()              
    source = obs.obs_get_source_by_name(sourcev1)
    if fadetrans == True:
        for x in range(10):
            obs.obs_source_set_enabled(obs.obs_source_get_filter_by_name(source,str((100-(x*10))),True)
            obs.obs_source_set_enabled(obs.obs_source_get_filter_by_name(source,str((100-(x-1)*10))),False)
            time.sleep(fadeinterval*10)
   
    else:
        obs.obs_source_set_enabled(obs.obs_source_get_filter_by_name(source,'100'),True)
        obs.obs_source_set_enabled(obs.obs_source_get_filter_by_name(source,'0'),False)

dofadeIn()
time.sleep(2)
dofadeOut()

My code is not perfect as it is a rush job.
But let me know if you find it useful.
 
Top