【OpenCV】基于libvlc SDK和Opencv播放rtsp流

RTST流:使用vlc作为rtsp服务器

vlc2.1.2

VS2013+OpenCV3.0

C++


1、编译时记得导入vlc 的vlc.dll、vlccore.dll和plugins文件夹,这些可从VLC官网下载安装后导入

2、需在VS2013对Opencv进行配置



#include 
#include 
#include 
#include"vlc.h"
#include "stdafx.h"
#include "string.h"
using namespace cv;
using namespace std;

int VIDEO_WIDTH = 1024;
int VIDEO_HEIGHT = 578;
static char * videobuf = 0;
string Vlc_Vertion="";
void *lock(void *data, void**p_pixels)
{
	*p_pixels = videobuf;
	return NULL;
}
void display(void *data, void *id)
{
	IplImage *img = cvCreateImage(cvSize(VIDEO_WIDTH, VIDEO_HEIGHT), IPL_DEPTH_8U, 4);
	img->imageData = videobuf;
	cvShowImage(libvlc_get_version(), img);
	cvWaitKey(10);
	cvReleaseImage(&img);
}
void unlock(void *data, void *id, void *const *p_pixels)
{
	(void)data;
	assert(id == NULL);
}

int main()
{
	cvNamedWindow("image", CV_WINDOW_AUTOSIZE);
	libvlc_media_t* media = NULL;
	libvlc_media_player_t* mediaPlayer = NULL;
	char const* vlc_args[] =
	{
		"-I",
		"dummy",
		"--ignore-config",
	};
	Vlc_Vertion=libvlc_get_version();
	videobuf = (char*)malloc((VIDEO_WIDTH * VIDEO_HEIGHT) << 2);
	memset(videobuf, 0, (VIDEO_WIDTH * VIDEO_HEIGHT) << 2);
	
	libvlc_instance_t* instance = libvlc_new(sizeof(vlc_args) / sizeof(vlc_args[0]), vlc_args);	
	
	media = libvlc_media_new_location(instance, "rtsp://192.168.200.20:8554/test");
	mediaPlayer = libvlc_media_player_new_from_media(media);
	libvlc_media_release(media);

	//libvlc_media_player_set_media(mediaPlayer, media);
	libvlc_video_set_callbacks(mediaPlayer, lock, unlock, display, NULL);
	libvlc_video_set_format(mediaPlayer, "RV32", VIDEO_WIDTH, VIDEO_HEIGHT, VIDEO_WIDTH<<2);
	libvlc_media_player_play(mediaPlayer);
	
	while (1)
	{
	}
	return 0;
}

参考资料:


VLC做客户端解Rtsp码流

           http://blog.csdn.net/q339659207/article/details/38303831  


Read mms stream for open cv 

           http://stackoverflow.com/questions/9104842/read-mms-stream-for-open-cv


你可能感兴趣的:(VLC)