MJPEG tidbits

An MJPEG video stream is a sequence of JPEG images.

Each JPEG image is supposed to start with SOI and ends with EOI, but some MJPEG streams have data beyond EOI.  Some JPEG decoders do not need these extra data. MS Windows' codec is one of them.   Some do.  Android devices need these extra data to decode the JPEG. Some Android devices can decode these JPEGs without the extra data and generate correct dimensions, but the outputs are black images.  Some Android devices are unable to decode these JPEGs without the extra data at all.

The stream data look like the following

Client:

GET /axis-cgi/mjpg/video.cgi HTTP/1.1

Host: 192.168.1.163

Connection: keep-alive

Cache-Control: max-age=0

Authorization: Digest username="root", realm="AXIS_00408CE070B9", nonce="005b4574Y752308d67a6f5b7ab969d2cddee8d75af6f2a1", uri="/axis-cgi/mjpg/video.cgi", response="4e6046e9d2e1aba97acfbb183c8fb3aa", qop=auth, nc=00000001, cnonce="4c7c0908bf51f915"

Upgrade-Insecure-Requests: 1

User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36

Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7

Accept-Encoding: gzip, deflate

Accept-Language: en-US,en;q=0.9,zh-CN;q=0.8,zh;q=0.7

Server:

HTTP/1.0 200 OK

X-Frame-Options: sameorigin

Cache-Control: no-cache

Pragma: no-cache

Expires: Thu, 01 Dec 1994 16:00:00 GMT

Connection: close

Content-Type: multipart/x-mixed-replace; boundary=myboundary

 

--myboundary

Content-Type: image/jpeg

Content-Length: 101337

 

......JFIF..............

[binary data]

--myboundary

Content-Type: image/jpeg

Content-Length: 101448

 

......JFIF..............

[binary data]

--myboundary

Content-Type: image/jpeg

Content-Length: 101627

 

......JFIF..............

[binary data]

 

This article was updated on 18:24:40 2024-05-07