搭建基于QT Creator的ffmpeg开发环境

date
Sep 24, 2020
slug
2020-09-24-qt-creator-ffmpeg
status
Published
tags
QT
ffmpeg
type
Post
AI summary
summary
总结在Windows环境中基于QT Creator搭建ffmpeg的开发环境及其测试代码。
操作系统版本:Windows 10.

从ffmpeg上下载windows平台上预编译好的ffmpeg库

下载地址: https://ffmpeg.zeranoe.com/builds/。
在基于动态链接库开发的情况下,需要下载下图中的Shared和Dev两个包:
notion image
下载后解压缩到某个指定的目录中备用,此处把两个包均解压缩到D:\development\ffmpeg_lib目录下:
notion image

在系统环境变量中设置动态链接库的目录

notion image
  • 这样就不需要把动态链接库拷贝到应用程序所在的目录下了;

新建QT项目,修改QT项目的pro文件,增加头文件和库文件路径

INCLUDEPATH += D:\development\ffmpeg_lib\ffmpeg-4.3-win64-dev\include
LIBS += D:\development\ffmpeg_lib\ffmpeg-4.3-win64-dev\lib\avcodec.lib \
				D:\development\ffmpeg_lib\ffmpeg-4.3-win64-dev\lib\avdevice.lib \
				D:\development\ffmpeg_lib\ffmpeg-4.3-win64-dev\lib\avfilter.lib \
				D:\development\ffmpeg_lib\ffmpeg-4.3-win64-dev\lib\avformat.lib \
				D:\development\ffmpeg_lib\ffmpeg-4.3-win64-dev\lib\avutil.lib \
				D:\development\ffmpeg_lib\ffmpeg-4.3-win64-dev\lib\postproc.lib \
				D:\development\ffmpeg_lib\ffmpeg-4.3-win64-dev\lib\swresample.lib \
				D:\development\ffmpeg_lib\ffmpeg-4.3-win64-dev\lib\swscale.lib

环境测试代码

#include "widget.h"
#include <QApplication>
#include <QDebug>

//ffmpeg include
extern "C"
{
#include "libavcodec/avcodec.h"
#include "libavformat/avformat.h"
#include "libavutil/pixfmt.h"
#include "libswscale/swscale.h"
#include "libavutil/time.h"
#include "libavutil/mathematics.h"
}

int main(int argc, char *argv[])
{
	QApplication a(argc, argv);
	Widget w;

	av_register_all();
	
	unsigned int version = avcodec_version();

	qDebug()<< version;
	char * filename="D:\\video.mp4";

	AVFormatContext * fc = NULL;

	int ret = avformat_open_input(&fc, filename, 0, 0);
	if(ret == 0){
		qDebug() << "Video Duration:" << fc->duration / AV_TIME_BASE << " secs";
		avformat_close_input(&fc);
	}
	w.show();

	return a.exec();
}

参考资料:

 

© Pavel Han 2020 - 2024