[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

How to decode a MJPEG file

Posted on 2012-09-04
10
Medium Priority
?
3,120 Views
Last Modified: 2013-11-08
Hello.
I need help to understand how one specific MJPEG file is put together. The file(s) are produced by a Synology Disk Station. The disk station is connected to Axis M1054 cameras which produce a MJPEG stream. I believe that the disk station is actually just saving images from the camera directly to the disk, but at the same time, it probably adds encapsulation to the file. I want to build a program that can browse quickly in the files produced by the disk, so I need information on how to read the file. I tried to read the file by VirtualDub and it was capable to browse through it super fast, so that's why I believe it is a MJPEG file. I will put it out on a .torrent soon, cause it is very big.

Are there any programs that will show me which bytes are for what, like Wireshark is doing for a network packet?
0
Comment
Question by:lefodnes
8 Comments
 

Author Comment

by:lefodnes
ID: 38365921
I analyzed the file in MediaInfo, and I'm attaching the result from it. I'm not allowed to upload a torrent file here, so it is accessible from http://lef.no/mjpeg_test.avi.torrent
mjpeg-test.txt
0
 
LVL 70

Expert Comment

by:Merete
ID: 38366313
I find wiki is good for a starter explains the inner workings
Motion JPEG
http://en.wikipedia.org/wiki/Motion_JPEG
MJPEG Tools
The mjpeg programs are a set of tools that can do recording of videos and playback, simple cut-and-paste editing and the MPEG compression of audio and video. Command line tools
http://www.videohelp.com/tools/MJPEG-Tools
http://mjpeg.sourceforge.net/
0
 

Author Comment

by:lefodnes
ID: 38367275
From what I can tell, wiki gives no information about the inner workings of Motion JPEG, except the workings of a http stream. Just pro/cons, tools that can edit video, which is not what I am after. I am not looking for simple editing software (MJPEG-Tools).

I'm looking for information on the protocol, so that I will be able to decode AVI/MJPEG from the byte level of a file.
0
Eye-catchers on the conference table

Challenge: The i-unit group was not satisfied with the audio quality during remote meetings. They were looking for a portable solution with excellent audio quality for use in their conference room but also at their client’s offices.

 
LVL 31

Expert Comment

by:Zoppo
ID: 38372189
Hi lefodnes,

did you already take a look at ffmpeg? With this tool you should be able to extract single frames from the MJPEG. You can find it here: http://ffmpeg.org/

If you want to write your own program to extract frames I think you could use libav which is a free library which supports audio/video en-/decoding: http://libav.org/

ZOPPO
0
 

Author Comment

by:lefodnes
ID: 38372329
Hi Zoppo,
Thank you for the link to libav.org. I will have a look at it.
My goal is to make something that reads the file in an optimized way, since the file is stored on a Synology on a LAN. I'd like to download only certain parts of the file on the fly, and build this file locally as a cache. This's why I need to understand the bits and bytes of the file. In my search I will also be looking closer at the RIFF/AVI format, since this MJPEG is contained in an AVI.
As I mentioned earlier, I do not need a program or library that can show or edit the file as video or images. I need a program from which I can learn how to read and browse quickly inside an AVI / MJPEG file.
0
 
LVL 83

Assisted Solution

by:leakim971
leakim971 earned 400 total points
ID: 38372463
0
 
LVL 25

Accepted Solution

by:
kode99 earned 1600 total points
ID: 38374925
The Synology unit stores the mjpeg in avi format but the 'frames' or jpg files are easily extracted.

All you need to do is scan the file for the start marker for the jpg pictures,  it will be a hex sequence 0xFF 0xD8.  This is the start of a jpg picture.  Then just scan ahead for the next start marker and everything before it is the jpg file - including the start marker.

So,

0xFF 0xD8 ...... picture data ...  0xFF 0xD8 .... next picture data ... etc

You can check this out with a hex editor so you can look at the raw data in the files.  A hex editor is the equivalent to wireshark but for files.  

Heres a free editor that works good,  
http://www.chmaas.handshake.de/delphi/freeware/xvi32/xvi32.htm

Search out the marker and you can check it out by cutting out a frame and pasting it into a new file.  I actually verified this on a file from a synology unit just to be sure they did not re-encode anything.

Jpeg uses the 0xFF <2nd hex value> as the start for headers and encoding information.  The 0xFF 0xD8 is always the start of the whole picture though.

When you look at jpg files with the hex editor you will likely see other 0xFF sections at the start with other information.  For example I'm looking at a jpg file and it shows me a date time and that the file was created with Adobe Photoshop.  If the Axis camera puts in a date and time you would be able to extract that as well.
0
 

Author Closing Comment

by:lefodnes
ID: 38375150
Hi kode99 and leakim971,

Thank you both for providing good information.

kode99, I appreciate that you actually verified the file format and described this in a good way.

leakim971, Thank you for the links. I have not read them all yet, but you both provided very good information for me to continue working with this project.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
Steps to fix error: “Couldn’t mount the database that you specified. Specified database: HU-DB; Error code: An Active Manager operation fail”
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question