1.首先下载ffmpeg:下载地址
2.选择合适的版本,这里我用的是:
3.解压到QT的工程目录,首先介绍下不同版本的含义
- bin文件夹:下面包含了ffmpeg.exe、ffplay.exe、ffprobe.exe三个可执行程序,没有头文件和库文件。
- lib文件夹:包含了相关dll、lib等动态库文件。
- include文件夹 : 这个包含了头文件。
- ffmpeg.exe: 用于转码的工具
- ffplay.exe: 用于播放的工具
- ffprobe.exe: 用于解析媒体文件格式的工具
解压之后的文件处理:
将解压后目录下的include文件夹,lib文件夹拷贝到工程目录下,最好新建一个文件夹来存放。
如图所示
将 bin文件夹下的除了*.exe文件都拷贝程序生成的文件夹下。
在QT工程中添加文件路径,包含头文件等,图下图所示:
为了方便大家构建环境,放上源代码:
INCLUDEPATH += $$PWD/ffmpeg/include
LIBS += $$PWD/ffmpeg/lib/avcodec.lib\
$$PWD/ffmpeg/lib/avdevice.lib\
$$PWD/ffmpeg/lib/avfilter.lib\
$$PWD/ffmpeg/lib/avformat.lib\
$$PWD/ffmpeg/lib/avutil.lib\
$$PWD/ffmpeg/lib/postproc.lib\
$$PWD/ffmpeg/lib/swresample.lib\
$$PWD/ffmpeg/lib/swscale.lib
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>
}
extern "C"
{
#ifdef __cplusplus
#define __STDC_CONSTANT_MACROS
#ifdef _STDINT_H
#undef _STDINT_H
#endif
#include<stdint.h>
#endif
}
在main.c文件中添加打印版本信息,确定环境构建可以正常使用
//输出FFmpeg版本测试环境部署是否成功
avcodec_configuration();
unsigned version = avcodec_version();
qDebug()<<"version: "<<version;
编译运行,可以看到版本号被打印出来
至此ffmpeg在QT上移植完成