步骤

  • 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

  1. <a name="rkiSP"></a>
  2. ## 遇到的问题
  3. <a name="LcipR"></a>
  4. ### 在代码中添加ffmpeg的接口测试工程,发现会报错,结果crashed
  5. 测试代码:
  6. ```cpp
  7. extern "C"
  8. {
  9. #include <libavcodec/avcodec.h>
  10. #include <libavformat/avformat.h>
  11. #include <libswscale/swscale.h>
  12. #include <libavdevice/avdevice.h>
  13. #include <libavformat/version.h>
  14. #include <libavutil/time.h>
  15. #include <libavutil/mathematics.h>
  16. }
  17. QtPlayer::QtPlayer(QWidget *parent)
  18. : QMainWindow(parent)
  19. , ui(new Ui::QtPlayer)
  20. {
  21. ui->setupUi(this);
  22. ui->setupUi(this);
  23. qDebug() << avcodec_configuration();
  24. unsigned version = avcodec_version();
  25. QString ch = QString::number(version, 10);
  26. qDebug() << "version:" << version;
  27. }

解决办法:
将下载的ffmpeg->bin目录下的dll拷贝到生成的exe目录下,重新运行就可以了
*输出结果

  1. 10:53:05: Starting F:\qt-code\build-qtplayer-Desktop_Qt_5_12_10_MinGW_64_bit-Debug\debug\qtplayer.exe ...
  2. --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
  3. version: 3867493