I am parsing the GBD header of h.264 live frames received from XProtect Professional+ 2018 R2.
The code for parsing is below:
bytes = RecvFixed(sock, bytesReceived, 2, 34);
if (!(bytes == 34 || bytes == -34))
{
throw new Exception("Receive error C");
}
// Parse the GBD header
// Encoding
byte\[\] bufEncoding = new byte\[2\];
Buffer.BlockCopy(bytesReceived, 0, bufEncoding, 0, 2);
if (BitConverter.IsLittleEndian)
Array.Reverse(bufEncoding);
UInt16 encoding = BitConverter.ToUInt16(bufEncoding, 0);
byte\[\] bufFlags = new byte\[4\];
Buffer.BlockCopy(bytesReceived, 4, bufFlags, 0, 4);
if (BitConverter.IsLittleEndian)
Array.Reverse(bufFlags);
Int32 flags = BitConverter.ToInt32(bufFlags, 0);
// start timestamp
byte\[\] bufStart = new byte\[8\];
Buffer.BlockCopy(bytesReceived, 12, bufStart, 0, 8);
if (BitConverter.IsLittleEndian)
Array.Reverse(bufStart);
Int64 startTime = BitConverter.ToInt64(bufStart, 0);
// end timestamp
byte\[\] bufEnd = new byte\[8\];
Buffer.BlockCopy(bytesReceived, 20, bufEnd, 0, 8);
if (BitConverter.IsLittleEndian)
Array.Reverse(bufEnd);
Int64 endTime = BitConverter.ToInt64(bufEnd, 0);
byte\[\] picWidth = new byte\[2\];
Buffer.BlockCopy(bytesReceived, 28, picWidth, 0, 2);
if (BitConverter.IsLittleEndian)
Array.Reverse(picWidth);
Int16 pic\_width = BitConverter.ToInt16(picWidth, 0);
byte\[\] picHeight = new byte\[2\];
Buffer.BlockCopy(bytesReceived, 30, picHeight, 0, 2);
if (BitConverter.IsLittleEndian)
Array.Reverse(picHeight);
Int16 pic\_height = BitConverter.ToInt16(picHeight, 0);
// number of pictures
byte\[\] bufNumPics = new byte\[2\];
Buffer.BlockCopy(bytesReceived, 34, bufNumPics, 0, 2);
if (BitConverter.IsLittleEndian)
Array.Reverse(bufNumPics);
Int16 numPics = BitConverter.ToInt16(bufNumPics, 0);
Console.WriteLine("encoding {0} start time {1} end time {2} num frames {3} flags {4} width {5} height {6} counter {7}",
encoding, startTime, endTime, numPics, flags, pic\_width, pic\_height, \_counter);
The output is the following:
ncoding 16 start time 1533757984581 end time 1533757984715 num frames 1 flags 12648458 width 0 height 0 counter 1
encoding 16 start time 1533757984581 end time 1533757984848 num frames 1 flags 8388618 width 0 height 0 counter 2
encoding 16 start time 1533757984581 end time 1533757984981 num frames 1 flags 8257546 width 0 height 0 counter 3
encoding 16 start time 1533757984581 end time 1533757985081 num frames 1 flags 11468810 width 0 height 0 counter 4
encoding 16 start time 1533757984581 end time 1533757985215 num frames 1 flags 11272202 width 0 height 0 counter 5
encoding 16 start time 1533757984581 end time 1533757985348 num frames 1 flags 11993098 width 0 height 0 counter 6
encoding 16 start time 1533757984581 end time 1533757985481 num frames 1 flags 8454154 width 0 height 0 counter 7
encoding 16 start time 1533757985581 end time 1533757985581 num frames 1 flags -1546059766 width 0 height 0 counter 8
encoding 16 start time 1533757985581 end time 1533757985715 num frames 1 flags 10289162 width 0 height 0 counter 9
encoding 16 start time 1533757985581 end time 1533757985848 num frames 1 flags 6946826 width 0 height 0 counter 10
encoding 16 start time 1533757985581 end time 1533757985981 num frames 1 flags 7405578 width 0 height 0 counter 11
encoding 16 start time 1533757985581 end time 1533757986081 num frames 1 flags 8192010 width 0 height 0 counter 12
encoding 16 start time 1533757985581 end time 1533757986215 num frames 1 flags 7733258 width 0 height 0 counter 13
encoding 16 start time 1533757985581 end time 1533757986349 num frames 1 flags 18415626 width 0 height 0 counter 14
encoding 16 start time 1533757985581 end time 1533757986482 num frames 1 flags 9764874 width 0 height 0 counter 15
encoding 16 start time 1533757986582 end time 1533757986582 num frames 1 flags -1559166966 width 0 height 0 counter 16
encoding 16 start time 1533757986582 end time 1533757986715 num frames 1 flags 10813450 width 0 height 0 counter 17
encoding 16 start time 1533757986582 end time 1533757986849 num frames 1 flags 6684682 width 0 height 0 counter 18
encoding 16 start time 1533757986582 end time 1533757986982 num frames 1 flags 10027018 width 0 height 0 counter 19
encoding 16 start time 1533757986582 end time 1533757987082 num frames 1 flags 10420234 width 0 height 0 counter 20
I verified that the frames received are valid H.264 examining the stream via Elecard StreamEye.
Please let me know how to get the frame width and height.
Thank you very much for your help.
Regards,
Ruslan