How to compile ffmpeg on windows

To compile FFmpeg on Windows, you can use MSYS2 or Cygwin to configure the compilation environment, and then use tools such as MinGW or Visual Studio to compile. Here are the steps using MSYS2 and MinGW:

  1. Download and install MSYS2: https://www.msys2.org/

  2. Open the MSYS2 terminal and update the package list:

pacman -Syu

  1. Install the compilation toolchain and dependent libraries:

pacman -S --needed base-devel mingw-w64-x86_64-toolchain pacman -S git perl yasm pkg-config pacman -S libx264 libx265 libvpx libopus libmp3lame libfdk-aac

  1. Clone the FFmpeg source code and switch to the latest stable version:

git clone https://git.ffmpeg.org/ffmpeg.git ffmpeg cd ffmpeg git checkout n4.4

  1. Configure compilation parameters:

./configure --toolchain=mingw64 --arch=x86_64 --enable-shared --disable-static --prefix=/usr/local --disable-debug --enable-pic --enable-gpl --enable-version3 --enable-nonfree --disable-doc --disable-htmlpages --disable-manpages --disable-podpages --disable-txtpages --extra-cflags=-I/usr/local/include --extra-ldflags=-L/usr/local/lib --pkg-config-flags=--static

The meaning of the parameters here is as follows:

  • --toolchain=mingw64: Compile the toolchain with MinGW.

  • --arch=x86_64: Compile as a 64-bit program.

  • --enable-shared: Build a shared library.

  • --disable-static: Disable static libraries.

  • --prefix=/usr/local: Specify the installation path.

  • --disable-debug: Disable debugging.

  • --enable-pic: Enable position independent code.

  • --enable-gpl: Enable the GPL license.

  • --enable-version3: Enable LGPLv3 license.

  • --enable-nonfree: Enable nonfree software.

  • --disable-doc --disable-htmlpages --disable-manpages --disable-podpages --disable-txtpages: Suppresses documentation generation.

  • --extra-cflags=-I/usr/local/include --extra-ldflags=-L/usr/local/lib: Add header file and library file paths.

  • --pkg-config-flags=--static: Use statically linked pkg-config.

  • Compile and install:

make -j$(nproc) make install

-j$(nproc)The parameter is to use the number of CPU cores for multi-thread compilation, which can speed up compilation.

  1. The header files and library files of FFmpeg will be installed into /usr/local/include and /usr/local/lib, and you can use them in your own projects.

Precautions:

  1. If you need to encode H.264 or H.265 video, you need to install x264 and x265 dependent libraries.

  2. If you need to encode and decode VP8 or VP9 video, you need to install the libvpx dependency library.

  3. If you need to encode Opus audio, you need to install the libopus dependency library.

  4. If you need to encode MP3 audio, you need to install the libmp3lame dependency library.

  5. If you need to encode AAC audio, you can use libfdk-aac or libvo-aacenc dependent library.

★The business card at the end of the article can receive audio and video development learning materials for free, including (FFmpeg, webRTC, rtmp, hls, rtsp, ffplay, srs) and audio and video learning roadmaps, etc.

see below!

Guess you like

Origin blog.csdn.net/yinshipin007/article/details/130394350