Resource icon

Reload browser in preview scene V1.0.1

DCStrato

Member
DCStrato - Thanks v.much for your rapid reply. i'll give this new script an outing!

You mention above some new code for auto camera control; is that the same/development as mentioned above (Sept 13 2020)? Is the code available as per Sept 15 2020 above? Does it integrate with OBS Studio?
I find the PTZ Optics Controller not that user friendly (and the User Manual out of date and useless!)
So I would be very interested in trying out something different (using Visca over IP?)
What do you mean by " doing "show" tests with callbacks " ?!!

(Sorry, I'm in UK and so 7 hours ahead of you in Colorado)
The line obs.signal_handler_connect(sh,"show",showing) sets a signal handler for the refresh source that gets called when that source is "Showing" anywhere in OBS (preview or program).
 

DCStrato

Member
Here is a link to the Git repository if you want to see the source code to the controller. I wrote it in VB initially using Visual Studio, mostly because I had always developed in C and was just curious to learn VB. Don't expect a lot of internal comments but most of the code is pretty readable. github.com/DCStrato/SimpleCam
 

DCStrato

Member
Here is an updated Refresh Browser In Preview Source script. I had a chance to need this for closing credits that get updated by a team via a Google doc. It seems to be working as expected for me. Sorry, I am just now getting around to testing the script.
 

Attachments

  • refreshonpreview.zip
    846 bytes · Views: 93

amanatides

New Member
For those who had trouble
So I followed this instructions by creating a file in the specified directory and setting its contents to this script. I then added the script to OBS and it showed up as an available source. I add the source to my scene but when I click on my scene the camera does not zoom to the preset (we are using zcams and PTZ cams by PTZOptics). The browser source that we are using to call the preset is named 'Organist Zoom' if that matters. What did I do wrong?

I had this problem as well when controlling a PTZOptics camera. However, when I created a different Refresh Browser on Preview source for each Scene rather than using an existing source, it started to work.
 

vdefilip

New Member
Copy the script text and save it as a .lua file. Typically they are stored here... C:\Program Files\obs-studio\data\obs-plugins\frontend-tools\scripts. Add the new lua script in OBS and it should offer you a new "source" that you can add to a scene to refresh the browser when it is loaded in a preview window. I have this feature as a checkbox in the controller I wrote as well as a "delay" option so the camera will move after the transition but following a preset delay so the move does not show up in any crossfade transitions. Here is the source text again. I don't use PTZOptics cameras, nor do I use a browser to interface my Visca PTZ Cameras with OBS, so it might need testing. I just wrapped your code in a source shell.
++--------------------------------------------------------------
obs = obslua
bit = require("bit")

source_def = {}
source_def.id = "Refresh_Browser"
source_def.type = OBS_SOURCE_TYPE_INPUT;
source_def.output_flags = bit.bor(obs.OBS_SOURCE_CUSTOM_DRAW)

source_def.get_name = function()
return "Refresh Browser On Preview"
end
function script_description()
return "Adds a Refresh Browser On Show Source"
end
source_def.get_properties = function (data)
end
source_def.destroy = function(source)
end
source_def.create = function(settings, source)
end
source_def.activate = function(data)
end

source_def.show = function(data)
local scenesource = obs.obs_frontend_get_current_preview_scene()
if scenesource == nil then
return
end
local scene = obs.obs_scene_from_source(scenesource)
local scene_name = obs.obs_source_get_name(scenesource)
local scene_items = obs.obs_scene_enum_items(scene)
if scene_items ~= nil then
for _, scene_item in ipairs(scene_items) do
local source = obs.obs_sceneitem_get_source(scene_item)
local source_id = obs.obs_source_get_unversioned_id(source)
if source_id == "browser_source" then
local settings = obs.obs_source_get_settings(source)
local fps = obs.obs_data_get_int(settings, "fps")
if fps % 2 == 0 then
obs.obs_data_set_int(settings,"fps",fps + 1)
else
obs.obs_data_set_int(settings,"fps",fps - 1)
end
obs.obs_source_update(source, settings)
obs.obs_data_release(settings)
end
end
end
obs.sceneitem_list_release(scene_items)
obs.obs_source_release(scenesource)
obs.source_list_release(sources)
end

obs.obs_register_source(source_def);
++----------------------------------------------------------------------------------
Good day,

I'm new to this program, if i understand well, this code automaticallyrefreshes the browser when i'm streaming ?
For now i always have to tap on the refresh button to resume streaming after an interruption.
for info: i'm using esp32cam in a modeltrain, so from time to time power to the cam is interrupted. I searcha solution to restart stream after this.
Thanks a lot .
Filip
 

Heino Falcke

New Member
Thanks. I use my own (different) code for controlling five cameras automatically in scenes. I am doing "show" tests with callbacks now as they seem a bit more reliable. Try this shorter script. Good Luck.
-----++
obs = obslua
bit = require("bit")
source_def = {}
source_def.id = "Refresh_Browser"
source_def.type = OBS_SOURCE_TYPE_INPUT;
source_def.output_flags = bit.bor(obs.OBS_SOURCE_CUSTOM_DRAW)
source_def.get_name = function()
return "Refresh Browser On Preview"
end
function script_description()
return "Adds a Refresh Browser On Show Source"
end
source_def.create = function(settings, source)
data = {}
sh = obs.obs_source_get_signal_handler(source)
obs.signal_handler_connect(sh,"show",showing) --Set Preview Callback
return data
end
function showing(cd)
local scenesource = obs.obs_frontend_get_current_preview_scene()
if scenesource == nil then
return
end
local scene = obs.obs_scene_from_source(scenesource)
local scene_name = obs.obs_source_get_name(scenesource)
local scene_items = obs.obs_scene_enum_items(scene)
if scene_items ~= nil then
for _, scene_item in ipairs(scene_items) do
local source = obs.obs_sceneitem_get_source(scene_item)
local source_id = obs.obs_source_get_unversioned_id(source)
if source_id == "browser_source" then
local settings = obs.obs_source_get_settings(source)
local fps = obs.obs_data_get_int(settings, "fps")
if fps % 2 == 0 then
obs.obs_data_set_int(settings,"fps",fps + 1)
else
obs.obs_data_set_int(settings,"fps",fps - 1)
end
obs.obs_source_update(source, settings)
obs.obs_data_release(settings)
end
end
end
obs.sceneitem_list_release(scene_items)
obs.obs_source_release(scenesource)
obs.source_list_release(sources)
print("Refresh Browser")
end
obs.obs_register_source(source_def);
------++


I used that script to control a Sony PTZ camera and it works sort of. I defined different scenes for each preset, which then uses browser cgi calls to recall the camera's presets. I do this, because the VISCA-over-IP plugin doesn't seem to work for us. The script above with the cgi-calls seems to work, when I use the main window. However, it stops working, when I use the multiview - it is already enough that multiview is launched and I switch scenes from the main window. Any idea how to make that script work with multiview being launched?
 

DCStrato

Member
I used that script to control a Sony PTZ camera and it works sort of. I defined different scenes for each preset, which then uses browser cgi calls to recall the camera's presets. I do this, because the VISCA-over-IP plugin doesn't seem to work for us. The script above with the cgi-calls seems to work, when I use the main window. However, it stops working, when I use the multiview - it is already enough that multiview is launched and I switch scenes from the main window. Any idea how to make that script work with multiview being launched?
Hi, I have not done much with multi-view. I use the above to be sure our Credits Google Doc is refreshed before it streams. I use my own code for PTZ control fully integrated with OBS, so I don't have to use browser calls to control our VISCA-IP cameras in scenes. I will take a look at multi-view and see how that might work. I know the new OBS update said something about a browser refresh button, but my techs would forget to push it for sure. :)

DC
 

Heino Falcke

New Member
Hi, I have not done much with multi-view. I use the above to be sure our Credits Google Doc is refreshed before it streams. I use my own code for PTZ control fully integrated with OBS, so I don't have to use browser calls to control our VISCA-IP cameras in scenes. I will take a look at multi-view and see how that might work. I know the new OBS update said something about a browser refresh button, but my techs would forget to push it for sure. :)

DC

Thanks a lot. I checked the access log of the camera. When Multiview is launched, all cgi commands are refreshed (and hence logged) at once. Afterwards changing scenes doesn't lead to a refresh anymore. So, it looks like Multiview calls the show function for all scenes at the beginning and then inhibits it somehow.
 
Last edited:

DCStrato

Member
Yes. There is not an actual "In_preview" function. All the scenes in the multiview meet the "Is Showing" criteria as soon the window opens and moving the selected window does not cause that is_showing function of the source to be called again. I am trying to find a way to know what scene is currently selected in multi-view but I don't think it exists. At least it appears to not be exposed in the API.
 

tstrong

New Member
Hello, I am a newb to OBS, but have multiple browser sources being switched, I don't need to control PTZ anything, just refresh the browser when it hits the preview window. which version of this script on this thread will help me do that?
 

tstrong

New Member
Copy the script text and save it as a .lua file. Typically they are stored here... C:\Program Files\obs-studio\data\obs-plugins\frontend-tools\scripts. Add the new lua script in OBS and it should offer you a new "source" that you can add to a scene to refresh the browser when it is loaded in a preview window. I have this feature as a checkbox in the controller I wrote as well as a "delay" option so the camera will move after the transition but following a preset delay so the move does not show up in any crossfade transitions. Here is the source text again. I don't use PTZOptics cameras, nor do I use a browser to interface my Visca PTZ Cameras with OBS, so it might need testing. I just wrapped your code in a source shell.
++--------------------------------------------------------------
obs = obslua
bit = require("bit")

source_def = {}
source_def.id = "Refresh_Browser"
source_def.type = OBS_SOURCE_TYPE_INPUT;
source_def.output_flags = bit.bor(obs.OBS_SOURCE_CUSTOM_DRAW)

source_def.get_name = function()
return "Refresh Browser On Preview"
end
function script_description()
return "Adds a Refresh Browser On Show Source"
end
source_def.get_properties = function (data)
end
source_def.destroy = function(source)
end
source_def.create = function(settings, source)
end
source_def.activate = function(data)
end

source_def.show = function(data)
local scenesource = obs.obs_frontend_get_current_preview_scene()
if scenesource == nil then
return
end
local scene = obs.obs_scene_from_source(scenesource)
local scene_name = obs.obs_source_get_name(scenesource)
local scene_items = obs.obs_scene_enum_items(scene)
if scene_items ~= nil then
for _, scene_item in ipairs(scene_items) do
local source = obs.obs_sceneitem_get_source(scene_item)
local source_id = obs.obs_source_get_unversioned_id(source)
if source_id == "browser_source" then
local settings = obs.obs_source_get_settings(source)
local fps = obs.obs_data_get_int(settings, "fps")
if fps % 2 == 0 then
obs.obs_data_set_int(settings,"fps",fps + 1)
else
obs.obs_data_set_int(settings,"fps",fps - 1)
end
obs.obs_source_update(source, settings)
obs.obs_data_release(settings)
end
end
end
obs.sceneitem_list_release(scene_items)
obs.obs_source_release(scenesource)
obs.source_list_release(sources)
end

obs.obs_register_source(source_def);
++----------------------------------------------------------------------------------



Do I have to change any text in this code?
Do I have to name my browser source something specific? (I currently have them named as 'Cam1' 'Cam2' 'Cam3' 'Cam4')
I cannot tell if it is working, which feels like it is not working.

I copied your text to a text document, not changing any characters> changed that to a LUA file > put that in the scripts location provided > imported the script into OBS > it shows up as a "source" > I add that to the scene, at the top and keep it visible > and run the obs switchers > and it does not look like it actually refreshes the browser source.

Any help?

Thanks in advance!
 

DCStrato

Member
It should just create a source called "Refresh Browser on Preview". Here it is as a lua file.
 

Attachments

  • RefreshBrowserSource.zip
    858 bytes · Views: 42
Top