I need to display UDP raw data coming from my Drone.
Unfortunately the Drone does not just use one of the existing standards for streaming video such as RTSP. Instead, the raw video packets are sent via UDP and need to be reassembled and decoded before they can be viewed..
Since the size of a single video frame is larger than the size of a single UDP packet, the Tello breaks apart each frame, and sends the packets with header of 2 bytes to indicate how they need to be reassembled.
The video data itself is just H264 encoded YUV420p. Using this information, it is possible to decode the video using standard tools such as ffmpeg, once you remove the header bytes.
Any idea how I can do this with C#?
Position Usage
0 Sequence number
1 Sub-sequence number
2-n Video data
UdpClient receiver = new UdpClient(11111);
//receiver.Client.ReceiveBufferSize = 1024;
IPEndPoint hostEP = new IPEndPoint(IPAddress.Parse("192.168.10.1"),0);
receiver.Connect(hostEP);
IPEndPoint ep = new IPEndPoint(IPAddress.Parse("0.0.0.0"), 0);
int i = 0;
string fileName = "car_pic";
while (true)
{
if (receiver.Available > 0)
{
//Debug.Write("Packet Received");
byte[] data = receiver.Receive(ref ep);
MemoryStream stream = new MemoryStream(data);
Device.BeginInvokeOnMainThread(() =>
{
try
{
//DronController.displayImage.Source =
ImageSource.FromStream(()=>stream);
//DronController.displayPath.Text =
data.ToString();
//stream.Close();
}
catch (Exception ex)
{
Debug.WriteLine("Exception!!!");
Debug.WriteLine(ex);
}
});
}
}