Win10 compiles the x264 library (there are also generated lib files)

Hits: 0

[FFmpeg] has its own H.264 decoder, but it does not have its own H.264 encoder, so the x264 library is used.

Table of contents

1. What is x264?

x264 is an open source H.264/MPEG-4 AVC video encoding library, through which h264 video can be encoded

Second, the configuration process

1. Download

msys official website: https://www.msys2.org/
After downloading, install it all the way

2. Configure the tools required for compilation

  1. Replace the domestic source
    Add the three mirrorlist files in \etc\pacman.d to the front of the official mirror respectively

mirrorlist.mingw32:

Server = http://mirrors.ustc.edu.cn/msys2/mingw/i686/

mirrorlist.mingw64:

Server = http://mirrors.ustc.edu.cn/msys2/mingw/x86_64/

mirrorlist.mingw:

Server = http://mirrors.ustc.edu.cn/msys2/msys/$arch/

  1. Update software library

pacman  -Syu//It will restart after the first input, you need to change the source 
pacman  -Su 
pacman  -S mingw-w64-i686-gcc 
pacman  -S mingw-w64-x86_64-gcc 
pacman  -S base-devel 
pacman  -S nasm 
pacman  -S yasm

  1. Check:
    Open MSYS2 64bit, execute gcc -v, if there is no error , it means it is safe

3. Configure x264

  1. Download the x264 source package, address: https://www.videolan.org/developers/x264.html
  2. After downloading, put it under msys64\home
  3. Open MSYS2 MinGW 64-bit, the execution ./configure --prefix=../build --host=x86_64-w64-mingw32 --enable-shared --extra-ldflags=-Wl,--output-def=libx264.defwill generate a def file
  4. Put x264.dll under the bin of vs/vc, for example, my directory is C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\bin\Hostx64\ Under x64, cmd command:

lib /machine:x64 /def:libx264.def

The lib file we want is generated (x264-155.dll, .def, .lib
link: https://pan.baidu.com/s/1mcNkEXjOJUZs9LcI5YKT7w
extraction code: w1js)

4. Test

  1. Add x264.h, x264_config.h, libx264.dll and libx264.lib to the project
  2. In Project->Properties->Linker->Input->Input->Additional Dependencies->Add libx264.lib
  3. The test code is as follows:

#include <iostream>
#include <string>
#include "stdint.h"  
extern "C"
{
#include "x264.h"
#include "x264_config.h"
};
using namespace std;

int main(int argc, char **argv)
{
    x264_param_t param;
    x264_param_default(¶m);
    cout << "hello,x264" << endl;
    return 0;
}

success! ! !

You may also like...

Leave a Reply

Your email address will not be published.