Metropolis Microservices/RidgeRun Services/PTZ: Difference between revisions

From RidgeRun Developer Wiki
No edit summary
 
(56 intermediate revisions by 2 users not shown)
Line 1: Line 1:
<noinclude>
<noinclude>
{{Metropolis Microservices/Head|previous=Getting_Started/Introduction|next=Application_services|metakeywords=Metropolis|title=RidgeRun PTZ Microservices|metadescription=This page provides a general overview of the PTZ RidgeRun Service}}
{{Metropolis Microservices/Head
|previous=https://developer.ridgerun.com/wiki/index.php/Metropolis_Microservices/RidgeRun Services
|next=https://developer.ridgerun.com/wiki/index.php/Metropolis_Microservices/RidgeRun Services/Detection
|metakeywords=Metropolis
|title=RidgeRun PTZ Microservice
|metadescription=This page provides a general overview of the PTZ RidgeRun Service
}}
</noinclude>
</noinclude>




PTZ Microservice is a custom microservice developed by RidgeRun. What makes it special is that it allows you to navigate a '''360-degrre''' video through PTZ. PTZ are the controls available that can be updated at any time during execution, and it means:
PTZ Microservice is a microservice developed by RidgeRun. It allows you to navigate a '''360-degree''' video through pan, tilt, and zoom (PTZ).
* PAN (horizontal)
* TILT (vertical)
* ZOOM (magnify or decrease the view of the image)


This microservice leverages the RidgeRun [[ Spherical Video PTZ | Spherical Video PTZ ]] to make possible the selection of your region of interest within the sphere.  
This microservice leverages the RidgeRun [[ Spherical Video PTZ | Spherical Video PTZ ]] to make possible the selection of your region of interest within the sphere.  


Briefly, this service gets an RTSP stream, performs the PTZ depending on the user instructions, and then returns as the output the transformed stream using the same protocol, RTSP.
Briefly, this service works in this way:
# Gets an RTSP stream as an input
# Performs the PTZ depending on user instructions
# Returns the transformed video as a separate RTSP stream


[[File:ptz_microservice.jpg|600px|center|thumb| Ridgerun's Detection Microservice General Idea]]


==API documentation==


Usually, in the Microservices architectures the communication  with the outside world is handle through well-defined APIs. This APIs specify methods, data formats, and protocols for interaction.
{{Colored box|background-content-color=#EDF1F7|background-title-color=#6586B9|title-color=#FFFFFF|title='''TL;DR'''|icon=notice-icon-white.png
  |style=overflow:hidden;
  |content=
You can run this microservice with the following command:


In our PTZ Microservice, the API documentation can be found here, there you can the list of the available requests.
<syntaxhighlight lang="bash">
docker run --runtime nvidia -it --privileged --net=host --ipc=host --name ptz-service  ridgerun/ptz-service:latest --host=0.0.0.0
</syntaxhighlight>


{{Review|We need to point this to the official documentation, not the repo|efernandez}}
This will run PTZ in port 5020
{{Review|We could include here the link to the project documentation|efernandez}}


Then, see the PTZ output stream with:
<syntaxhighlight lang="bash">
vlc rtsp://BOARD_IP:5021/ptz_out
</syntaxhighlight>


}}


{{Colored box|background-content-color=#F0FBFF|background-title-color=#0086B9|title-color=#FFFFFF|title='''Service Documentation'''|icon=notice-icon-white.png
  |style=overflow:hidden;
  |content=
* [https://ridgerun.github.io/ptz-service/ Service Documentation]
* [https://ridgerun.github.io/ptz-service/api.html Api Documentation]
<br>
See [[Metropolis Microservices/Tools/API Usage|API Usage]] for an example of how to use the API documentation to control the service
}}


==Running the service==
==Running the service==


{{Review|Here you can specify that the service can be run directly into the host or using docker. Then describe both options|efernandez}}
PTZ Microservice can run as a standalone application or as a docker image. The docker approach has some benefits, for example: since the application is encapsulated along with its dependencies, fewer conflicts arise in the deployment.  


PTZ Microservice can run as a standalone application or as docker image. The docker approach has some benefits, for example: since the application is encapsulated along with its dependencies, less conflicts arise in the process of deployment.  
===As a docker image===
 
Before starting with docker support make sure you have Nvidia runtime in your system. Follow [https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/latest/install-guide.html#configuration these instructions] to have docker up and running in your Jetson Board.
 
====Use prebuild image ====
 
For convenience, a docker image is available in dockerhub which as of today is available for Jetpack 6.0. Use the following command to pull it.
 
<syntaxhighlight lang="bash">
docker pull ridgerun/ptz-service
</syntaxhighlight>
 
====Build your image (Dockerfile)====
 
If you instead want to build your image, a convenient Dockerfile is included as part of the service.
 
First, we need to prepare the context and include all the projects that are needed by the service.
 
<syntaxhighlight lang="bash">
mkdir ptz-context
cd ptz-context
git clone https://gitlab.ridgerun.com/open/ridgerun-microservices/ptz.git
git clone https://gitlab.ridgerun.com/open/ridgerun-microservices/rrms-utils.git
# Include gst-cuda, gst-rr-panoramaptz, gst-rtsp-sink, and libpanorama
</syntaxhighlight>
 
The context directory should look like this:
 
<syntaxhighlight lang="bash">
ptz-context/
.
├── gst-cuda
├── gst-rr-panoramaptz
├── gst-rtsp-sink
├── libpanorama
├── ptz
└── rrms-utils
</syntaxhighlight>
 
Then, build the container image running the following command from the folder containing the Dockerfile and context directory:
 
<syntaxhighlight lang="bash">
sudo docker build \
--network=host \
-f ptz-context/ptz/docker/Dockerfile \
-t ridgerun/ptz-service:latest ptz-context/
</syntaxhighlight>
 
Change '''ptz-context''' to your context's path and the tag (-t) to the name you want to give to your image.
 
====Launch the container====
 
Either you pulled the prebuilt image or you built your own, a docker container can be launched by running the following command:
 
<syntaxhighlight lang="bash">
docker run --runtime nvidia -it --privileged --net=host --ipc=host --name ptz-service  ridgerun/ptz-service:latest
</syntaxhighlight>
 
You can modify the name you want to give to your container with the option '''--name'''.
 
Here we are creating a container called '''ptz-service''' that will start the ptz-service application in the default address and port and use the default output resolution. If a different address, port, or output resolution has to be used, you can do it by running:
 
<syntaxhighlight lang="bash">
docker run --runtime nvidia -it --privileged --net=host --ipc=host --name ptz-service  ridgerun/ptz-service:latest --host=HOST --port=PORT --ptz-window-size=PTZ_WINDOW_SIZE
</syntaxhighlight>


===As a standalone application===
===As a standalone application===


Before running the service, you should make sure you have all the dependencies installed. The intructions to do it can be found here: [https://developer.ridgerun.com/wiki/index.php/Spherical_Video_PTZ/User_Guide/Building_and_Installation Spherical Video PTZ Building and Installation]
The service can also be run directly into your jetson device.


Then you have to clone into your device the repository project, available [https://gitlab.ridgerun.com/ridgerun/rnd/jetson-microservices-and-genai/ptz here]
Before running the service, you should make sure you have all the dependencies installed. The instructions to do it can be found here: [https://developer.ridgerun.com/wiki/index.php/Spherical_Video_PTZ/User_Guide/Building_and_Installation Spherical Video PTZ Building and Installation] and: [https://developer.ridgerun.com/wiki/index.php/GstRtspSink_-_Building_the_plug-in GstRtspSink plugin]
 
 
Then you have to clone into your device the repository project:
 
<syntaxhighlight lang="bash">
git clone https://github.com/RidgeRun/ptz-service.git
</syntaxhighlight>


The project is configured (via setup.py) to install the service with the name '''ptz'''. So to install it run:
The project is configured (via setup.py) to install the service with the name '''ptz'''. So to install it run:


<pre>
<syntaxhighlight lang="bash">
cd ptz
pip install .
pip install .
</pre>
</syntaxhighlight>


Then you will have the service with the following options:
Then you will have the service with the following options:


<pre>
<syntaxhighlight lang="bash">
usage: ptz [-h] [--port PORT] [--host HOST]
usage: ptz [-h] [--port PORT] [--host HOST] [--ptz-window-size PTZ_WINDOW_SIZE]


options:
options:
-h, --help   show this help message and exit
  -h, --help           show this help message and exit
--port PORT Port for server
  --port PORT           Port for server
--host HOST Server ip address
  --host HOST           Server ip address
</pre>
  --ptz-window-size PTZ_WINDOW_SIZE
                        Size of the PTZ output window in pixels. The final resolution will be (Size x Size)
</syntaxhighlight>


===As a docker image===
After this, the service will be available under the name '''ptz'''.


Before starting with docker support make sure you have nvidia runtime in your system. Follow [https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/latest/install-guide.html#configuration these instructions] to have docker up and runing in your Jetson Board.
==Examples==


As we mentioned at the beginning of the wiki. If you see PTZ Microservice as a black box, with an input and an output. It works in this way:


====Use prebuild image (dockerhub) ====
#Get an RTSP stream as the input.
#Performs the PTZ in the stream, depending on the user's instructions.
#Returns the stream transformed using the same protocol, RTSP, as the output.


docker pull
RidgeRun developed a convenient package called rrms_utils that makes the interaction with our microservices easier.


{{Review|The service will be hosted in dockerhub, when uploaded we will update this section|efernandez}}
{{Colored box|background-content-color=#EDF1F7|background-title-color=#6586B9|title-color=#FFFFFF|title='''Note'''|icon=notice-icon-white.png
  |style=overflow:hidden;
  |content=
You can get and install '''rrms-utils''' by running:


<syntaxhighlight lang="bash">
git clone https://github.com/RidgeRun/rrms-utils.git
cd rrms-utils
pip install .
</syntaxhighlight>
}}


====Build your own image (Dockerfile)====
An example of a typical application using rrms_utils to control the PTZ microservice follows.


In the example above we assume the following:


* A 360-degree RTSP Stream is being played in the URI: rtsp://192.168.100.20:4000/sream_in,
* The PTZ microservice is running in: (IP) host=192.168.100.15, port=7000


===Build the container===
<syntaxhighlight lang="python">
from rrms_utils.ptz import PTZ
from rrms_utils.models.ptz.stream import Stream
from rrms_utils.models.ptz.position import Position
from rrms_utils.models.ptz.position import Zoom


We can build the ptz microservice container using the Dockerfile in the docker directory. This includes a base NVIDA image and the dependencies to run the ptz microservice application.


{{Review|Add link to the repository|mortigoza}}
# Create client (by default will talk to address 127.0.0.1 and port 5020)
# Change the host and port for the IP address and port of the service.
client = PTZ(host=192.168.100.15, port=7000)


First, we need to prepare the context directory for this build, please create a directory and include all the needed repositories (listed below). The Dockerfile will look for all the source code in the context directory and copy them to the container.


<pre>
# Configure Stream
ptz-context/
stream = Stream(in_uri="rtsp://192.168.100.20:4000/sream_in", out_port=8000, out_mapping="stream_out")
.
set_stream_result = client.set_stream(stream)
├── gst-cuda
├── gst-rr-panoramaptz
├── gst-rtsp-sink
├── libpanorama
├── ptz
└── rrms-utils
</pre>


Then build the container image running the the following command from the folder containing the Dockerfile and context directory:
if not set_stream_result:
    print("Something went wrong")


<pre>
# Perform PTZ
sudo docker build \
--network=host \
-f Dockerfile \
-t ridgerun/ptz-service:latest ptz-context/
</pre>


Change '''ptz-context''' to your context's path and the tag (-t) to the name you want to give to your image.
#Change pan and tilt
position = Position(pan=50, tilt=20)
set_position_result = client.set_position(position)


===Launch the container===
if not set_position_result:
    print("Something went wrong")


The container can be launched by running the following command:
# Change zoom
zoom = Zoom(zoom=0.5)
set_zoom_result = client.set_zoom(zoom)


if not set_zoom_result:
    print("Something went wrong")


<pre>
</syntaxhighlight>
sudo docker run --runtime nvidia -it --privileged --net=host --ipc=host --name ptz-service  ridgerun/ptz-service:latest
</pre>


You can modify the name you want to give to your container with the option '''--name'''.
The previous example will create an output stream at port 8000 with mapping stream_out. To display it you can use a player like VLC:


Here we are creating a container called '''ptz-service''' that will start the ptz-service application in the default address and path. If a different address and port have to be used, you can do it by running:
<syntaxhighlight lang="bash">
vlc rtsp://BOARD_IP_ADDRESS:8000/stream_out
</syntaxhighlight>


<pre>
Just replace '''BOARD_IP_ADDRESS''' with the IP address of the board running the service.
sudo docker run --runtime nvidia -it --privileged --net=host --ipc=host --name ptz-service ridgerun/ptz-service:latest --host=HOST --port=PORT
</pre>


===Code WalkTrough===


Once installed, we can use the rrms_utils module to create a client that "talks" to the server created into the ptz microservices.


First, we have to import the required models and modules:


<syntaxhighlight lang="python">
from rrms_utils.ptz import PTZ
from rrms_utils.models.ptz.stream import Stream
from rrms_utils.models.ptz.position import Position
from rrms_utils.models.ptz.position import Zoom
</syntaxhighlight>


Then we create the "client" using this command:


<syntaxhighlight lang="python">
# Create client
client = PTZ(host=192.168.100.15, port=7000)
</syntaxhighlight>


By default, it will talk to address 127.0.0.1 and port 5020. In this example, we are configuring it to talk to address 192.168.100.15 and port 7000


==Examples==
Here we prepare the "stream" model we want to configure into the PTZ Microservice:
Once you have a ptz-microservices-docker running you can run and test its functionality:


{{Review|For this section you can start by assuming there is an RTSP stream in a given location. Then use the client in rrms_utils to show how you can configure the stream and change the pan, tilt and/or zoom of the video|efernandez}}
<syntaxhighlight lang="python">
# Configure Stream
stream = Stream(in_uri="rtsp://192.168.100.20:4000/sream_in", out_port=8000, out_mapping="stream_out")
</syntaxhighlight>


* in_uri is the URI where the PTZ Microservice will be "listening" to get the incoming RTSP stream.
* out_port is the port where the  PTZ Microservice is going to locate its output (RTSP stream transformed with the PTZ specified), in this case, port 8000
* out_mapping is the mapping where the  PTZ Microservice is going to locate its output (RTSP stream transformed with the PTZ specified), in this case, /stream_out


====Run the ptz microservice====
Once the "stream" model is ready, we send the request to the PTZ Microservice, using this command:
<pre>
<syntaxhighlight lang="python">
ptz --host=192.168.100.15 –port=5010
#Send request to set stream in PTZ Microservice
</pre>
set_stream_result = client.set_stream(stream)


====Create an stream RTSP source using this pipeline:====
if not set_stream_result:
    print("Something went wrong")
</syntaxhighlight>


<pre>
gst-launch-1.0 videotestsrc pattern=0 ! video/x-raw,width=640,height=480 ! queue ! videoconvert ! queue ! videoscale ! video/x-raw,width=1920,height=1080,format=I420 ! queue ! x264enc key-int-max=30 option-string="keyint=30:min-keyint=30:repeat-headers=1" bitrate=10000 ! video/x-h264, mapping=/stream_in ! perf ! rtspsink service=7000  -v
</pre>


(you can modify th IPs, ports, and mapping depending on your needs. Just make sure you configure the other pipelines to match them)
Using the same logic as in the stream. We can send requests to update pan, tilt, and zoom, using these commands:
<syntaxhighlight lang="python">
# Perform PTZ


====Set and update the desired ptz values via the API following the format specified in [https://gitlab.ridgerun.com/ridgerun/rnd/jetson-microservices-and-genai/apis/-/blob/develop/ptz/openapi.yaml?ref_type=heads here]:====
#Set the Position model to send
position = Position(pan=50, tilt=20)


Set the input URI, the output port, and the output mapping (in this example we assume that the RTSP source is being played from the same IP as the ptz microservice):
#Send the request to change pan and tilt
set_position_result = client.set_position(position)


<pre>
if not set_position_result:
curl -X PUT -H "Content-Type: application/json" -d '{"in_uri": "rtsp://192.168.100.15:7000/stream_in","out_port": "8000","out_mapping": "/stream_out"}' http://192.168.100.15:5010/stream
    print("Something went wrong")
</pre>


(you can modify th IPs, ports, and mapping depending on your needs. Just make sure you configure the other pipelines to match them)
#Set the Zoom model to send
zoom = Zoom(zoom=0.5)


Using the client ****
#Send the request to change the zoom
set_zoom_result = client.set_zoom(zoom)


if not set_zoom_result:
    print("Something went wrong")
</syntaxhighlight>


====Receive the output result via RTSP using this pipeline:====


<pre>
Finally, we can see the output result with VLC using the commands:
gst-launch-1.0 rtspsrc location=rtsp://192.168.100.15:8000/stream_out ! queue ! decodebin ! queue ! videoconvert ! autovideosink -v
</pre>


(you can modify th IPs, ports, and mapping depending on your needs. Just make sure you configure the other pipelines to match them)
<syntaxhighlight lang="bash">
#Receive the PTZ output - RTSP Stream:
vlc rtsp://192.168.100.15:8000/stream_out
</syntaxhighlight>




<noinclude>
<noinclude>
{{Metropolis Microservices/Foot||}}
{{Metropolis Microservices/Foot
|previous=https://developer.ridgerun.com/wiki/index.php/Metropolis_Microservices/RidgeRun Services
|next=https://developer.ridgerun.com/wiki/index.php/Metropolis_Microservices/RidgeRun Services/Detection
}}
</noinclude>
</noinclude>

Latest revision as of 21:46, 3 October 2024






PTZ Microservice is a microservice developed by RidgeRun. It allows you to navigate a 360-degree video through pan, tilt, and zoom (PTZ).

This microservice leverages the RidgeRun Spherical Video PTZ to make possible the selection of your region of interest within the sphere.

Briefly, this service works in this way:

  1. Gets an RTSP stream as an input
  2. Performs the PTZ depending on user instructions
  3. Returns the transformed video as a separate RTSP stream
Ridgerun's Detection Microservice General Idea


TL;DR

You can run this microservice with the following command:

docker run --runtime nvidia -it --privileged --net=host --ipc=host --name ptz-service  ridgerun/ptz-service:latest --host=0.0.0.0

This will run PTZ in port 5020

Then, see the PTZ output stream with:

vlc rtsp://BOARD_IP:5021/ptz_out
Service Documentation


See API Usage for an example of how to use the API documentation to control the service

Running the service

PTZ Microservice can run as a standalone application or as a docker image. The docker approach has some benefits, for example: since the application is encapsulated along with its dependencies, fewer conflicts arise in the deployment.

As a docker image

Before starting with docker support make sure you have Nvidia runtime in your system. Follow these instructions to have docker up and running in your Jetson Board.

Use prebuild image

For convenience, a docker image is available in dockerhub which as of today is available for Jetpack 6.0. Use the following command to pull it.

docker pull ridgerun/ptz-service

Build your image (Dockerfile)

If you instead want to build your image, a convenient Dockerfile is included as part of the service.

First, we need to prepare the context and include all the projects that are needed by the service.

mkdir ptz-context
cd ptz-context
git clone https://gitlab.ridgerun.com/open/ridgerun-microservices/ptz.git
git clone https://gitlab.ridgerun.com/open/ridgerun-microservices/rrms-utils.git
# Include gst-cuda, gst-rr-panoramaptz, gst-rtsp-sink, and libpanorama

The context directory should look like this:

ptz-context/
.
├── gst-cuda
├── gst-rr-panoramaptz
├── gst-rtsp-sink
├── libpanorama
├── ptz
└── rrms-utils

Then, build the container image running the following command from the folder containing the Dockerfile and context directory:

sudo docker build \
--network=host \
-f ptz-context/ptz/docker/Dockerfile \
-t ridgerun/ptz-service:latest ptz-context/

Change ptz-context to your context's path and the tag (-t) to the name you want to give to your image.

Launch the container

Either you pulled the prebuilt image or you built your own, a docker container can be launched by running the following command:

docker run --runtime nvidia -it --privileged --net=host --ipc=host --name ptz-service  ridgerun/ptz-service:latest

You can modify the name you want to give to your container with the option --name.

Here we are creating a container called ptz-service that will start the ptz-service application in the default address and port and use the default output resolution. If a different address, port, or output resolution has to be used, you can do it by running:

docker run --runtime nvidia -it --privileged --net=host --ipc=host --name ptz-service  ridgerun/ptz-service:latest --host=HOST --port=PORT --ptz-window-size=PTZ_WINDOW_SIZE

As a standalone application

The service can also be run directly into your jetson device.

Before running the service, you should make sure you have all the dependencies installed. The instructions to do it can be found here: Spherical Video PTZ Building and Installation and: GstRtspSink plugin


Then you have to clone into your device the repository project:

git clone https://github.com/RidgeRun/ptz-service.git

The project is configured (via setup.py) to install the service with the name ptz. So to install it run:

cd ptz
pip install .

Then you will have the service with the following options:

usage: ptz [-h] [--port PORT] [--host HOST] [--ptz-window-size PTZ_WINDOW_SIZE]

options:
  -h, --help            show this help message and exit
  --port PORT           Port for server
  --host HOST           Server ip address
  --ptz-window-size PTZ_WINDOW_SIZE
                        Size of the PTZ output window in pixels. The final resolution will be (Size x Size)

After this, the service will be available under the name ptz.

Examples

As we mentioned at the beginning of the wiki. If you see PTZ Microservice as a black box, with an input and an output. It works in this way:

  1. Get an RTSP stream as the input.
  2. Performs the PTZ in the stream, depending on the user's instructions.
  3. Returns the stream transformed using the same protocol, RTSP, as the output.

RidgeRun developed a convenient package called rrms_utils that makes the interaction with our microservices easier.

Note

You can get and install rrms-utils by running:

git clone https://github.com/RidgeRun/rrms-utils.git
cd rrms-utils
pip install .

An example of a typical application using rrms_utils to control the PTZ microservice follows.

In the example above we assume the following:

  • A 360-degree RTSP Stream is being played in the URI: rtsp://192.168.100.20:4000/sream_in,
  • The PTZ microservice is running in: (IP) host=192.168.100.15, port=7000
from rrms_utils.ptz import PTZ
from rrms_utils.models.ptz.stream import Stream
from rrms_utils.models.ptz.position import Position
from rrms_utils.models.ptz.position import Zoom


# Create client (by default will talk to address 127.0.0.1 and port 5020)
# Change the host and port for the IP address and port of the service.
client = PTZ(host=192.168.100.15, port=7000)


# Configure Stream
stream = Stream(in_uri="rtsp://192.168.100.20:4000/sream_in", out_port=8000, out_mapping="stream_out")
set_stream_result = client.set_stream(stream)

if not set_stream_result:
    print("Something went wrong")

# Perform PTZ

#Change pan and tilt
position = Position(pan=50, tilt=20)
set_position_result = client.set_position(position)

if not set_position_result:
    print("Something went wrong")

# Change zoom
zoom = Zoom(zoom=0.5)
set_zoom_result = client.set_zoom(zoom)

if not set_zoom_result:
    print("Something went wrong")

The previous example will create an output stream at port 8000 with mapping stream_out. To display it you can use a player like VLC:

vlc rtsp://BOARD_IP_ADDRESS:8000/stream_out

Just replace BOARD_IP_ADDRESS with the IP address of the board running the service.

Code WalkTrough

Once installed, we can use the rrms_utils module to create a client that "talks" to the server created into the ptz microservices.

First, we have to import the required models and modules:

from rrms_utils.ptz import PTZ
from rrms_utils.models.ptz.stream import Stream
from rrms_utils.models.ptz.position import Position
from rrms_utils.models.ptz.position import Zoom

Then we create the "client" using this command:

# Create client 
client = PTZ(host=192.168.100.15, port=7000)

By default, it will talk to address 127.0.0.1 and port 5020. In this example, we are configuring it to talk to address 192.168.100.15 and port 7000

Here we prepare the "stream" model we want to configure into the PTZ Microservice:

# Configure Stream
stream = Stream(in_uri="rtsp://192.168.100.20:4000/sream_in", out_port=8000, out_mapping="stream_out")
  • in_uri is the URI where the PTZ Microservice will be "listening" to get the incoming RTSP stream.
  • out_port is the port where the PTZ Microservice is going to locate its output (RTSP stream transformed with the PTZ specified), in this case, port 8000
  • out_mapping is the mapping where the PTZ Microservice is going to locate its output (RTSP stream transformed with the PTZ specified), in this case, /stream_out

Once the "stream" model is ready, we send the request to the PTZ Microservice, using this command:

#Send request to set stream in PTZ Microservice
set_stream_result = client.set_stream(stream)

if not set_stream_result:
    print("Something went wrong")


Using the same logic as in the stream. We can send requests to update pan, tilt, and zoom, using these commands:

# Perform PTZ

#Set the Position model to send
position = Position(pan=50, tilt=20)

#Send the request to change pan and tilt
set_position_result = client.set_position(position)

if not set_position_result:
    print("Something went wrong")

#Set the Zoom model to send
zoom = Zoom(zoom=0.5)

#Send the request to change the zoom
set_zoom_result = client.set_zoom(zoom)

if not set_zoom_result:
    print("Something went wrong")


Finally, we can see the output result with VLC using the commands:

#Receive the PTZ output - RTSP Stream:
vlc rtsp://192.168.100.15:8000/stream_out