Example Code

MJPEG stream over RTSP

Code and Documents

Attachment

This is based on RTSP communication example by GriffinRU. Only instead of saving H.264 stream to file, it converts MJPEG stream to JPEG files according to according to RFC 2435 standard.

What is not implemented:

  • Generating quantization tables from Q-factor. Since video-server I'm working with always sends tables itself. There is an example in RFC 2435 appendix A, which is really simple.
  • Using restart markers. Since I'm not sure why would I need them.
  • Converting JPEG-string to LabVIEW picture is pretty lousy, since there is no native solution to it, and I didn't want to include extra DLL's.

VIs description

RTP and RTSP VIs are described in aforementioned document.

RTP_RTSP - Parse JPEG payload

1.png

VI parses the payload, extracts headers and appends image data to previous data until RTP marker becomes TRUE.

Parse main header

2.png

Extracts JPEG's main header

Parse restart markers

3.png

Reads Restart Marker Header if image type is 64-127.

Parse quant tables

4.png

If Q-factor is 128-255 VI reads quantization table header and data from the payload. If quantisation header is present, but tables length == 0, it uses tables from previous payload.

Generating tables from Q-factor can be added here, or in the next VI.

JPEG is marked as ready according to RTP marker.

Create JPEG image

5.png

Recreates JPEG image from recieved data. Restart marker header is not used. Huffman tables are created according to example in RFC 2435 Appendix B.

It might be wise to check for EOI marker (0xFFD9) here, but I was in a hurry.

JPEG string to picture

6.png

That is just sad. I'm going to try this solution someday, and update this document.

That's it!

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.

Contributors