I want to receive JPEG images from an IP camera (over RTSP). For this, I tried cvCreateFileCapture_FFMPEG
in OpenCV. But ffmpeg seems to have some problem with the MJPEG format of the streaming (since it automatically tries to detect the streaming info) and I end up with the following error
mjpeg: unsupported coding type
I, then, decided to use live555 for streaming. Till now, I can successfully establish streaming and capture (non-decoded) images through openRTSP.
The question is how can I do this in my application, e.g., in OpenCV. How can I use openRTSP in OpenCV to get images and save them in JPEG format?
I have heard that the data from openRTSP can be sent to a buffer (or a named pipe) and then read in OpenCV's IplImage
. But I don't know how to do this.
I will really appreciate any help/suggestion in about this problem. I need answers of either of the following questions:
- How can I disable ffmpeg's automatic stream information detection and specify my own format (mjpeg), or
- How can I use openRTSP in OpenCV?
Regards,
Is this an Axis IP camera? Either way, most IP cameras that provide MPEG4 RTSP stream that can be decoded using OpenCV using cvCreateFileCapture_FFMPEG. However, ffmpeg decoder's MJPEG codec has a widely known unresolved issues. I am sure you would have received an error similar to
Option1 : Using opencv, libcurl and libjpeg
To view mjpeg stream in opencv take a look at the following implementation
http://www.eecs.ucf.edu/~rpatrick/code/onelinksys.c or http://cse.unl.edu/~rpatrick/code/onelinksys.c
Option2: Using gstreamer (no opencv)
I would recommend looking at gstreamer if your goal is to just view or save jpeg images
To view MJPEG stream one may execute media pipeline string as follows
For RTSP
To work with C API see
http://wiki.maemo.org/Documentation/Maemo_5_Developer_Guide/Using_Multimedia_Components/Camera_API_Usage
For a simple example take a look at my other post on rtsp for constructing gstreamer C API media pipeline (This is same as gst-launch string but rather implemented as a C API)
Playing RTSP with python-gstreamer
To save MJPEG stream as multiple images the pipeline (Let us put a vertical flip BIN and connect the PADS to the previous and the next BINS to make it fancier)
Also maybe worthwhile have a look at gst-opencv
UPDATE:
Option3: Using gstreamer, Named Pipe and opencv
On Linux one may get mjpeg stream and convert it to mpeg4 and feed it to a named pipe. Then read the data from the named pipe in opencv
Step 1. Create Named Pipe
Step 2. Create opencvvideo_test.c
Step 3. Prepare To Convert From MJPEG to MPEG4 using gstreamer (rate of incoming frames critical)
Step 4. Display Stream in OpenCV