Review of the previous period
FFmpeg open class of FFmpeg code architecture
Now audio and video is very hot, FFmpeg is audio and video developers can not get around the past an open source project, we generally need to transplant FFmpeg on the mobile end, but Android running example is more tedious, and the compilation and running are slow, here we recommend running FFmpeg on THE PC, Debug the program on the PC before porting it to the mobile terminal.
PC compilation
Since we mainly use Mac to develop programs, we also started our compilation project on Mac.
Download the FFmpeg source code
git clone https://github.com/FFmpeg/FFmpeg
Copy the code
Once you’ve downloaded it, you need to switch to the branch of crime:
Git checkout -b local_n4.4Copy the code
The latest stable version of tag is N4.4, and we switched to this branch based on that.
Configure the configuration
When you configure FFmpeg on your computer, you must try to support as many features as possible. Here is a reference:
./configure –enable-shared –enable-pthreads –enable-version3 –cc=clang –host-cflags= –host-ldflags= –enable-ffplay –enable-gnutls –enable-gpl –enable-libaom –enable-libbluray –enable-libmp3lame –enable-libopus –enable-librubberband –enable-libsnappy –enable-libtesseract –enable-libtheora –enable-libvidstab –enable-libvorbis –enable-libvpx –enable-libwebp –enable-libx264 –enable-libx265 –enable-libxvid –enable-lzma –enable-libfontconfig –enable-libfreetype –enable-frei0r –enable-libass –enable-libopencore-amrnb –enable-libopencore-amrwb –enable-libopenjpeg –enable-libspeex –enable-libsoxr –enable-videotoolbox –disable-libjack –disable-indev=jack –disable-x86asm –prefix=/usr/local/ffmpeg –prefix=/usr/local/ffmpeg indicates that the installation is under the /usr/local/ffmpeg folder.
Compile the installation
Execute the following instructions in turn:
sudo make -j4
sudo make install
Copy the code
The files in the /usr/local/ffmpe directory are the libraries you’ll need to run the ffmpeg example on your next PC.
- Bin is an executable file
- Include is the compilation header file
- Lib is a dependency library
- Share is the config file
The files in the share directory are very important, so let’s compile the pkg-config configuration that we need it to provide.
The compile file references the FFmpeg library
Here are the files we need to compile:
#include <stdio.h> #include <libavformat/avformat.h> #include <libavutil/dict.h> int main (int argc, char **argv) { AVFormatContext *fmt_ctx = NULL; AVDictionaryEntry *tag = NULL; int ret; if (argc ! = 2) { printf("usage: %s <input_file>\n" "example program to demonstrate the use of the libavformat metadata API.\n" "\n", argv[0]); return 1; } if ((ret = avformat_open_input(&fmt_ctx, argv[1], NULL, NULL))) return ret; if ((ret = avformat_find_stream_info(fmt_ctx, NULL)) < 0) { av_log(NULL, AV_LOG_ERROR, "Cannot find stream information\n"); return ret; } while ((tag = av_dict_get(fmt_ctx->metadata, "", tag, AV_DICT_IGNORE_SUFFIX))) printf("%s=%s\n", tag->key, tag->value); avformat_close_input(&fmt_ctx); return 0; }Copy the code
When we find that we reference the AvFormat library, we need to encode the AvFormat library when we compile. The compiler executes the following commands:
gcc -g -o metadata metadata.c `pkg-config --libs --cflags libavformat`
Copy the code
Pgg-config –libs –cflags libavFormat = libavformat = libavformat
-i/usr/local/Cellar/ffmpeg / 4.4 _2 / include - L/usr/local/Cellar/ffmpeg _2 / lib / 4.4 - lavformatCopy the code
This allows us to use FFmpeg functionality on a PC.
You all know that to use third-party libraries, you need to use third-party header files and libraries. We must specify the location of these header and library files when compiling and linking.
For a large third-party library, the number of header files and library files is large. If we were to write them one by one manually, it would be quite cumbersome. So, PKG-config was born. Pkg-config can indicate the location of these header and library files for use by the compiler. If you have GTK installed on your system, try the following command $pkg-config –cflags GTK +-2.0. You can see that the output is the path to GTK’s header file.
This is how we normally use PKG-config. $GCC main.c pkg-config –cflags –libs GTK +-2.0 -o main
** pgg-config –cflags –libs GTK +-2.0** lists GTK header paths and library files for compilation. –cflags and –libs specify header and library files, respectively.
Ps: ‘in a command is not a quotation mark, but the key to the left of the number 1.
In fact, pgg-config has many options like other commands, but we usually only use the –libs and –cflags options.