在Ubuntu下编译VLC并实现播放视频
在Ubuntu下编译VLC并实现播放视频
- 一、下载VLC源码
- 二、安装VLC依赖的库
- 三、VLC编译与安装
- 1、编译与安装
- 2、库文件
- 3、头文件
- 四、调用VLC实现播放视频
- 1、添加头文件、库路径
- 2、封装播放器类VLCPlayer
- 3、测试代码
- 五、报错解决
- 1、报错(You must put some ‘source’ URIs in your sources.list)
- 2、报错(error: “You cannot build VLC with Qt-5.5.0. You need to backport I78ef29975181ee22429c9bd4b11d96d9e68b7a9c”)
VLC官网:https://www.videolan.org/
VLC Github:https://github.com/videolan/vlc
测试环境:Ubuntu 16.04 64位系统,Qt Creator + GCC
一、下载VLC源码
下载地址:http://download.videolan.org/pub/videolan/vlc/2.2.4/vlc-2.2.4.tar.xz
二、安装VLC依赖的库
输入如下命令,安装依赖库:
sudo apt-get build-dep vlc
报错:You must put some ‘source’ URIs in your sources.list
参考第五章,进行解决。
三、VLC编译与安装
1、编译与安装
解压VLC压缩包,注意J为大写
tar -xvJf vlc-2.2.4.tar.xz
进入VLC源码目录
cd vlc-2.2.4
进行配置,先执行
./bootstrap
再执行
./configure
报错如下:error: “You cannot build VLC with Qt-5.5.0. You need to backport I78ef29975181ee22429c9bd4b11d96d9e68b7a9c”
参考第五章,进行解决之后继续。
编译
make
安装
sudo make install
编译安装后,即可在/usr/local/lib和/usr/local/include看到库和头文件。
2、库文件
VLC库文件位于/usr/local/lib。
我们程序调用VLC库运行时,依赖的so有libvlc.so、libvlc.so.5、libvlc.so.5.5.0、libvlccore.so、libvlccore.so.8、libvlccore.so.8.0.0共6个,如下:
另外,还依赖于/usr/local/lib/vlc/plugins目录下的插件。
建议打包时,直接拷贝plugins目录,并按/usr/local/lib下的相对目录结构组织,即vlc目录与so同一级,plugins目录放在vlc目录下。
3、头文件
VLC头文件位于/usr/local/include。
四、调用VLC实现播放视频
1、添加头文件、库路径
我们建立一个Qt测试工程,pro文件中加入包含头文件、库路径,如下:
unix {# VLC相关库
LIBS += -L/usr/local/lib -lvlc# VLC头文件目录
INCLUDEPATH += /usr/local/include
}
2、封装播放器类VLCPlayer
VLC实现一个基本的播放流程,如下:
过程也是非常的简单,我们封装一个简单的播放器类VLCPlayer。
VLCPlayer.h
#ifndef VLCPLAYER_H
#define VLCPLAYER_H#include <QString>
#include <qwindowdefs.h>
#include <vlc/vlc.h>class VLCPlayer
{public:enum State{Stopped, // 停止Playing, // 正在播放Paused // 暂停};VLCPlayer();~VLCPlayer();void setMedia(const QString& file); // 设置视频文件路径void setVideoOutput(WId winId); // 设置视频播放窗口id,视频在该窗口进行播放void play(); // 播放void pause(); // 暂停void resume(); // 继续void stop(); // 停止State state(); // 获取当前播放器状态private:libvlc_instance_t* instance; ///>VLC实例libvlc_media_player_t* player; ///>VLC媒体播放器libvlc_media_t* media; ///>可以播放的媒体
};#endif // VLCPLAYER_H
VLCPlayer.cpp
#include "VLCPlayer.h"
#include <QDir>VLCPlayer::VLCPlayer(): media(nullptr)
{// 创建VLC实例instance = libvlc_new (0, nullptr);// 创建VLC媒体播放器player = libvlc_media_player_new(instance);
}VLCPlayer::~VLCPlayer()
{// 释放媒体if (media){libvlc_media_release(media);media = nullptr;}// 释放VLC媒体播放器libvlc_media_player_release(player);player = nullptr;// 释放VLC实例libvlc_release(instance);instance = nullptr;
}void VLCPlayer::setMedia(const QString &file)
{// 将路径转换为本地系统路径风格// win下时,如将路径"a/b/c"转换为"a\\b\\c"形式// linux下时,将路径转换为"a/b/c"形式QString path = QDir::toNativeSeparators(file);// 释放旧的媒体if (media){libvlc_media_release(media);media = nullptr;}// 创建新的媒体media = libvlc_media_new_path(instance, path.toStdString().c_str());libvlc_media_player_set_media(player, media); // 把新的媒体设置给播放器
}void VLCPlayer::setVideoOutput(WId winId)
{// 设置播放句柄
#if defined(Q_OS_WIN)libvlc_media_player_set_hwnd(player, (void *)winId);
#elif defined(Q_OS_LINUX)libvlc_media_player_set_xwindow(player, winId);
#elif defined(Q_OS_MAC)libvlc_media_player_set_nsobject(player, (void *)winId);
#endif
}void VLCPlayer::play()
{libvlc_media_player_play(player);
}void VLCPlayer::pause()
{libvlc_media_player_pause(player);
}void VLCPlayer::resume()
{play();
}void VLCPlayer::stop()
{libvlc_media_player_stop(player);
}VLCPlayer::State VLCPlayer::state()
{libvlc_state_t s = libvlc_media_player_get_state(player);if (s == libvlc_Ended || s == libvlc_Stopped){return Stopped;}else if (s == libvlc_Paused){return Paused;}else if (s == libvlc_Playing){return Playing;}else{return Stopped;}
}
注意:
libvlc_media_new_path函数,第二个参数视频文件路径,在win下时,需要传入形如"D:\\video.mp4"
的路径;而在linux下时,需要传入形如"/root/video.mp4"
的路径。
3、测试代码
在主窗口中,添加如下测试代码。
mainwindow.h
class MainWindow : public QMainWindow
{Q_OBJECTpublic:explicit MainWindow(QWidget *parent = nullptr);~MainWindow();private slots:void on_pushButton_play_clicked();void on_pushButton_pause_clicked();void on_pushButton_resume_clicked();void on_pushButton_stop_clicked();private:Ui::MainWindow *ui;VLCPlayer player;
};
mainwindow.cpp
MainWindow::MainWindow(QWidget *parent) :QMainWindow(parent),ui(new Ui::MainWindow)
{ui->setupUi(this);player.setMedia(qApp->applicationDirPath() + "/video.mp4");player.setVideoOutput(ui->label_video->winId());
}MainWindow::~MainWindow()
{delete ui;
}void MainWindow::on_pushButton_play_clicked()
{player.play();
}void MainWindow::on_pushButton_pause_clicked()
{player.pause();
}void MainWindow::on_pushButton_resume_clicked()
{player.resume();
}void MainWindow::on_pushButton_stop_clicked()
{player.stop();
}
测试代码也十分简单,通过setMedia指定需要播放的视频文件,setVideoOutput指定在QLabel上进行播放,然后通过4个按钮进行播放控制。
执行效果如下:
五、报错解决
1、报错(You must put some ‘source’ URIs in your sources.list)
原因:找不到VLC相关的源
解决办法:修改Ubuntu服务器设置,步骤如下。
(1)选择“System Settings”菜单
(2)选择“Software & Updates”
(3)先勾选“Source code”,然后选择“Download from”中的“Other…”
(4)展开“China”,选择阿里云“mirrors.aliyun.com”,再点击“Choose Server”
(5) 点击“Close”,关闭窗口
(6)弹出软件信息过期提示,选择“Reload”
一会后就更新完毕。
再次执行:sudo apt-get build-dep vlc
,进行安装。
安装一段时间后,又报错误:
E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?
E: Failed to process build dependencies
我们按照提示,执行:sudo apt-get build-dep vlc --fix-missing
执行完毕,VLC依赖库,即可成功安装。
2、报错(error: “You cannot build VLC with Qt-5.5.0. You need to backport I78ef29975181ee22429c9bd4b11d96d9e68b7a9c”)
解决办法:在VLC源码目录下,configure.ac文件中找这一行,并注释掉
#PKG_CHECK_EXISTS([Qt5Core >= 5.5.0 Qt5Core < 5.6.0], [
# AC_MSG_ERROR(["You cannot build VLC with Qt-5.5.0. You need to backport I78ef29975181ee22429c9bd4b11d96d9e68b7a9c"])
#])
如下:
保存后,执行如下命令:autoconf
再执行./configure
命令,即可配置成功。
本文涉及工程代码:
https://gitee.com/bailiyang/cdemo/tree/master/Qt/63VLCTest/VLCPlayer
若对你有帮助,欢迎点赞、收藏、评论,你的支持就是我的最大动力!!!
同时,阿超为大家准备了丰富的学习资料,欢迎关注公众号“超哥学编程”,即可领取。
在Ubuntu下编译VLC并实现播放视频相关推荐
- 在Windows下编译VLC并实现播放视频
在Windows下编译VLC并实现播放视频 一.编译Win版的VLC真麻烦 二.获取VLC的SDK 1.下载VLC播放器 2.库文件 3.头文件 三.调用VLC实现播放视频 1.拷贝头文件和库文件 2 ...
- linux 编译 suitesparse,Ubuntu下编译SuiteSparse-4.4.1和METIS-4.0.3
ubuntu下编译caffe Ubuntu下编译caffe 纯粹是个人编译的记录.不用CUDA(笔记本是amd卡,万恶的nvidia):不手动编译依赖包(apt-get是用来干啥的?用来直接装二进制包 ...
- 从零开始,手把手教你如何在Ubuntu下编译VLC-Android源码
前言 公司项目中使用的libvlcjni.so库文件,有点老,对Android 6.0+系统兼容性太差了,当程序运行在Android6.0+系统上时,回弹出警告框,提示libvlcjni.so:tex ...
- Ubuntu 下编译ffmpeg和x264解编码器(翻译的一篇文章:)
拿出自己一篇早期接触Ubuntu时翻译的文章,对逝去的SEO-DIC.COM.CN这个网站默哀. Ubuntu 下编译ffmpeg和x264解编码器 今年初由于个人的一些原因和其它因素:希奥开源(ht ...
- Ubuntu下编译ffmpeg+openh264+x264
[笔记] Ubuntu下编译ffmpeg+openh264+x264 原文:https://www.cnblogs.com/journeyonmyway/p/4648820.html - ffmpeg ...
- 解决ubuntu下的firefox无法在线播放音频和视频的问题
解决ubuntu下的firefox无法在线播放音频和视频的问题 参考文章: (1)解决ubuntu下的firefox无法在线播放音频和视频的问题 (2)https://www.cnblogs.com/ ...
- [C++]Linux之Ubuntu下编译C程序出现错误:“ stray ‘\302‘或者‘\240‘ in program”的解决方案
[C++]Linux之Ubuntu下编译C程序出现错误:" stray '\302'或者'\240' in program"的解决方案 参考文章: (1)[C++]Linux之Ub ...
- Ubuntu下编译SHTOOLS
SHTOOLS是使用Fortran语言写的一个专门用于处理球谐函数的一个开源库,更多的介绍请猛戳这里,关于这个库的安装和使用,都在官网上有详细的说明,虽然很详细,但是编译的时候还是比较费劲,下面将我在 ...
- Ubuntu16.04下使用VLC media player播放器实现倍速播放
Ubuntu16.04下使用VLC media player播放器实现倍速播放 打开软件 开启倍速功能 打开软件 视频文件右键"属性"-"打开方式"-" ...
最新文章
- L09-10老男孩Linux运维实战培训-Nginx服务生产实战应用指南05(架构解决方案)
- linux 下用户管理
- 下列关于python的描述正确的是-以下关于Python中模块的说法正确的是(_____)。...
- SQLServer创建用户自定义数据库用户
- Faster R-CNN 深入理解 改进方法汇总
- Exchange Server2010系列之七:多邮箱搜索找出神秘邮件的幕后黑手
- Chrome开发者工具network标签页里的transferred over network和resources loaded by the page的区别
- 数据结构java语言kmp_数据结构(java语言描述)模式匹配——KMP算法
- 将log4cplus.so集成到linux下报undefined reference to 错误
- python makefile
- C++多线程Demo
- Linux的tasklet函数详解
- 戴尔t40服务器接显示器,Dell PowerEdge T40 机架式服务器
- mapgis安装|计算机中丢失basroot.dll
- 利用Travis IC实现Hexo博客自动化部署
- KepServerv设置为OPCUA通讯说明
- 浏览器中的js不能同步更新的解决方案
- PYTHON对接国际验证码接口
- 简单的交换排序法(选择排序)。
- Linux 10GE端口,问GE和10G区别,10GE和GE区别
热门文章
- 超200家上市企业布局!从千余条备案信息看区块链产业
- 利用腾讯云api实现手写字体识别
- 基于javaweb的宠物医院管理系统设计和实现(java+springboot+ssm+mysql+jsp)
- C - Censor KMP算法
- quagga-zebra路由协议 nsm 模块说明
- 四元数非正式笔记梳理_Quaternion kinematics for the error-state Kalman filter
- 微信小程序 视频列表 封面图 禁止多个视频同时播放
- 黑马程序员前端培训深圳首期班火爆开班
- 终于解决了打开快速关机无法断电的问题
- Linux中的缓存分类:free中的buff/cache;pagecache、dentries和inodes的区别