def run_import(props, prop): global template_scene_name global image_directory template_source = obs.obs_get_source_by_name(template_scene_name) template_scene = obs.obs_scene_from_source(template_source) # expecting filenames like '01 - test.jpg' files = glob.glob(image_directory + "/*") files.sort() for filename in files: # try to remove the initial ordinal, but don't error if it isn't present. # '01 - test.jpg' -> 'test' # 'test.jpg' -> 'test' parts = Path(filename).stem.split('-') bare_name = parts[len(parts) - 1].strip() new_scene = obs.obs_scene_duplicate(template_scene, bare_name, obs.OBS_SCENE_DUP_REFS) source_data = obs.obs_data_create() obs.obs_data_set_string(source_data, 'file', filename) source = obs.obs_source_create('image_source', 'Image - ' + bare_name, source_data, None) scene_item = obs.obs_scene_add(new_scene, source) obs.obs_sceneitem_set_order(scene_item, obs.OBS_ORDER_MOVE_BOTTOM) import_utils.fit_to_screen(scene_item) obs.obs_source_release(source) obs.obs_scene_release(new_scene) obs.script_log(obs.LOG_INFO, "created scene '" + bare_name + "' from " + filename) obs.obs_source_release(template_source)
def run_import(props, prop): global template_scene_name global video_directory template_source = obs.obs_get_source_by_name(template_scene_name) template_scene = obs.obs_scene_from_source(template_source) files = glob.glob(video_directory + "/*") files.sort() transition_number = 0 for filename in files: transition_number += 1 bare_name = "Transition " + str(transition_number) new_scene = obs.obs_scene_duplicate(template_scene, bare_name, obs.OBS_SCENE_DUP_REFS) source_data = obs.obs_data_create() obs.obs_data_set_string(source_data, 'local_file', filename) source = obs.obs_source_create('ffmpeg_source', 'Video - ' + bare_name, source_data, None) scene_item = obs.obs_scene_add(new_scene, source) obs.obs_sceneitem_set_order(scene_item, obs.OBS_ORDER_MOVE_BOTTOM) import_utils.fit_to_screen(scene_item) obs.obs_source_release(source) obs.obs_scene_release(new_scene) obs.script_log(obs.LOG_INFO, "created scene '" + bare_name + "' from " + filename) obs.obs_source_release(template_source)
def create_colorcorrection_filter(source_name, filter_name): 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 None: new_filter = obs.obs_source_create("color_filter", filter_name, None, None) obs.obs_source_filter_add(source, new_filter) obs.obs_source_release(new_filter) obs.obs_source_release(filter_) obs.obs_source_release(source)
def update_gst_source(self,source_name, pipeline): source = obs.obs_get_source_by_name(source_name) settings = obs.obs_data_create() obs.obs_data_set_string(settings, "pipeline", pipeline) if source is None: obs.script_log(obs.LOG_INFO,"Creating non-existant GStreamer source: {source_name}".format(source_name=source_name)) source = obs.obs_source_create("gstreamer-source",source_name,None,None) # TODO - this doesn't seem to create sources else: obs.script_log(obs.LOG_INFO,"Updating {source_name} pipeline to: {pipeline}".format(source_name=source_name,pipeline=pipeline)) obs.obs_source_update(source, settings) obs.obs_data_release(settings) obs.obs_source_release(source)
def crete_text_source(self): current_scene = S.obs_frontend_get_current_scene() scene = S.obs_scene_from_source(current_scene) settings = S.obs_data_create() S.obs_data_set_string(settings, "text", "The quick brown fox jumps over the lazy dog") # doesnt work on private sources source = S.obs_source_create("text_gdiplus", "1test_py", settings, None) S.obs_scene_add(scene, source) S.obs_scene_release(scene) S.obs_data_release(settings) S.obs_source_release(source)
def scan_folder(): global target_scene global group_name scene = scene_name_to_scene(target_scene) group = obs.obs_scene_find_source(scene, group_name) if group is not None: obs.obs_sceneitem_remove(group) group = obs.obs_scene_add_group(scene, group_name) for file in os.listdir(song_directories): if file.endswith((".mp3", ".webm", ".m4a", ".ogg")): settings = obs.obs_data_create() obs.obs_data_set_string(settings, "local_file", song_directories + "/" + file) obs.obs_data_set_string(settings, "group", group_name) source = obs.obs_source_create("ffmpeg_source", file, settings, None) scene_item = obs.obs_scene_add(scene, source) group = obs.obs_scene_get_group(scene, group_name) obs.obs_sceneitem_group_add_item(group, scene_item)
def sad_threaded(props, prop): # 1. Make it grayscale cam_source = obs.obs_get_source_by_name("Shitty Webcam") grayscale_filter = obs.obs_source_get_filter_by_name(cam_source, "Gray") data = obs.obs_data_create() obs.obs_data_set_double(data, "clut_amount", 1.0) obs.obs_source_update(grayscale_filter, data) # 2. Save initial props 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) cam_sceneitem = obs.obs_scene_find_source(current_scene, "Shitty Webcam") initial_scale = obs.vec2() obs.obs_sceneitem_get_scale(cam_sceneitem, initial_scale) initial_pos = obs.vec2() obs.obs_sceneitem_get_pos(cam_sceneitem, initial_pos) initial_box_transform = obs.matrix4() obs.obs_sceneitem_get_box_transform(cam_sceneitem, initial_box_transform) initial_crop = obs.obs_sceneitem_crop() obs.obs_sceneitem_get_crop(cam_sceneitem, initial_crop) # matrix4.x.x -> x size # matrix4.y.y -> y size # matrix4.t.x -> x position # matrix4.t.y -> y position # for prop in ["x", "y", "z", "t"]: # print(f"Matrix property {prop}") # vec = getattr(initial_box_transform, prop) # print(dir(vec)) # for vec_prop in ["m", "w", "x", "y", "z"]: # print(f"Vec Property {vec_prop}: {getattr(vec, vec_prop)}") size_x = initial_box_transform.x.x size_y = initial_box_transform.y.y initial_draw_transform = obs.matrix4() obs.obs_sceneitem_get_draw_transform(cam_sceneitem, initial_draw_transform) print(dir(initial_draw_transform)) # 3. Mute desktop audio, play sound of silence desktop_audio = obs.obs_get_output_source(4) obs.obs_source_set_muted(desktop_audio, True) song = obs.obs_source_create("ffmpeg_source", "Sound of Silence", None, None) song_settings = obs.obs_data_create() obs.obs_data_set_string( song_settings, "local_file", "C:\\Users\\avikn\\Downloads\\sound_of_silence.mp3") obs.obs_source_update(song, song_settings) obs.obs_data_release(song_settings) song_item = obs.obs_scene_add(current_scene, song) # 4. Scale up / reposition the camera. # It's gross but it works don't touch it. dynamic_scale = obs.vec2() obs.vec2_copy(dynamic_scale, initial_scale) increment = obs.vec2() increment.x = 0.0015 increment.y = 0.0015 crop = (initial_crop.top, initial_crop.right, initial_crop.bottom, initial_crop.left) size_x, size_y = get_size(cam_sceneitem) dynamic_crop = obs.obs_sceneitem_crop() bounds = obs.vec2() bounds.x = size_x bounds.y = size_y obs.obs_sceneitem_set_bounds(cam_sceneitem, bounds) for _ in range(240): obs.obs_sceneitem_set_bounds_type(cam_sceneitem, 0) obs.vec2_add(dynamic_scale, dynamic_scale, increment) obs.obs_sceneitem_set_scale(cam_sceneitem, dynamic_scale) nsize_x, nsize_y = get_size(cam_sceneitem) x_delta = nsize_x - size_x + (dynamic_crop.right * 2) y_delta = nsize_y - size_y + (dynamic_crop.top * 2) dynamic_crop.top = int(y_delta / 2) dynamic_crop.right = int(x_delta / 2) dynamic_crop.bottom = int(y_delta / 2) dynamic_crop.left = int(x_delta / 2) obs.obs_sceneitem_set_crop(cam_sceneitem, dynamic_crop) obs.obs_sceneitem_set_bounds_type(cam_sceneitem, 1) obs.obs_frontend_preview_program_trigger_transition() time.sleep(0.1) # 5. Cleanup obs.obs_source_set_muted(desktop_audio, False) obs.obs_sceneitem_set_scale(cam_sceneitem, initial_scale) obs.obs_sceneitem_set_crop(cam_sceneitem, initial_crop) obs.obs_data_set_double(data, "clut_amount", 0.0) obs.obs_source_update(grayscale_filter, data) obs.obs_sceneitem_remove(song_item) obs.obs_source_release(song) time.sleep(0.1) obs.obs_frontend_preview_program_trigger_transition()
def source_create_ar(id, source_name, settings): try: _source = obs.obs_source_create(id, source_name, settings, None) yield _source finally: obs.obs_source_release(_source)
def auto_setup(props, prop): # Todo: add BO3 and BO5 global game_item global social_item global overlay_item global bar_0_item global blue_cheer_item global orange_cheer_item global bar_1_item global blue_name_item global orange_name_item global blue_dev_name_item global orange_dev_name_item global blue_boost_item global orange_boost_item global boost_0_item global boost_1_item global goal_item global game_source global social_source global overlay_source global bar_0_source global blue_cheer_source global orange_cheer_source global bar_1_source global blue_name_source global orange_name_source global blue_boost_source global orange_boost_source global boost_0_source global boost_1_source global goal_source if not check_for_scene('RLBot - AutoLeague'): main_scene = obs.obs_scene_create('RLBot - AutoLeague') # Game Capture temp_settings = get_settings('Game Capture') game_source = obs.obs_source_create('game_capture', 'Game', temp_settings, None) game_item = obs.obs_scene_add(main_scene, game_source) obs.obs_data_release(temp_settings) obs.obs_source_release(game_source) # obs.obs_sceneitem_release(game_item) # Social temp_settings = get_settings('Social') temp_path = os.path.join(files_path, 'social.png') obs.obs_data_set_string(temp_settings, 'file', temp_path) social_source = obs.obs_source_create('image_source', 'Social', temp_settings, None) social_item = obs.obs_scene_add(main_scene, social_source) obs.obs_data_release(temp_settings) obs.obs_source_release(social_source) # obs.obs_sceneitem_release(social_item) # RLBot Overlay temp_settings = get_settings('RLBot Overlay') temp_path = os.path.join(files_path, 'overlay.png') obs.obs_data_set_string(temp_settings, 'file', temp_path) overlay_source = obs.obs_source_create('image_source', 'Overlay', temp_settings, None) overlay_item = obs.obs_scene_add(main_scene, overlay_source) obs.obs_data_release(temp_settings) obs.obs_source_release(overlay_source) # obs.obs_sceneitem_release(overlay_item) # Blue-Name temp_settings = get_settings('Blue Team Name') blue_name_source = obs.obs_source_create('text_gdiplus', 'Blue-Name', temp_settings, None) blue_name_item = obs.obs_scene_add(main_scene, blue_name_source) obs.obs_data_release(temp_settings) obs.obs_source_release(blue_name_source) # obs.obs_sceneitem_release(blue_name_item) # Orange-Name temp_settings = get_settings('Orange Team Name') orange_name_source = obs.obs_source_create('text_gdiplus', 'Orange-Name', temp_settings, None) orange_name_item = obs.obs_scene_add(main_scene, orange_name_source) obs.obs_data_release(temp_settings) obs.obs_source_release(orange_name_source) # obs.obs_sceneitem_release(orange_name_item) # Blue-Dev-Name temp_settings = get_settings('Blue Dev Name') blue_dev_name_source = obs.obs_source_create('text_gdiplus', 'Blue-Dev-Name', temp_settings, None) blue_dev_name_item = obs.obs_scene_add(main_scene, blue_dev_name_source) obs.obs_data_release(temp_settings) obs.obs_source_release(blue_dev_name_source) # obs.obs_sceneitem_release(blue_name_item) # Orange-Dev-Name temp_settings = get_settings('Orange Dev Name') orange_dev_name_source = obs.obs_source_create('text_gdiplus', 'Orange-Dev-Name', temp_settings, None) orange_dev_name_item = obs.obs_scene_add(main_scene, orange_dev_name_source) obs.obs_data_release(temp_settings) obs.obs_source_release(orange_dev_name_source) # obs.obs_sceneitem_release(orange_name_item) logo_pos = [300, 10] logo_scale = 0.25 # Logo-0 temp_settings = get_settings('Logo') temp_path = os.path.join(files_path, 'logo.png') obs.obs_data_set_string(temp_settings, 'file', temp_path) logo_0_source = obs.obs_source_create('image_source', 'Logo-0', temp_settings, None) logo_0_item = obs.obs_scene_add(main_scene, logo_0_source) obs.obs_data_release(temp_settings) obs.obs_source_release(logo_0_source) vec = obs.vec2() obs.vec2_set(vec, logo_pos[0], logo_pos[1]) obs.obs_sceneitem_set_pos(logo_0_item, vec) obs.vec2_set(vec, logo_scale, logo_scale) obs.obs_sceneitem_set_scale(logo_0_item, vec) # obs.obs_sceneitem_release(social_item) # Logo-1 temp_settings = get_settings('Logo') temp_path = os.path.join(files_path, 'logo.png') obs.obs_data_set_string(temp_settings, 'file', temp_path) logo_0_source = obs.obs_source_create('image_source', 'Logo-1', temp_settings, None) logo_0_item = obs.obs_scene_add(main_scene, logo_0_source) obs.obs_data_release(temp_settings) obs.obs_source_release(logo_0_source) vec = obs.vec2() obs.vec2_set(vec, 1920-100-logo_pos[0], logo_pos[1]) obs.obs_sceneitem_set_pos(logo_0_item, vec) obs.vec2_set(vec, logo_scale, logo_scale) obs.obs_sceneitem_set_scale(logo_0_item, vec) # obs.obs_sceneitem_release(social_item) # Goal temp_settings = get_settings('Goal') temp_path = os.path.join(files_path, 'goal.mov') obs.obs_data_set_string(temp_settings, 'local_file', temp_path) goal_source = obs.obs_source_create('ffmpeg_source', 'Goal', temp_settings, None) goal_item = obs.obs_scene_add(main_scene, goal_source) obs.obs_data_release(temp_settings) obs.obs_source_release(goal_source) # obs.obs_sceneitem_release(goal_item) obs.obs_scene_release(main_scene) set_text_pos() do_reset_bar() else: print('Scene already exists, please delete or rename RLBot scene before continuing')
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 auto_setup(props, prop): # Todo: add BO3 and BO5 global game_item global social_item global overlay_item global bar_0_item global blue_cheer_item global orange_cheer_item global bar_1_item global blue_name_item global orange_name_item global blue_boost_item global orange_boost_item global boost_0_item global boost_1_item global goal_item global game_source global social_source global overlay_source global bar_0_source global blue_cheer_source global orange_cheer_source global bar_1_source global blue_name_source global orange_name_source global blue_boost_source global orange_boost_source global boost_0_source global boost_1_source global goal_source if not check_for_scene('RLBot - AutoLeague'): main_scene = obs.obs_scene_create('RLBot - AutoLeague') # Game Capture temp_settings = get_settings('Game Capture') game_source = obs.obs_source_create('game_capture', 'Game', temp_settings, None) game_item = obs.obs_scene_add(main_scene, game_source) obs.obs_data_release(temp_settings) obs.obs_source_release(game_source) # obs.obs_sceneitem_release(game_item) # Social temp_settings = get_settings('Social') temp_path = os.path.join(files_path, 'social.png') obs.obs_data_set_string(temp_settings, 'file', temp_path) social_source = obs.obs_source_create('image_source', 'Social', temp_settings, None) social_item = obs.obs_scene_add(main_scene, social_source) obs.obs_data_release(temp_settings) obs.obs_source_release(social_source) # obs.obs_sceneitem_release(social_item) # RLBot Overlay temp_settings = get_settings('RLBot Overlay') temp_path = os.path.join(files_path, 'overlay.png') obs.obs_data_set_string(temp_settings, 'file', temp_path) overlay_source = obs.obs_source_create('image_source', 'Overlay', temp_settings, None) overlay_item = obs.obs_scene_add(main_scene, overlay_source) obs.obs_data_release(temp_settings) obs.obs_source_release(overlay_source) # obs.obs_sceneitem_release(overlay_item) # Bar-0 temp_settings = get_settings('bar-0') temp_path = os.path.join(files_path, 'bar-0.png') obs.obs_data_set_string(temp_settings, 'file', temp_path) bar_0_source = obs.obs_source_create('image_source', 'Bar-0', temp_settings, None) bar_0_item = obs.obs_scene_add(main_scene, bar_0_source) obs.obs_data_release(temp_settings) obs.obs_source_release(bar_0_source) # obs.obs_sceneitem_release(bar_0_item) # Bar-1 temp_settings = get_settings('bar-1') temp_path = os.path.join(files_path, 'bar-1.png') obs.obs_data_set_string(temp_settings, 'file', temp_path) bar_1_source = obs.obs_source_create('image_source', 'Bar-1', temp_settings, None) bar_1_item = obs.obs_scene_add(main_scene, bar_1_source) obs.obs_data_release(temp_settings) obs.obs_source_release(bar_1_source) # obs.obs_sceneitem_release(bar_1_item) # Blue-Name temp_settings = get_settings('Blue Team Name') blue_name_source = obs.obs_source_create('text_gdiplus', 'Blue-Name', temp_settings, None) blue_name_item = obs.obs_scene_add(main_scene, blue_name_source) obs.obs_data_release(temp_settings) obs.obs_source_release(blue_name_source) # obs.obs_sceneitem_release(blue_name_item) # Orange-Name temp_settings = get_settings('Orange Team Name') orange_name_source = obs.obs_source_create('text_gdiplus', 'Orange-Name', temp_settings, None) orange_name_item = obs.obs_scene_add(main_scene, orange_name_source) obs.obs_data_release(temp_settings) obs.obs_source_release(orange_name_source) # obs.obs_sceneitem_release(orange_name_item) # Blue-Boost-0 temp_settings = get_settings('Blue Boost 0') blue_boost_0_source = obs.obs_source_create('color_source', 'Blue-Boost-0', temp_settings, None) blue_boost_0_item = obs.obs_scene_add(main_scene, blue_boost_0_source) obs.obs_data_release(temp_settings) obs.obs_source_release(blue_boost_0_source) # obs.obs_sceneitem_release(blue_boost_item) # Orange-Boost-0 temp_settings = get_settings('Orange Boost 0') orange_boost_0_source = obs.obs_source_create('color_source', 'Orange-Boost-0', temp_settings, None) orange_boost_0_item = obs.obs_scene_add(main_scene, orange_boost_0_source) obs.obs_data_release(temp_settings) obs.obs_source_release(orange_boost_0_source) # obs.obs_sceneitem_release(orange_boost_item) # Boost-0 temp_settings = get_settings('Boost-0') temp_path = os.path.join(files_path, 'Boost-0.png') obs.obs_data_set_string(temp_settings, 'file', temp_path) boost_0_source = obs.obs_source_create('image_source', 'Boost-0', temp_settings, None) boost_0_item = obs.obs_scene_add(main_scene, boost_0_source) obs.obs_data_release(temp_settings) obs.obs_source_release(boost_0_source) # obs.obs_sceneitem_release(bar_1_item) # Goal temp_settings = get_settings('Goal') temp_path = os.path.join(files_path, 'goal.mov') obs.obs_data_set_string(temp_settings, 'local_file', temp_path) goal_source = obs.obs_source_create('ffmpeg_source', 'Goal', temp_settings, None) goal_item = obs.obs_scene_add(main_scene, goal_source) obs.obs_data_release(temp_settings) obs.obs_source_release(goal_source) # obs.obs_sceneitem_release(goal_item) obs.obs_scene_release(main_scene) set_text_pos() do_reset_bar() else: print( 'Scene already exists, please delete or rename RLBot scene before continuing' )