Android Tutorial MJPEG / CCTV Server

Status
Not open for further replies.
A few days ago I've helped a developer with implementing a MJPEG client: https://www.b4x.com/android/forum/threads/73702/#content
It was a good experience as while implementing it I've become familiar with the MJPEG protocol.
MJPEG is quite simple. Each frames look like:

--myboundary
Content-Type:image/jpeg
Content-Length:xxx

<image data>

Note that the end of lines are made of Chr(13) & Chr(10) and not the standard Chr(10) which is the value of CRLF in B4A, B4i and B4J (this is the natural end of line character on those platforms).

This example turns the device into a CCTV camera. You can connect to it with any browser (including mobile browsers) and see the video stream. You can also access it over the internet if the router is configured to allow it.

The nice thing about this example is that it supports multiple clients.

SS-2016-12-04_15.35.36.jpg


Each connection is managed by a different instance of the "client" class. This makes it simple to support multiple and concurrent clients. AsyncStreams is responsible for the concurrency.

Note that the image sent as-is. The orientation might be wrong.


The frame rate is currently set to 6 frames per second. You can change it by modifying IntervalMS. Set it to 50 (1000 / 50 = 20 fps) and it will look much better.

Test it by running the app on the device and then enter the device ip address in the browser followed by the port (51042).

B4i example is available here: https://www.b4x.com/android/forum/threads/mjpeg-cctv-server.73821/
 

Attachments

  • MJPEG_CCTV.zip
    12.6 KB · Views: 3,247
Last edited:
Status
Not open for further replies.
Top