首先保证linux已经成功安装ffmpeg,测试下面的命令有输出表示已经成功安装ffmpeg
[root@localhost bin]# ./ffmpeg
ffmpeg version 4.4.git Copyright (c) 2000-2022 the FFmpeg developers
built with gcc 4.8.5 (GCC) 20150623 (Red Hat 4.8.5-44)
configuration: --prefix=/usr/local/ffmpeg --enable-debug=3 --disable-static --enable-shared --enable-sdl2
libavutil 57. 23.100 / 57. 23.100
libavcodec 59. 23.100 / 59. 23.100
libavformat 59. 18.101 / 59. 18.101
libavdevice 59. 5.100 / 59. 5.100
libavfilter 8. 27.100 / 8. 27.100
libswscale 6. 5.100 / 6. 5.100
libswresample 4. 4.100 / 4. 4.100
Hyper fast Audio and Video encoder
usage: ffmpeg [options] [[infile options] -i infile]... {[outfile options] outfile}...
其次保证已经安装了qt5和qt-creator,不会的看我的另一篇文章,有介绍怎么安装
新建一个普通的c++工程
一路下一步就建好了
在建好的项目目录下面新建一个lib目录,把装好的ffmpeg目录拷贝到这个目录下。
修改xxx.pro文件,加入下面代码
unix{
INCLUDEPATH += $$PWD/lib/ffmpeg/include
LIBS += -L$$PWD/lib/ffmpeg/lib -lavcodec -lavdevice -lavfilter -lavformat -lavutil -lswresample -lswscale
}
如图
修改mian.cpp,代码如下
#include <iostream>
using namespace std;
extern "C"
{
#include "libavcodec/avcodec.h"
#include "libavformat/avformat.h"
#include "libswscale/swscale.h"
#include "libavdevice/avdevice.h"
}
int main(int argc, char *argv[])
{
cout << "Hello ffmpeg!" << endl;
avdevice_register_all();
unsigned version=avcodec_version();
cout<< "version is :"<<version;
return 0;
}
如图:
编译执行如图,表示集成ffmpeg成功