Automating OBS from PowerShell Script

Open Broadcaster Software (OBS) is a great, open source, product that can be used to capture, record and stream a mixture of sources. With support for Decklink cards, it is easy to include the output of an ATEM vision mixer.

Using Windows PowerShell would let you automate OBS using XKeys or a Midi device and even coordinate switching ATEM inputs or playing out graphics from CasparCG at the same time (see my other PowerShell add-ons in https://ianmorrish.wordpress.com/v-ise/)

What you need:

Web Socket add-in for OBS https://obsproject.com/forum/resources/obs-websocket-remote-control-of-obs-studio-made-easy.466/download?version=1124

The following files in your Documents\WindowsPowerShell directory (remember to un-block them after downloading)

WebSocket-Sharp.dll https://1drv.ms/u/s!ApGpqMMpRLhijrNWU5eDhO1PzJZkAg

NewtonSoft.Json.dll https://1drv.ms/u/s!ApGpqMMpRLhijrNYgWt2nKGOqx2XGQ

OBS-WebSocket-Net.dll https://1drv.ms/u/s!ApGpqMMpRLhijrNXDV9u52u6CWbdbQ

Sample script

Add-Type -path ‘documents\WindowsPowerShell\obs-websocket-dotnet.dll’
$obs = new-object OBSWebsocketDotNet.OBSWebsocket
$obs.Connect(“ws://127.0.0.1:4444”, “password”)
$scenes = $obs.ListScenes()
$scenes
$obs.SetCurrentScene(“Intro”)
#Loop through each scene
$loop = $true; $i =1
Do{
$obs.SetCurrentScene($scenes[$i].Name)

if($i -eq $scenes.Count){$i=1}
   else{$i++}
Start-Sleep 5
}While($loop)
#Other commands
$obs.ToggleStreaming()
$obs.ToggleRecording()

All methods and properties for OBS Websocket:
OBSCommands

Automate Behringer X32 mixers from PowerShell using OSC

Here is a simple example using the OSC DLL with Windows PowerShell to control the Behringer X32 range of audio mixers.

I have tried this with the XR12 but will also work with any of the X Air XR16, XR18 and X32 models.

Sample script showing some basic settings:

# Connection Behringer X32
add-type -path ‘C:\Users\imorrish\OneDrive\PowerShell\OSC\SharpOSC.dll’
$sender = new-object SharpOSC.UDPSender “192.168.1.66”, 10023

#Mute channels 1 – 5
1..5 |% {$message = new-object SharpOSC.OscMessage “/ch/0$($_)/mix/on”, 0;$sender.Send$message)}

#Mute group 1
$message = new-object SharpOSC.OscMessage “/config/mute/1”, 0;
$sender.Send($message)

#Label channel name
$message = new-object SharpOSC.OscMessage “/ch/04/config/name”, “Lead Singer”
$sender.Send($message)

#fade up from 0 (0-1024 max)
1..200 | % {$message = new-object SharpOSC.OscMessage “/ch/04/mix/fader”, ($_ *4); sender.Send($message);Start-Sleep -Milliseconds 1}

It would be easy to use the faders on a midi device like my demo for controlling the ATEM audio levels.

See the following link for all OSC commands that are supported.
http://behringerwiki.music-group.com/index.php?title=OSC_Remote_Protocol#Client_initiated_messages_.28client_.E2.86.92_X32_console.29

And Channel specific controls http://behringerwiki.music-group.com/index.php?title=Channel_(/ch)_data

Snapshot ATEM Mixer settings with PowerShell

This is a work in progress and will be added to ISE as a standard menu to provide selective backup/restore of ATEM settings like the BMD Software Panel but using JSON format rather than XML.

Example snippet of code for the ME properties:

add-type -path ‘C:\Users\imorrish\Documents\WindowsPowerShell\SwitcherLib.dll’
$atem = New-Object SwitcherLib.Switcher(“192.168.1.8”)
$atem.Connect()
$ME = $atem.GetMEs()
$me1SnapShot = $me[0] |select-object -property * -ExcludeProperty “me” | ConvertTo-Json

Which produces the following:

{
    “Program”: 1,
    “Preview”: 1,
    “TransitionStyle”: “Mix”,
    “NextTransitionStyle”: “Mix”,
    “InTransition”: false,
    “TransitionFramesRemaining”: 25,
    “TransitionPosition”: 0,
    “FadeToBlackRate”: 25,
    “InFadeToBlack”: false,
    “FadeToBlackInTransition”: null,
    “FadeToBlackFullyBlack”: false,
    “PreviewLive”: false,
    “PreviewTransition”: false,
    “TransitionSelection”: 1,
    “MixRate”: 25,
    “WipeBorderSize”: 0,
    “WipeBorder”: 2001,
    “WipeReverse”: 0,
    “WipeFlipFlop”: 0,
    “WipeSoftness”: 0,
    “WipeSymmetry”: 0.5,
    “WipeHorizontalOffset”: 0.5,
    “WipeVerticalOffset”: 0.5,
    “TransitionWipePattern”: “DiamondIris”,
    “DVERate”: 25,
    “DVELogoRate”: 25,
    “DVEeReverse”: 0,
    “DVEFlipFlop”: 0,
    “DVETransitionStyle”: “PushRight”,
    “DVEInputFill”: 3010,
    “DVEInputCut”: 3011,
    “DVEEnableKey”: 1,
    “DVEClip”: 0.5,
    “DVEGain”: 0.7,
    “DIPRate”: 25,
    “DIPInput”: 2001,
    “index”: 1
}

I still have to sort out some inconsistencies with properties that should be Boolean and making the internal class private.

ATEM MultiView configuration options updated

Now that I have a Television Studio HD I feel like one of the big boys. I have added the ability to set VU options and routing of inputs to a window of the MultiView.

This means you could in theory do VU follow window via X-Keys. I often have more than 8 inputs to preview so I can assign 2 or more of the windows to toggle between different inputs and enable/disable the VU meters depending on whether they are relevant for the input or not.

$mv=$atem.GetMultiViews()

$mv[0].Layout = “Top”

$mv[0].CanRouteInputs

$mv[0].WindowCount

$mv[0].CanToggleSafeArea

$mv[0].SupportsProgramPreviewSwapp

$mv[0].SafeAreaEnabled=1

$mv[0].ProgramPreviewSwapped=1

$mv[0].VuMeterOpacity=.7

$mv[0].SetVuMeterEnabled(7,2)

$mv[0].SetWindowInput(9,3020) #MP2 in last window

If you have a 2 M/E then $mv[1] would also exist

I have added a GetSwitcherLibVersion method so I can start adding a “requires” function to my scripts and modules.

$atem.GetSwitcherLibVersion() needs to be 2.9.6.0 for the sample above to work.

There is still some inconsistency in the way I have implemented the properties. Some values are bool and some are int 0 or 1 for enabled or disabled settings. Haven’t decided which way I’ll go. The ATEM API is a bit strange, documented properties that are Bool in the API actually output as Int32 in C#

ATEM SuperSource support in PowerShell

I have not been able to test this except for a brief confirmation that the object is returned. I ran out of time while I had access to a 2 M/E so have implemented all the SuperSource methods and properties as per the API.

I should be able to test this and fix any issues next weekend.
Update: GetSuperSourceBox causes a memory error, requires some more work…

Update: It is now working 🙂

#Get the SuperSource (only one - at the moment)
$Supersources = $atem.GetSuperSource()
$Supersource[0] #this will show all properties and methods of SuperShource

$Supersources[0].InputCut = 3011 # MediaPlayer1 Cut
$Supersources[0].InputFill = 3010 #MediaPlayer1 Fill

#Get the SuperSource boxes
$SSBox = $Atem.GetSuperSourceBox()
$SSBox[0] #this will show all methods and properties of the first box

$SSBox[0].InputSource=2
$SSBox[1].InputSource=3
$SSBox[0].Enabled=1
$SSBox[1].Enabled=1 

This dll is now the current version of SwitcherLib.dll and is available from the downloads page.
I’m looking forward to creating some demos that show how to move the SuperSource boxes around while they are live

Adjust ATEM USK Chroma Key settings with Midi Device

I found it a bit frustrating trying to set up the chroma key using the Blackmagic Design ATEM Software panel. Trying to change the values using the mouse while looking at the preview monitor was not very efficient.

So I used a MIDI device that has some rotary encoders and PowerShell to make the adjustments. See the video below for a demo

Using this almost made it fun playing with the options.

The Behringer CMD DC-1 seems to be on special at https://www.bhphotovideo.com/c/search?Ntt=cmd+dc-1

This was automated using Windows PowerShell but could have just as easily been done with JustMacros.

You can find example code for this here… https://gist.github.com/imorrish/5614d4369ca111f7096aff31d27e4d98

Description of the chroma key values for Hue, Gain, Y Suppress, Lift and Narrow from the ATEM manual:

Chroma Key parameters

Automating Characterworks from PowerShell

I saw a question on the BMD forum asking about the possibility of triggering an action in Characterworks. A quick check of the Characterworks online help showed that the CW Remote Control Server listens to requests on port 5201 and accepts HTTP POST requests containing JSON-encoded commands.

It would be easy to define a keyboard shortcut or X-Keys button that initiated the Characterworks action and switched the input, or enabled a key, on the Blackmagic ATEM using a PowerShell script.

Below is a simple example PowerShell script showing how to send a command to Characterworks:

$url = "http://localhost:5201/"
$command = '{ "action" : "play_motions", "motions" : [ "Motion 1" ], "channel" : "live1" }'

$bytes = [System.Text.Encoding]::ASCII.GetBytes($command)
$web = [System.Net.WebRequest]::Create($url)
$web.Method = "POST"
$web.ContentLength = $bytes.Length
$web.ContentType = "application/x-www-form-urlencoded"
$stream = $web.GetRequestStream()
$stream.Write($bytes,0,$bytes.Length)
$stream.close()

$reader = New-Object System.IO.Streamreader -ArgumentList $web.GetResponse().GetResponseStream()
$reader.ReadToEnd()
$reader.Close()

It would be easy to wrap this in a function to take the motions and channel values as parameters and return the response.