參考:https://www.cnblogs.com/WushiShengFei/p/10837264.html
參考:https://blog.csdn.net/leixiaohua1020/article/details/15811977
參考:https://blog.csdn.net/weixin_43834265/article/details/89648294
參考Qt如何添加第三方庫文件:https://blog.csdn.net/qq_22374265/article/details/79349779
文末有模板例程下載
前提
一定要搞清楚自己的編譯版本才選擇FFMPEG的版本:不然會報錯
- MSVC版本是64位的就下載64位的FFMPEG的三個文件
- MinGW版本是32位的下載32位的FFMPEG的三個文件
FFmpeg庫可以使用源碼編譯也可以從網上下載已經編譯好的庫文件,這裏使用從網上下載編譯好的庫文件。編譯好的庫文件
Static,Shared,Dev三個文件都要下載。
新建工程
過程略,目的爲了測試FFMpeg能不能用。
我的文件結構:
在.pro文件裏面添加:
INCLUDEPATH += D:/Software/FFMPEG/ffmpeg32/dev/include
LIBS += D:/Software/FFMPEG/ffmpeg32/dev/lib/libavcodec.dll.a\
D:/Software/FFMPEG/ffmpeg32/dev/lib/libavdevice.dll.a\
D:/Software/FFMPEG/ffmpeg32/dev/lib/libavfilter.dll.a\
D:/Software/FFMPEG/ffmpeg32/dev/lib/libavformat.dll.a\
D:/Software/FFMPEG/ffmpeg32/dev/lib/libavutil.dll.a\
D:/Software/FFMPEG/ffmpeg32/dev/lib/libswresample.dll.a\
D:/Software/FFMPEG/ffmpeg32/dev/lib/libswscale.dll.a\
D:/Software/FFMPEG/ffmpeg32/dev/lib/libpostproc.dll.a
或者另一種風格:參考 https://blog.csdn.net/qq_22374265/article/details/79349779
INCLUDEPATH += D:/Software/FFMPEG/ffmpeg32/dev/include
LIBS += -LD:/Software/FFMPEG/ffmpeg32/dev/lib/ -lavcodec -lavdevice -lavfilter -lavformat -lavutil -lpostproc -lswresample -lswscale
在mainwindows.h裏面添加
using namespace std;
extern "C"
{
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
#include <libswscale/swscale.h>
#include <libavdevice/avdevice.h>
#include <libavformat/version.h>
#include <libavutil/time.h>
#include <libavutil/mathematics.h>
}
在mainwindows.c裏面添加:
ui->setupUi(this);
qDebug() << avcodec_configuration();
unsigned version = avcodec_version();
QString ch = QString::number(version, 10);
qDebug() << "version:" << version;
不知爲什麼會報錯
以上是由於,編譯器版本與FFMPEG版本不一樣導致的:我的問題是:MSVC2017 64bit + FFMPEG 32bit。所導致的,很明顯版本不一樣,所以無法運行將其修改成:MSVC2017 64bit + FFMPEG 64bit就沒問題了。
最後
編譯成功通過,但是運行不起來,這就需要把 D:\Software\FFMPEG\ffmpeg64\shared\bin 文件裏面的所有 .dll文件拷貝到生成文件下 D:\Output\Qt_WGT\2.FFmpeg\1.FFmpegTest\build-FFmpegTest-Desktop_Qt_5_11_2_MSVC2017_64bit-Debug\debug 。