資源簡介
打包后太大了,只有源程序。在vs2013可運行成功
1、新建一個win32控制臺程序
2、自己需在vs 配置好vlc 和opencv
3、導入代碼就可以,在換成自己的url

代碼片段和文件信息
//?OpencvVLC.cpp?:?定義控制臺應用程序的入口點。
//
#include?“stdafx.h“
#include?
using?namespace?cv;
struct?ctx
{
???Mat*?image;
???HANDLE?mutex;
???uchar*????pixels;
};
//?define?output?video?resolution
#define?VIDEO_WIDTH?????1920
#define?VIDEO_HEIGHT????1080
void?*lock(void?*data?void**p_pixels)
{
???struct?ctx?*ctx?=?(struct?ctx*)data;
???WaitForSingleobject(ctx->mutex?INFINITE);
???//?pixel?will?be?stored?on?image?pixel?space
???*p_pixels?=?ctx->pixels;???
???return?NULL;
}
void?display(void?*data?void?*id){
???(void)?data;
???assert(id?==?NULL);
}
void?unlock(void?*data?void?*id?void?*const?*p_pixels){
???
???//?get?back?data?structure?
???struct?ctx?*ctx?=?(struct?ctx*)data;
???/*?VLC?just?rendered?the?video?but?we?can?also?render?stuff?*/
???//?show?rendered?image
???imshow(“test“?*ctx->image);
???waitKey(1);
???ReleaseMutex(ctx->mutex);
}
int?main()
{
???//?VLC?pointers
???libvlc_instance_t?*vlcInstance;
???libvlc_media_player_t?*mp;
???libvlc_media_t?*media;
???
???const?char?*?const?vlc_args[]?=?{
??????“-I“?“dummy“?//?Don‘t?use?any?interface
??????“--ignore-config“?//?Don‘t?use?VLC‘s?config
??????“--extraintf=logger“?//?Log?anything
??????“--verbose=2“?//?Be?much?more?verbose?then?normal?for?debugging?purpose
???};
???vlcInstance?=?libvlc_new(sizeof(vlc_args)?/?sizeof(vlc_args[0])?vlc_args);
???//?Read?a?distant?video?stream
???media?=?libvlc_media_new_location(vlcInstance?“rtsp://用戶:密碼@ip:rtsp端口號/PSIA/streaming/channels/通道號碼流“);
???//?Read?a?local?video?file
??//?media?=?libvlc_media_new_path(vlcInstance?“d:\\a.mp4“);
???mp?=?libvlc_media_player_new_from_media(media);
???libvlc_media_release(media);
???struct?ctx*?context?=?(?struct?ctx*?)malloc(?sizeof(?*context?)?);
???context->mutex?=?CreateMutex(NULL?FALSE?NULL);
???context->image?=?new?Mat(VIDEO_HEIGHT?VIDEO_WIDTH?CV_8UC3);
???context->pixels?=?(unsigned?char?*)context->image->data;???
???//?show?blank?image
???imshow(“test“?*context->image);
???waitKey(1);
???libvlc_video_set_callbacks(mp?lock?unlock?display?context);
???libvlc_video_set_format(mp?“RV24“?VIDEO_WIDTH?VIDEO_HEIGHT?VIDEO_WIDTH?*?24?/?8);?//?pitch?=?width?*?BitsPerPixel?/?8
???
???int?ii?=?0;
???int?key?=?0;
???while(key?!=?27)
???{
??????ii++;
??????if?(ii?>?5)
??????{
?????????libvlc_media_player_play(mp);
??????}
??????float?fps?=??libvlc_media_player_get_fps(mp);
??????printf(“fps:%f\r\n“fps);
??????key?=?waitKey(100);?//?wait?100ms?for?Esc?key
???}
???libvlc_media_player_stop(mp);
???
???return?0;
}
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????1839??2016-07-29?02:36??OpencvVLC\Debug\OpencvVLC.log
?????文件?????265263??2016-07-29?02:36??OpencvVLC\Debug\OpencvVLC.obj
?????文件???10944512??2016-07-29?02:10??OpencvVLC\Debug\OpencvVLC.pch
?????文件???????1662??2016-07-29?02:36??OpencvVLC\Debug\OpencvVLC.tlog\cl.command.1.tlog
?????文件??????37324??2016-07-29?02:36??OpencvVLC\Debug\OpencvVLC.tlog\CL.read.1.tlog
?????文件???????1162??2016-07-29?02:36??OpencvVLC\Debug\OpencvVLC.tlog\CL.write.1.tlog
?????文件???????1914??2016-07-29?02:36??OpencvVLC\Debug\OpencvVLC.tlog\li
?????文件???????4426??2016-07-29?02:36??OpencvVLC\Debug\OpencvVLC.tlog\li
?????文件????????616??2016-07-29?02:36??OpencvVLC\Debug\OpencvVLC.tlog\li
?????文件????????170??2016-07-29?02:36??OpencvVLC\Debug\OpencvVLC.tlog\OpencvVLC.lastbuildstate
?????文件?????344659??2016-07-29?02:10??OpencvVLC\Debug\stdafx.obj
?????文件????1231872??2016-07-29?02:36??OpencvVLC\Debug\vc120.idb
?????文件????2600960??2016-07-29?02:36??OpencvVLC\Debug\vc120.pdb
?????文件???????2670??2016-07-29?02:42??OpencvVLC\OpencvVLC.cpp
?????文件???????4633??2016-07-29?02:36??OpencvVLC\OpencvVLC.vcxproj
?????文件???????1316??2016-07-29?02:36??OpencvVLC\OpencvVLC.vcxproj.filters
?????文件???????1524??2016-07-29?00:58??OpencvVLC\ReadMe.txt
?????文件????????432??2016-07-29?01:17??OpencvVLC\stdafx.cpp
?????文件????????299??2016-07-29?01:16??OpencvVLC\stdafx.h
?????文件????????236??2016-07-29?00:58??OpencvVLC\targetver.h
?????文件?????203202??2016-07-29?02:37??OpencvVLC\vlc-log.txt
?????目錄??????????0??2016-07-29?02:36??OpencvVLC\Debug\OpencvVLC.tlog
?????目錄??????????0??2016-07-29?02:36??OpencvVLC\Debug
?????目錄??????????0??2016-07-29?02:36??OpencvVLC
-----------?---------??----------?-----??----
?????????????15650691????????????????????24
評論
共有 條評論