
簡介
- VLC 是一款自由、開源的跨平台多媒體播放器及框架,可播放大多數多媒體文件,以及 DVD、音頻 CD、VCD 及各類流媒體協議。
- 由於VLC是完全開源的,所以我們可以獲得所有的項目源碼,並在此基礎上進行二次開發
VLC的官網:http://www.videolan.org/
VLC源碼下載地址:http://download.videolan.org/pub/videolan/vlc/2.2.4/
測試代碼參考雷神的博客:http://blog.csdn.net/leixiaohua1020/article/details/42363079
qt配置vlc環境
下載vlc源碼
點擊下載地址選擇win64/win32,我選的是win64,下載.7z結尾的,我下載的是vlc-2.2.4-win64.7z

下載解壓之后是下面這個樣子

解壓后找到sdk文件夾,這個文件夾非常重要
simple_libvlc_qt_player
第一次提交代碼,最簡單的libvlc播放器
-
創建控制台項目(參考qt環境搭建教程)
-
配置
.pro文件
在底部添加如下代碼
win32{
INCLUDEPATH += $$PWD/sdk/include
LIBS += -L$$PWD/sdk/lib -llibvlc -llibvlccore
}else{
INCLUDEPATH += /usr/local/include
LIBS += -L/usr/local/lib -lvlc -lvlccore
}
- 配置sdk
將解壓后的sdk文件夾復制到main.cpp文件夾下即可

測試代碼見simple_libvlc_qt_player
運行結果播放cuc_ieschool.flv這個視頻
- 測試代碼
#include <QCoreApplication>
#include <Windows.h>
#include "vlc/vlc.h"
using namespace std;
int main(int argc, char* argv[])
{
libvlc_instance_t* inst;
libvlc_media_player_t* mp;
libvlc_media_t* m;
libvlc_time_t length;
int width;
int height;
int wait_time = 5000;
const char* version;
version = libvlc_get_version();
printf("version: %s\n", version);
inst = libvlc_new(NULL, NULL);
char filename[1024] = "../simple_libvlc_qt_player/cuc_ieschool.flv";
//m = libvlc_media_new_location (inst,"rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mov" );
m = libvlc_media_new_path (inst,filename);
mp = libvlc_media_player_new_from_media(m);
libvlc_media_release(m);
libvlc_media_player_play(mp);
//wait until the tracks are created
_sleep(wait_time);
length = libvlc_media_player_get_length(mp);
width = libvlc_video_get_width(mp);
height = libvlc_video_get_height(mp);
printf("Stream Duration: %ds\n", length / 1000);
printf("Resolution: %d x %d\n", width, height);
//Let it play
_sleep(length - wait_time);
// Stop playing
libvlc_media_player_stop(mp);
libvlc_media_player_release(mp);
libvlc_release(inst);
return 0;
}
- 程序發布
在
simple_libvlc_qt_player文件夾下有一個release文件夾將里面的動態鏈接庫放到打包的程序目錄下即可發布
項目地址
GitHub項目地址:https://github.com/ADeRoy/libvlc_qt_demo
如果幫助到你,可以給個star
