Changing image source's image using python scripting

ItzDragon

New Member
I'm currently trying to create a obs script using python, and i'm blocked, i cant find a function in the documentation which enable me to change the image of an image source thank you for your answers
 
This is hacked out of one of my Lua scripts, but Python should be very similar.
Given an image source configured to show the contents of an image file, you can change to a different file like this:
local settings = obs.obs_data_create() obs.obs_data_set_string(settings, "file", new_filename) obs.obs_source_update(source, settings) obs.obs_data_release(settings)
 

ItzDragon

New Member
thank you :)
just some question (sorry im a realy big noob -_-)
what does "new_filename" content ? is it the image path ?
is "source" a scene item ?
and eventually what is "file"

again thank you for taking the time to answer me
 

ItzDragon

New Member
okay uptdate :
i've done this :

Python:
current_scene_as_source = obs.obs_frontend_get_current_scene()

if current_scene_as_source:

  current_scene = obs.obs_scene_from_source(current_scene_as_source)

  scene_item = obs.obs_scene_find_source_recursive(current_scene, "image")

  if scene_item:

    settings = obs.obs_data_create()

    obs.obs_data_set_string(settings, "file", "path")

    obs.obs_source_update(obs.obs_sceneitem_get_source(scene_item), settings)

    obs.obs_data_release(settings)

  obs.obs_source_release(current_scene_as_source)


But nothing happens
 
I presume that "image" is the name that you gave your Image source when you created it in OBS, and that where you have "path" above your actual code has the full filespec ("C:\where I keep stuff\file.png") of the image file you want to display?

When you exit OBS, the last setting value that you wrote will be saved in the scene collection json file, in the "settings" chunk of the image_source that you are changing.

Beyond that, you can add print statements to make sure that you are getting the scene and source items you expect. Output appears in the log file, or you can see it live by clicking "Script log" in the Scripts dialog (at least it does for Lua scripts - I haven't use Python in OBS)
 
Top