Detailed compilation process of FFMPEG on Windows platform, including environment Installation

Source: Internet
Author: User
Tags svn client svn update tortoisesvn

Start as follows:
FFmpeg is an open-source project developed based on Linux. The source code is incompatible with the C/C ++ compiler provided by the most common Visual Studio in windows. Therefore, it cannot be compiled using msvc ++. To use FFMPEG, the first problem to be solved is to configure a Linux-like compiling environment in windows, compile FFMPEG into a binary library, and then use it for further development.
Msvc ++ does not strictly follow the C standard, so the entire compilation process must be completed using the msys + mingw system. If you select to compile a dynamic link library (DLL), these libraries will be used in the same way as other dynamic link libraries, you can use msvc ++ to link these libraries to your own programs. In this case, msvc ++ is supported.
The compilation process of FFMPEG in Windows is as follows:

  • Prepare the msys + mingw System

1) install msys
To http://sourceforge.net/project/showfiles.php? Group_id = 2435 download file:
Bash-3.1-MSYS-1.0.11-snapshot.tar.bz2
MsysCORE-1.0.11-2007.01.19-1.tar.bz2
(There may be version changes, the same as below)
Decompress msyscore-1.0.11-2007.01.19-1.tar.bz2, for example, decompress it to D: \ msys (this path is used for the following content ).
Decompress bash-3.1-msys-1.0.11-snapshot.tar.bz2 to generate a directory named bash-3.1. There is a subdirectory named bin in this directory, and other directories do not need to be concerned. Copy all the files in the bin directory to D: \ msys \ bin, and select Yes when the system prompts that the volume must overwrite sh.exe.
Run pi. bat in the "D: \ msys \ postinstall" directory. Enter N in the prompt and press any key to exit.
2) install mingw
Is it to http://sourceforge.net/project/showfiles.php? Group_id = 2435 download file:
Binutils-2.17.50-20060824-1.tar.gz
Gcc-core-3.4.5-20060117-1.tar.gz
Gcc-g00000000-3.4.5-20060117-1.tar.gz
W32api-3.9.tar.gz
Mingw-runtime-3.12.tar.gz
Decompress all of them to D: \ msys \ mingw.
3) modify "msys. Bat"
Open D: \ msys in a text editor. bat, Because you plan to use msvc ++ to compile the program, you need. the LIB file can be linked to the FFMPEG library. the LIB file can be generated using the Lib command in Microsoft's tool chain. Therefore, Microsoft Visual Studio or visual C ++ must be installed on the machine. Add the following row to msys. at the beginning of BAT, replace the path with the actual path of vcvars32.bat on the machine, for example, in "D: \ Program Files \ Microsoft Visual Studio. NET 2003 \ vc7 \ bin ", so add:
Call "D: \ Program Files \ Microsoft Visual Studio. NET 2003 \ vc7 \ bin \ vcvars32.bat"
4) System Integration
Copy D: \ msys \ etc \ fstab. The sample is D: \ msys \ etc \ fstab, and open D: \ msys \ etc \ fstab in the text editor. (You need to use an editor that supports UNIX line breaks, such as NotePad ++:
D:/mingw
Changed:
D:/msys/mingw
After completing the preceding steps, the msys + mingw system is configured.

  • Obtain FFMPEG using SVN

Because the source code of FFmpeg is stored in the svn repository, you must use the command line program or graphical interface program to access it. For convenience, I use tortoisesvn, a graphical interface program, because it works very well with Windows Resource Manager.
First to http://sourceforge.net/project/showfiles.php? Group_id = 138498 download tortoisesvn and install it. After the installation is complete, you need to restart it to use it. If you want to use the Chinese language, you can download the languagepack-version-win32-zh_cn.exe, so that the software becomes a familiar Chinese interface.
Since tortoisesvn is fully integrated into windows Resource Manager, we only need to enable resource manager and right-click the directory where you want to store the code and select "SVN check out ..." You can start tortoisesvn. I stored the FFMPEG source code in the "D: \ FFMPEG" directory, so right-click the Directory and select "SVN check out ..." In the displayed dialog box, enter the following content:

Figure 1

Click "OK" to start the download process. tortoisesvn downloads the FFMPEG source code of the latest version to the local directory. After the download is complete, the compilation process starts.
Due to the large number of FFMPEG maintenance personnel, there will inevitably be errors in the downloaded version, and even the current downloaded version cannot be compiled at all, so it should be updated frequently. The update method is simple. Right-click the directory where FFmpeg is located and select "SVN Update.

  • Compile

First, start msys through msys. bat in the msys installation directory. a command line window will appear, which is a rxvt program running bash, such:

Figure 2

This is a shell similar to Linux and runs on Windows, just like using a real Linux Shell. Note the following when using this shell:
→ The directory name is separated by a forward slash instead of a backslash (for example, "d:/FFMPEG" rather than "D: \ FFMPEG ").
→ The drive letter (for example, "C: \") can be accessed from the root directory (like this "/C /").
→ If the file name or directory name contains spaces, it must be enclosed in double quotation marks (for example, "/C/Program Files" with double quotation marks ).
Switch to the directory where the FFMPEG source code is stored by entering "CD/D/FFMPEG ".
Next, configure FFMPEG and select the library included in the compilation. For how to add support for third-party libraries, refer to the subsequent description. Enter:
./Configure-enable-memalign-hack
-The enable-memalign-hack option must be specified when FFmpeg is successfully compiled on Windows. After the configuration is complete, return to the command prompt and see the following figure:

Figure 3

If there is no error, you can "make" The FFMPEG with basic functions. Enter "make" at the prompt ".
The compilation process will last for a long time. If everything is normal, the prompt will be returned after the end, with the following output screen:

Figure 4

At this time, the program has been compiled. You can find the ffmpeg.exe file in the directory where the ffmpegsource code is stored.
Then, if you want to install FFMPEG to the system, you can perform the installation step: "make install", which will copy all generated important files to the local folder of msys.
Since I only use ffmpeg, I have not installed ffmpeg.exe. Instead, I copied ffmpeg.exe to the desired directory and used it as a module.
If you want to use the libavcodec library included in FFMPEG to develop a multimedia file processing program, you also need to compile the libavcodec DLL dynamic link library. The compilation process is slightly different from the above process, as described below:
Switch to the source code directory of FFMPEG, and use "make distclean" to clear the intermediate file left last time before compilation. Then, pass two more parameters to the configure script:
./Configure-enable-shared-Disable-static-enable-memalign-hack
Run the "make" command.
This compilation method can obtain the files used by msvc ++ for further development.

  • Link

The FFMPEG directory contains three subdirectories: libavutil, libavcodec, and libavformat. If a dynamic link library is successfully generated in the preceding step, so there is a file like slibname_with_major.lib under these three directories, for example, what I generated is avcodec-51.lib, avformat-51.lib and avutil-49.lib, msvc ++ can know the export function of DLL from these files.
Now, you can write an application with the FFMPEG function by including the header file of FFMPEG and linking the above three lib files.

  • Added support for third-party Libraries

Taking the support for mp3lame as an example, I will describe how to add a third-party library.
First, you need to download the mp3lame. There are two solutions available:
→ To http://sourceforge.net/project/showfiles.php? Group_id1_290download lame-3.97.tar.gz and use the following command to compile and install it in the mingw Library:
./Configure-Prefix =/static-Disable-shared-enable-static
Make
Make install
Or compile mp3lame as a dynamic link library:
./Configure-Prefix =/shared
Make
Make install
→ To orders.
Next, similar to the preceding steps, switch to the directory where the FFMPEG source code is stored, and add "-enable-libmp3lame" when passing configuration parameters, that is, use the following command to configure:
./Configure-enable-static-enable-shared-enable-memalign-hack-enable-libmp3lame
The information displayed after configuration is as follows:

Figure 5

We can see that the libmp 3lame is already enabled, and you only need to compile it using the "make" command.
My FFMPEG configuration is:
-Enable-GPL-enable-PP-enable-swscaler-enable-pthreads-enable-liba52-enable-avisynth-enable-libdts-enable-libfaac-enable-libfaad-enable-libgsm-enable-libmp3lame -Enable-libnut-enable-libogg-enable-libtheora-enable-libvorbis-enable-x264-enable-Xvid
-Enable-amr_nb-enable-amr_wb-CPU = i686-enable-memalign-hack-extra-ldflags =-static
================== Gorgeous separation line ========
This article references. Star character ☆ back character tag: blogger.com, 1999: blog-399668078016494547.post-35850969380399542382007-05-21T22: 08: 00.000 + 08: 002007-05-21t23: 33: 28.932 + 08: 00 in order to write a thesis, I had to repeat the tedious FFMPEG compilation process. Tired!

Another article:

1. Download
SVN client tortoisesvn
Http://nchc.dl.sourceforge.net/sourceforge/tortoisesvn/TortoiseSVN-1.4.8.12137-win32-svn-1.4.6.msi

Mingw + msys
Http://sourceforge.net/project/showfiles.php? Group_id = 2435
MinGW-5.1.3.exe (related compilers are automatically downloaded according to options during installation)
MSYS-1.0.11-20071204.tar.bz2 (extract the files in the bin and overwrite the installed msys directory)
Bash-3.1-MSYS-1.0.11-1.tar.bz2 (extract the files in the bin and overwrite the installed msys directory)
Coreutils-5.97-MSYS-1.0.11-snapshot.tar.bz2 (pr.exe in pull bin, copy to the corresponding msys directory, configure will use this tool)

Http://gd.tuwien.ac.at/gnu/mingw? Fisel = 0-9, A-Z, A-Z
MSYS-1.0.11-2004.04.30-1.exe (msys installer)

2. Installation
Install MinGW-5.1.3.exe
Install MSYS-1.0.11-2004.04.30-1.exe
Configure fstab in etc of msys and specify the location of mingw.

3. Obtain FFMPEG source code
Use tortoisesvn to checkout the FFMPEG source code to the local device.
SVN: // SVN. mplayerhq. hu/FFMPEG/trunk

4. Compile
./Configure .................................... (Various parameters)
Make
Make install

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.