FFmpeg Development Notes (1) Building a Linux System Development Environment

For beginners, how to build the FFmpeg development environment is not a small obstacle, because FFmpeg uses many third-party development kits, so these third-party source codes must be compiled first, and then the compiled third-party libraries can be integrated into FFmpeg.
However, considering that we only call the FFmpeg API at the beginning, we will not change the source code of FFmpeg immediately, so as long as the compiled FFmpeg dynamic library is installed on the system, we can start writing a simple FFmpeg program. For example, this website https://github.com/BtbN/FFmpeg-Builds/releases provides compiled FFmpeg development kits, including development versions for Linux, Windows and other system environments. For the Linux version of FFmpeg installation package provided by this website, it is necessary to install the glibc library not lower than version 2.22 in advance, otherwise the error "undefined reference to `_ZGVdN4vv_pow@GLIBC_2.22'" will be reported when compiling the FFmpeg program. The following describes the detailed steps to install the compiled FFmpeg on the Linux system.

1. Install glibc

1. Go to this website to download the glibc source code package of version 2.23 http://ftp.gnu.org/gnu/glibc/ . Note: Although the glibc version is required to be no lower than 2.22, it is not advisable to install a higher version of glibc, because the higher version of glibc depends on python, and it will take a lot of effort to complete the python environment, so get a slightly higher version than 2.22 Version 2.23 is enough, that is, download this compressed package http://ftp.gnu.org/gnu/glibc/glibc-2.23.tar.gz .
2. Unzip the glibc source code package first, then enter the glibc source code directory, then create a build directory and enter this directory, that is, execute the following commands in sequence:

tar zxvf glibc-2.23.tar.gz
cd glibc-2.23
mkdir build
cd build

3. Execute the following commands in order to configure, compile and install glibc in the build directory:

../configure --prefix=/usr
make
make install

After the installation is successful, you will find the latest libc.so (also libc.so.6 and libc-2.23.so) and libmvec.so (also libmvec.so.1 and libmvec-2.23. so) and other library files.

2. Install FFmpeg

1. Go to this website to download the FFmpeg installation package compiled in the Linux environment https://github.com/BtbN/FFmpeg-Builds/releases, such as ffmpeg-master-latest-linux64-gpl-shared.tar.xz.
2. Unzip the downloaded FFmpeg installation package to the /usr/local/ffmpeg directory, that is, execute the following commands in sequence:

cd /usr/local
tar xvf ffmpeg-master-latest-linux64-gpl-shared.tar.xz
mv ffmpeg-master-latest-linux64-gpl-shared ffmpeg

3. Enter the cd command to return to the initial directory of the current user, and use vi to open the .bash_profile in this directory, that is, execute the following commands in sequence:

cd
vi .bash_profile

4. Move the cursor to the end of the file, press the a key to enter the edit mode, and then add the following four lines of environment variable configuration at the end of the file:

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

Then save and exit the file, that is, first press the Esc key to exit the editing mode, then press the colon key, then enter wq and press the Enter key to complete the modification operation.
5. Execute the following command to load the latest environment variables:

source .bash_profile

Then run the following environment variable view command:

env | grep PATH

It is found that the PATH string echoed by the console contains /usr/local/ffmpeg/bin, and the LD_LIBRARY_PATH string contains /usr/local/ffmpeg/lib, indicating that the bin directory and lib directory of FFmpeg are loaded into the environment variable.

3. Write the test program

1. Create a C code file called hello.c, and fill in the following code content:

#include <libavutil/avutil.h>

int main(int argc, char* argv[]) {
    av_log(NULL, AV_LOG_INFO, "hello world\n");
}

2. Save and exit the file, execute the following command to compile hello.c:

gcc hello.c -o hello -I/usr/local/ffmpeg/include -L/usr/local/ffmpeg/lib -lavformat -lavdevice -lavfilter -lavcodec -lavutil -lswscale -lswresample -lpostproc -lm

3. Run the compiled hello program, that is, execute the following command:

./hello

It is found that the console echoes the log information "hello world", indicating that the test program is running normally, indicating that the FFmpeg development environment has been successfully established.
 

Guess you like

Origin blog.csdn.net/aqi00/article/details/130141095