多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
在某个项目中需要在树莓派上播放广告视频,由于QT默认的QMultimedia播放视频性能堪忧(也可能没有用好!),于是想到了omxplayer这个性能一流的的播放器。 # 第1步,安装ffmpeg ###配置C++编译开发环境 ~~~ $ sudo apt-get install build-essential ~~~ 安装automake ~~~ $ sudo apt-get install automake1.11 ~~~ 如果是windows环境,还要安装yasm ~~~ $ sudo apt-get install yasm ~~~ 通过git下载ffmpeg源码 ~~~ $sudo git clone git://source.ffmpeg.org/ffmpeg.git ffmpeg ~~~ 生成makefile,编译 ~~~ ./configure make make install ~~~ 在树莓派下默认安装是在/usr/local 头文件在/usr/local/include 库文件在/usr/local/lib # 第2步,安装omxplayer 可通过git下载源码安装 ~~~ https://github.com/popcornmix/omxplayer ~~~ 也可apt-get直接安装编译好的包 ~~~ $ sudo apt-get install omxplayer ~~~ 现在可通过命令行输入播放视频了 ~~~ $ omxplayer /home/pi/myVideo.mp4 --win '100,100,500,300' 在100,100处播放myVideo.mp4,视频大小设定为500 × 300 ~~~ # 第3步,python使用dbus调用omxplayer 找到一个pytho的调用omxplayer的程序,哈哈 https://github.com/willprice/python-omxplayer-wrapper/ 下载安装 ~~~ $ git clone https://github.com/willprice/python-omxplayer-wrapper python-omxplayer-wrapper ~~~ 确保python-dbus已经安装了 ~~~ $ sudo apt-get install python-dbus ~~~ 进入python-omxplayer-wrapper目录安装 ~~~ $ python setup.py install ~~~ 然后就是照着例子写个Hello程序吧 ``` from omxplayer import OMXPlayer from time import sleep player = OMXPlayer('/home/pi/myVideo.mp4', args=['--win','100,100,500,300']) player.play() sleep(5) player.pause() player.quit() ``` # 第4步,使用QT调用omxplayer 在树莓派上,使用QT5.3编译 ~~~ #include "mainwindow.h" #include "ui_mainwindow.h" #include <QStringList> #include <QtCore/QCoreApplication> #include <QtDBus/QtDBus> MainWindow::MainWindow(QWidget *parent): QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); QString prog = "/usr/bin/omxplayer"; QStringList args; args <<"/home/pi/myVideo.mp4"<<"--win"<<"100,100,500,300"; QProcess *omxplayer = new QProcess(); omxplayer->startDetached(prog, args); } MainWindow::~MainWindow() { delete ui; } void MainWindow::on_pushButtonPause_clicked() { QString prog = "/root/omxplayer/dbuscontrol.sh"; QStringList args; args << "pause"; QProcess *pause = new QProcess(); pause->startDetached(prog,args); } ~~~