def update_crop(self): """ Create 2 display captures. Create crop filter with this name: cropXY. Check relative. Set Width and Height to relatively small numbers e.g : 64x64 . Image mask blend + color correction might be an option too. Run script,select this source as cursor source , check Update crop, click start. """ source = obs.obs_get_source_by_name(self.source_name) crop = obs.obs_source_get_filter_by_name(source, "cropXY") filter_settings = obs.obs_source_get_settings(crop) _x, _y = get_position() # https://github.com/obsproject/obs-studio/blob/79981889c6d87d6e371e9dc8fcaad36f06eb9c9e/plugins/obs-filters/crop-filter.c#L87-L93 w = obs.obs_data_get_int(filter_settings, "cx") h = obs.obs_data_get_int(filter_settings, "cy") h, w = int(h / 2), int(w / 2) obs.obs_data_set_int(filter_settings, "left", _x - h) obs.obs_data_set_int(filter_settings, "top", _y - w) obs.obs_source_update(crop, filter_settings) obs.obs_data_release(filter_settings) obs.obs_source_release(source) obs.obs_source_release(crop)
def _obs_filter_get_property_values(self, filter_name, owner_name): with self._filter_by_name(owner_name, filter_name) as s: d = _obs.obs_source_get_settings(s) try: return _data.get_values(d) finally: _obs.obs_data_release(d)
def playsound(filename, volume, speed): obs.script_log(obs.LOG_DEBUG, "Trying to play " + filename + " to source " + sourcename) scenesource = obs.obs_frontend_get_current_scene() scene = obs.obs_scene_from_source(scenesource) #obs.script_log(obs.LOG_DEBUG,"Scene "+str(scene)) sceneitem = obs.obs_scene_find_source(scene, sourcename) #obs.script_log(obs.LOG_DEBUG,"Scene item "+str(sceneitem)) source = obs.obs_sceneitem_get_source(sceneitem) obs.obs_source_set_volume(source, volume) set_source_speed(source, speed) obs.obs_sceneitem_set_visible(sceneitem, False) settings = obs.obs_source_get_settings(source) #obs.script_log(obs.LOG_DEBUG,str(obs.obs_data_get_json(settings))) obs.obs_data_set_string(settings, "local_file", audiofolder + filename) #obs.script_log(obs.LOG_DEBUG,str(obs.obs_data_get_json(settings))) obs.obs_source_update(source, settings) obs.obs_sceneitem_set_visible(sceneitem, True) obs.obs_data_release(settings) obs.obs_source_release(scenesource)
def is_ql_source(self): source = obs.obs_get_source_by_name(self.source_name) setting = obs.obs_source_get_settings(source) name = obs.obs_data_get_string(setting, "window") if QUAKELIVE_PROCESS in name and (not self.onlyruninql or self.is_ql_running()): return True else: return False
def getSourceSettings(source): """ Context manager to get source settings and release them when done. """ settings = obs.obs_source_get_settings(source) yield settings if settings is not None: obs.obs_data_release(settings)
def tulosta(props, p): global settings nimi = obs.obs_data_get_string(settings, "valinta") source = obs.obs_get_source_by_name(nimi) data = obs.obs_source_get_settings(source) color = obs.obs_data_get_int(data, "color") print(color)
def data_ar(source_settings=None): if not source_settings: settings = obs.obs_data_create() if source_settings: settings = obs.obs_source_get_settings(source_settings) try: yield settings finally: obs.obs_data_release(settings)
def unsetfilename(): source = obs.obs_get_source_by_name(sourcename) #obs.script_log(obs.LOG_DEBUG,"Source "+str(source)) settings = obs.obs_source_get_settings(source) #obs.script_log(obs.LOG_DEBUG,str(obs.obs_data_get_json(settings))) obs.obs_data_set_string(settings, "local_file", "") #obs.script_log(obs.LOG_DEBUG,str(obs.obs_data_get_json(settings))) obs.obs_source_update(source, settings) obs.obs_data_release(settings) obs.obs_source_release(source)
def set_filter_value(source_name, filter_name, filter_field_name, value): source = obs.obs_get_source_by_name(source_name) if source is not None: filter = obs.obs_source_get_filter_by_name(source, filter_name) if filter is not None: # Get the settings data object for the filter filter_settings = obs.obs_source_get_settings(filter) # Update the hue_shift property and update the filter with the new settings obs.obs_data_set_int(filter_settings, filter_field_name, value) obs.obs_source_update(filter, filter_settings) # Release the resources obs.obs_data_release(filter_settings) obs.obs_source_release(filter) obs.obs_source_release(source)
def update_color(self): source = obs.obs_get_source_by_name(self.source_name) scroll = obs.obs_source_get_filter_by_name(source, "py_color") filter_settings = obs.obs_source_get_settings(scroll) value = self.value if value: self.last_value = value if value == 0: value = self.last_value value = 50 - value obs.obs_data_set_int(filter_settings, "opacity", value) obs.obs_source_update(scroll, filter_settings) obs.obs_data_release(filter_settings) obs.obs_source_release(source) obs.obs_source_release(scroll)
def set_crop(self, inOut): # Set crop filter dimensions totalFrames = int(self.zoom_d / self.refresh_rate) source = obs.obs_get_source_by_name(self.source_name) crop = obs.obs_source_get_filter_by_name(source, "ZoomCrop") if crop is None: # create filter _s = obs.obs_data_create() obs.obs_data_set_bool(_s, "relative", False) f = obs.obs_source_create_private("crop_filter", "ZoomCrop", _s) obs.obs_source_filter_add(source, f) obs.obs_source_release(f) obs.obs_data_release(_s) s = obs.obs_source_get_settings(crop) i = obs.obs_data_set_int if inOut == 0: self.zi_timer = 0 if self.zo_timer < totalFrames: self.zo_timer += 1 time = self.cubic_in_out(self.zo_timer / totalFrames) i(s, "left", int(((1 - time) * self.z_x))) i(s, "top", int(((1 - time) * self.z_y))) i( s, "cx", self.zoom_w + int(time * (self.d_w - self.zoom_w)), ) i( s, "cy", self.zoom_h + int(time * (self.d_h - self.zoom_h)), ) else: i(s, "left", 0) i(s, "top", 0) i(s, "cx", self.d_w) i(s, "cy", self.d_h) else: self.zo_timer = 0 if self.zi_timer < totalFrames: self.zi_timer += 1 time = self.cubic_in_out(self.zi_timer / totalFrames) i(s, "left", int(time * self.z_x)) i(s, "top", int(time * self.z_y)) i( s, "cx", self.d_w - int(time * (self.d_w - self.zoom_w)), ) i( s, "cy", self.d_h - int(time * (self.d_h - self.zoom_h)), ) else: i(s, "left", self.z_x) i(s, "top", self.z_y) i(s, "cx", self.zoom_w) i(s, "cy", self.zoom_h) obs.obs_source_update(crop, s) obs.obs_data_release(s) obs.obs_source_release(source) obs.obs_source_release(crop) if (inOut == 0) and (self.zo_timer >= totalFrames): obs.remove_current_callback()
def obs_source_print_json(source): settings = obs.obs_source_get_settings(source) json = obs.obs_data_get_json(settings) print(json)
def cache_scenes(): global scene_win_map global cached_items global tagRegex global dimensions clear_cache() cached_num = 0 currentScene = obs.obs_frontend_get_current_scene() sceneName = obs.obs_source_get_name(currentScene) sceneObject = obs.obs_scene_from_source(currentScene) items = obs.obs_scene_enum_items(sceneObject) if items is not None: for item in items: source = obs.obs_sceneitem_get_source(item) source_id = obs.obs_source_get_id(source) source_name = obs.obs_source_get_name(source) #find = re.match(tagRegex, source_name) #print(tagRegex, source_name) if (re.match(tagRegex, source_name) and source_id == "window_capture"): modifiers = {} flagsSearch = re.findall(tagRegex, source_name) flags = flagsSearch[0].split(",") for flag in flags: modifiers[flag.lower()] = True data = obs.obs_source_get_settings(source) windowData = obs.obs_data_get_string(data, "window") windowSplit = windowData.split(":") windowTitle = windowSplit[0].replace("#3A", ":") #print("Window Title: " + windowData[0]) #print("Window EXE: " + windowData[1]) obs.obs_data_release(data) try: if (windowData in scene_win_map): myWin = scene_win_map[windowData] else: myWin = win.FindWindow(None, windowTitle) scene_win_map[windowData] = myWin except: pass cached_items[cached_num] = { "item": item, "source": source, "modifiers": modifiers, "win32gui": myWin } cached_num += 1 else: #obs.obs_source_release(source) obs.obs_sceneitem_release(item) pass #obs.obs_source_release(source) #obs.obs_sceneitem_release(item) obs.obs_scene_release(sceneObject) #obs.obs_source_release(currentScene) #print("Cached %d items." % (cached_num)) dimensions = obs.obs_video_info() obs.obs_get_video_info(dimensions)
def set_source_speed(source, speed): settings = obs.obs_source_get_settings(source) speedpct = int(speed * 100) obs.obs_data_set_int(settings, "speed_percent", speedpct) obs.obs_source_update(source, settings) obs.obs_data_release(settings)