marklagendijk / obs-scene-execute-command-script

OBS script for executing any CLI command whenever whenever a scene is activated
MIT License
28 stars 6 forks source link

Sony SRG-X120 NDI #2

Closed kadams79 closed 4 years ago

kadams79 commented 4 years ago

I am running Windows 10 & OBS 25.0.8 connected to a Sony SRG-X120 camera with firmware 2.10.

We recently purchased the Sony SRG-X120 to use with OBS for live streaming. I would like to use CGI commands to activate presets on the camera when switching to different scenes in OBS. I am fairly new to programming and having trouble getting the camera to respond. The command I'm entering into Command Prompt, based on Sony's CGI documentation, is: curl "http://192.168.1.101/command/presetposition.cgi?PresetCall=1". I get a 401 Unauthorized error back. The documentation states that CGI commands require the proper authorization header but gives no indication as to how that should be inserted into the command. I'm guessing they assume I'm already an experienced programmer. I've sent a help request to Sony and tried multiple suggestions found via web search but no luck yet. Both RTSP Authentication and Referer Check are disabled on the camera so at this point there should be no authorization limitations.

When I run the preset command from the camera web interface I get the following command: curl "http://192.168.1.101/command/presetposition.cgi?PresetCall=1&_=1601082343318" -H "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:81.0) Gecko/20100101 Firefox/81.0" -H "Accept: /" -H "Accept-Language: en-US,en;q=0.5" --compressed -H "X-Requested-With: XMLHttpRequest" -H "Connection: keep-alive" -H "Referer: http://192.168.1.101/index.html?lang=en" -H "Cookie: SRG-X120_viewsize-pulldown=x1; SRG-X120volume-slider=1.00" -H "Authorization: Digest username=""admin"", realm=""SRG-X120"", nonce=""ZmUyZGIyOTM0MGY2MTRjNmI2ZmVjNjIzNzY1MDA5ZTg="", uri=""/command/presetposition.cgi?PresetCall=1&=1601082343318"", algorithm=MD5, response=""028656408aa4c18eff439d28b696920c"", qop=auth, nc=00000001, cnonce=""a2a289483baa13a2""". I tried plugging this directly into Command Prompt but get this in response: curl: option --compressed: the installed libcurl version doesn't support this. Obviously none of these commands work in OBS either. Any help you can provide would be greatly appreciated.

St-Philip-Lutheran commented 4 years ago

All of the double double quotes ("") seems a bit odd to me.

FWIIW, For my Datavideo PTC-140, I captured the preset command sent by the web interface in Chrome, stripped some pretty formatting "^ newlines" and substituted SCENE_VALUE where the camera preset number was in the command.

Here is what I use as the script command: curl "http://192.168.5.163/ajaxcom" -H "Connection: keep-alive" -H "Accept: application/json, text/javascript, /; q=0.01" -H "X-Requested-With: XMLHttpRequest" -H "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.105 Safari/537.36" -H "Content-Type: application/x-www-form-urlencoded; charset=UTF-8" -H "Origin: http://192.168.5.163" -H "Referer: http://192.168.5.163/pages/live.asp" -H "Accept-Language: en-US,en;q=0.9" -H "Cookie: updateTips=true; language=en; LoginResult=false; -goahead-session-=::webs.session::c1e71319c63d813d9f8fb4286334e66f" --data-raw "szCmd=%7B%22SysCtrl%22%3A%7B%22PtzCtrl%22%3A%7B%22nChanel%22%3A0%2C%22szPtzCmd%22%3A%22preset_call%22%2C%22byValue%22%3ASCENE_VALUE%7D%7D%7D"

On Fri, Sep 25, 2020 at 10:27 PM kadams79 notifications@github.com wrote:

I am running Windows 10 & OBS 25.0.8 connected to a Sony SRG-X120 camera with firmware 2.10.

We recently purchased the Sony SRG-X120 to use with OBS for live streaming. I would like to use CGI commands to activate presets on the camera when switching to different scenes in OBS. I am fairly new to programming and having trouble getting the camera to respond. The command I'm entering into Command Prompt, based on Sony's CGI documentation, is: curl "http://192.168.1.101/command/presetposition.cgi?PresetCall=1". I get a 401 Unauthorized error back. The documentation states that CGI commands require the proper authorization header but gives no indication as to how that should be inserted into the command. I'm guessing they assume I'm already an experienced programmer. I've sent a help request to Sony and tried multiple suggestions found via web search but no luck yet. Both RTSP Authentication and Referer Check are disabled on the camera so at this point there should be no authorization limitations.

When I run the preset command from the camera web interface I get the following command: curl " http://192.168.1.101/command/presetposition.cgi?PresetCall=1&_=1601082343318" -H "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:81.0) Gecko/20100101 Firefox/81.0" -H "Accept: /" -H "Accept-Language: en-US,en;q=0.5" --compressed -H "X-Requested-With: XMLHttpRequest" -H "Connection: keep-alive" -H "Referer: http://192.168.1.101/index.html?lang=en" -H "Cookie: SRG-X120_viewsize-pulldown=x1; SRG-X120volume-slider=1.00" -H "Authorization: Digest username=""admin"", realm=""SRG-X120"", nonce=""ZmUyZGIyOTM0MGY2MTRjNmI2ZmVjNjIzNzY1MDA5ZTg="", uri=""/command/presetposition.cgi?PresetCall=1&=1601082343318"", algorithm=MD5, response=""028656408aa4c18eff439d28b696920c"", qop=auth, nc=00000001, cnonce=""a2a289483baa13a2""". I tried plugging this directly into Command Prompt but get this in response: curl: option --compressed: the installed libcurl version doesn't support this. Obviously none of these commands work in OBS either. Any help you can provide would be greatly appreciated.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/marklagendijk/obs-scene-execute-command-script/issues/2, or unsubscribe https://github.com/notifications/unsubscribe-auth/AQSNO5PVB46GXNXDE7BEETTSHVGSBANCNFSM4R2TJ3YA .

marklagendijk commented 4 years ago

@kadams79 try the command as is, but without the --compressed.

kadams79 commented 4 years ago

Thanks for the responses. I've continued trying to get this to work but no luck thus far. I tried removing "--compressed" with no change in response. Sony finally responded to my inquiry and stated that CGI commands to the camera require Digest Authentication but did not state exactly how the request should be formatted. They also stated that there were some steps required on the client side for communication to be established with the camera but did not go into detail. Since I'm not a seasoned programmer I'm still a bit lost. From what I'm understanding Digest Authentication requires a back and forth rather than just sending the credentials. Is the OBS plugin capable of that?

I captured the preset command via Chrome this time and this is what it produced:

curl "http://192.168.1.160/command/presetposition.cgi?PresetCall=1^&_=1602544479241" ^ -H "Connection: keep-alive" ^ -H "Authorization: Digest username=^\^"admin^\^", realm=^\^"SRG-X120^\^", nonce=^\^"ZjkwNjliMGVkYzFmNjRlNjYwMDBmNzYyNWNjNjM0Yjc=^\^", uri=^\^"/command/presetposition.cgi?PresetCall=1^&_=1602544479241^\^", algorithm=MD5, response=^\^"764fa85f98e3e89758d84ff2d48ade65^\^", qop=auth, nc=00000002, cnonce=^\^"efe293d91af89df6^\^"" ^ -H "Accept: /" ^ -H "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.75 Safari/537.36" ^ -H "X-Requested-With: XMLHttpRequest" ^ -H "Referer: http://192.168.1.160/index.html?lang=en" ^ -H "Accept-Language: en-US,en;q=0.9" ^ -H "Cookie: SRG-X120_viewsize-pulldown=x1; SRG-X120_volume-slider=1.00" ^ --compressed ^ --insecure

I entered the captured command into command prompt and received this reply:

curl "http://192.168.1.160/command/presetposition.cgi?PresetCall=1^&_=1602544479241" ^ More? -H "Connection: keep-alive" ^ More? -H "Authorization: Digest username=^\^"admin^\^", realm=^\^"SRG-X120^\^", nonce=^\^"ZjkwNjliMGVkYzFmNjRlNjYwMDBmNzYyNWNjNjM0Yjc=^\^", uri=^\^"/command/presetposition.cgi?PresetCall=1^&_=1602544479241^\^", algorithm=MD5, response=^\^"764fa85f98e3e89758d84ff2d48ade65^\^", qop=auth, nc=00000002, cnonce=^\^"efe293d91af89df6^\^"" ^

401 Unauthorized

401 Unauthorized

Your client does not have permission to get URL from this server.

curl: (6) Could not resolve host: realm="SRG-X120", curl: (6) Could not resolve host: nonce="ZjkwNjliMGVkYzFmNjRlNjYwMDBmNzYyNWNjNjM0Yjc=", curl: (6) Could not resolve host: uri=" curl: (6) Could not resolve host: algorithm=MD5, curl: (6) Could not resolve host: response="764fa85f98e3e89758d84ff2d48ade65", curl: (6) Could not resolve host: qop=auth, curl: (6) Could not resolve host: nc=00000002, curl: (6) Could not resolve host: cnonce="efe293d91af89df6" ^

C:\Users\adams> -H "Accept: /" ^ More? -H "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.75 Safari/537.36" ^ More? -H "X-Requested-With: XMLHttpRequest" ^ More? -H "Referer: http://192.168.1.160/index.html?lang=en" ^ More? -H "Accept-Language: en-US,en;q=0.9" ^ More? -H "Cookie: SRG-X120_viewsize-pulldown=x1; SRG-X120_volume-slider=1.00" ^ More? --compressed ^ More? --insecure

marklagendijk commented 4 years ago

It is possible to create a script that consists of multiple commands, and call that from the OBS plugin. In Windows this is called a batch file, and has the .cmd extension. However, getting that too work will be non-trivial (you need scripting experience to be able to create something like that).

Does your camera happen to support ONVIF? If it does you can try this approach.

kadams79 commented 4 years ago

Yeah, creating a script is certainly out of my league. Unfortunately, based on everything I've read so far, the camera does not support ONVIF. Sony did get back with me though and recommended I try using the command, "http://:@/command/presetposition.cgi?PresetCall=1" in Microsoft Edge since it supports Digest Authentication directly. I did so and the camera responds. I also tried the command in Firefox and it works there as well. It still doesn't work in OBS though so I'm guessing that OBS does not currently support Digest Authentication directly. I could still be doing something incorrectly though so please correct me if I'm wrong. Thanks for all your help.

marklagendijk commented 4 years ago

It is not about what OBS supports, since with my script you can execute any command. The question is how to execute the correct command via curl.

I think I found out how:

curl  http://192.168.1.160/command/presetposition.cgi?PresetCall=1 --digest -u admin:password123

Note: be sure to first test / tweak the command from the commandline until it works, before trying it via OBS.

kadams79 commented 4 years ago

Just tried the command and it works like a charm! I've tried it in OBS with multiple presets and it works every time. Thanks for all your help and your patience with my ignorance.

marklagendijk commented 4 years ago

Nice! I'll add it to the documentation. Please leave a rating / review on the forum: https://obsproject.com/forum/resources/scene-execute-command.1028/