下载ubuntu
https://releases.ubuntu.com/16.04/ubuntu-16.04.7-desktop-amd64.iso
下载ffmpeg
https://ffmpeg.org/download.html
下载QtAV
https://github.com/wang-bin/QtAV/releases
更新
sudo apt update
安装库
sudo apt-get install libglu1-mesa-dev freeglut3-dev mesa-common-dev
sudo apt-get install libavutil-dev libavcodec-dev libavformat-dev libswscale-dev
sudo apt-get install libopenal-dev libpulse-dev libva-dev libxv-dev libass-dev libegl1-mesa-dev
编译ffmpeg
./configure --enable-shared --disable-yasm --prefix=/usr/local/ffmpeg
make
sudo make install
ffmepg可不编译
安装qt4
sudo apt install qt4-default
编译QtAV
cd QtAV-1.12.0
mkdir build
cd build
qmake ..
make
用例
untitled1.pro
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = untitled1
TEMPLATE = app
SOURCES += main.cpp\
playerwindow.cpp
HEADERS += playerwindow.h
INCLUDEPATH += $$PWD/include
LIBS += -L$$PWD/lib_linux_x86_64/ -Wl,-rpath=$$PWD/lib_linux_x86_64/ -lQtAV -lQtAVWidgets
playerwindow.h
#ifndef PLAYERWINDOW_H
#define PLAYERWINDOW_H
#include <QWidget>
#include <QtAV/VideoOutput.h>
#include <QtAV/AVPlayer.h>
QT_BEGIN_NAMESPACE
class QSlider;
class QPushButton;
QT_END_NAMESPACE
class PlayerWindow : public QWidget
{
Q_OBJECT
public:
explicit PlayerWindow(QWidget *parent = 0);
public Q_SLOTS:
void openMedia();
void seekBySlider(int value);
void seekBySlider();
void playPause();
private Q_SLOTS:
void updateSlider(qint64 value);
void updateSlider();
void updateSliderUnit();
private:
QtAV::VideoOutput *m_vo;
QtAV::AVPlayer *m_player;
QSlider *m_slider;
QPushButton *m_openBtn;
QPushButton *m_playBtn;
QPushButton *m_stopBtn;
int m_unit;
};
#endif // PLAYERWINDOW_H
playerwindow.cpp
#include "playerwindow.h"
#include <QPushButton>
#include <QSlider>
#include <QLayout>
#include <QMessageBox>
#include <QFileDialog>
using namespace QtAV;
PlayerWindow::PlayerWindow(QWidget *parent) : QWidget(parent)
{
m_unit = 1000;
setWindowTitle(QString::fromLatin1("QtAV simple player example"));
m_player = new AVPlayer(this);
QVBoxLayout *vl = new QVBoxLayout();
setLayout(vl);
m_vo = new VideoOutput(this);
if (!m_vo->widget()) {
QMessageBox::warning(0, QString::fromLatin1("QtAV error"), tr("Can not create video renderer"));
return;
}
m_player->setRenderer(m_vo);
vl->addWidget(m_vo->widget());
m_slider = new QSlider();
m_slider->setOrientation(Qt::Horizontal);
connect(m_slider, SIGNAL(sliderMoved(int)), SLOT(seekBySlider(int)));
connect(m_slider, SIGNAL(sliderPressed()), SLOT(seekBySlider()));
connect(m_player, SIGNAL(positionChanged(qint64)), SLOT(updateSlider(qint64)));
connect(m_player, SIGNAL(started()), SLOT(updateSlider()));
connect(m_player, SIGNAL(notifyIntervalChanged()), SLOT(updateSliderUnit()));
vl->addWidget(m_slider);
QHBoxLayout *hb = new QHBoxLayout();
vl->addLayout(hb);
m_openBtn = new QPushButton(tr("Open"));
m_playBtn = new QPushButton(tr("Play/Pause"));
m_stopBtn = new QPushButton(tr("Stop"));
hb->addWidget(m_openBtn);
hb->addWidget(m_playBtn);
hb->addWidget(m_stopBtn);
connect(m_openBtn, SIGNAL(clicked()), SLOT(openMedia()));
connect(m_playBtn, SIGNAL(clicked()), SLOT(playPause()));
connect(m_stopBtn, SIGNAL(clicked()), m_player, SLOT(stop()));
}
void PlayerWindow::openMedia()
{
QString file = QFileDialog::getOpenFileName(0, tr("Open a video"));
if (file.isEmpty())
return;
m_player->play(file);
}
void PlayerWindow::seekBySlider(int value)
{
if (!m_player->isPlaying())
return;
m_player->seek(qint64(value*m_unit));
}
void PlayerWindow::seekBySlider()
{
seekBySlider(m_slider->value());
}
void PlayerWindow::playPause()
{
if (!m_player->isPlaying()) {
m_player->play();
return;
}
m_player->pause(!m_player->isPaused());
}
void PlayerWindow::updateSlider(qint64 value)
{
m_slider->setRange(0, int(m_player->duration()/m_unit));
m_slider->setValue(int(value/m_unit));
}
void PlayerWindow::updateSlider()
{
updateSlider(m_player->position());
}
void PlayerWindow::updateSliderUnit()
{
m_unit = m_player->notifyInterval();
updateSlider();
}
main.cpp
#include <QApplication>
#include "playerwindow.h"
#include <QtAVWidgets/global.h>
int main(int argc, char *argv[])
{
QtAV::Widgets::registerRenderers();
QApplication a(argc, argv);
PlayerWindow player;
player.show();
player.resize(800, 600);
return a.exec();
}
参考:Qt第三方库QtAV--- ubuntu编译与运行_那时风起的博客-CSDN博客