diy ptz camera control

Noah Vogt 6b6559117a init commit 10 months ago
LICENSE 6b6559117a init commit 10 months ago
README.md 6b6559117a init commit 10 months ago
switch.py 6b6559117a init commit 10 months ago

README.md

diy_ptz_switch

For a typical livestream production environment consisting of 2 ptz cameras and one joystick / controller board, most commercial options like the Skaarhoj PTZ Fly are

  • expensive
  • offer no API
  • nearly impossible to automate
  • offer no rs485 serial connection support (basically only IP via RJ45)

To fix this, I thought why not connect the ptz cameras via their rs485 to a rs485 <-> usb serial converter to a computer and use a server that selects which ptz camera is sent the current joystick input. It also has a http api that allows seleting the current camera target and ptz commands like save_preset or goto_preset.

See the following ascii diagram for the architecture.

                        +------------------------+
                        |      PTZ Joystick      |
                        |  (Pelco-D via RS-485)  |
                        +------------------------+
                                     |
                                     v
                     +--------------------------------+
                     |   /dev/ttyUSBX (JOYTICK_PORT)  |
                     |   [async serial reader]        |
                     +--------------------------------+
                                     |
                                     v
                      +------------------------------+
                      |  Python asyncio PTZ Router   |
                      |------------------------------|
                      | - Parse Pelco-D packets      |
                      | - current_target: cam1/cam2  |
                      | - Forward to selected cam    |
                      | - Handle HTTP API requests   |
                      |                              |
                      |   +-----------------------+  |
                      |   |     HTTP API (Flask)  |  |
                      |   |-----------------------|  |
                      |   | POST /set_target      |  |
                      |   | GET  /status          |  |
                      |   | POST /goto_preset     |  |
                      |   | POST /save_preset     |  |
                      |   +-----------------------+  |
                      +------------------------------+
                                     |
                +--------------------+---------------------+
                |                                          |
                v                                          v
  +-----------------------------+         +-----------------------------+
  |  /dev/ttyUSBY (CAM1_PORT)   |         |  /dev/ttyUSBZ (CAM2_PORT)   |
  |  [async serial writer]      |         |  [async serial writer]      |
  +-----------------------------+         +-----------------------------+
                |                                          |
                v                                          v
     +----------------------+                    +----------------------+
     |   PTZ Camera 1       |                    |   PTZ Camera 2       |
     +----------------------+                    +----------------------+