How to compile git's FFmpeg in the linux environment of Tencent Cloud Ubuntu20.04LTS

Introduction

Compiling ffmpeg under windows is said to use the cygwin virtual environment, and I uninstalled VS before, and there is an algorithm on hand that requires libavformat compiled by ffmpeg, and I don’t want to allocate a few gigabytes of memory to reinstall the virtual machine on the old office computer, so I chose the cloud server. I searched Tencent Cloud’s personal server for only 40 yuan a year. Thinking... There are so many pitfalls here, it took me a whole morning to find them. . . So let me introduce the correct installation method after countless pits. In order to write this, I also reinstalled the system by the way.

start from 0

First of all, let me show you my cloud server configuration. The lw in the name means light weight, that is, my server is a lightweight application server (the cheapest, and exclusive for new users), 40 per year.
insert image description here

Click the one-click login in the lower left corner, and a familiar and unfamiliar command line pops up:
insert image description here
Next, let's take down the latest ffmpeg Git:

git clone https://github.com/FFmpeg/FFmpeg.git

While waiting, let’s take a look at the directory structure of the current system, so as not to search for files here and there like me: the
insert image description here
root directory of the system is /, and our current directory (that is, the directory where the login command line is located) is actually /home/lighthouse/…. There are no files in the current directory, so the ls command did not return anything. I thought it was broken at first . .
After a long wait for the clone to complete, don’t rush to make install, it will report an error. Note here that many tutorials will configure some things with ./configure before make install, and will tell you that you need to install yasm so that no error will be reported, which is simply nonsense! (They don't even know there is an option --disable-yasm)

Error in the middle

./configure reported an error: gcc is unable to create an executable file c compiler test failed
insert image description here
make reported an error: /tests/Makefile: No such file or directory, No rule to make target
insert image description here
These two seemingly unrelated reasons actually have only one reason: this Tencent Cloud server does not have the basic components of C installed , so it needs:

sudo apt-get install build-essential

You will be prompted to install about 73.7MB, and then enter Y to install, but Tencent’s own source components may be 404, if not, please try a few more times, or change the source to Ali source , how to change the source (please skip to the next part if the installation is complete and there is no error) see the following:

cd /etc/apt #进入目录
sudo rm -f sources.list #强制删除原来的源
touch sources.list #创建新文件用来写入源
chmod 777 sources.list #赋予最大权限777,即三种用户都能读写
vi sources.list #用vi编辑器打开进行写入

For vi, enter i to enter the input mode, right click the mouse in the input mode and paste the following content:

deb http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse

Then press esc to exit the input mode, enter: wq (write and save, pay attention to the : number in front), after writing the source, don't rush to apt-get install, you need to:

sudo apt-get update

After updating the software list, repeat the previous sudo apt-get install build-essential.

last step

./configure --prefix=/home/lighthouse/ff --enable-pic --disable-yasm --enable-shared

First configure the directory you installed –prefix=xxxxxxxxxx, then copy the following options and you’re done. Normally, a whole page of information will appear to remind you that the configuration is complete, and then:

make install

After a long wait (it is normal that there may be some warning information in the middle), the compilation is successfully completed!
As shown below:
insert image description here

Guess you like

Origin blog.csdn.net/weixin_43945848/article/details/123274449