VLC版本2.1.3
vs 2008.
为了从Rtsp地址获取实时帧数据,看了Live555和VLC的一些Demo。
VLC作为Rtsp的客户端,拉网络视频流。然后进行实时解码(内部进行),自己获得码流(RGBA数据,32位RGB),显示.
</pre><pre name="code" class="cpp">介绍就不说了,基本流程。
1. libvlc_new
2. libvlc_media_new_location
3. libvlc_media_player_new_from_media
libvlc_media_release
4. libvlc_video_set_callbacks
libvlc_video_set_format
如果仅仅只想显示,第四步骤换为:
libvlc_media_player_set_hwnd
5. libvlc_media_player_play
loop
6. libvlc_media_player_release
libvlc_release
if(m_bNew == true)
{
m_bNew = false;
m_vlcMedia = libvlc_media_new_location(m_vlcInst, "rtsp://码流地址");
m_vlcMplay = libvlc_media_player_new_from_media(m_vlcMedia);
libvlc_media_release(m_vlcMedia);
libvlc_media_player_set_hwnd(m_vlcMplay, m_hWndVideo);
libvlc_video_set_callbacks(m_vlcMplay, libvlc_video_lock_cb_callback, libvlc_video_unlock_cb_callback, libvlc_video_display_cb_callback, 0);
libvlc_video_set_format(m_vlcMplay, "RGBA", width, height, width*4);
}
int res = libvlc_media_player_play(m_vlcMplay);
为了获得实时流,就需要进行回调libvlc_video_set_callbacks
就需要设置三个回调, 我们需要获得buffer的大小,视频的width和height,buffer大小为width*height*4。在lock函数中需要锁住,在unlock中解锁。干活在display中,
这里为了方便,直接利用opencv显示出来了。
原先用CMutex类和CSinglelock进行锁,结果一直出问题,就自己弄了两个函数。目前在单个视频流还没问题。
这里比较重要的是,display会将 *planes 赋值,数据指针,就必须传给*planes。
void *libvlc_video_lock_cb_callback(void *opaque, void **planes)
{
Lock();
memset(buffer, 0, sizeof buffer);
*planes = buffer;
return NULL;
}
void libvlc_video_unlock_cb_callback(void *opaque, void *picture,
void *const *planes)
{
Unlock();
}
void libvlc_video_display_cb_callback(void *opaque, void *picture)
{
if (Islock())
{
IplImage *img = cvCreateImage(cvSize(width, height), IPL_DEPTH_8U, 4);
img->imageData = buffer;
cvShowImage(name, img);
cvWaitKey(10);
cvReleaseImage(&img);
//fwrite(buffer, sizeof buffer, 1, fp);
}
}
BOOL lock = FALSE;
void Lock()
{
lock = TRUE;
}
void Unlock()
{
lock = FALSE;
}
BOOL Islock()
{
return lock;
}
VLC Doxygen文档: http://www.videolan.org/developers/vlc/doc/doxygen/html/group__libvlc.html
VLC网址: videolan.org
VLC Documentation: https://wiki.videolan.org/LibVLC/
VLC维护人员?不知道是不是: http://www.jbkempf.com/blog/
VLC平台编译: http://jeremiah.blog.51cto.com/539865/114550
VS编译VLC方法: http://wenku.baidu.com/link?url=i91eXbrOY7Gf-8tO1TG6J7BWC7lIOZtheFSQ9YRaTuMD1kQowxQUFdX--LmYyTMnZAVU4NHdJ6VoztRnZmLpeTJQ2XXnFxadX97bfRWHnDq
VLC简介及使用说明、编译: http://blog.csdn.net/zhoujiaxq/article/details/9958793
windows使用libvlc进行网络串流遇到的一些问题及解决方法: http://www.cnblogs.com/youfal/p/3830830.html