QT+ffmpeg环境配置

1.新建一个qt项目

2.下载ffmpeg文件Releases · BtbN/FFmpeg-Builds · GitHub

3.解压后,打开qt项目地址,将ffmpeg文件复制进qt项目

4.打开新建的qt项目头文件新加入如下内容:(如有需求可按需求添加)

复制代码
INCLUDEPATH +=$$PWD/include

LIBS += $$PWD/lib/avcodec.lib \
        $$PWD/lib/avfilter.lib \
        $$PWD/lib/avformat.lib \
        $$PWD/lib/avutil.lib \
        $$PWD/lib/postproc.lib \
        $$PWD/lib/swresample.lib \
        $$PWD/lib/swscale.lib

5.测试

将mainwindows.cpp文件替换为如下内容:(注意:调用ffmpeg头文件必须用extern "C",因为ffmpeg为纯c)

复制代码
#include "mainwindow.h"
#include "ui_mainwindow.h"

#include <QDebug>
extern "C"
{
#include <libavformat/avformat.h>
#include <libavcodec/avcodec.h>
}
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    avformat_network_init();


    const char* filename = "input.mp4"; // Ensure this file exists or change to a valid path
    AVFormatContext* formatContext = nullptr;
    if (avformat_open_input(&formatContext, filename, nullptr, nullptr) != 0) {
        qWarning() << "Could not open the file.";
    } else {
        // Print some information about the file
        qDebug() << "Format:" << formatContext->iformat->name;
        qDebug() << "Duration:" << formatContext->duration / AV_TIME_BASE << "seconds";
        qDebug() << "Bit rate:" << formatContext->bit_rate;

        // Clean up
        avformat_close_input(&formatContext);
    }
}

MainWindow::~MainWindow()
{
    delete ui;
}
相关推荐
Chh07157 分钟前
《R语言SCI期刊论文绘图专题计划》大纲
开发语言·r语言
Yeats_Liao8 分钟前
Go 语言 TCP 端口扫描器实现与 Goroutine 池原理
开发语言·tcp/ip·golang
Thomas_YXQ39 分钟前
Unity3D IK解算器技术分析
开发语言·搜索引擎·unity·全文检索·unity3d·lucene
机器视觉知识推荐、就业指导39 分钟前
开源QML控件:进度条滑动控件(含源码下载链接)
前端·qt·开源·qml
liuweidong08021 小时前
【Pandas】pandas DataFrame rsub
开发语言·python·pandas
whoarethenext1 小时前
c++的jsoncpp使用
开发语言·c++·jsoncpp
niuTaylor2 小时前
Linux驱动开发快速上手指南:从理论到实战
linux·运维·开发语言·驱动开发·c#
CH3_CH2_CHO2 小时前
不吃【Numpy】版
开发语言·python·numpy
苦学编程的谢2 小时前
再谈String
java·开发语言
神奇小永哥2 小时前
那些年踩过的坑之Arrays.asList
java·开发语言