scchn
scchn

Reputation: 325

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?

Upvotes: 3

Views: 5279

Answers (2)

tripulse
tripulse

Reputation: 1149

Note that, this method only works if you're using FFmpeg and enabled bitstream-filters while compilation.

# this converts a MJPEG frame into a JPEG frame (adds a huffman table at the beginning.)
ffmpeg -i IN -bsf:v mjpeg2jpeg OUT

Upvotes: 1

scchn
scchn

Reputation: 325

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

Whomever need it, here it is :

JPEGFixer

Upvotes: 2

Related Questions