一、自定义插件目录
在Windows平台,使用LibVLC,只需要在VLC官网的nightly builds下载最新的win32 debug或win64 debug包,
解压缩之后,会有libvlc.dll libvlccore.dll , sdks目录下面包含lib和头文件
如果需要自定义插件目录,使用--plugin-path无效的时候,需要使用如下的代码
typedef int (__stdcall* PFN_putenv)(const char *envstring); pfn_putenv = (PFN_putenv)GetProcAddress( LoadLibrary(L"msvcrt.dll"), "_putenv" ); if ( pfn_putenv ) { pfn_putenv(szENV); }
这是因为在vlc的代码中,src\modules\bank.c AllocateAllPlugins函数中,会调用如下的代码获取插件目录
/* If the user provided a plugin path, we add it to the list */ paths = getenv( "VLC_PLUGIN_PATH" ); if( paths == NULL ) return; paths = strdup( paths ); /* don't harm the environment ! :) */ if( unlikely(paths == NULL) ) return;
而getenv在msdn中解释如下
getenv and _putenv use the copy of the environment pointed to by the global variable _environ to access the environment. getenv operates only on the data structures accessible to the run-time library and not on the environment "segment" created for the process by the operating system. Therefore, programs that use the envp argument to or may retrieve invalid information.
可以看到getenv和_putenv是读取和设置CRT运行时库的_environ全局变量,而libvlc.dll 以及 libvlccore.dll都是依赖的msvcrt.dll
所以,在开发的时候,如果直接调用 _putenv 设置VLC_PLUGIN_PATH,是设置不到msvcrt的全局变量的,而是设置到了msvcr100.dll 或msvcr140.dll这样不同
C运行时库的版本。
二、获取FPS的方法
在libvlc里面使用libvlc_media_player_get_fps获取FPS经常获取不到,返回值为0,虽然调用了libvlc_media_parse,根据最新版本的libvlc,建议使用
libvlc_media_tracks_get函数获取,试验后代码如下
uiStreamCount = libvlc_media_tracks_get(pMedia, &ppTracks); for ( unsigned i = 0; i < uiStreamCount; i++ ) { libvlc_media_track_t* pTrack = ppTracks[i]; if ( pTrack && libvlc_track_video == pTrack->i_type) { libvlc_video_track_t* pVideoTrack = pTrack->video; fps = pVideoTrack->i_frame_rate_num / pVideoTrack->i_frame_rate_den; } }