步骤
- mingw和ffmpeg库需保持一致(都是32位或64位)
- ffmpeg官网下载ffmpeg相关的库文件
下载地址:https://github.com/BtbN/FFmpeg-Builds/releases
- 创建qt的工程,并在*pro文件的最后添加以下代码 ```cpp INCLUDEPATH+=C:/qtplayer/ffmpeg-win64/include
LIBS+=C:/qtplayer/ffmpeg-win64/lib/libavcodec.dll.a\ C:/qtplayer/ffmpeg-win64/lib/libavdevice.dll.a\ C:/qtplayer/ffmpeg-win64/lib/libavfilter.dll.a\ C:/qtplayer/ffmpeg-win64/lib/libavformat.dll.a\ C:/qtplayer/ffmpeg-win64/lib/libavutil.dll.a\ C:/qtplayer/ffmpeg-win64/lib/libswresample.dll.a\ C:/qtplayer/ffmpeg-win64/lib/libswscale.dll.a\ C:/qtplayer/ffmpeg-win64/lib/libpostproc.dll.a
<a name="rkiSP"></a>
## 遇到的问题
<a name="LcipR"></a>
### 在代码中添加ffmpeg的接口测试工程,发现会报错,结果crashed
测试代码:
```cpp
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>
}
QtPlayer::QtPlayer(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::QtPlayer)
{
ui->setupUi(this);
ui->setupUi(this);
qDebug() << avcodec_configuration();
unsigned version = avcodec_version();
QString ch = QString::number(version, 10);
qDebug() << "version:" << version;
}
解决办法:
将下载的ffmpeg->bin目录下的dll拷贝到生成的exe目录下,重新运行就可以了
*输出结果
10:53:05: Starting F:\qt-code\build-qtplayer-Desktop_Qt_5_12_10_MinGW_64_bit-Debug\debug\qtplayer.exe ...
--prefix=/ffbuild/prefix --pkg-config-flags=--static --pkg-config=pkg-config --cross-prefix=x86_64-w64-mingw32- --arch=x86_64 --target-os=mingw32 --enable-gpl --enable-version3 --disable-debug --enable-shared --disable-static --disable-w32threads --enable-pthreads --enable-iconv --enable-libxml2 --enable-zlib --enable-libfreetype --enable-libfribidi --enable-gmp --enable-lzma --enable-fontconfig --enable-libvorbis --enable-opencl --enable-libvmaf --enable-vulkan --enable-amf --enable-libaom --enable-avisynth --enable-libdav1d --enable-libdavs2 --disable-libfdk-aac --enable-ffnvcodec --enable-cuda-llvm --enable-libglslang --enable-libgme --enable-libass --enable-libbluray --enable-libmp3lame --enable-libopus --enable-libtheora --enable-libvpx --enable-libwebp --enable-lv2 --enable-libmfx --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-librav1e --enable-librubberband --enable-schannel --enable-sdl2 --enable-libsoxr --enable-libsrt --enable-libsvtav1 --enable-libtwolame --enable-libuavs3d --enable-libvidstab --enable-libx264 --enable-libx265 --enable-libxavs2 --enable-libxvid --enable-libzimg --extra-cflags=-DLIBTWOLAME_STATIC --extra-cxxflags= --extra-ldflags=-pthread --extra-ldexeflags= --extra-libs=-lgomp --extra-version=20210705
version: 3867493