FFmpeg audio and video processing technology: FFmpeg environment construction based on QT Creator under Linux (the most complete in history)

Preface

  Friends who read this article should note that the author mainly builds the FFmpeg environment from four aspects (fully adapted to the use of common operating system platforms for FFmpeg audio and video development). You can choose the corresponding environment to build according to your needs: (
1 ) FFmpeg command line environment construction under Linux (ubuntu)
(2) FFmpeg command line environment construction under Windows
(3) FFmpeg environment construction for QT Creator under Linux (ubuntu)
(4) FFmpeg environment construction for QT Creator under Windows (late update... )

1. Building the FFmpeg command line environment under Linux (ubuntu)

1. Enter the command in the Linux terminal: sudo apt update or sudo apt-get update

2. Enter the command in the Linux terminal: sudo apt install ffmpeg or sudo apt-get install ffmpeg

3. Test whether FFmpeg is installed successfully. Enter the command in the Linux terminal: ffmpeg --version. If version information appears, the environment is installed successfully.

Insert image description here

4. If you need to uninstall FFmpeg, enter the command in the terminal: sudo apt-get purge ffmpeg or sudo apt purge ffmpeg

2. Building FFmpeg command line environment under Windows

Note: You need to go to the FFmpeg official website to download the compiled FFmpeg package. FFmpeg official website:

http://ffmpeg.org/

1. Download the corresponding package from the FFmpeg official website

What this author downloaded is: FFmpeg4.2.2 version. You can download the corresponding version according to actual needs. If you cannot find the version you want, you can use the following URL: http://ffmpeg.org/releases/
Insert image description here

2. Add the bin file in the downloaded FFmpeg package to the system environment variable Path

Insert image description here

3. Test the downloaded FFmpeg environment. Use the command line tool cmd under Windows. Enter the command: ffmpeg -version. If the version information appears, the environment installation is successful.

Insert image description here

4. You can test whether the video can be played. Enter the cmd command line tool: ffplay -x 800 -y 1000 C:/Users/lenovo/Desktop/meeting_01.mp4

Insert image description here

Insert image description here

3. Setting up the FFmpeg environment of QT Creator under Linux (ubuntu)

Note: Since the author is not a FFmpeg professional, he refers to the articles and video links published by the following blogger (CSDN name: Yuntianzhi, blog number: qq214517703) to build the environment (the author has deleted the H265 encoding part), if any In case of infringement, please contact the original author at QQ: 35175419. The author will delete it in time to protect the legitimate rights and interests of the original author.

Blogger article link:

https://blog.csdn.net/qq214517703/article/details/106500008

Blogger video link:

https://www.bilibili.com/video/BV1Sz411v7Wm/?spm_id_from=888.80997.embed_other.whitelist&t=767&vd_source=8c0e94c43c8556178a1925558ef1ae3e

1. Download the FFmpeg resource dependency package

(1)yasm package

Link:
http://www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gz

(2) nasm package

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

(3) x264 package

Link:
http://ftp.videolan.org/pub/videolan/x264/snapshots/

(4) x265 package (can be downloaded as needed)

Link:
http://ftp.videolan.org/pub/videolan/x265/

2. Copy the downloaded yasm, nasm, x264, and x265 to the virtual machine and unzip it

Insert image description here

3. Start installing the FFmpeg dependent environment

(1) Install yasm
Step 1: Enter the yasm file, open the terminal, and enter the command: ./configure

Insert image description here
Insert image description here

Step 2: Continue to enter the command in the terminal: make or sudo make to compile.

Insert image description here

Step 3: Continue to enter the command in the terminal: make install or sudo make install (note: it is best to use sudo to elevate permissions) to download

Insert image description here

(2) Install nasm
Step 1: Enter the nasm file, open the terminal, and enter the command: ./configure

Insert image description here
Insert image description here

Step 2: Continue to enter the command in the terminal: make or sudo make

Insert image description here

Step 3: Continue to enter the command in the terminal: make install or sudo make install (Note: It is best to add sudo to elevate permissions)

Insert image description here

(3) Install cmake (required when building x265 encoding. Since the author does not use x265, it can be installed or not), open the terminal and enter the command: sudo apt install cmake -y or apt install cmake -y

Insert image description here

(4) Compile x264 static library
Step 1: Go to the x264 file, open the terminal, and enter the command: ./configure --enable-static --prefix=…/x264 --enable-pic

Insert image description here

Step 2: Continue to enter the command in the terminal: sudo make -j16 or make -j16

Insert image description here

Step 3: Continue to enter the command in the terminal: sudo make install or make install

Insert image description here

(5) Download the FFmpeg source code and start installing the FFmpeg environment (Note: The FFmpeg command line environment installed before does not conflict with the FFmpeg environment installed here)
Step 1: Download the FFmpeg source code and copy it to the virtual machine to decompress it.

Insert image description here
Insert image description here

Step 2: Enter the FFmpeg-6.0 folder, open the terminal, and enter the command: export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:…/x264/lib/pkgconfig

Insert image description here
Insert image description here

Step 3: Continue to enter the command in the terminal: ./configure --enable-shared --enable-nonfree --enable-gpl --enable-pthreads --enable-libx264 --prefix=…/ffmpeg

Insert image description here

Step 4: Continue to enter the command in the terminal: sudo make -j64 or make -j64 //This step takes more time

Insert image description here

Step 5: Continue to enter the command in the terminal: sudo make install or make install

Insert image description here
######################### The entire environment is now set up ################### #######

  After the compilation is completed, it is found that the ffmpeg folder is generated in the path (the third step above), which was generated during compilation. The corresponding dynamic library and static library are generated in this file.
Insert image description here

4. Build FFmpeg environment with QT Creator under Linux

(1) Build QT Creator environment under Linux
This author’s link: https://blog.csdn.net/Mr_zhang1911116/article/details/132184656?spm=1001.2014.3001.5502
(2) QT Creator builds FFmpeg environment
Step 1: Create a QT Creator project (the author’s project name: QT_Test), and copy the previously generated ffmpeg file to the QT_Test project file

Insert image description here

Step 2: In the QT_Test project file QT_Test.pro, import the FFmpeg library
导入的内容如下:
INCLUDEPATH += $$PWD/ffmpeg/include
LIBS +=-L$$PWD/ffmpeg/lib -lavcodec -lavutil -lavformat -lavdevice -lavfilter -lpostproc -lswresample -lswscale
#注:-L是指在指定路径下,$$PWD是指当前路径

Insert image description here

Step 3: Add the FFmpeg library file to the main interface file dialog.cpp (of course you can choose which file to add according to the actual situation)
导入的内容如下:
extern "C"{
    
    
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
#include <libswscale/swscale.h>
#include <libavutil/imgutils.h>
#include <libswresample/swresample.h>
}   //可以根据自己需要进行添加即可,由于ffmpeg是C的库,故需要extern “C”进行引入

Insert image description here

Step 4: In the program file, call any library function, for example: av_version_info() //Print version information function, and then run the entire QT_Test project. If version information appears, the environment installation is complete

Insert image description here

4. Setting up the FFmpeg environment of QT Creator under Windows

Later update! ! !

Guess you like

Origin blog.csdn.net/Mr_zhang1911116/article/details/132202952