实际上这就是一个Qt增加第三方库的例子。实际上添加第三方库,就是配置include 和lib 到qt的 pro文件中。
需要下载ffmpeg的dev 和share包。其中include 和lib在dev包中。dll在share包中。
一、方法一:
1.使用Qt的图形化界面,添加库。
2.在弹出的添加库对话框中选择外部库,点下一步。
3.在这一步选择外部库文件(这种图形操作每次只能添加一个lib文件)
4.最终告诉增加的pro配置语句。
win32: LIBS += -L$$PWD/../../ffmpeg/ffmpeg-4.2.3-win64-dev/lib/ -lavcodec
INCLUDEPATH += $$PWD/../../ffmpeg/ffmpeg-4.2.3-win64-dev/include
DEPENDPATH += $$PWD/../../ffmpeg/ffmpeg-4.2.3-win64-dev/include
很不推荐这种方法,ffmpeg 的lib 库是多个文件,include都在一个目录下。首先他不支持多个库文件添加,第二include文件夹虽然是相同,但是程序依旧会死死的重复添加。
二、方法二:
自己直接修改pro文件
INCLUDEPATH += $$PWD/ffmpeg-4.2.3-win64-dev/include
LIBS += -L$$PWD/"ffmpeg-4.2.3-win64-dev/lib" -lavcodec \
-L$$PWD/"ffmpeg-4.2.3-win64-dev/lib" -lavdevice \
-L$$PWD/"ffmpeg-4.2.3-win64-dev/lib" -lavfilter \
-L$$PWD/"ffmpeg-4.2.3-win64-dev/lib" -lavformat \
-L$$PWD/"ffmpeg-4.2.3-win64-dev/lib" -lavutil \
-L$$PWD/"ffmpeg-4.2.3-win64-dev/lib" -lpostproc \
-L$$PWD/"ffmpeg-4.2.3-win64-dev/lib" -lswresample \
-L$$PWD/"ffmpeg-4.2.3-win64-dev/lib" -lswscale \
这种办法效率很高。说一下语法
$$PWD:是项目根目录
-L 是寻找目录,注意跟后面的路径buneng 有空格。
-l 是寻找库 ,同样不能有空格
对于多个库 用“\” 符合结尾。
另外相对于QT 图形化工具,我这里少了 DEPENDPATH(应用程序所依赖的搜索路径)。实际操作发现不配置这个变量,程序也可以正常编译执行。
三、其他:
1.最后需要把share包里的dll放到编译后exe相同的目录下。一般是qt 的debug目录。
2.我们是可以把ffmpeg的dev包甚至源文件文件直接放到项目里的。方法是右击项目——add Existing Directiry。

它实际上也是在pro文件里面增加配置代码,但是添加了DISTFILES 和include 环境变量依旧还需要配置libs环境变量。
DISTFILES += \
ffmpeg-4.2.3-win64-dev/lib/avcodec-58.def \
ffmpeg-4.2.3-win64-dev/lib/avcodec.lib \
ffmpeg-4.2.3-win64-dev/lib/avdevice-58.def \
ffmpeg-4.2.3-win64-dev/lib/avdevice.lib \
ffmpeg-4.2.3-win64-dev/lib/avfilter-7.def \
ffmpeg-4.2.3-win64-dev/lib/avfilter.lib \
ffmpeg-4.2.3-win64-dev/lib/avformat-58.def \
ffmpeg-4.2.3-win64-dev/lib/avformat.lib \
ffmpeg-4.2.3-win64-dev/lib/avutil-56.def \
ffmpeg-4.2.3-win64-dev/lib/avutil.lib \
ffmpeg-4.2.3-win64-dev/lib/libavcodec.dll.a \
ffmpeg-4.2.3-win64-dev/lib/libavdevice.dll.a \
ffmpeg-4.2.3-win64-dev/lib/libavfilter.dll.a \
ffmpeg-4.2.3-win64-dev/lib/libavformat.dll.a \
ffmpeg-4.2.3-win64-dev/lib/libavutil.dll.a \
ffmpeg-4.2.3-win64-dev/lib/libpostproc.dll.a \
ffmpeg-4.2.3-win64-dev/lib/libswresample.dll.a \
ffmpeg-4.2.3-win64-dev/lib/libswscale.dll.a \
ffmpeg-4.2.3-win64-dev/lib/postproc-55.def \
ffmpeg-4.2.3-win64-dev/lib/postproc.lib \
ffmpeg-4.2.3-win64-dev/lib/swresample-3.def \
ffmpeg-4.2.3-win64-dev/lib/swresample.lib \
ffmpeg-4.2.3-win64-dev/lib/swscale-5.def \
ffmpeg-4.2.3-win64-dev/lib/swscale.lib
HEADERS += \
ffmpeg-4.2.3-win64-dev/include/libavcodec/ac3_parser.h \
ffmpeg-4.2.3-win64-dev/include/libavcodec/adts_parser.h \
ffmpeg-4.2.3-win64-dev/include/libavcodec/avcodec.h \
ffmpeg-4.2.3-win64-dev/include/libavcodec/avdct.h \
ffmpeg-4.2.3-win64-dev/include/libavcodec/avfft.h \
ffmpeg-4.2.3-win64-dev/include/libavcodec/d3d11va.h \
ffmpeg-4.2.3-win64-dev/include/libavcodec/dirac.h \
ffmpeg-4.2.3-win64-dev/include/libavcodec/dv_profile.h \
ffmpeg-4.2.3-win64-dev/include/libavcodec/dxva2.h \
ffmpeg-4.2.3-win64-dev/include/libavcodec/jni.h \
ffmpeg-4.2.3-win64-dev/include/libavcodec/mediacodec.h \
ffmpeg-4.2.3-win64-dev/include/libavcodec/qsv.h \
ffmpeg-4.2.3-win64-dev/include/libavcodec/vaapi.h \
ffmpeg-4.2.3-win64-dev/include/libavcodec/vdpau.h \
ffmpeg-4.2.3-win64-dev/include/libavcodec/version.h \
ffmpeg-4.2.3-win64-dev/include/libavcodec/videotoolbox.h \
ffmpeg-4.2.3-win64-dev/include/libavcodec/vorbis_parser.h \
ffmpeg-4.2.3-win64-dev/include/libavcodec/xvmc.h \
ffmpeg-4.2.3-win64-dev/include/libavdevice/avdevice.h \
ffmpeg-4.2.3-win64-dev/include/libavdevice/version.h \
ffmpeg-4.2.3-win64-dev/include/libavfilter/avfilter.h \
ffmpeg-4.2.3-win64-dev/include/libavfilter/buffersink.h \
ffmpeg-4.2.3-win64-dev/include/libavfilter/buffersrc.h \
ffmpeg-4.2.3-win64-dev/include/libavfilter/version.h \
ffmpeg-4.2.3-win64-dev/include/libavformat/avformat.h \
ffmpeg-4.2.3-win64-dev/include/libavformat/avio.h \
ffmpeg-4.2.3-win64-dev/include/libavformat/version.h \
ffmpeg-4.2.3-win64-dev/include/libavutil/adler32.h \
ffmpeg-4.2.3-win64-dev/include/libavutil/aes.h \
ffmpeg-4.2.3-win64-dev/include/libavutil/aes_ctr.h \
ffmpeg-4.2.3-win64-dev/include/libavutil/attributes.h \
ffmpeg-4.2.3-win64-dev/include/libavutil/audio_fifo.h \
ffmpeg-4.2.3-win64-dev/include/libavutil/avassert.h \
ffmpeg-4.2.3-win64-dev/include/libavutil/avconfig.h \
ffmpeg-4.2.3-win64-dev/include/libavutil/avstring.h \
ffmpeg-4.2.3-win64-dev/include/libavutil/avutil.h \
ffmpeg-4.2.3-win64-dev/include/libavutil/base64.h \
ffmpeg-4.2.3-win64-dev/include/libavutil/blowfish.h \
ffmpeg-4.2.3-win64-dev/include/libavutil/bprint.h \
ffmpeg-4.2.3-win64-dev/include/libavutil/bswap.h \
ffmpeg-4.2.3-win64-dev/include/libavutil/buffer.h \
ffmpeg-4.2.3-win64-dev/include/libavutil/camellia.h \
ffmpeg-4.2.3-win64-dev/include/libavutil/cast5.h \
ffmpeg-4.2.3-win64-dev/include/libavutil/channel_layout.h \
ffmpeg-4.2.3-win64-dev/include/libavutil/common.h \
ffmpeg-4.2.3-win64-dev/include/libavutil/cpu.h \
ffmpeg-4.2.3-win64-dev/include/libavutil/crc.h \
ffmpeg-4.2.3-win64-dev/include/libavutil/des.h \
ffmpeg-4.2.3-win64-dev/include/libavutil/dict.h \
ffmpeg-4.2.3-win64-dev/include/libavutil/display.h \
ffmpeg-4.2.3-win64-dev/include/libavutil/downmix_info.h \
ffmpeg-4.2.3-win64-dev/include/libavutil/encryption_info.h \
ffmpeg-4.2.3-win64-dev/include/libavutil/error.h \
ffmpeg-4.2.3-win64-dev/include/libavutil/eval.h \
ffmpeg-4.2.3-win64-dev/include/libavutil/ffversion.h \
ffmpeg-4.2.3-win64-dev/include/libavutil/fifo.h \
ffmpeg-4.2.3-win64-dev/include/libavutil/file.h \
ffmpeg-4.2.3-win64-dev/include/libavutil/frame.h \
ffmpeg-4.2.3-win64-dev/include/libavutil/hash.h \
ffmpeg-4.2.3-win64-dev/include/libavutil/hdr_dynamic_metadata.h \
ffmpeg-4.2.3-win64-dev/include/libavutil/hmac.h \
ffmpeg-4.2.3-win64-dev/include/libavutil/hwcontext.h \
ffmpeg-4.2.3-win64-dev/include/libavutil/hwcontext_cuda.h \
ffmpeg-4.2.3-win64-dev/include/libavutil/hwcontext_d3d11va.h \
ffmpeg-4.2.3-win64-dev/include/libavutil/hwcontext_drm.h \
ffmpeg-4.2.3-win64-dev/include/libavutil/hwcontext_dxva2.h \
ffmpeg-4.2.3-win64-dev/include/libavutil/hwcontext_mediacodec.h \
ffmpeg-4.2.3-win64-dev/include/libavutil/hwcontext_qsv.h \
ffmpeg-4.2.3-win64-dev/include/libavutil/hwcontext_vaapi.h \
ffmpeg-4.2.3-win64-dev/include/libavutil/hwcontext_vdpau.h \
ffmpeg-4.2.3-win64-dev/include/libavutil/hwcontext_videotoolbox.h \
ffmpeg-4.2.3-win64-dev/include/libavutil/imgutils.h \
ffmpeg-4.2.3-win64-dev/include/libavutil/intfloat.h \
ffmpeg-4.2.3-win64-dev/include/libavutil/intreadwrite.h \
ffmpeg-4.2.3-win64-dev/include/libavutil/lfg.h \
ffmpeg-4.2.3-win64-dev/include/libavutil/log.h \
ffmpeg-4.2.3-win64-dev/include/libavutil/lzo.h \
ffmpeg-4.2.3-win64-dev/include/libavutil/macros.h \
ffmpeg-4.2.3-win64-dev/include/libavutil/mastering_display_metadata.h \
ffmpeg-4.2.3-win64-dev/include/libavutil/mathematics.h \
ffmpeg-4.2.3-win64-dev/include/libavutil/md5.h \
ffmpeg-4.2.3-win64-dev/include/libavutil/mem.h \
ffmpeg-4.2.3-win64-dev/include/libavutil/motion_vector.h \
ffmpeg-4.2.3-win64-dev/include/libavutil/murmur3.h \
ffmpeg-4.2.3-win64-dev/include/libavutil/opt.h \
ffmpeg-4.2.3-win64-dev/include/libavutil/parseutils.h \
ffmpeg-4.2.3-win64-dev/include/libavutil/pixdesc.h \
ffmpeg-4.2.3-win64-dev/include/libavutil/pixelutils.h \
ffmpeg-4.2.3-win64-dev/include/libavutil/pixfmt.h \
ffmpeg-4.2.3-win64-dev/include/libavutil/random_seed.h \
ffmpeg-4.2.3-win64-dev/include/libavutil/rational.h \
ffmpeg-4.2.3-win64-dev/include/libavutil/rc4.h \
ffmpeg-4.2.3-win64-dev/include/libavutil/replaygain.h \
ffmpeg-4.2.3-win64-dev/include/libavutil/ripemd.h \
ffmpeg-4.2.3-win64-dev/include/libavutil/samplefmt.h \
ffmpeg-4.2.3-win64-dev/include/libavutil/sha.h \
ffmpeg-4.2.3-win64-dev/include/libavutil/sha512.h \
ffmpeg-4.2.3-win64-dev/include/libavutil/spherical.h \
ffmpeg-4.2.3-win64-dev/include/libavutil/stereo3d.h \
ffmpeg-4.2.3-win64-dev/include/libavutil/tea.h \
ffmpeg-4.2.3-win64-dev/include/libavutil/threadmessage.h \
ffmpeg-4.2.3-win64-dev/include/libavutil/time.h \
ffmpeg-4.2.3-win64-dev/include/libavutil/timecode.h \
ffmpeg-4.2.3-win64-dev/include/libavutil/timestamp.h \
ffmpeg-4.2.3-win64-dev/include/libavutil/tree.h \
ffmpeg-4.2.3-win64-dev/include/libavutil/twofish.h \
ffmpeg-4.2.3-win64-dev/include/libavutil/tx.h \
ffmpeg-4.2.3-win64-dev/include/libavutil/version.h \
ffmpeg-4.2.3-win64-dev/include/libavutil/xtea.h \
ffmpeg-4.2.3-win64-dev/include/libpostproc/postprocess.h \
ffmpeg-4.2.3-win64-dev/include/libpostproc/version.h \
ffmpeg-4.2.3-win64-dev/include/libswresample/swresample.h \
ffmpeg-4.2.3-win64-dev/include/libswresample/version.h \
ffmpeg-4.2.3-win64-dev/include/libswscale/swscale.h \
ffmpeg-4.2.3-win64-dev/include/libswscale/version.h
四、调试
创建一个测试文件
#include <iostream>
#include <stdio.h>
using namespace std;
extern "C" {
#include "libavcodec/avcodec.h"
#include "libavformat/avformat.h"
#include "libswscale/swscale.h"
#include "libavdevice/avdevice.h"
}
int main()
{
printf("Hello World!\n");
cout << "Test FFmpeg!" << endl;
// av_register_all();
unsigned version = avcodec_version();
cout << "version :" << version;
return 0;
}
执行后。