GStreamer Pan Tilt Zoom and Rotate Element - PTZR with an Xbox controller
| GStreamer PTZR |
|---|
| GstPTZR Basics |
| User Guide |
| Getting Started |
| Examples |
| Contact Us |
Introduction
This demo demonstrates a basic PTZ (pan, tilt, and zoom) application using GStreamer and an Xbox 360 controller. The goal of the demo is to show how joystick and buttons input can be read in real time and converted into smooth pan, tilt, and zoom movements applied to a video stream. This video stream will also be transmitted to a laptop using UDP. It allows the user to zoom in an area of a video and move around it as desired. This demo was tested on a Jetson Orin Nano with Jetpack 6.
The next steps will guide you to build the code and install the libraries
Dependencies
Please install the dependencies with the following command:
sudo apt install libusb-1.0-0-dev gstreamer1.0-tools gstreamer1.0-plugins-good gstreamer1.0-plugins-bad \
gstreamer1.0-plugins-ugly gstreamer1.0-libav
Code
Inquire at support@ridgerun.com for the PTZR evaluation binary and the XBox controller demo source code.
Then build the code:
cd ridgerun-products-demos/ git checkout develop cd reference_designs/ptzr-with-xbox-controller/ autoreconf -vfi ./configure make -j cd src
Run the demo
1. Create a udev rule to enable the user to use the Xbox 360 controller device.
sudo vi /etc/udev/rules.d/99-xbox360-libusb.rules
Add the following contents:
SUBSYSTEM=="usb", ATTR{idVendor}=="045e", ATTR{idProduct}=="028e", MODE="0666"
And then reload udev rules:
sudo udevadm control --reload-rules sudo udevadm trigger
2. Connect the Xbox 360 controller to the USB port on the Jetson Orin Nano.
3. Run the auxiliar script to set up OpenGL usage:
chmod +x modify-auth-for-display.sh ./modify-auth-for-display.sh
3. Run the demo with the following command:
DISPLAY=:0 XAUTHORITY=$HOME/.Xauthority ./demoptzrjetson /home/nvidia/video.mp4 192.168.55.100 5000 2000
- This script takes a mp4 file as an input. The first parameter (/home/nvidia/video.mp4) is the path to this file.
- Second parameter is the IP address to send the stream to.
- Third parameter is the port to use.
- Fourth parameter is the bitrate of encoding.
The output should look like the following:
Pipeline: filesrc location="/home/nvidia/video.mp4" ! qtdemux name=demux demux.video_0 ! h264parse ! avdec_h264 ! videoconvert ! video/x-raw,format=RGBA,width=1920,height=1080 ! ptzr name=ptz pan-level=0 tilt-level=0 zoom-level=1.0 normalize-translation=true output-reference=true ! videoconvert ! video/x-raw,format=I420 ! x264enc tune=zerolatency speed-preset=ultrafast key-int-max=30 bitrate=2000 ! rtph264pay pt=96 config-interval=1 ! identity name=id signal-handoffs=true ! udpsink host=192.168.55.100 port=5000 sync=false async=false set_state(PLAYING) returned: 1 Streaming RTP/H264 over UDP to 192.168.55.100:5000 Input file: /home/nvidia/video.mp4 Controls: left stick pan/tilt, A zoom in, B zoom out Ctrl+C to quit. Pipeline state: NULL -> READY Pipeline state: READY -> PAUSED Pipeline state: PAUSED -> PLAYING libusb connected. iface=0 ep_in=0x81 [sender] buffers flowing, cnt=60 [sender] buffers flowing, cnt=120 [sender] buffers flowing, cnt=180 [sender] buffers flowing, cnt=240 [sender] buffers flowing, cnt=300 [sender] buffers flowing, cnt=360 [sender] buffers flowing, cnt=420 [sender] buffers flowing, cnt=480 [sender] buffers flowing, cnt=540
This demo sends through UDP to a laptop connected via USB-C. The video stream can be received on the laptop with the following pipeline:
gst-launch-1.0 -v udpsrc port=5000 caps="application/x-rtp,media=video,encoding-name=H264,payload=96,clock-rate=90000" ! rtpjitterbuffer latency=200 ! rtph264depay ! h264parse ! avdec_h264 ! videoconvert ! autovideosink sync=false