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;
}
相关推荐
似水明俊德13 小时前
02-C#.Net-反射-面试题
开发语言·面试·职场和发展·c#·.net
Thera77714 小时前
C++ 高性能时间轮定时器:从单例设计到 Linux timerfd 深度优化
linux·开发语言·c++
炘爚15 小时前
C语言(文件操作)
c语言·开发语言
阿蒙Amon15 小时前
C#常用类库-详解SerialPort
开发语言·c#
凸头15 小时前
CompletableFuture 与 Future 对比与实战示例
java·开发语言
wuqingshun31415915 小时前
线程安全需要保证几个基本特征
java·开发语言·jvm
Moksha26215 小时前
5G、VoNR基本概念
开发语言·5g·php
jzlhll12316 小时前
kotlin Flow first() last()总结
开发语言·前端·kotlin
W.D.小糊涂16 小时前
gpu服务器安装windows+ubuntu24.04双系统
c语言·开发语言·数据库
用头发抵命16 小时前
Vue 3 中优雅地集成 Video.js 播放器:从组件封装到功能定制
开发语言·javascript·ecmascript