Image Transmission Protocol
The image transmission protocol uses MAVLink as the communication channel to transport any kind of image (raw images, Kinect data, etc.) from one MAVLink node to another. It basically takes a live camera image, splits it into small chunks and sends it over MAVLink.
This topic describes how the image streaming functionality works and covers both the communication protocol and implementation details (for a vehicle and QGroundControl).
At time of writing (March 2018) the protocol is mainly used to transfer images from a vehicle to QGroundControl (to show PX4 Flow images for focusing). The protocol could also be used to send any other file types.
The image streaming component uses two MAVLink messages: A handshake message, DATA_TRANSMISSION_HANDSHAKE, to initiate, control and stop the image streaming; and a data container message, ENCAPSULATED_DATA, to transport the image data.
- The communication is initiated by the QGroundControl with a request to start the stream. To do so, one must set the following fields in the MAVLink message:
target: to the ID of the targeted MAV,
state: to 0 for a request,
id: an ID for the image stream,
For the moment, the image streamer only supports one stream per image type and therefore requires you to set the
idto the same integer as the
type: any of the types in the enum MAVLINK_DATA_STREAM_TYPE in mavlink.h,
freq: bigger than 0 for "frames per seconds", lower than 0 for "seconds per frame"
It is possible to request for a specific image quality. To do so, you must set the ''quality'' field. All other fields should be zero in the initial request.
When the targeted MAV receives the handshake request, it sends back an acknowledgment and starts the image stream at the requested framerate. The handshake ACK packet normally contains the same values as requested by the GCS (
stateset to 1, because it's an ACK), and adds data about the size of the next sent image:
- The field
packetscontains the number of MAVLink
- the field
payloadspecifies the size of the payload of each data packet (normally 252 bytes),
- and the
sizefield specifies the image size in bytes.
- The field
The image data is then split into chunks to fit into normal MAVLink messages. They are then packed into
ENCAPSULATED_DATApackets and sent over MAVLink. Every packet contains a sequence number as well as the ID of the image stream it belongs to. The image streamer now sends periodically new images, there is no further interaction needed. Every new image comes with a new
DATA_TRANSMISSION_HANDSHAKEACK packet with updated image
payloadfields. After this ACK packet, the new image arrives as a series of
The sequence number starts at 0 for every new image of the stream.
To stop an image stream you must send a new
DATA_TRANSMISSION_HANDSHAKErequest packet with the frequency set to 0. The MAVLink node will acknowledge this by sending back an ACK packet containing the same data as in the request.
Usage / Configuration
To use the two modules on your MAV, you have to do the following steps:
- Compile the
mavconnmiddleware for your MAV: Guide, Github.
- Start at least these components on the MAV:
px_mavlink_bridge_udp & px_system_control --heartbeat & px_camera -o lcm &
- Compile and start QGroundControl.
- Start the image streaming component (you can add the
-vflag to see some more output):
- Initiate the image stream: Open the HUD widget, right-click into the widget and choose Enable live Image Streaming.
You should now be able to see the live video feed with one image per second (default, hardcoded at the moment).
Out-of-the-box, the image streaming component only implements JPEG streaming of the camera image. To implement your own image stream, you have to do the following:
- Write a MAVLink handler, which handles requests to start image streams of your type of choice.
- Write a data handler, which takes your desired data (i.e. a stereo camera image), encodes it into the format of your choice (i.e. rawimage, JPEG, BMP) and splits/sends the data over MAVLink.
- Extend the data/message handler in the UAS component of QGroundControl to correctly handle your data (i.e. unpacking of the chosen format).
- Write or extend a widget to display your data according to your wishes.