Question

I'm just trying to read a video Stream out of an IP Camera (Basler BIP-1280c). The stream I want to have is saved in a buffer on the camera, has a length of 40 seconds and is decoded in MJPEG.

Now if I access the stream via my webbrowser it shows me the 40 seconds without any problems. But actually I need an application which is capable of downloading and saving the stream by itself.

The camera is accessed via http, so I am using libcurl to access it. This works fine and I also can download the stream without any troubles. I have chosen to save the stream data into an *.avi file (hope that's correct…?).

But now to the problem: I can open the video (tried with Totem Video Player and VLC) and also view all that has been recorded — BUT it's way too fast. The whole video lasts like 5 seconds (instead of 40). Is there in MJPEG anything in a header where to put information like the total video length or the fps? I mean there must be some information missing for the video players, so that they play it way to fast?

Update:

As suggested in the answers, I opened the file with a hexeditor and what I found was this:

--myboundary..Content-Type: image/jpeg..Content-Length: 39050.........*Exif..II*...............V...........................2...................0210................FrameNr=000398732 6.AOI=(0800x0720)@(0240,0060)/(1280x0720).Motion=00000 (no) [00000 | 00000 | 00000 | 00000 | 00000].Alarm=0000 (no) .IO =000.RtTrigger=0...Basler..BIP2-1280c..1970:01:05 23:08:10.8 98286......JFIF.................................. ....&"((

This header reoccurs in the file all over ( followed by a a lot of Bytes of binary Data ). This is actually okay, since I read in the camera manual that all MJPEG Pictures get this Header.

More interesting ins the JFIFin the last line. As in the answers suggested this is maybe the indicator of the file format. But afaik JFIF is a single picture format just like jpg. So does this maybe even mean that the whole video file is just some "brainless" chained pictures? And my Player just assumes that he should show this pictures one after another, without any knowledge about the framerate?

Was it helpful?

Solution

There is not a single format to use with MJPEG. From Wikipedia:

[...] there is no document that defines a single exact format that is universally recognized as a complete specification of “Motion JPEG” for use in all contexts.

The formats differ by vendor. My advice would be to closely inspect the file you download. Check if it is really an AVI container. (Some cameras can send the frames wrapped in a MIME container).

After the container format is clear, you can check out the documentation of that container and look for a file which has that format and the desired fps. Then you can start adjusting your downloaded file to have the desired effect.

You might also find this project useful: http://mjpeg.sourceforge.net/

Edit:

According to your sample data your camera sends the frames packed into a MIME container. (The first line is the boundary, then the headers until you encounter an empty line, then the file data itseld, followe by the boundary and so on).

These are JPEG files as the header suggests: image/jpeg. JFIF is the standard file format to store JPEG data.

I recommend you to:

  1. Extract the contents of the file into multiple jpeg files (with munpack for instance), then
  2. use ffmpeg or mplayer to create a movie file out of the series of jpegs.

This way you can specify the desired frame rate too.

It can make things more complicated if the camera dynamically canges AOI (area of interest), meaning it can send only a smaller part of the image where change occured. But you should check first if the simple approach works.

OTHER TIPS

on un*x systems (linux, osx,...), you can use the file cmdline tool to make a (usually good) guess about the file format.

--myboundary is an indication that the stream is regular M-JPEG streamed as multipart content over HTTP. There is no well known file format which can hold this stream "as is" and be playable (that is if you rename this to AVI it is not supposed to play back).

The format itself is a sequence of (boundary, subheader, JPEG image), (boundary, subheader, JPEG image), ... etc. The stream does not have time stamps, so playback speed completely depends on the player.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top