vs2017使用vlc視訊播放器

weixin_33912246發表於2018-09-17

下載原始碼

vlc原始碼

vs新建工程

根據自己的情況調整,我是debug的x64。

對著專案右鍵屬性

找到c/c++下的附加包含目錄

3534535-5930b4015a5e2754.png
image.png

找到連結器下的附加庫目錄

3534535-879ba969aff84f2a.png
image.png

拷貝

最後,將vlc檔案目錄下的plugins資料夾以及libvlc.dll和libvlccore.dll這兩個檔案複製到你專案工程的/x64/debug目錄下。如果沒有這個目錄,就先執行一次空程式,目錄下就會有了。

準備工作完成

測試

#include "vlc/vlc.h" 
#pragma comment(lib,"libvlc.lib")
#pragma comment(lib,"libvlccore.lib")
 
 
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;
 
    //libvlc_time_t length;  
 
    /* Load the VLC engine */
    inst = libvlc_new(0, NULL);
 
    //Create a new item  
    //Method 1:  
    m = libvlc_media_new_location (inst, "rtsp://XXXXX你的RTSP流XXXXX");  
    //Screen Capture  
    //m = libvlc_media_new_location (inst, "screen://");  
    //Method 2:  
    //m = libvlc_media_new_path(inst, "cuc_ieschool.flv");
 
    /* Create a media player playing environement */
    mp = libvlc_media_player_new_from_media(m);
 
 
    /* No need to keep the media now */
    libvlc_media_release(m);
 
    // play the media_player  
    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);
 
    // Free the media_player  
    libvlc_media_player_release(mp);
 
    libvlc_release(inst);
 
    return 0;
}

可以播放視訊就是成功了~

相關文章