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

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

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

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

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.
 

GHQ

New Member
I'm also a newbie and have cut and pasted your "refresh browser" script (the code between the two ++---------) into Notepad and saved it as a .lua file in the stated directory. I have added it as a script into OBS but it doesn't show up as a source. Have you any suggestions as to what I am doing wrong?
Many thanks.
 

DCStrato

Member
I'm also a newbie and have cut and pasted your "refresh browser" script (the code between the two ++---------) into Notepad and saved it as a .lua file in the stated directory. I have added it as a script into OBS but it doesn't show up as a source. Have you any suggestions as to what I am doing wrong?
Many thanks.
Sorry for the delay in response. I only get back here once a week or so.
I did exactly as you described. Copied the post between the ++--- lines, pasted it into notepad. Saved it as preview.lua. Added script preview.lua to OBS version 26.0.2. Went to a scene and added Refresh Browser on Preview as a source. I can't visualize why your OBS does not function in the same way. You might try displaying the script log where you added the script in OBS and see if any error messages are shown indicating why the source didn't load. Be sure that last line in the script made it.

obs.obs_register_source(source_def);

This is the one that actually adds the script as a source in OBS. I know the first time I posted I forgot to include this one when I pasted it into the forum.
 

GHQ

New Member
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?
Did you get anywhere using DCStrato's "Refresh browser in Preview" with PTZ Optics cams? I can't make it work - the script that "refreshes in preview" using a hotkey does work.
 

GHQ

New Member
Sorry for the delay in response. I only get back here once a week or so.
I did exactly as you described. Copied the post between the ++--- lines, pasted it into notepad. Saved it as preview.lua. Added script preview.lua to OBS version 26.0.2. Went to a scene and added Refresh Browser on Preview as a source. I can't visualize why your OBS does not function in the same way. You might try displaying the script log where you added the script in OBS and see if any error messages are shown indicating why the source didn't load. Be sure that last line in the script made it.

obs.obs_register_source(source_def);

This is the one that actually adds the script as a source in OBS. I know the first time I posted I forgot to include this one when I pasted it into the forum.
I now have your lua installed in OBS. I added it to the Scene together with the Browser "PTZ Optics Preset call", setting "Refresh browser when scene becomes active".
I then created another scene with a different preset call (on the same camera).
In "Studio" mode if I select these scenes in preview and nothing happens!
If I use the original (mball2301) "Hotkey" lua script the cameras go to the correct preset (in preview) when the hotkey is pressed.
As you say this is boring to have to press an extra key.. I only wish I could get your script to work!!
 
Last edited:

DCStrato

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

GHQ

New 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)
 

GHQ

New Member
DCStrato - Just noticed your 16 Dec 2020 post in another string which implies that your "Simple Cam" won't work with PTZ Optics? Does your programme work using Visca commands? Are they different to PTZ Optics Visca -surely not.
Please excue my ignorance in all this - I am a retired TV Sound Engineer on a big learning curve!!
 

DCStrato

Member
It sends standard VISCA over either IP or Serial ports. I only use VISCA over IP but tested it with serial ports. I have updated it quite a bit with stability fixes if you are interested in trying it. I am using it every week with zero issues running three cameras. I don't have a manual for it as I only wrote it for myself to use. I will push the project to GiT and share it if you are interested in seeing the camera code. The Lua Script is readable. Display on controller is one or two cameras wide and each panel can select on of five cameras to control. Most places in the EXE are clickable. Home is double click. Clicking +/- above/below zoom slider zooms into digital zoom if camera supports it. Set then preset button saves current location to camera. Rename then present button allows you to enter a new label for the preset, then press ENTER to save it. Any label changes in the controller will be automatically changed in any scenes. Same with Camera Names. Click on them to change their name and those will also update in scenes. Duplicate or same source used in multiple scenes has an * added and it turns orange so you know if you change one you change them all! I only use it with Windows 10 and have not tested it on other platforms.
 

Attachments

  • SimpleCamPTZ.zip
    144.4 KB · Views: 41
Top