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;
}
相关推荐
小浣熊熊熊熊熊熊熊丶2 小时前
《Effective Java》第25条:限制源文件为单个顶级类
java·开发语言·effective java
木千2 小时前
Qt中关于eventFilter函数无法过滤QTableWidget鼠标事件的处理方式
qt
啃火龙果的兔子2 小时前
JDK 安装配置
java·开发语言
星哥说事2 小时前
应用程序监控:Java 与 Web 应用的实践
java·开发语言
等....3 小时前
Miniconda使用
开发语言·python
zfj3213 小时前
go为什么设计成源码依赖,而不是二进制依赖
开发语言·后端·golang
醇氧3 小时前
org.jetbrains.annotations的@Nullable 学习
java·开发语言·学习·intellij-idea
Java&Develop3 小时前
Aes加密 GCM java
java·开发语言·python
weixin_462446233 小时前
使用 Go 实现 SSE 流式推送 + 打字机效果(模拟 Coze Chat)
开发语言·后端·golang
JIngJaneIL3 小时前
基于springboot + vue古城景区管理系统(源码+数据库+文档)
java·开发语言·前端·数据库·vue.js·spring boot·后端