在VS2015下配置libvlc并实现一个简单RTSP的播放器

来源:互联网 发布:上帝不会掷骰子 知乎 编辑:程序博客网 时间:2024/06/06 01:04

简介

  • VLC 是一款自由、开源的跨平台多媒体播放器及框架,可播放大多数多媒体文件,以及 DVD、音频 CD、VCD 及各类流媒体协议。
  • 由于VLC是完全开源的,所以我们可以获得所有的项目源码,并在此基础上进行二次开发
  • 这篇文章主要介绍了Win10 64位环境下在VS2015中配置libvlc的方法,并提供了一个简单的播放RTSP流的测试样例

VLC的官网:http://www.videolan.org/
VLC源码下载地址:http://download.videolan.org/pub/videolan/vlc/2.2.4/
测试代码来源,雷神的博客:http://blog.csdn.net/leixiaohua1020/article/details/42363079

PS.可能需要翻墙才能进入官网

配置方法

  • 从上面所提供的VLC源码下载地址中下载所需要的.7z文件,如下图,我们下载第一个就行了

这里写图片描述

  • 解压到任意文件夹
  • 打开VS2015,新建一个工程
  • 将项目属性调整为Release x64模式,如下图所示

这里写图片描述

  • 打开 项目—项目属性 窗口,将你解压出的vlc文件目录下的sdk\include添加到C/C++选项下的“附加包含目录”中

这里写图片描述

  • 将你解压出的vlc文件目录下的sdk\lib添加到链接器选项下的“附加库目录”中

这里写图片描述

  • 最后,将vlc文件目录下的plugins文件夹以及libvlc.dll和libvlccore.dll这两个文件复制到你项目工程的/x64/release目录下。如果没有这个目录,就先运行一次空程序,目录下就会有了。

  • 至此,我们便完成了libvlc的基本配置。

测试代码样例

#include <Windows.h>  #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;}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60

运行结果

这里写图片描述

想要退出播放的话,在命令行界面 Ctrl+C 即可。

阅读全文
0 0
原创粉丝点击