一、LibVLC的SDK下载
地址:下载
特别注意
二、LibVLC的使用(vs系列)
三、运行出现问题
1.问题 C2065 “libvlc_media_read_cb”: 未声明的标识符
1.解决
在#include "vlc/vlc.h" 之前加入
#ifdef _WIN32
#include <basetsd.h>
typedef SSIZE_T ssize_t;
#endif
2.问题
2.解决
将plugins文件夹放入你的可执行文件目录下面
四、使用libvlc播放视频
1.实例代码 此处用到雷神的代码 雷神博客地址https://me.csdn.net/leixiaohua1020
#ifdef _WIN32
#include <basetsd.h>
typedef SSIZE_T ssize_t;
#endif
#include <Windows.h>
#include <iostream>
#include "vlc/vlc.h"
#pragma comment(lib,"libvlc.lib")
#pragma comment(lib,"libvlccore.lib")
int main(int argc, char* argv[])
{
libvlc_instance_t* inst = NULL ;
libvlc_media_player_t* mp = NULL;
libvlc_media_t* m = NULL;
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, "file:///F:\\movie\\cuc_ieschool.flv");
//Screen Capture
//m = libvlc_media_new_location (inst, "screen://");
//Method 2:
m = libvlc_media_new_path(inst, "F:\\VSCode\\LibVLCTest\\bin\\cuc_ieschool.flv");
if (!m) {
std::cout << "libvlc_media_new_path fail!!!" << std::endl;
return -1;
}
/* 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;
}
2.程序效果