FFmpeg source code compilation environment construction

ffmpeg is the most commonly used open source software for video development. ffmpeg is powerful and versatile. It provides almost all operations related to video development that you can think of. Many commercial software are developed and customized based on ffmpeg.

FFmpeg: FFmpeg is a free and open-source project consisting of a vast software suite of libraries and programs for handling video, audio, and other multimedia files and streams. At its core is the FFmpeg program itself, designed for command-line-based processing of video and audio files, and widely used for format transcoding, basic editing (trimming and concatenation), video scaling, video post-production effects, and standards compliance (SMPTE, ITU) . 摘自wikipedia

ffmpeg has huge functions and provides developers with a wealth of function library calls. Commonly used function libraries include:

  • libavcodec - audio and video codecs for various formats

  • libavformat - Generation and analysis of various audio and video packaging formats, including functions such as obtaining information required for decoding, reading audio and video data, etc.

  • libswscale - A library for video image scaling, providing functions for color space conversion and image format conversion

  • libavutil - Tool library, including arithmetic operations, character operations, etc.

  • libpostproc - library for preprocessing video

  • libpostproc - filter function library

  • libavdevice - Provides access to capture and playback devices

In addition, ffmpeg also provides developers with a wealth of command line tools. For developers who are not familiar with ffmpeg, they can first use these command line tools to have a general understanding of the basic functions of ffmpeg. Let's start the formal discussion .

1. ffmpeg installation

Here we take the Ubuntu 16 LTS version as an example to introduce the installation of FFmpeg.

1.1 Add PPA source

ffmpeg 4 is the latest release version. If you want to install this version, you need to add the PPA source. Execute the following command to add the PPA warehouse to the Ubuntu system

sudo add-apt-repository ppa:jonathonf/ffmpeg-4

1.2 Install ffmpeg

Install ffmpeg with the following command

sudo apt-get update
sudo apt-get install ffmpeg

You can see that related dynamic library files such as x264 will also be installed together

sudo apt-get install ffmpeg
[sudo] password for ron: 
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following additional packages will be installed:
  libaom0 libavcodec58 libavdevice58 libavfilter7 libavformat58 libavresample4 libavutil56 libbs2b0 libchromaprint1 libcodec2-0.4
  libflite1 liblilv-0-0 libmysofa1 libnorm1 libopenjp2-7 libopenmpt0 libpgm-5.2-0 libpocketsphinx3 libpostproc55 librabbitmq4
  librubberband2v5 libserd-0-0 libsodium18 libsord-0-0 libsphinxbase3 libsratom-0-0 libsrt1-gnutls libswresample3 libswscale5
  libvdpau1 libvidstab1.1 libx264-155 libx265-192 libzmq5 mesa-vdpau-drivers vdpau-driver-all
Suggested packages:
  ffmpeg-doc serdi sordi libvdpau-va-gl1 nvidia-vdpau-driver nvidia-legacy-340xx-vdpau-driver
Recommended packages:
  pocketsphinx-hmm-en-hub4wsj | pocketsphinx-hmm-zh-tdt | pocketsphinx-hmm-en-tidigits pocketsphinx-lm-en-hub4
  | pocketsphinx-lm-zh-hans-gigatdt | pocketsphinx-lm-zh-hant-gigatdt
The following NEW packages will be installed:
  ffmpeg libaom0 libavcodec58 libavdevice58 libavfilter7 libavformat58 libavresample4 libavutil56 libbs2b0 libchromaprint1
  libcodec2-0.4 libflite1 liblilv-0-0 libmysofa1 libnorm1 libopenjp2-7 libopenmpt0 libpgm-5.2-0 libpocketsphinx3 libpostproc55
  librabbitmq4 librubberband2v5 libserd-0-0 libsodium18 libsord-0-0 libsphinxbase3 libsratom-0-0 libsrt1-gnutls libswresample3
  libswscale5 libvdpau1 libvidstab1.1 libx264-155 libx265-192 libzmq5 mesa-vdpau-drivers vdpau-driver-all
0 upgraded, 37 newly installed, 0 to remove and 233 not upgraded.
Need to get 29.2 MB of archives.
After this operation, 106 MB of additional disk space will be used.
Do you want to continue? [Y/n]

1.3 Confirm that ffmpeg is installed successfully

After the ffmpeg installation is complete, you can use the ffmpeg -version command to print the FFmpeg version number, and if you can print it successfully, you can confirm that the ffmpeg installation is successful.

ffmpeg -version

2. ffmpeg source code compilation

ffmpeg source code compilation does not require a complicated compilation environment, only basic compilers and dependent libraries are required. ffmpeg supports the development of multiple mainstream platforms, here mainly describes how to compile in the linux environment.

2.1 ffmpeg compilation environment preparation

Here we take the ubuntu system as an example, and the principles of other linux distributions are similar. Compiling on the linux system requires the installation of gcc make and other components, which can be installed with the following command

sudo apt-get install build-essential

Enter the gcc -v command to query the current gcc version number

gcc -v

2.2 ffmpeg dependent library preparation

ffmpeg source code compilation mainly depends on the two components x264 and yasm. It is very easy to find their source code packages in search engines. The way of compiling and installing source code packages can also be used in embedded environments

x264: x264 is a free software library and application for encoding video streams into the H.264/MPEG-4 AVC compression format, and is released under the terms of the GNU GPL.

Yasm: Yasm is a complete rewrite of the NASM assembler under the “new” BSD License,Yasm currently supports the x86 and AMD64 instruction sets, accepts NASM and GAS assembler syntaxes, outputs binary, ELF32, ELF64, 32 and 64-bit Mach-O, RDOFF2, COFF, Win32, and Win64 object formats, and generates source debugging information in STABS, DWARF 2, and CodeView 8 formats.

The link address of the source package is given below

Download FFmpeg Index of /pub/videolan/x264/snapshots/ Download - The Yasm Modular Assembler Project

[Learning address]: Advanced development of FFmpeg/WebRTC/RTMP/NDK/Android audio and video streaming media
[Article Benefits]: Receive more audio and video learning materials packages, Dachang interview questions, technical videos and learning roadmaps for free, including ( C/C++, Linux, FFmpeg webRTC rtmp hls rtsp ffplay srs, etc.) If you need it, you can click 1079654574 to join the group to receive it~

The source code versions tested here are

x264-0.148 (x264 snapshot-20170307-2245)
yasm-1.3.0
ffmpeg-3.2.4

Among them, x264 provides support for h.264 encoder, and yasm is used to support assembly optimization. If assembly optimization support is not required, you can turn off yasm in the compilation option (–disable-yasm)

Under Linux, compile options can be configured in the following ways:

2.2.1 yasm configure configuration

./configure --prefix=/usr/local/3rdparty/yasm

2.2.2 x264 configure configuration

./configure --prefix=/usr/local/3rdparty/x264 --enable-shared --enable-static --enable-yasm

After the Makefile is generated, enter the make command to start the compilation process. After the compilation is completed, execute the make install command to install

make 
sudo make install

After the compilation of x264 and yasm is completed, the system needs to be able to find the corresponding installation location. Open the /etc/profile configuration file and add the environment variables of each component at the bottom of the file

# YASM
export PATH="$PATH:/usr/local/3rdparty/yasm/bin/"
export LD_LIBRARY_PATH=/usr/local/3rdparty/yasm/lib:$LD_LIBRARY_PATH
​
# X264
export PATH="$PATH:/usr/local/3rdparty/x264/bin/"
export LD_LIBRARY_PATH=/usr/local/3rdparty/x264/lib:$LD_LIBRARY_PATH
export PKG_CONFIG_PATH=/usr/local/3rdparty/x264/lib/pkgconfig:$PKG_CONFIG_PATH

Use the source /etc/profile command to refresh environment variables

source /etc/profile

After the environment variable configuration is complete, you can use the following command to confirm whether dependent components such as x264 are successfully compiled and installed

x264 --version
x264 0.148.x
built on May 22 2019, gcc: 5.4.0 20160609
x264 configuration: --bit-depth=8 --chroma-format=all
libx264 configuration: --bit-depth=8 --chroma-format=all
x264 license: GPL version 2 or later
​
yasm --version
yasm 1.3.0
Compiled on May  6 2015.
Copyright (c) 2001-2014 Peter Johnson and other Yasm developers.
Run yasm --license for licensing overview and summary.

2.3 ffmpeg source code compilation

Under Linux, compile options can be configured in the following ways:

2.3.1 ffmpeg configure configuration

./configure --prefix=/usr/local/3rdparty/ffmpeg --enable-shared --enable-yasm --enable-libx264 --enable-gpl --enable-pthreads --extra-cflags=-I/usr/local/3rdparty/x264/include --extra-ldflags=-L/usr/local/3rdparty/x264/lib

After the Makefile is generated, enter the make command to start the compilation process. After the compilation is completed, execute the make install command to install

make 
sudo make install

After the compilation is complete, command line tools such as ffmpeg, ffserver, and ffprobe are generated in the source code directory, among which

  • ffmpeg - command line tool supports video codec, video transcoding, video format conversion, video streaming and other functions

  • ffserver - The command line tool cooperates with ffmpeg and is responsible for responding to the client's streaming media request and sending the streaming media data to the client

  • ffprobe - command line tool to view description information of multimedia files

2.4 ffmpeg environment variable configuration

After the compilation of ffmpeg and its dependent environment is completed, the system needs to be able to find the corresponding installation location. Open the /etc/profile configuration file and add the environment variables of each component at the bottom of the file

# FFMPEG
export PATH="$PATH:/usr/local/3rdparty/ffmpeg/bin/"
export LD_LIBRARY_PATH=/usr/local/3rdparty/ffmpeg/lib:$LD_LIBRARY_PATH
export PKG_CONFIG_PATH=/usr/local/3rdparty/ffmpeg/lib/pkgconfig:$PKG_CONFIG_PATH

Use the source /etc/profile command to refresh environment variables

source /etc/profile

Use the ffmpeg -version command to print the version number, the ffmpeg used here is version 3.2.4

ffmpeg -version
ffmpeg version 3.2.4 Copyright (c) 2000-2017 the FFmpeg developers
built with gcc 5.4.0 (Ubuntu 5.4.0-6ubuntu1~16.04.12) 20160609
configuration: --prefix=/usr/local/3rdparty/ffmpeg --enable-shared --enable-yasm --enable-libx264 --enable-gpl --enable-pthreads --extra-cflags=-I/usr/local/3rdparty/x264/include --extra-ldflags=-L/usr/local/3rdparty/x264/lib
libavutil      55. 34.101 / 55. 34.101
libavcodec     57. 64.101 / 57. 64.101
libavformat    57. 56.101 / 57. 56.101
libavdevice    57.  1.100 / 57.  1.100
libavfilter     6. 65.100 /  6. 65.100
libswscale      4.  2.100 /  4.  2.100
libswresample   2.  3.100 /  2.  3.100
libpostproc    54.  1.100 / 54.  1.100

Under the ffmpeg source code path , you can use the ldd command to query all components that ffmpeg depends on. If some of the components cannot be found, you need to refer to this article to check whether there are dependent components that have not configured environment variables. Similarly, you can also use the ldd command to query the dependencies of components such as x264 in the corresponding path.

ldd ffmpeg
    linux-vdso.so.1 =>  (0x00007ffc24f84000)
    libavdevice.so.57 => /usr/local/3rdparty/ffmpeg/lib/libavdevice.so.57 (0x00007fc17da42000)
    libavfilter.so.6 => /usr/local/3rdparty/ffmpeg/lib/libavfilter.so.6 (0x00007fc17d613000)
    libavformat.so.57 => /usr/local/3rdparty/ffmpeg/lib/libavformat.so.57 (0x00007fc17d1f3000)
    libavcodec.so.57 => /usr/local/3rdparty/ffmpeg/lib/libavcodec.so.57 (0x00007fc17bcbf000)
    libpostproc.so.54 => /usr/local/3rdparty/ffmpeg/lib/libpostproc.so.54 (0x00007fc17baa3000)
    libswresample.so.2 => /usr/local/3rdparty/ffmpeg/lib/libswresample.so.2 (0x00007fc17b887000)
    libswscale.so.4 => /usr/local/3rdparty/ffmpeg/lib/libswscale.so.4 (0x00007fc17b5ff000)
    libavutil.so.55 => /usr/local/3rdparty/ffmpeg/lib/libavutil.so.55 (0x00007fc17b385000)
    libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fc17b07c000)
    libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fc17ae5f000)
    libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fc17aa95000)
    libXv.so.1 => /usr/lib/x86_64-linux-gnu/libXv.so.1 (0x00007fc17a890000)
    libX11.so.6 => /usr/lib/x86_64-linux-gnu/libX11.so.6 (0x00007fc17a556000)
    libXext.so.6 => /usr/lib/x86_64-linux-gnu/libXext.so.6 (0x00007fc17a344000)
    libxcb.so.1 => /usr/lib/x86_64-linux-gnu/libxcb.so.1 (0x00007fc17a122000)
    libxcb-shm.so.0 => /usr/lib/x86_64-linux-gnu/libxcb-shm.so.0 (0x00007fc179f1e000)
    libxcb-xfixes.so.0 => /usr/lib/x86_64-linux-gnu/libxcb-xfixes.so.0 (0x00007fc179d16000)
    libxcb-shape.so.0 => /usr/lib/x86_64-linux-gnu/libxcb-shape.so.0 (0x00007fc179b12000)
    libasound.so.2 => /usr/lib/x86_64-linux-gnu/libasound.so.2 (0x00007fc179812000)
    libSDL2-2.0.so.0 => /usr/local/3rdparty/sdl2/lib/libSDL2-2.0.so.0 (0x00007fc1794df000)
    libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007fc1792c5000)
    libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007fc1790c1000)
    libx264.so.148 => /usr/local/3rdparty/x264/lib/libx264.so.148 (0x00007fc178d1b000)
    liblzma.so.5 => /lib/x86_64-linux-gnu/liblzma.so.5 (0x00007fc178af9000)
    /lib64/ld-linux-x86-64.so.2 (0x00007fc17dc5a000)
    libXau.so.6 => /usr/lib/x86_64-linux-gnu/libXau.so.6 (0x00007fc1788f5000)
    libXdmcp.so.6 => /usr/lib/x86_64-linux-gnu/libXdmcp.so.6 (0x00007fc1786ef000)
    librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007fc1784e7000)

Original link: ffmpeg source code compilation environment construction_ffmpeg compilation environment_breakpointlab's blog-CSDN blog

Guess you like

Origin blog.csdn.net/irainsa/article/details/130630343