Use ffmpeg source code installation +vscode development environment to build a detailed explanation

Foreword:

 

Hello everyone, today I would like to share with you an article on the construction of the ffmpeg development environment. I also installed the ffmpeg source code a long time ago, but I did not build the development environment for you, and the version at that time was relatively old, and there were many details. Did not show you how to solve it!

Today I will show you the detailed ffmpeg latest version 5.1 source code installation steps and vscode development environment setup! We have to keep up with the development of technology, so we use the latest version as the development environment this time!

If you need to perform cross-compilation, you can refer to the previous tutorial on transplanting rv1126!

ok, let's start the official sharing, here it is recommended to install the environment on ubuntu18!

1. The open source encoding format required for compilation and installation:

First of all, before compiling and installing these open source encoding formats, we need to understand why they are needed:

  • aac

  • x264

  • x265

Why do you need it? If you know a little bit about ffmpeg, ffmpeg itself is a framework, and it does not support these three encoding formats by default, so we need to add them manually to support them!

Ok, after understanding this, let's start to download the source code packages of these three open source encoding formats:

1. Compile aac:

aac download link:

wget https://sourceforge.net/projects/opencore-amr/files/fdk-aac/fdk-aac-2.0.2.tar.gz

Start compiling:

- 1、./configure --prefix=/usr/local/ffmpeg/ --enable-shared
- 2、make -j8 && make install

Here I put all the compiled things in /usr/local/ffmpeg/, and only the dynamic library is compiled here; you can follow the above two steps:

The final compiled dynamic library is placed under /usr/local/ffmpeg/lib, and the header file is under /usr/local/include:

2. Compile x264:

x264 download link:

wget http://ftp.videolan.org/pub/videolan/x264/snapshots/x264-snapshot-20191024-2245-stable.tar.bz2

Start compiling:

1、./configure  --prefix=/usr/local/ffmpeg --enable-static --enable-pic
2、 make -j8 && make install

Here the compiled things are also placed in the path /usr/local/ffmpeg, and the static library is compiled:

Note: If you install it for the first time here, an error will be reported that the nasm version is too low. At this time, you need to re-download the nasm source code to install and compile:

Here I will give you the installation steps of nasm; the first is the download link of nasm:

wget https://www.nasm.us/pub/nasm/releasebuilds/2.14.02/nasm-2.14.02.tar.bz2

Compilation steps:

1、./configure
2、make -j8 && make install

Ok, this operation is relatively simple, you can follow this operation; if you install x264 for the first time, you can solve the error by reinstalling nasm, and then we will install x264:

The final generated header files and static libraries are also placed in the /usr/local/ffmpeg path:

3. Compile x265:

x265 download link:

wget http://ftp.videolan.org/pub/videolan/x265/x265_3.2.tar.gz

Compilation steps:

1、cd x265_3.2/build/linux/
2、 ./make-Makefiles.bash
3、 make -j8 && make install

We can see that the library and header files compiled by x265 are placed in the /usr/local/lib and /usr/local/include paths respectively!

2. Compile and install the latest ffmpeg source code:

Here we use the source code on gitte, the download on github will be a bit slow:

git clone https://gitee.com/mirrors/ffmpeg/

We downloaded it and switched the branch to version 5.1:

 git checkout -b remotes/origin/release/5.1

Then start compiling:

1、./configure --prefix=/usr/local/ffmpeg --enable-gpl --enable-shared --enable-version3 --enable-nonfree --enable-pthreads --enable-libx264 --enable-libx265 --enable-libfdk-aac

2、make -j8 && make install

The first step here is to manually enable the aac, x264, and x265 encoding formats. Here are also the functions of other enable:

  • --enable-pthreads: Enable pthreads (multithreading) (default off, there may be thread safety issues)

  • --enable-gpl: enable use of the GPL (default off)

  • --enable-shared : Build shared libraries (default off)

  • --enable-version3: upgrade GPL to version 3 (default: off)

  • --enable-nonfree: Allow use of non-free code, resulting libraries and binaries will not be redistributable

  • --prefix=/usr/local/ffmpeg: Put all the things compiled by ffmpeg in this path

We found that libfdk_aac could not be found, so how to solve it, the problem is that its path cannot be found, so let's configure the environment variable:

vi ~/.bashrc

Add the following statement:

export PKG_CONFIG_PATH="$PKG_CONFIG_PATH:/usr/local/ffmpeg/lib/pkgconfig"

Then exit, execute source ~/.bashrc to make it effective. Why do we do this here? Here we mainly locate fdk-aac through the fdk-aac.pc file in the following:

At this time, execute the configuration just now to solve this problem. If you encounter similar problems later, you can refer to this method to solve it. The core is to find the file corresponding to the .pc suffix you compiled:

Then continue to compile, this process is relatively long, I will only show you the make install part:

Finally, we can see the generated library under the /usr/local/ffmpeg/lib path:

Executable program and header file:

Here also configure the environment variables:

export PATH="$PATH:/usr/local/ffmpeg/bin"
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/usr/local/ffmpeg/lib"

At this time, I can check the version of ffmpeg in any terminal path:

3. Use vscode to build ffmpeg development environment:

First go to vscode official website to download vscode:

https://code.visualstudio.com/

Download the following version, because my current environment is ubuntu18:

Then click the downloaded package directly to install vscode:

Finally, you can see the installed vscode:

Now let's build a heh.c project, and install c/c++ and gdb plug-ins first:

Terminal compilation:

gcc heh.c -lavutil -lavformat

Guess you like

Origin blog.csdn.net/weixin_41114301/article/details/130134782