FFMpeg环境搭建(WIN10)

0、前期准备

软件环境:Win10 + qtcreator

软件准备:MSYS2 安装包FFmpeg源码

1、软件安装

通过MSYS2安装编译工具

1、打开MSYS2安装包,一路next即可
(注:如果需要更改路径可以自行更改)


2、安装完成之后,打开软件,输入以下命令进行mingw安装,命令如下

bash 复制代码
# 先运行
pacman -Syu
pacman -S make
# 64位工具链
pacman -S mingw-w64-x86_64-nasm mingw-w64-x86_64-gcc mingw-w64-x86_64-SDL2
# 32位工具链
pacman -S mingw-w64-i686-nasm mingw-w64-i686-gcc mingw-w64-i686-SDL2 \
      mingw-w64-i686-pkgconf mingw-w64-i686-binutils

编译FFMpeg

1、打开MSYS2 安装路径
(笔者安装的路径为:D:\msys64,具体看安装时选择的路径)

  • 进入home文件夹,里面有一个以用户名的命名的文件夹,
  • 进入该文件夹里面(如D:\msys64\home\xxx)
  • 将下载好的FFmpeg源码拷贝到该文件夹,然后解压,然后返回上两层文件夹(D:\msys64)

2、根据要编译的dll为32位还是64位,打开相对应的软件

3、打开之后输入gcc -v,检查编译链的版本位数是否是想要的位数,如下:

4、输入 ls 查看是否有刚才解压的ffmpeg文件,如下:

5、确认有该文件之后,若无该文件回到第4步骤检查,清楚文件路径是否正确,进入解压后的文件,输入下面配置(具体配置看自己的需要来选择),然后回车
(注意:configure时间有点长要稍微等一会,出现下面现在之后表示配置成功)

bash 复制代码
./configure \
  --prefix="$HOME/ffmpeg_build" \
  --extra-cflags="-I$HOME/ffmpeg_build/include" \
  --extra-ldflags="-L$HOME/ffmpeg_build/lib" \
  --extra-libs=-lpthread \
  --extra-libs=-lm \
  --bindir="$HOME/ffmpeg_build/bin" \
  --enable-gpl \
  --enable-nonfree \
  --enable-shared \
  --enable-decoder=h264 \
  --enable-parser=h264 


6、输入make -j4 && make install进行编译安装
7、编译安装完成之后,来到D:\msys64\home\xxx目录下,就会看到ffmpeg_build目录,该目录下的内容如下

8、进行文件分类,新建 ffmpeg 文件夹,进入 ffmepg 文件夹,

新建 lib 文件夹,将 ffmpeg_build 中的 bin 文件中的.lib文件拷贝到该目录

新建 dll 文件夹,将 ffmpeg_build 中的 bin 文件中的.dll文件拷贝到该目录

将 ffmpeg_build 中的文件 include 文件夹拷贝到ffmepg目录

2、测试

文件拷贝

1、将ffmpeg_build目录名字修改为ffmpeg之后(可以不修改),拷贝到qt项目之下,如下:

打开QT Creator

1、新建qt工程
2、修改.pro文件,修改后的内容如下

c 复制代码
QT -= gui

CONFIG += c++11 console
CONFIG -= app_bundle

# The following define makes your compiler emit warnings if you use
# any Qt feature that has been marked deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS

# You can also make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0

SOURCES += \
        main.cpp

# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target

win32: LIBS += -L$$PWD/ffmpeg/lib/ -lavcodec\
                -L$$PWD/ffmpeg/lib/ -lavdevice\
                -L$$PWD/ffmpeg/lib/ -lavfilter\
                -L$$PWD/ffmpeg/lib/ -lavformat\
                -L$$PWD/ffmpeg/lib/ -lavutil\
                -L$$PWD/ffmpeg/lib/ -lpostproc\
                -L$$PWD/ffmpeg/lib/ -lswresample\
                -L$$PWD/ffmpeg/lib/ -lswscale\

INCLUDEPATH += $$PWD/ffmpeg/include
DEPENDPATH += $$PWD/ffmpeg/include

3、mian.cpp文件中,输入如下代码

c 复制代码
#include <QCoreApplication>
#include <iostream>
#include <string>

using namespace std;
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>
}

int main()
{
    av_log_set_level(AV_LOG_DEBUG);
    av_log(NULL, AV_LOG_DEBUG,"Hello ffmpeg!\n");
    av_log(NULL, AV_LOG_DEBUG,"ffmpeg version = %s\n", av_version_info());
    return 0;
}

4、编译运行。结果如下:
(注意:记得把ffmpeg/bin/下的dll文件拷贝到生成的exe文件目录下,否则无法运行成功)

到此完结

相关推荐
0点51 胜12 小时前
[ffmpeg] 音视频编码
ffmpeg·音视频
0点51 胜14 小时前
[ffmpeg]音频格式转换
开发语言·c++·ffmpeg
PlumCarefree1 天前
基于鸿蒙API10的RTSP播放器(五:拖动底部视频滑轨实现跳转)
华为·ffmpeg·音视频
LuckyInn1 天前
从安装ffmpeg开始,把一个视频按照每秒30帧fps剪切为图片
ffmpeg·音视频
cuijiecheng20181 天前
FFmpeg源码:skip_bits、skip_bits1、show_bits函数分析
ffmpeg
__Destiny__1 天前
视频格式转为mp4(使用ffmpeg)
ffmpeg·视频编解码
<Sunny>1 天前
SDL 2.0视频数据渲染到窗口上播放流程
ffmpeg·音视频
PlumCarefree2 天前
USB摄像头视频流转RTSP流
图像处理·ffmpeg·音视频·媒体·视频编解码
PlumCarefree2 天前
基于鸿蒙API10的RTSP播放器(八:音量和亮度调节功能的整合)
华为·ffmpeg·音视频·harmonyos
源之缘-OFD先行者2 天前
ffmpeg实现视频的合成与分割
ffmpeg·音视频