A robust system for automating drone video streaming based on arming/disarming states. This project integrates MAVSDK for drone telemetry with GStreamer for low-latency video streaming, enabling automatic stream control based on drone operation status.
- Automatic Stream Control: Video streaming starts when drone arms, stops when it disarms
- MAVSDK Integration: Real-time monitoring of drone telemetry
- GStreamer Pipeline: Hardware-accelerated video encoding on Jetson Nano
- SSH-based Remote Control: Secure communication between ground station and drone
- Robust Error Handling: Graceful recovery from connection issues
This system consists of three main components:
- Ground Station PC: Runs the control script (controller.py) with MAVSDK
- PX4 Flight Controller: Provides arming/disarming telemetry
- Jetson Nano: Executes the GStreamer pipeline for video streaming
- Python 3.8+
- MAVSDK Python package
- SSH client
- JetPack 4.6+ (includes GStreamer with NVIDIA acceleration)
- SSH server
- Network connectivity to ground station
git clone https://github.com/asifpatankar/drone-video-automation.git
cd drone-video-automationconda env create -f environment.yml
conda activate drone_stream_envThis critical step eliminates password prompts during operation:
- Generate SSH key pair (if you don't already have one):
ssh-keygen -t rsa -b 4096Press Enter to accept default locations and skip passphrase if desired.
- Copy the public key to your Jetson Nano:
ssh-copy-id username@jetson-ip-addressReplace username and jetson-ip-address with your actual values.
- Test the connection:
ssh username@jetson-ip-addressYou should connect without a password prompt.
- Connect to your Jetson Nano:
ssh username@jetson-ip-address- Create a directory for the streaming script:
mkdir -p /media/video-stream- Create the stream script:
nano /media/video-stream/stream_script.sh- Paste the following content:
#!/bin/bash
log_file="/tmp/stream_script.log"
echo "$(date): Received command: $1" >> $log_file
case $1 in
  start)
    echo "$(date): Starting stream" >> $log_file
    gst-launch-1.0 nvarguscamerasrc ! "video/x-raw(memory:NVMM)",width=1920,height=1080,framerate=30/1,format=NV12 ! videoconvert ! omxh264enc control-rate=constant bitrate=5000000 iframeinterval=15 ! h264parse ! rtph264pay name=pay0 pt=96 config-interval=-1 ! udpsink host=GROUND_STATION_IP port=5600 sync=false &
    echo $! > /tmp/stream_pid
    ;;
  stop)
    echo "$(date): Stopping stream" >> $log_file
    if [ -f /tmp/stream_pid ]; then
      pid = $(cat /tmp/stream_pid)
      kill $pid
      rm /tmp/stream_pid
      echo "$(date): Stopped stream process $pid" >> $log_file
    else
      echo "$(date): No stream process found to stop" >> $log_file
    fi
    ;;
  *)
    echo "$(date): Unknown command" >> $log_file
    ;;
esacReplace GROUND_STATION_IP with your ground station's IP address.
- Make the script executable:
chmod 755 /media/video-stream/stream_script.shEdit the controller.py file to match your setup:
# Update these values to match your configuration
JETSON_USER = "username"  # Jetson username
JETSON_IP = "192.168.x.x"  # Jetson IP address
STREAM_SCRIPT = "/media/video-stream/stream_script.sh"On your ground station:
conda activate drone_stream_env
python controller.pyThe script will:
- Connect to the drone via MAVSDK
- Monitor the drone's armed state
- Automatically start/stop video streaming based on arming status
Open QGroundControl and configure the video settings:
- Open QGroundControl
- Go to Application Settings (Q icon) > General
- In the Video section, configure:
- Video Source: UDP h.264 Video Stream
- UDP Port: 5600
 
- Check SSH connectivity: ssh username@jetson-ip-address
- Verify script permissions: ls -l /media/video-stream/stream_script.sh
- Check logs on Jetson: cat /tmp/stream_script.log
- Ensure ground station and Jetson are on the same network
- Verify UDP port 5600 is not blocked by firewall
- Check GStreamer pipeline output for errors
- Improve network stability between ground station and drone
- Add error handling and reconnection logic to controller script
Modify the GStreamer pipeline in stream_script.sh:
- For lower bandwidth: Reduce resolution (width=1280,height=720) and bitrate (bitrate=2000000)
- For higher quality: Increase resolution and bitrate, but monitor CPU usage
To manage multiple drones:
- Assign unique UDP ports for each drone
- Create separate controller instances with different configuration
This project is available under a dual licensing model:
For academic, personal, and non-commercial use, this project is available under the MIT License. See the LICENSE file for details.
For commercial use, including but not limited to using this code in commercial products, services, or any revenue-generating activities, please contact [email protected] to obtain a commercial license.
Commercial users have the following options:
- One-time licensing fee
- Revenue sharing arrangement
- Repository sponsorship
- Custom licensing terms
All commercial inquiries will be handled on a case-by-case basis.