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;
}
相关推荐
Joey_friends37 分钟前
【Linux】线程详解
开发语言
_GR42 分钟前
Qt开发⑧Qt的窗口_下_浮动窗口+对话框
开发语言·css·c++·qt·microsoft
Good Note1 小时前
Golang——常用库context和runtime
开发语言·爬虫·golang
清河__1 小时前
【Go】十七、grpc 服务的具体功能编写
开发语言·后端·golang
张声录11 小时前
国密算法Sm2工具类--golang实现版
开发语言·后端·golang
HH牛码2 小时前
C# 中 Array、ArrayList 和 List 的比较
开发语言·c#
zr想努力3 小时前
Lua的table类型的增删改查操作
java·开发语言·lua
Evand J4 小时前
【MATLAB代码】RSA加密和解密例程
开发语言·算法·matlab
go54631584657 小时前
本地部署 GitHub 上的 Python 人脸识别项目
开发语言·python·github
wjs20248 小时前
PHP 连接 Memcached 服务
开发语言