[Wiki] Motion JPEG

Motion JPEG, also known as MJPEG, is a video codec which saves every single frame as jpeg image.

In contrary to videos which are comprimized with MPEG codecs where, among other things, only the frame differences are stored, in MJPEG videos the whole frames are saved as separately jpeg images.  This brings advantages as also disadvantages with it.

On the one hand there are no artefacts in fast video sequences/scenes but on the other hand you get much larger video files because much more image information has to be stored. For a video in SVHS-quality, which is saved in MJPEG format, you need round about 25 MBit (3,1 MByte) per second.

MJPEG encoded video material can be found today usually only in the ip-cam sector.  (ip-cam = network camera) For network cameras the MJPEG codec seems to be ideal, because it needs hardly any hardware resources for encoding the video and nearly every browser can play MJPEG streams. Furthermore also devices like iPhone, iPad, Sony’s Playstation 3, Nintendo Wii and Android devices can deal with material in MJPEG format.

What about the structure of a MJPEG stream?

Because MJPEG encoded videos most times are send over the http-protocol and shall be watched in a webbrowser, they need a special MIME-type, which is named: “multipart/x-mixed-replace“.
After this MIME-header you need to write the following line into your stream: “;boundary=–boundary
The part after “boundary=“, can be chosen freely by the programmer. It’s the separator pattern which tells the consumer (browser, media player, etc) of the stream where the image data blocks begin and end.

The simplest form of a MJPEG stream could look like this:

HTTP/1.0 200 OK
Server: en.code-bude.net example server
Cache-Control: no-cache
Cache-Control: private
Content-Type: multipart/x-mixed-replace;boundary=--boundary

--boundary
Content-Type: image/jpeg
Content-Length: [length of the image bytes]

[write jpeg bytes]

--boundary
Content-Type: image/jpeg
Content-Length: [length of the image bytes]

[write jpeg bytes]

[...]

3 Comments

  1. As far as i know the header should be:
    boundary=boundary (without –)

    The boundaries should then be:
    –boundary (with –)

    • As I wrote it’s your choice: “The part after “boundary=“, can be chosen freely by the programmer. It’s the separator pattern which tells the consumer (browser, media player, etc) of the stream where the image data blocks begin and end.”

      • Jonathansays:

        No, you misread what she said.

        It’s boundary=MYBOUNDARY

        –MYBOUNDARY

        You declare the boundary “MYBOUNDARY” with “boundary=”
        You specify the boundary “MYBOUNDARY” with “–MYBOUNDARY”

Leave a Reply to Jonathan Cancel reply

Please be polite. We appreciate that. Your email address will not be published and required fields are marked