Esempio n. 1
0
def media_source_ar(media_path: str, monitoring_type: int):
    media_source = obs.obs_source_create_private("ffmpeg_source",
                                                 "Global Media Source", None)
    with data_ar() as settings:
        obs.obs_data_set_string(settings, "local_file", media_path)
        obs.obs_source_update(media_source, settings)
        obs.obs_source_set_monitoring_type(media_source, monitoring_type)
        try:
            yield media_source
        finally:
            obs.obs_source_release(media_source)
Esempio n. 2
0
def play_sound():
    mediaSource = S.obs_source_create_private("ffmpeg_source",
                                              "Global Media Source", None)
    s = S.obs_data_create()
    S.obs_data_set_string(s, "local_file", script_path() + "alert.mp3")
    S.obs_source_update(mediaSource, s)
    S.obs_source_set_monitoring_type(mediaSource,
                                     S.OBS_MONITORING_TYPE_MONITOR_AND_OUTPUT)
    S.obs_data_release(s)

    S.obs_set_output_source(outputIndex, mediaSource)
    return mediaSource
    def add_filter_to_source(self):
        source = S.obs_get_source_by_name("1test_py")
        settings = S.obs_data_create()

        S.obs_data_set_int(settings, "opacity", 50)
        source_color = S.obs_source_create_private("color_filter",
                                                   "opacity to 50", settings)
        S.obs_source_filter_add(source, source_color)

        S.obs_source_release(source)
        S.obs_data_release(settings)
        S.obs_source_release(source_color)
    def crete_text_source(self):
        current_scene = obs.obs_frontend_get_current_scene()
        scene = obs.obs_scene_from_source(current_scene)
        settings = obs.obs_data_create()

        obs.obs_data_set_string(settings, "text",
                                "The quick brown fox jumps over the lazy dog")
        source = obs.obs_source_create_private("text_gdiplus", "test_py",
                                               settings)
        obs.obs_scene_add(scene, source)

        obs.obs_scene_release(scene)
        obs.obs_data_release(settings)
        obs.obs_source_release(source)
    def sanic_effect(self):
        # add filter scroll to source if not present,
        self.update_text(self.scripted_text)
        with source_ar(self.source_name) as source, filter_ar(
                source, "py_scroll") as scroll:
            if scroll is None:
                with data_ar() as settings:
                    obs.obs_data_set_int(settings, "speed_x", 5000)

                    source_scroll = obs.obs_source_create_private(
                        "scroll_filter", "py_scroll", settings)
                    obs.obs_source_filter_add(source, source_scroll)
                    obs.obs_source_release(source_scroll)

            with data_ar(scroll) as filter_settings:
                obs.obs_data_set_int(filter_settings, "speed_x", 5000)
                obs.obs_source_update(scroll, filter_settings)
                if self.duration // self.refresh_rate <= 3:
                    obs.obs_source_filter_remove(source, scroll)
                    self.duration = 0
    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()
Esempio n. 7
0
def p_source_ar(id, source_name, settings):
    try:
        _source = obs.obs_source_create_private(id, source_name, settings)
        yield _source
    finally:
        obs.obs_source_release(_source)