这是安讯士网络摄像机?无论哪种方式,大多数IP摄像机提供了可使用OpenCV使用cvCreateFileCapture_FFMPEG解码的RTSP流。但是,ffmpeg解码器的编解码器有一个广为人知的悬而未决的问题。我相信你会收到错误类似
[ingenient @ 0x97d20c0]Could not find codec parameters (Video: mjpeg)
选项1:使用opencv,的libcurl和libjpeg的
要查看OpenCV的MJPEG流来看看下面的实现
http://www.eecs.ucf.edu/~rpatrick/code/onelinksys.c 或 http://cse.unl.edu/~rpatrick/code/onelinksys.c
选项2:使用的GStreamer(无OpenCV的)
我将在GStreamer的建议看,如果你的目标是只查看或保存JPEG图像
要视图 MJPEG流之一,如下所示可以执行媒体管道串
gst-launch -v souphttpsrc location="http://[ip]:[port]/[dir]/xxx.cgi" do-timestamp=true is_live=true ! multipartdemux ! jpegdec ! ffmpegcolorspace ! autovideosink
对于RTSP
gst-launch -v rtspsrc location="rtsp://[user]:[pass]@[ip]:[port]/[dir]/xxx.amp" debug=1 ! rtpmp4vdepay ! mpeg4videoparse ! ffdec_mpeg4 ! ffmpegcolorspace! autovideosink
要使用C API看到工作
http://wiki.maemo.org/Documentation/Maemo_5_Developer_Guide/Using_Multimedia_Components/Camera_API_Usage
举个简单的例子来看看我的其他职位上RTSP构建GStreamer的C API介质的管道(这是一样的GST-启动串,而是实现为C API)
Playing RTSP with python-gstreamer
要保存 MJPEG流作为多个图像管道(让我们把垂直翻转BIN并连接个PADS到先前和下一分档,使其票友)
gst-launch souphttpsrc location="http://[ip]:[port]/[dir]/xxx.cgi" do-timestamp=true is_live=true ! multipartdemux ! jpegdec ! videoflip method=vertical-flip ! jpegenc ! multifilesink location=image-out-%05d.jpg
而且也许值得看一看GST-OpenCV的
UPDATE:
2选项:使用gstreamer,命名管道和opencv
在Linux上,可以获取mjpeg流并将其转换为mpeg4并将其提供给命名管道。然后读取来自命名管道中的数据的OpenCV
步骤1.创建命名管道
mkfifo stream_fifo
步骤2.创建opencvvideo_test.c
// compile with gcc -ggdb `pkg-config --cflags --libs opencv` opencvvideo_test.c -o opencvvideo_test
#include <stdio.h>
#include "highgui.h"
#include "cv.h"
int main(int argc, char** argv){
IplImage *frame;
int key;
/* supply the AVI file to play */
assert(argc == 2);
/* load the AVI file */
CvCapture *capture = cvCreateFileCapture(argv[1]) ;//cvCaptureFromAVI(argv[1]);
/* always check */
if(!capture) return 1;
/* get fps, needed to set the delay */
int fps = (int)cvGetCaptureProperty(capture, CV_CAP_PROP_FPS);
int frameH = (int) cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_HEIGHT);
int frameW = (int) cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_WIDTH);
/* display video */
cvNamedWindow("video", CV_WINDOW_AUTOSIZE);
while(key != 'q') {
double t1=(double)cvGetTickCount();
/* get a frame */
frame = cvQueryFrame(capture);
double t2=(double)cvGetTickCount();
printf("time: %gms fps: %.2g\n",(t2-t1)/(cvGetTickFrequency()*1000.), 1000./((t2-t1)/(cvGetTickFrequency()*1000.)));
/* always check */
if(!frame) break;
/* display frame */
cvShowImage("video", frame);
/* quit if user press 'q' */
key = cvWaitKey(1000/fps);
}
/* free memory */
cvReleaseCapture(&capture);
cvDestroyWindow("video");
return 0;
}
步骤3。制备要使用的gstreamer(速率传入帧的关键)在OpenCV中
gst-launch -v souphttpsrc location="http://<ip>/cgi_bin/<mjpeg>.cgi" do-timestamp=true is_live=true ! multipartdemux ! jpegdec ! queue ! videoscale ! 'video/x-raw-yuv, width=640, height=480'! queue ! videorate ! 'video/x-raw-yuv,framerate=30/1' ! queue ! ffmpegcolorspace ! 'video/x-raw-yuv,format=(fourcc)I420' ! ffenc_mpeg4 ! queue ! filesink location=stream_fifo
步骤4.显示流
./opencvvideo_test stream_fifo
可否使用gsteamer创建从正被所述图像的视频从MJPEG转换为MPEG4得救了吗? gstreamer是否允许我访问EXIF标签? – 2014-03-26 04:59:00
@PrakharMohanSrivastava使用multifilesrc插件从图像创建视频http://gstreamer.freedesktop.org/data/doc/gstreamer/head/gst-plugins-good-plugins/html/gst-plugins-good-plugins-multifilesrc.html – enthusiasticgeek 2014-03-26 16:48:07
@PrakharMohanSrivastava在EXIF上阅读更多内容http://gstreamer.freedesktop.org/data/doc/gstreamer/head/gst-plugins-base-libs/html/gst-plugins-base-libs-gsttagexif.html – enthusiasticgeek 2014-03-26 16:49:25