[FFmpeg] Compile official examples

Official example address

If you have downloaded the source code, you can view it in ffmpeg-4.3.1/doc/examples/

On Ubuntu 16.04, after installing ffmpeg through the source code, run the official example

gcc -o demux demuxing_decoding.c -I /usr/local/include/ -L /usr/local/lib -lavcodec -lavformat -lavutil

As the installation configure path is / usr / local, header files will be installed in / usr / local / include, which is the default linux the header file search path, so -I /usr/local/include/do not need.

gcc -o demux demuxing_decoding.c -L /usr/local/lib -lavcodec -lavformat -lavutil

However, if you do not specify the dynamic library loading path -L /usr/local/lib, the path of -lavcodec will default to /usr/lib/x86_64-linux-gnu/libavcodec-ffmpeg.so.56, but the correct path should be /usr/local/lib/libavcodec. so.58. This is because before according to the official guide to install OpenCV, using apt required to install the appropriate libavcodec library ...

[required] sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev

When gcc compiles the program, the sequence of finding the so dynamic library is as follows:

  1. The path specified by the parameter -L when gcc is compiled

  2. Environment variable LIBRARY_PATH

  3. System default library location /lib, /usr/lib

Configure environment variables in the ~/.bashrc file

# 编译时链接动态库路径
export LIBRARY_PATH=/usr/local/lib/:$LIBRARY_PATH
# 运行时链接动态库路径
export LD_LIBRARY_PATH=/usr/local/lib/:$LD_LIBRARY_PATH

Make the ~/.bashrc file effective again

source ~/.bashrc

So just need

gcc -o demux demuxing_decoding.c -lavcodec -lavformat -lavutil

Guess you like

Origin blog.csdn.net/weixin_43742643/article/details/113790656