【Qt】 FFmpeg+Qt windows 32位或者64位环境搭建

简介

目前Ffmpeg官网(64位连接)下载的均为64位编译的,这要求我们采用的Qt creator也采用64位编译器。但是仍存在部分用户采用32位编译器,所以这部分用户需下载32 Ffmpeg(32位连接)。

根据使用的编译器位数下载ffmpeg版本,之后配置操作一致。

Note:32位与64位下载连接不同,请分别点击。

下载ffmpeg

Ffmpeg下载链接。建议下载稳定版本。

通过版本号命名的为稳定版,日期命名的为最新版。

这里会出现三个版本:

essentials:必要的组件,东西可能不全。

full:全面的,里面的库文件比较全。

shared:有动态链接库。

通过版本号命名的为稳定版,日期命名的为最新版。仅是使用的话下载essentials即可,Qt等调库需要选择shared(绿色箭头)。

下载完成后需要配置环境变量请参考:【流媒体】 通过ffmpeg硬解码拉流RTSP并播放。开头便是不在赘述。

配置头文件与库文件

在建立的Qt的.pro文件中添加文件路径。

复制代码
#-------------------------------------------------
#
# Project created by QtCreator 2024-07-14T21:21:58
#
#-------------------------------------------------

QT       += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = ffmpegtest
TEMPLATE = app

# The following define makes your compiler emit warnings if you use
# any feature of Qt which has been marked as deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS

# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0


SOURCES += \
        main.cpp \
        widget.cpp

HEADERS += \
        widget.h

FORMS += \
        widget.ui



FFMPEG_HOME=D:\LIB\ffmpeg-n6.0-latest-win32-lgpl-shared-6.0
    #设置 ffmpeg 的头文件
INCLUDEPATH += $$FFMPEG_HOME/include

   #设置导入库的目录一边程序可以找到导入库
    # -L :指定导入库的目录
    # -l :指定要导入的 库名称
LIBS +=  -L$$FFMPEG_HOME/lib \
             -lavcodec \
             -lavdevice \
             -lavfilter \
            -lavformat \
            -lavutil \
            -lswresample \
            -lswscale

将ffmpeg的 bin目录下的动态库文件(可以全选)复制到Qt工程的Debug文件下面。

全选复制到

配置代码测试环境

新建Qt工程,添加图示头文件及代码:

复制代码
#include "widget.h"
#include <QApplication>
#include <QDebug>

extern "C" {
#include <libavcodec/avcodec.h>
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
#include <libswscale/swscale.h>
#include <libavdevice/avdevice.h>
}


int main(int argc, char *argv[])
{
    qDebug() << "ffmpeg版本信息:"<< av_version_info();
    QApplication a(argc, argv);
    Widget w;
    w.show();

    return a.exec();
}

32的ffmpeg采用32位编译,64位使用64位编译器。

运行结果

输出版本信息即配置环境成功。

相关推荐
daqinzl23 分钟前
Mpegts.js+FFmpeg+WebSocket+Node实时视频流实现方案
websocket·ffmpeg·node·mpegts.js
未力忘39 分钟前
【无标题】
windows
大明者省1 小时前
在 Windows Server 2019 环境下配置 IIS 站点、本地端口服务、反向代理及内外网访问、多站点多服务部署
windows
您^_^1 小时前
ClaudeCode最近更新导致第三方模型Token消耗率暴涨,缓存命中也相当夸张!!
人工智能·windows·缓存·个人开发·claudecode·deepseek v4 pro
您^_^1 小时前
新手上路(四):Codex MCP 实战——让 Codex 连接外部世界
人工智能·windows·个人开发·codex·deepseek v4 pro
开开心心就好1 小时前
小白友好的程序联网封锁实用工具
windows·eureka·计算机外设·rabbitmq·word·excel·csdn开发云
宏笋1 小时前
qss/css 样式中margin和padding的作用和区别
css·qt
MageGojo1 小时前
小程序每日一谜怎么做:riddle 接口接入示例
windows·小程序·apache·谜语
Dfreedom.10 小时前
Windows、虚拟机、开发板组网通信原理及调试通联步骤
人工智能·windows·部署·边缘计算·开发板·模型加速
读书札记202211 小时前
Qt界面卡死问题探讨及解决方法
qt