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;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值