Search code examples
objective-ccjpegmjpeg

How to decode MJPEG frame into JPEG


I'm writing an iOS app to fetch motion jpeg stream via a tcp connection as in-memory data.

but the frame couldn't just save as a jpg file.


From what I googled, it seems like MJPEG frame doesn't have DHT like JPEG does,

but how to generate a DHT and put it into a mjpeg frame.

I also found few third-party libs like libjpeg-turbo, ffmpeg may accomplish that.

But most of the examples only show how to do it simply give an URL not in-memory data.


If you've done this in C/Objective-C before, hope you can tell me.

In the meantime, I'll keep searching for the answer.

and thanks for your time!


UPDATE:

Now I'm using DFJPEGTurbo and replace its libjpeg-turbo with the latest version.

It's easy to re-wrap mjpeg frame to a UIImage object.

It's the best way I've found, don't know if there's a better way.

and how can I do "ffmpeg -i {MJPEG_FILE} outputframe%d.jpg" programmatically?


Solution

  • I've already found the answer, which is quite easy to use.

    Whomever need it, here it is :

    JPEGFixer