QtAV for ubuntu16.04

下载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博客

相关推荐
Qter_Sean4 小时前
自己动手写Qt Creator插件
开发语言·qt
何曾参静谧4 小时前
「QT」文件类 之 QIODevice 输入输出设备类
开发语言·qt
yyqzjw11 小时前
【qt】控件篇(Enable|geometry)
开发语言·qt
csdn_kike11 小时前
QT Unknown module(s) in QT 以及maintenance tool的更详细用法(qt6.6.0)
开发语言·qt
西西弗Sisyphus11 小时前
Qt 获取当前系统中连接的所有USB设备的信息 lsusb版
qt
kaixin_learn_qt_ing13 小时前
Qt---双缓冲绘图
qt
西西弗Sisyphus17 小时前
Qt 监控USB设备的插入和移除
qt
怀澈12218 小时前
QT之QString常用函数
开发语言·qt
zanglengyu19 小时前
RK3568硬解码并与Qt界面融合显示深入探究
开发语言·qt·ffmpeg·rk3568硬解码rtsp
doll ~CJ20 小时前
定时器(QTimer)与随机数生成器(QRandomGenerator)的应用实践——Qt(C++)
c++·qt·计时器与随机数生成器运用·图片循环播放