teach you to compile libav under Windows using MinGW (refer to libx264)

Source: Internet
Author: User
Tags git client using git

Transferred from: http://www.th7.cn/Program/cp/201407/242762.shtml

teach you to compile libav under Windows using MinGW

LIBAV is in Linux under the use of pure C language development, inevitably, libav source uses some GCC features, it is difficult to use VC compilation under Windows, but the use of MinGW compilation is much simpler, I will step through the process of compiling LIBAV using MinGW and the problems encountered in this process and how to solve them.

1 Installing the MINGW compilation Environment 1.1 installation MinGW

L Download and run the latest version of Mingw-get-inst.

• Select the directory where the MinGW is installed, note that the path to the installation directory cannot contain spaces.

L Install optional Components: C + + compiler, Forthan compiler, objective-c compiler, Ada compiler, and Msys.

Figure 1: Select the components that need to be installed

Since we need to compile the libav with MinGW, we need to choose the C + + compiler and msys,1 in addition to the compiler.

Next, the Setup program downloads and runs the Mingw-get CLI installer to install GCC. Depending on your network condition, this process may last for several minutes. Before you use MinGW, add ${mingwdir}/bin to the PATH environment variable, where ${mingwdir} is the MinGW installation directory, ${MINGWDIR}=C:/MINGW by default.

After the installation is complete, open the MinGW shell, MinGW, programs, Start menu, run MinGW.

1.2 Installing Coreutils

Please check that ${mingwdir}/msys/1.0/bin (default is C:/mingw/msys/1.0/bin) has no pr.exe, if not, then in the compilation Libav process, execution./configure will error:PR Command not found.

Download Coreutils-win32-5.3.0-bin.zip, unzip and copy the contents of the Bin directory to ${mingwdir}/msys/1.0/bin (default = C:/mingw/msys/1.0/bin).

1.3 Installing Yasm.exe

Compile libav need to use Yasm.exe, if your system does not have Yasm.exe, execute./configure will error:yasm not found. Download the Windows 32-bit version of Yasm.exe (if using 64-bit systems, download the 64-bit yasm.exe).

After the download is complete, rename to Yasm.exe and copy it to ${mingwdir}/msys/1.0/bin (default = C:/mingw/msys/1.0/bin).

So far, the compilation environment has been built.

2 Installing Git

LIBAV is developed using git, so you need to install a git client to get git's source code.

Download the git client and install it by default. After the installation is complete, open the Start menu, programs, git-> git Bash run git console.

Git Bash is a class Linux Shell console that uses the same usage as bash under Linux.

3 Compiling libx264

If you run the./configure under Libav, the--enable-libx264 option is enabled, LIBAV will rely on libx264 during compilation, so you need to compile libx264 in advance. If you do not enable the--enable-libx264 option, then you can skip this section.

3.1 Get libx264 Source code

Create a new directory to hold the source code for libx264 (for example, I created a new directory named x264 under the D drive), note that the path where the code is stored should not contain whitespace .

Start git bash and go to the new directory you just created. In my case, enter cd/d/x264 under Git bash.

After entering the source directory, type git clone git://git.videolan.org/x264.git in git bash. After you press ENTER, GIT will automatically download the source code from the source repository to local. Depending on your network condition, this process may last for several minutes.

3.2 Compiling libx264

After the code download is complete, start MinGW and enter the x264 source directory. In my case, enter cd/d/x264/x264 under MinGW bash.

Enter./CONFIGURE–HELP View configuration options. You can choose the configuration options according to your needs.

My configuration options are--enable-shared--disable-cli--enable-win32thread (it is recommended to enable this option, Otherwise the compiled libx264 will rely on MinGW's pthreadGC2.dll, so that you can add a DLL file when you package the distribution program.

Type./configure--enable-shared--disable-cli--enable-win32thread, press ENTER to configure the compilation environment. After the configuration is successful, you will be prompted: You can run ' make ' or ' made fprofiled ' now.

Typing the make command will start compiling, and the process will soon end, if the compilation succeeds, You will be able to find the Libx264-128.dll file under the source directory (depending on your x264 source version, 128 may be an additional number, but this version number can not be less than 118, otherwise it cannot be checked by LIBAV configuration) and Libx264.dll.a file.

4 Compiling the libav4.1 configuration libx264

If you want your LIBAV support x264 encoding, then in the compilation Libav, your compilation environment needs to libx264 library, otherwise configuration libav, will error:error:libx264 not found; If you don't need x264, Then you can skip this section.

Copy the generated Libx264-128.dll (refer to section 3rd) to ${mingwdir}/bin (default = C:/mingw/bin); Copy the generated LIBX264.DLL.A to ${mingwdir}/lib (default = c:/ Mingw/lib), copy the source x264.h and X264_config.h to ${mingwdir}/include (the default is C:/mingw/include). This way your mingw will have a libx264 environment.

4.2 Get LIBAV Source code

Create a directory c++workspace (the directory name depends on your preferences) for storing the source code. Open git bash and go to that directory (cd/d/c++workspace/your path may be different from mine).

Type git config--global core.autocrlf false. By default, GIT will automatically replace the text file's newline character with the current system default line break based on your operating system environment, and if you use the Windows operating system, GIT will change the line break to/r/n, and if you use the Unix-like operating system, the newline will be replaced by/N. Since LIBAV is developed under Linux, all of its source code files are the newline characters are/n, then when you use Git clone its source code, GIT will replace all the/N to/r/n, when using MinGW compile, MinGW do not recognize/r/n, when you execute make, An error is reported:library.mak:92:*** missing separator. Stop. . The function of the polygon command is to let git not automatically replace/n with/r/n.

Then type git clone git://git.libav.org/libav.git. git will download the source code from the repository to local. The LIBAV download link provides multiple clone URLs. You can choose one according to your needs, and I choose the first one. Depending on your network condition, the process lasts for several minutes.

4.3 Compiling libav

After the source code gets finished, open MinGW bash. Enter the LIBAV directory, type./configure--help in the MinGW console to view all configuration options, you can customize the components you need as needed . I'll list my own compilation options below.

./configure--ENABLE-GPL--enable-shared--disable-static--disable-doc--disable-avconv-- Disable-avplay--disable-avprobe--disable-avserver--enable-libx264--disable-debug

For specific meanings of these compilation options, type./configure--help for help.

After the configuration is complete, there will be a warning message about Pkg-config, which can be ignored directly. (The reason to ignore this is because--disable-avplay is added to the configuration options, and if you do not add this option, you need to install the SDL MinGW Development Library and Pkg-config).

Type the Make–r command and start the compilation process for about half an hour. After the compilation is complete, the results of the build are distributed across subdirectories. The resulting list is as follows:

Libav/libavcodec directory: Avcodec-54.defavcodec-54.dll avcodec.dll avcodec.lib

Libav/libavformat directory: Avformat-54.defavformat-54.dll avformat.dll avformat.lib

And so on, because of the length of the reason, it is not listed here, you can go to each directory to find the generated files.

You can copy all the generated DLLs, Def, and Lib files to the same directory. For example, I copied all the generated dll,def and Lib files to the Libav/bin directory. Note: The generated LIBAV library relies on Libx264-128.dll, so you bundle Libx264-128.dll with the LIBAV library when you publish.

4.4 Using Lib.exe to regenerate Lib files

MinGW compile libav use Dlltool to generate LIB files if you use these Lib files in a VC environment. You need to set the linker-> optimization–> references under Project properties to No (/opt:noref), 2, or the program will crash.

Figure 2: Reference settings

LIB files generated using lib.exe do not have this requirement.

If you want to generate LIB that works correctly under the YES (/opt:ref) option (the default option in Release mode), you do the following:

1. Open Visual Studio Command Prompt.

2. Enter the storage directory for the compilation results (my d:/c++workspace/libav/bin).

3. Use Lib.exe to generate a new Lib file: type Lib/machine:i386/def:foo-version.def/out:foo.lib and replace the foo-version and Foo in the command with the library name. For example, if you want to regenerate Avcodec.lib, type Lib/machine:i386/def:avcodec-54.def/out:avcodec.lib.

4.5 Compatible with MSVC Inttypes.h

LIBAV will use two header files Stdint.h and inttypes.h. I found that VisualStudio 2010 has provided stdint.h,visual Studio 20,052 None, so if you need to use LIBAV, you need to download inttypes.h and place it where the VC can find it.

And you also need to define the __stdc_constant_macros macro in the precompilation option, otherwise a compilation error like "Int64_c cannot be found" appears.

Article Source: http://blog.csdn.net/wangpingfang/article/details/8133622

Official reference: https://libav.org/platform.html

teach you to compile libav under Windows using MinGW (refer to libx264)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.