FFmpeg: compile (Windows)

Compiler Environment

Windows 10

compilation process

install msys2

  1. Download: MSYS2
  1. Installation: Click the downloaded exe, select the default installation path here: C:\msys64.

  2. Configure environment variables: In the search bar on the lower left side of windows, search 环境变量and click 编辑系统环境变量. And C:\msys64add the installation path to the system variable Path.

  3. Search in the search bar of windows msys2to open the command line window of msys2.

  1. Download related compilation tools. Enter at the command line:
pacman -S mingw-w64-x86_64-toolchain
  1. Use Notepad++ to open C:\msys64\msys2_shell.cmd, search rem set MSYS2_PATH_TYPE=inherit, and remove rem, that is, change to:
set MSYS2_PATH_TYPE=inherit

Download FFmpeg source code

C:\sourceExecute the following git command below C:\source\ffmpeg:

git clone https://git.ffmpeg.org/ffmpeg.git ffmpeg

Compile FFmpeg

  1. Download and install Visual Studio .
  2. Search in the Windows search bar x64 Native Toolsand click on it x64 Native Tools Command Prompt For VS 2019.
  1. In the popup, enter:
msys2_shell.cmd -mingw64
  1. In the pop-up mingw64 command window, switch to the ffmpeg source code directory:
cd /c/source/ffmpeg
  1. Then enter the compile command:
./configure --toolchain=msvc --enable-shared --enable-debug --prefix=../ffmpeg_build --extra-cflags="-I../source/ffmpeg_build/include" --extra-ldflags="-LIBPATH:../source/ffmpeg_buid/lib"

Explain the compilation command:

  • ./configure: Execute the script file configure under the current directory, namely C:\source\ffmpeg. Open the configure file, and you will find the comments of some compilation commands commonly used by ffmpeg, such as --enable-sharedetc.
  • --enable-shared: Compile into a dynamic link library (dll).
  • --enable-debug: Allow debugging of ffmpeg source code.
  • --prefix=../ffmpeg_build: Specify the storage path of the compilation result C:\source\ffmpeg_build. The relative path is written here.
  • --extra-cflags="-I../source/ffmpeg_build/include": cflagsIndicates options for the C compiler. -IIndicates adding the dir directory to the search path list for header files. The dir directory here is specified as C:\source\ffmpeg_buildand also written as a relative path.
  • --extra-ldflags="-LIBPATH:../source/ffmpeg_buid/lib": ldflagsSet some optimization parameters used by compilers such as gcc, and you can also specify the location of the library file in it. -LIBPATH:It can also be abbreviated as -Lfollowed by the directory of the library file.

Regarding the differences --prefixwith --extra-cflagsand --extra-ldflagspaths:

C                       # C盘
├── msys64              # msys2安装目录,也是msys2_shell.cmd所在的目录
└── source
    ├── ffmpeg          # ffmpeg源码根目录,也是configure脚本文件所在目录
    └── ffmpeg_build    # 保存ffmpeg源码编译结果的目录

--prefixThe starting directory of ffmpeg is the root directory of the source code, namely: C:\source\ffmpeg. So the relative path of ffmpeg_build directory is: ../ffmpeg_build.

--extra-cflags, --extra-ldflagsThe initial directory is the directory where msys2_shell.cmd is located, that is C:\msys64. So the relative path of ffmpeg_build directory is: ../source/ffmpeg_buid.

  1. After the configure is finished, continue to enter the following command to compile the source code file into a binary executable file:
 make -j12 && make install

Verify FFmpeg compilation

  1. BelowC:\source\ffmpeg_build\bin you can see what was generated ffmpeg.exe:
  1. Change to C:\source\ffmpeg_build\binthe directory. Input ffmpeg -versionvalidation:

Note: It is recommended to add ffmpeg.exethe directory where you are, that is C:\source\ffmpeg_build\bin, to the windows system environment variable, and you can use the ffmpeg command line at any time.

References:

Compile ffmpeg and x264 under win10+vs2015

[FFmpeg notes] 04-Win10 compile ffmpeg4.2.1 (For Windows)

Guess you like

Origin blog.csdn.net/qq_34356130/article/details/123599743