Jump to content

Metropolis Microservices/RidgeRun Services/PTZ: Difference between revisions

no edit summary
No edit summary
No edit summary
Line 16: Line 16:
# Returns as the output the transformed stream using the same protocol, RTSP.
# Returns as the output the transformed stream using the same protocol, RTSP.


{{Review|Add link to the technical documentation?|mortigoza}}


==API documentation==
==API documentation==
Line 129: Line 130:




==Examples==
As we mentioned in 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:


#Get an RTSP stream as the input.
#Performs the PTZ in the stream, depending on the user instructions.
#Returns the stream transformed using the same protocol, RTSP, as the output.


We can use the modules available in here**, called rrms_utils, to create a client that "talks" to the server created into the ptz microservices, once it is installed and running.


These are the imports, and commands needed to do it: (Below we explain the purpose of each one)


<pre>
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




==Examples==
# Create client (by default will talk to address 127.0.0.1 and port 5020)
Once you have a ptz-microservices-docker running you can run and test its functionality:
client = PTZ(host=192.168.100.15, port=7000)


{{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}}


# 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)


====Run the ptz microservice====
if not set_stream_result:
<pre>
    print("Something went wrong")
ptz --host=192.168.100.15 –port=5010
</pre>


====Create an stream RTSP source using this pipeline:====


<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)
# 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]:====
#Change pan and tilt
position = Position(pan=50, tilt=20)
set_position_result = client.set_position(position)


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):
if not set_position_result:
    print("Something went wrong")


<pre>
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
</pre>


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


Using the client ****
if not set_zoom_result:
    print("Something went wrong")


</pre>


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


<pre>
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)




89

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.