Docs - Examples - scheduled-tasks
This script:
- Connects to an ATEM switcher
- After connection:
- Shows some switcher settings
- (optional, commented) Changes some settings
- From that point on:
- Watches changes in
PVW
/PGM
/DSK1
- Starts running a scheduled task every n seconds
- Randomly changes
PVW
/PGM
- Randomly forces a
CUT
- Randomly toggles
DSK1
- Randomly changes
- Watches changes in
$ python3 scheduled-tasks.py -h
[Tue Nov 24 22:55:31 2020] PyATEMMax demo script: scheduled-tasks
usage: scheduled-tasks.py [-h] [-m MIXEFFECT] [-i INTERVAL] ip
positional arguments:
ip switcher IP address
optional arguments:
-h, --help show this help message and exit
-m MIXEFFECT, --mixeffect MIXEFFECT
select mix effect (0/1), default 0
-i INTERVAL, --interval INTERVAL
wait INTERVAL seconds between scheduled actions,
default: 3.0
$ python3 scheduled-tasks.py 192.168.1.111
[Tue Dec 1 04:15:02 2020] PyATEMMax demo script: scheduled-tasks
04:15:02.994 INFO [PyATEMMax-demo] PyATEMMax demo script starting
04:15:02.994 INFO [PyATEMMax-demo] Initializing switcher
04:15:02.996 INFO [ATEMMax] Starting connection with ATEM switcher on 192.168.1.111
04:15:02.996 INFO [ATEMMax] Connecting for the first time
04:15:02.996 INFO [PyATEMMax-demo] Waiting for connection
04:15:02.997 INFO [ATEMMax] Sending HELLO packet
04:15:03.003 INFO [ATEMMax] Connected to switcher
04:15:03.035 INFO [ATEMMax] Initialization completed.
04:15:03.045 INFO [PyATEMMax-demo] Connected, initializing switcher settings
04:15:03.045 INFO [PyATEMMax-demo] No warnings from the switcher.
04:15:03.045 INFO [PyATEMMax-demo] videoMode format: f1080p50
04:15:03.045 INFO [PyATEMMax-demo] audioMixer master volume: 0.0dB
04:15:03.045 INFO [PyATEMMax-demo] audioMixer input1 volume: 0.0dB
04:15:03.045 INFO [PyATEMMax-demo] Starting scheduler (every 1.0s)
04:15:03.046 INFO [PyATEMMax-demo] Listening...
04:15:03.046 INFO [PyATEMMax-demo] PGM [6: input6] (CAM2: Camera 2 - Adrià)
04:15:03.046 INFO [PyATEMMax-demo] PVW [3: input3] (BBTY: Backdrop Beauty)
04:15:03.046 INFO [PyATEMMax-demo] DSK1 OFF
04:15:04.076 INFO [PyATEMMax-demo] PVW [2: input2] (INTW: Backdrop Interview)
04:15:05.074 INFO [PyATEMMax-demo] PVW [1000: colorBars] (Bars: Color Bars)
04:15:06.071 INFO [PyATEMMax-demo] PGM [2002: color2] (Col2: Color 2)
Code walkthrough
Start with the usual initial steps (explained in Examples)
In this case, to prepare the list of sources to be managed, the PyATEMMax.ATEMVideoSources
constant list is used to avoid writing the raw ATEM videoSourceId
.
At this point, startScheduler()
and timerFunc()
are defined, to manage a basic scheduler using a Python Timer object:
The showSwitcherSettings()
function will be called when the connection is established and allows to show initial info from the switcher.
The changeSwitcherSettings()
function will be called when the connection is established and allows to set some initial values.
Note that all code inside this function is commented… just in case. Feel free to uncomment and change everything, play with it!
The doScheduledTasks()
function is the one being periodically called.
In this case:
- Either
PGM
orPVW
will be changed to a random value (50% chances each) - A
CUT
will be randomly forced (10% chances) DSK1
wil be randomly toggled (30% chances)
The main()
function contains the startup initialization and the code to watch for changes:
In this case we find a switcher.setLogLevel(logging.INFO)
, which will activate the logging output of the library (that’s why you see that much messages on the console), try to set it to DEBUG
and see what happens.
This is the first example in which waitForConnection()
is called without parameters. By default, this function waits indefinitely until the switcher is fully connected. It means that if you start this script and wait a week before you turn your switcher on, the script will wait until it connects. It’s really stubborn :)
At this point, the initialization methods are called (the code was moved outside main()
to keep it clean)
Then, the scheduler is started.
From this point on, the script uses the provided variables
PGM
input:switcher.programInput[mixeffect].videoSource
PVW
input:switcher.previewInput[mixeffect].videoSource
DSK1
switcher.downstreamKeyer[dsk].onAir
- See how
switcher.dsks.dsk1
is used instead of the value0
- See how
Note that to show the ATEM source value from programInput[].videoSource
the script uses lastPGM.value
. This is because lastPGM
is an ATEMConstant
and it would print its name otherwise.
In this script, the logging
module has been initialized before calling main()
to demonstrate the logging capabilities of the library.