Created
November 24, 2023 16:36
-
-
Save UUoocl/44294dcef96947e869d460a992b3e660 to your computer and use it in GitHub Desktop.
OBS PTZ Move Filter: Get Camera Current Position LUA script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local obs = obslua | |
local ffi = require("ffi") | |
local obsffi | |
local cur_settings | |
local prev_settings | |
ffi.cdef[[ | |
struct obs_source; | |
struct obs_properties; | |
struct obs_property; | |
struct obs_data; | |
typedef struct obs_source obs_source_t; | |
typedef struct obs_properties obs_properties_t; | |
typedef struct obs_property obs_property_t; | |
typedef struct obs_data obs_data_t; | |
obs_source_t *obs_get_source_by_name(const char *name); | |
obs_source_t *obs_source_get_filter_by_name(obs_source_t *source, const char *name); | |
obs_properties_t *obs_source_properties(const obs_source_t *source); | |
obs_property_t *obs_properties_first(obs_properties_t *props); | |
bool obs_property_next(obs_property_t **p); | |
const char *obs_property_name(obs_property_t *p); | |
void obs_properties_destroy(obs_properties_t *props); | |
void obs_source_release(obs_source_t *source); | |
bool obs_property_button_clicked(obs_property_t *p, void *obj); | |
obs_data_t *obs_source_get_settings(const obs_source_t *source); | |
const char *obs_data_get_json(obs_data_t *data); | |
]] | |
if ffi.os == "OSX" then | |
obsffi = ffi.load("obs.0.dylib") | |
else | |
obsffi = ffi.load("obs") | |
end | |
local function filterTest() | |
local source = obsffi.obs_get_source_by_name("Video Capture Device data") | |
if source then | |
local fSource = obsffi.obs_source_get_filter_by_name(source, "mVideo") | |
if fSource then | |
local props = obsffi.obs_source_properties(fSource) | |
if props then | |
local prop = obsffi.obs_properties_first(props) | |
local name = obsffi.obs_property_name(prop) | |
if name then | |
local propCount = 1 | |
--obs.script_log(obs.LOG_INFO, string.format("Property 1 = %s", ffi.string(name))) | |
local _p = ffi.new("obs_property_t *[1]", prop) | |
local foundProp = obsffi.obs_property_next(_p) | |
prop = ffi.new("obs_property_t *", _p[0]) | |
while foundProp do | |
propCount = propCount + 1 | |
name = obsffi.obs_property_name(prop) | |
if ffi.string(name) == "value_get" then | |
--obs.script_log(obs.LOG_INFO, string.format("Property %d = %s", propCount, ffi.string(name))) | |
obsffi.obs_property_button_clicked(prop, fSource) | |
cur_settings = obsffi.obs_source_get_settings(fSource) | |
print(ffi.string(obsffi.obs_data_get_json(cur_settings))) | |
end | |
_p = ffi.new("obs_property_t *[1]", prop) | |
foundProp = obsffi.obs_property_next(_p) | |
prop = ffi.new("obs_property_t *", _p[0]) | |
end | |
end | |
obsffi.obs_properties_destroy(props) | |
end | |
obsffi.obs_source_release(fSource) | |
end | |
obsffi.obs_source_release(source) | |
end | |
end | |
local function timer_callback() | |
filterTest() | |
end | |
obs.timer_add(timer_callback, 1000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This GIST gets the current Pan, Tilt, Zoom position values from the Move Transition filter.
The PTZ Camera Source is named "Video Capture Device data" and the Move Video Filter is named "mVideo"
The current values are returned once per second. The 1 per second rate may be a firmware limit.
Add this script to the OBS scripts. Tools-->Scripts.
View the "Script log" to see the script results.