本机配置:win10 64位+VS2017+Qt5.9.1,其中Qt安装过程不再赘述,安装时选上MSVC2017-64(因为我的电脑是64位的且VS版本为2017)。
可根据自己的实际环境下载相应的库。
可以在下面的链接下载FFMPEG build库文件,其中dev中包含.h头文件和lib库,shared包含dll文件。
[FFMPEG bulild Download]
有了库文件以后,最主要的就是在Qt工程的.pro文件中配置库的目录。
1.将bin目录添加到系统环境变量中
2.配置pro文件
Video_player.pro:
#-------------------------------------------------
#
# Project created by QtCreator 2019-04-10T10:26:28
#
#-------------------------------------------------
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = Video_player
TEMPLATE = app
# The following define makes your compiler emit warnings if you use
# any feature of Qt which as 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 \
mainwindow.cpp \
video_player.cpp
HEADERS += \
mainwindow.h \
video_player.h
FORMS += \
mainwindow.ui
INCLUDEPATH += E:/ffmpeg4.1.1/include
LIBS += E:/ffmpeg4.1.1/lib/avcodec.lib \
E:/ffmpeg4.1.1/lib/avdevice.lib \
E:/ffmpeg4.1.1/lib/avfilter.lib \
E:/ffmpeg4.1.1/lib/avformat.lib \
E:/ffmpeg4.1.1/lib/avutil.lib \
E:/ffmpeg4.1.1/lib/postproc.lib \
E:/ffmpeg4.1.1/lib/swresample.lib \
E:/ffmpeg4.1.1/lib/swscale.lib
至此Qt Creator中配置FFmpeg完成。
注意FFmpeg是C语言写的库,在Qt项目中包含头文件时要用extern C,示例如下:
//ffmpeg include
extern "C"
{
#include "libavcodec/avcodec.h"
#include "libavformat/avformat.h"
#include "libavutil/pixfmt.h"
#include "libswscale/swscale.h"
#include "libavutil/time.h"
#include "libavutil/mathematics.h"
}