def update_match_video(): global last_video_path print('update_match_video') # TODO: actually set the video starting at the start of the game, rather # than the slot. Also involves ensuring that our timings are in step with # the compbox. path = video_path.get() if last_video_path == path: print(f"{path!r} has already played") return # TODO: can we pull the current video from the source? I tried this but # couldn't work out how. last_video_path = path print(f"Updating to {path!r}") source = obs.obs_get_source_by_name(source_name) if source != None: print('got source') settings = obs.obs_data_create() source_id = obs.obs_source_get_id(source) if source_id == "ffmpeg_source": obs.obs_data_set_string(settings, "local_file", path) obs.obs_data_set_bool(settings, "is_local_file", True) # updating will automatically cause the source to # refresh if the source is currently active obs.obs_source_update(source, settings) # TODO: this ends up resetting the size of the video within OBS. Can # we inspect the source beforehand and preserve the apparent size? # Might be moot if all our videos are the same size and we're # showing them at 100% scale, but would be good to sort properly. elif source_id == "vlc_source": # "playlist" array = obs.obs_data_array_create() item = obs.obs_data_create() obs.obs_data_set_string(item, "value", path) obs.obs_data_array_push_back(array, item) obs.obs_data_set_array(settings, "playlist", array) # updating will automatically cause the source to # refresh if the source is currently active obs.obs_source_update(source, settings) obs.obs_data_release(item) obs.obs_data_array_release(array) obs.obs_data_release(settings) obs.obs_source_release(source) print('update_match_video done')
def script_load(settings): obs.obs_frontend_add_event_callback(on_event) Data._format_ = obs.obs_data_get_string(settings, 'format') Data._autoStart_ = obs.obs_data_get_bool(settings, 'auto_start') if not Data._format_: Data._format_ = Data._defaultFormat_ obs.obs_data_set_string(settings, 'format', Data._format_) obs.obs_data_set_bool(settings, 'auto_start', Data._autoStart_)
def change_input(): global globSettings url = obs.obs_data_get_string(globSettings, "url") source = obs.obs_data_get_string(globSettings, "source") if url != None and source != None: sourceObj = obs.obs_get_source_by_name(source) try: streamUrl = streamlink.streams(url)["best"].url if sourceObj != None: settings = obs.obs_data_create() obs.obs_data_set_string(settings, "input", streamUrl) obs.obs_data_set_bool(settings, "is_local_file", False) obs.obs_source_update(sourceObj, settings) obs.obs_data_release(settings) except streamlink.StreamlinkError: pass obs.obs_source_release(sourceObj)
def change_input(): global globSettings url = obs.obs_data_get_string(globSettings, "url") source = obs.obs_data_get_string(globSettings, "source") qual = obs.obs_data_get_string(globSettings, "res") if url != None and source != None: sourceObj = obs.obs_get_source_by_name(source) try: streamUrl = "" stream = streamlink.streams(url) if qual in stream: streamUrl = stream[qual].url elif qual + "60" in stream: streamUrl = stream[qual + "60"].url elif qual + "_alt" in stream: streamUrl = stream[qual + "_alt"].url elif qual + "60_alt" in stream: streamUrl = stream[qual + "60_alt"].url elif "best" in stream: streamUrl = stream["best"].url if streamUrl != "" and sourceObj != None: source_id = obs.obs_source_get_id(sourceObj) settings = obs.obs_data_create() if source_id == "ffmpeg_source": obs.obs_data_set_string(settings, "input", streamUrl) obs.obs_data_set_bool(settings, "is_local_file", False) obs.obs_source_update(sourceObj, settings) else: array = obs.obs_data_array_create() data = obs.obs_data_create() obs.obs_data_set_string(data, "name", streamUrl) obs.obs_data_set_string(data, "value", streamUrl) obs.obs_data_array_push_back(array, data) obs.obs_data_release(data) obs.obs_data_set_array(settings, "playlist", array) obs.obs_source_update(sourceObj, settings) obs.obs_data_array_release(array) obs.obs_data_release(settings) except streamlink.StreamlinkError: pass obs.obs_source_release(sourceObj)
def script_update(settings): global Debug_Mode if Debug_Mode: print("Calling Update") global Enabled_Recording global Enabled_Streaming global Pause_Time global Recording_Start global Recording_Timer global Recording_End global Time_To_Record global Avoid_These_Days if obs.obs_data_get_bool(settings, "enabled") is not Enabled_Recording: if obs.obs_data_get_bool(settings, "enabled") is True: if Debug_Mode: print("Loading Timer") print("timer_check_recording(): [{}] vs [{}]".format( str(datetime.today().strftime("%a")), Avoid_These_Days)) Enabled_Recording = True obs.timer_add(timer_check_recording, 30000) else: if Debug_Mode: print("Unloading Timer") Enabled_Recording = False obs.timer_remove(timer_check_recording) if obs.obs_data_get_int(settings, "duration") == 0: Recording_Timer = 30 * 60 else: Recording_Timer = obs.obs_data_get_int(settings, "duration") * 60 Time_To_Record = time.time() + Recording_Timer if obs.obs_data_get_string( settings, "start_time") == "" or obs.obs_data_get_string( settings, "start_time") == "None" or obs.obs_data_get_string( settings, "start_time") == obs.obs_data_get_string( settings, "end_time"): Recording_Start = "None" obs.obs_data_set_bool(settings, "enabled_stream", False) Enabled_Streaming = False else: Recording_Start = obs.obs_data_get_string(settings, "start_time") if obs.obs_data_get_string(settings, "end_time") == "": Recording_Start = "None" obs.obs_data_set_bool(settings, "enabled_stream", False) Enabled_Streaming = False else: Recording_End = obs.obs_data_get_string(settings, "end_time") if obs.obs_data_get_string(settings, "avoid_days") == "": Avoid_These_Days = "Sat Sun" obs.obs_data_set_bool(settings, "enabled_stream", False) Enabled_Streaming = False else: Avoid_These_Days = obs.obs_data_get_string(settings, "avoid_days") Debug_Mode = obs.obs_data_get_bool(settings, "debug_mode") Enabled_Streaming = obs.obs_data_get_bool(settings, "enabled_stream")
def script_load(settings): obs.obs_frontend_add_event_callback(on_event) Data._format_ = obs.obs_data_get_string(settings, "format") Data._autoStart_ = obs.obs_data_get_bool(settings, "auto_start") Data._autoStop_ = obs.obs_data_get_bool(settings, "auto_stop") Data._recording_ = obs.obs_data_get_bool(settings, "recording") Data._visible_ = obs.obs_data_get_bool(settings, "visible") if not Data._format_: Data._format_ = Data._defaultFormat_ obs.obs_data_set_string(settings, "format", Data._format_) obs.obs_data_set_bool(settings, "auto_start", Data._autoStart_) obs.obs_data_set_bool(settings, "auto_stop", Data._autoStop_) obs.obs_data_set_bool(settings, "recording", Data._recording_) obs.obs_data_set_bool(settings, "visible", Data._visible_)
def setSourceTextColorByName(self, sourceName, color, outline=None): """ Sets the color of the given text source by name. The color should be an int, in OBS color format. The outline color can either be None (meaning no outline) or an int in OBS color format. """ with getSourceByName(sourceName) as source: if source is None: return with createObsData() as settings: if obs.obs_source_get_id(source) == 'text_ft2_source': obs.obs_data_set_int(settings, 'color1', color) obs.obs_data_set_int(settings, 'color2', color) # FreeType2 currently doesn't support setting # outline colors. We *could* turn the outline on, # but that's probably not what whoever specified an # outline wanted. So we just won't. elif obs.obs_source_get_id(source) == 'text_gdiplus': colorRGB = rgbaToColor(*colorToRgba(color)[:3]) colorA = int(colorToRgba(color)[3] * 100 / 255) obs.obs_data_set_int(settings, 'color', colorRGB) obs.obs_data_set_int(settings, 'opacity', colorA) obs.obs_data_set_bool(settings, 'outline', outline is not None) if outline is not None: outlineRGB = rgbaToColor(*colorToRgba(outline)[:3]) outlineA = int(colorToRgba(outline)[3] * 100 / 255) obs.obs_data_set_int(settings, 'outline_color', outlineRGB) obs.obs_data_set_int(settings, 'outline_opacity', outlineA) obs.obs_source_update(source, settings)
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 script_save(settings): obs.obs_data_set_bool(settings, "use_podium", rtgg_obs.timer.use_podium_colors) obs.obs_data_set_string(settings, "last_session_race", rtgg_obs.selected_race)
def script_load(settings): global Debug_Mode if Debug_Mode: print("Calling Load") obs.obs_data_set_bool(settings, "enabled", False)
def script_defaults(settings): obs.obs_data_set_bool(settings, "reset_time", True) obs.obs_data_set_bool(settings, "stop_stream", False)
def do_stuff(props, prop): obs.obs_frontend_recording_start() obs.obs_frontend_recording_stop() time.sleep(0.35) # 1. Get Freeze Frame, Save it to disk somewhere latest_frame = helpers.get_latest_frame() sepia_frame = helpers.sepia_filter(latest_frame) mixed_frame = cv2.addWeighted(latest_frame, 0.4, sepia_frame, 0.6, 0) blurred_frame = helpers.blur(mixed_frame, kernel_size=21) # Dunno why default folder isn"t loading ? img_path = os.path.join("C:\\Users\\avikn\\Videos\\", "blurred.png") cv2.imwrite(img_path, blurred_frame) # 2. Add the freeze frame as a new full sized source current_scene_source = obs.obs_frontend_get_current_scene() obs.obs_frontend_set_current_preview_scene(current_scene_source) current_scene = obs.obs_scene_from_source(current_scene_source) freeze_frame = obs.obs_source_create("image_source", "FreezeFrame", None, None) image_settings = obs.obs_data_create() obs.obs_data_set_string(image_settings, "file", img_path) obs.obs_source_update(freeze_frame, image_settings) obs.obs_data_release(image_settings) freeze_item = obs.obs_scene_add(current_scene, freeze_frame) obs.obs_frontend_preview_program_trigger_transition() #3. Add A text source for the We'll be right back text = obs.obs_source_create("text_gdiplus", "BeRightBack", None, None) text_settings = obs.obs_data_create() font_settings = obs.obs_data_create() obs.obs_data_set_string(font_settings, "face", "Helvetica") obs.obs_data_set_int(font_settings, "size", 128) obs.obs_data_set_obj(text_settings, "font", font_settings) obs.obs_data_set_bool(text_settings, "outline", True) obs.obs_data_set_double(text_settings, "outline_size", 10) obs.obs_data_set_double(text_settings, "outline_color", 0) obs.obs_data_set_bool(text_settings, "extents", True) obs.obs_data_set_bool(text_settings, "extents_wrap", True) obs.obs_data_set_int(text_settings, "extents_cx", 300) obs.obs_data_set_int(text_settings, "extents_cy", 600) obs.obs_data_set_string(text_settings, "text", "We'll Be Right Back") obs.obs_source_update(text, text_settings) obs.obs_data_release(text_settings) text_item = obs.obs_scene_add(current_scene, text) #4. Add a media source for the sound byte song = obs.obs_source_create("ffmpeg_source", "Jingle", None, None) song_settings = obs.obs_data_create() obs.obs_data_set_string(song_settings, "local_file", "C:\\Users\\avikn\\Downloads\\brb_jingle.mp3") obs.obs_source_update(song, song_settings) obs.obs_data_release(song_settings) song_item = obs.obs_scene_add(current_scene, song) #5. Trigger the transition so that it updates, mute other audio sources. obs.obs_frontend_preview_program_trigger_transition() desktop_audio = obs.obs_get_output_source(1) obs.obs_source_set_muted(desktop_audio, True) mic_audio = obs.obs_get_output_source(4) obs.obs_source_set_muted(mic_audio, True) #6. Artificial delay, then cleanup. time.sleep(4) obs.obs_sceneitem_remove(freeze_item) obs.obs_source_release(freeze_frame) obs.obs_sceneitem_remove(text_item) obs.obs_source_release(text) obs.obs_sceneitem_remove(song_item) obs.obs_source_release(song) obs.obs_source_set_muted(desktop_audio, False) obs.obs_source_set_muted(mic_audio, False) obs.obs_frontend_preview_program_trigger_transition()
def script_load(settings): print("Calling Load") obs.obs_data_set_bool(settings, "enabled", False)
def create_match_video_output(): global output, output_video_encoder, output_audio_encoder print(f'Creating match video OBS output') if output: print(f'WARNING: Match video OBS output already exists') print() return # create output for match video files output_settings = obs.obs_data_create() obs.obs_data_set_bool(output_settings, 'allow_overwrite', True) output = obs.obs_output_create('ffmpeg_muxer', 'match_file_output', output_settings, None) obs.obs_data_release(output_settings) if not output: print(f'ERROR: Could not create match video output') print() return # create output video encoder for match video files output_video_settings = obs.obs_data_create() obs.obs_data_set_string(output_video_settings, 'rate_control', 'CBR') obs.obs_data_set_int(output_video_settings, 'bitrate', obs.obs_data_get_int(settings, 'video_bitrate')) output_video_encoder = obs.obs_video_encoder_create( obs.obs_data_get_string(settings, 'video_encoder'), 'match_video_encoder', output_video_settings, None) obs.obs_data_release(output_video_settings) if not output_video_encoder: print(f'ERROR: Could not create match video encoder') destroy_match_video_output() return if not obs.obs_encoder_get_codec(output_video_encoder): print(f'ERROR: Invalid codec for match video encoder') destroy_match_video_output() return obs.obs_encoder_set_video(output_video_encoder, obs.obs_get_video()) if not obs.obs_encoder_video(output_video_encoder): print(f'ERROR: Could not set video handler') destroy_match_video_output() return obs.obs_output_set_video_encoder(output, output_video_encoder) if not obs.obs_output_get_video_encoder(output): print(f'ERROR: Could not set video encoder to output') destroy_match_video_output() return # create output audio encoder for match video files output_audio_settings = obs.obs_data_create() obs.obs_data_set_string(output_audio_settings, 'rate_control', 'CBR') obs.obs_data_set_int(output_audio_settings, 'bitrate', obs.obs_data_get_int(settings, 'audio_bitrate')) output_audio_encoder = obs.obs_audio_encoder_create( obs.obs_data_get_string(settings, 'audio_encoder'), 'match_audio_encoder', output_audio_settings, 0, None) obs.obs_data_release(output_audio_settings) if not output_audio_encoder: print(f'ERROR: Could not create match audio encoder') destroy_match_video_output() return if not obs.obs_encoder_get_codec(output_audio_encoder): print(f'ERROR: Invalid codec for match audio encoder') destroy_match_video_output() return obs.obs_encoder_set_audio(output_audio_encoder, obs.obs_get_audio()) if not obs.obs_encoder_audio(output_audio_encoder): print(f'ERROR: Could not set audio handler') destroy_match_video_output() return obs.obs_output_set_audio_encoder(output, output_audio_encoder, 0) if not obs.obs_output_get_audio_encoder(output, 0): print(f'ERROR: Could not set audio encoder to output') destroy_match_video_output() return # set handler for output signals handler = obs.obs_output_get_signal_handler(output) obs.signal_handler_connect(handler, 'stop', stop_recording_action) print()