Compiler Environment
Windows 10
compilation process
install msys2
- Download: MSYS2
-
Installation: Click the downloaded exe, select the default installation path here:
C:\msys64
. -
Configure environment variables: In the search bar on the lower left side of windows, search
环境变量
and click编辑系统环境变量
. AndC:\msys64
add the installation path to the system variable Path. -
Search in the search bar of windows
msys2
to open the command line window of msys2.
- Download related compilation tools. Enter at the command line:
pacman -S mingw-w64-x86_64-toolchain
- Use Notepad++ to open
C:\msys64\msys2_shell.cmd
, searchrem set MSYS2_PATH_TYPE=inherit
, and removerem
, that is, change to:
set MSYS2_PATH_TYPE=inherit
Download FFmpeg source code
C:\source
Execute the following git command below C:\source\ffmpeg
:
git clone https://git.ffmpeg.org/ffmpeg.git ffmpeg
Compile FFmpeg
- Download and install Visual Studio .
- Search in the Windows search bar
x64 Native Tools
and click on itx64 Native Tools Command Prompt For VS 2019
.
- In the popup, enter:
msys2_shell.cmd -mingw64
- In the pop-up mingw64 command window, switch to the ffmpeg source code directory:
cd /c/source/ffmpeg
- 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-shared
etc.--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 resultC:\source\ffmpeg_build
. The relative path is written here.--extra-cflags="-I../source/ffmpeg_build/include"
:cflags
Indicates options for the C compiler.-I
Indicates adding the dir directory to the search path list for header files. The dir directory here is specified asC:\source\ffmpeg_build
and also written as a relative path.--extra-ldflags="-LIBPATH:../source/ffmpeg_buid/lib"
:ldflags
Set 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-L
followed by the directory of the library file.
Regarding the differences --prefix
with --extra-cflags
and --extra-ldflags
paths:
C # C盘
├── msys64 # msys2安装目录,也是msys2_shell.cmd所在的目录
└── source
├── ffmpeg # ffmpeg源码根目录,也是configure脚本文件所在目录
└── ffmpeg_build # 保存ffmpeg源码编译结果的目录
--prefix
The 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-ldflags
The 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
.
- 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
- Below
C:\source\ffmpeg_build\bin
you can see what was generatedffmpeg.exe
:
- Change to
C:\source\ffmpeg_build\bin
the directory. Inputffmpeg -version
validation:
Note: It is recommended to add ffmpeg.exe
the 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: