Resource icon

Reload browser in preview scene V1.0.1

mball2301

New Member
mball2301 submitted a new resource:

Reload browser in preview scene - Ability to refresh a browser source in preview when using studio mode

This script will refresh any browser sources in the preview window of studio mode. I create this script because I am using browser triggers to set PTZOptics camera to a specific preset. I have to have the preset in the browser normally trigger on the scene becoming active. This is so same camera fades do not trigger in preview normally (use a stinger to fade same camera).

This script should be considered beta. I am still trying to track down memory leaks.
Also in my "test" OBS...
Read more about this resource...
 

mball2301

New Member
I found the issue with the button. I did not change the function to execute from refresh_browsers to refresh_preview_browsers
 

DCStrato

New Member
You could also do it as a source so you would not need to press a button...

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
 

Tpallot

New Member
You could also do it as a source so you would not need to press a button...

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
Can you please explain (step by step) how we go about doing this? I'm assuming I need to copy and paste these commands (with the additional line from your followup post), but where do I paste them? Thanks for your help!
 

DCStrato

New Member
Can you please explain (step by step) how we go about doing this? I'm assuming I need to copy and paste these commands (with the additional line from your followup post), but where do I paste them? Thanks for your help!
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);
++----------------------------------------------------------------------------------
 

kmill243

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);
++----------------------------------------------------------------------------------
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?
 

DCStrato

New Member
So you still have your "Browser" command in the scene to move your camera? All this does is refresh the browser. It won't send the VIsca command to your camera. If you are using Windows and want to help test some code I will send you what I wrote for our church. At the moment it manages 5 cameras via Visca over IP. Video Capture is SDI. Layout can double and show up to two camera controls at a time. Either control can select any camera with up to 14 nameable preset. Setup allows for IP address or serial port and address for each of the five cameras, mix and match. Controls are 8-point compass with home (double click). Zoom and digital zoom are supported via slider and +/- keys. Movement speed is via a slider below compass. Cameras can be renamed. Interface to OBS is via LUA script source. Add the source to any scene and select Camera (by its name) and current preset (by its name). Also HOME is selectable in OBS as a 15th preset. Options allow for movement in preview only, program only, or both. The program movement can be delayed up to 9 seconds to keep camera steady until after the transition. All names are synced with OBS. So for example, if your Camera 1 was called Left Camera and it had the Organ Zoom preset selected for the source in a given scene, it would be renamed in that scene to "2. Move Left Camera to Organ Zoom". The numbers are the source numbers for unique entries and keep the names unique. If this was a "referenced" source created from a copy paste for example, then there is an option to mark those with *. If selected the the source would be renamed "2. Move Left Camera to Organ Zoom *". And if you change any names in the control software they automatically change in all the scenes. So if you rename the Organ Zoom preset to Piano Zoom, then all the previous scenes will now read "2. Move Camera Left to Piano Zoom". I wrote this stuff because our streaming volunteers could not keep all the browser stuff straight and we had cameras going all over the place. I will attach a few screen shots.
SIngleControl.png
OBS Preset.png
OBS Source Entry.png
Referenced Source Mark.png
 

kmill243

New Member
So you still have your "Browser" command in the scene to move your camera? All this does is refresh the browser. It won't send the VIsca command to your camera. If you are using Windows and want to help test some code I will send you what I wrote for our church. At the moment it manages 5 cameras via Visca over IP. Video Capture is SDI. Layout can double and show up to two camera controls at a time. Either control can select any camera with up to 14 nameable preset. Setup allows for IP address or serial port and address for each of the five cameras, mix and match. Controls are 8-point compass with home (double click). Zoom and digital zoom are supported via slider and +/- keys. Movement speed is via a slider below compass. Cameras can be renamed. Interface to OBS is via LUA script source. Add the source to any scene and select Camera (by its name) and current preset (by its name). Also HOME is selectable in OBS as a 15th preset. Options allow for movement in preview only, program only, or both. The program movement can be delayed up to 9 seconds to keep camera steady until after the transition. All names are synced with OBS. So for example, if your Camera 1 was called Left Camera and it had the Organ Zoom preset selected for the source in a given scene, it would be renamed in that scene to "2. Move Left Camera to Organ Zoom". The numbers are the source numbers for unique entries and keep the names unique. If this was a "referenced" source created from a copy paste for example, then there is an option to mark those with *. If selected the the source would be renamed "2. Move Left Camera to Organ Zoom *". And if you change any names in the control software they automatically change in all the scenes. So if you rename the Organ Zoom preset to Piano Zoom, then all the previous scenes will now read "2. Move Camera Left to Piano Zoom". I wrote this stuff because our streaming volunteers could not keep all the browser stuff straight and we had cameras going all over the place. I will attach a few screen shots.
View attachment 60928View attachment 60929View attachment 60930View attachment 60931
This looks pretty slick and I would love to test it with you. I am a newbie (as you might have guessed) so I might need some hand holding at first on installation and use.
 
Top