在 ubuntu22 中编译安装 ffmpeg

编译运行环境:

test@test-virtual-machine:~$ lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 22.04.4 LTS
Release:	22.04
Codename:	jammy
test@test-virtual-machine:~$ uname -a
Linux test-virtual-machine 6.5.0-35-generic #35~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Tue May  7 09:00:52 UTC 2 x86_64 x86_64 x86_64

下载源码包:

ffmpeg官网download 页面下载。
解压 ffmpeg-7.0.1.tar.xz :

tar xvf ffmpeg-7.0.1.tar.xz

下面编译 ffmpeg 会支持 H.264 ,所以要编译安装 libx264
注:libx264 也可以直接通过命令安装:

sudo apt-get install libx264-dev

下载 x264 源码包。
解压源码包:

tar -jxvf x264-snapshot-20191217-2245-stable.tar.bz2

编译安装

编译安装 x264

创建安装文件夹:

mkdir x86_64-x264

生成 makefile :

test@test-virtual-machine:~/ThirdParty/x264-snapshot-20191217-2245-stable$ ./configure --prefix=/home/test/ThirdParty/x264-snapshot-20191217-2245-stable/x86_64-x264 --enable-shared --enable-static --disable-asm

编译:

make

安装:

make install

在 ~/.bashrc 中添加以下命令:

export PATH=$PATH:/home/test/ThirdParty/x264-snapshot-20191217-2245-stable/x86_64-x264/bin
export LD_LIBRARY_PATH=/home/test/ThirdParty/x264-snapshot-20191217-2245-stable/x86_64-x264/lib:$LD_LIBRARY_PATH
export PKG_CONFIG_PATH=/home/test/ThirdParty/x264-snapshot-20191217-2245-stable/x86_64-x264/lib/pkgconfig:$PKG_CONFIG_PATH

使修改生效:

source ./.bashrc

编译安装 ffmpeg

创建安装文件夹:

mkdir x86_64-ffmpeg

生成 makefile :

./configure --prefix=/home/test/ThirdParty/ffmpeg-7.0.1/x86_64-ffmpeg --enable-shared --enable-libx264 --enable-gpl --enable-pthreads --disable-asm --extra-cflags=-I/home/test/ThirdParty/x264-snapshot-20191217-2245-stable/x86_64-x264/include --extra-ldflags=-L/home/test/ThirdParty/x264-snapshot-20191217-2245-stable/x86_64-x264/lib

编译:

make

安装:

make install

之后编译出来的 库、可执行程序、以及头文件就都安装在 x86_64-ffmpeg 中了。

安装编译 debug 调试用的 ffmpeg

配置如下:
注:在以上编译中没有使用 --enable-ffplay 选项,所以没有将 可执行程序 ffplay 编译出来,因此下面添加了 --enable-ffplay 。

./configure --disable-shared --enable-static --disable-asm --enable-debug --enable-ffplay

注:ffplay 依赖于 SDL(Simple DirectMedia Layer)库,该库用于视频渲染和窗口管理,可通过命令直接安装。

sudo apt-get install libsdl2-dev

下面是编译成功后 ffmpeg-7.0.1 中的文件,可以看到生成的可执行程序都有两份,如 ffplay 与 ffplay_g
在这里插入图片描述

下面是 ffplay 与 ffplay_g 文件的详细信息,可以看到 ffplay 经过 stripped ,ffplay_g 没有经过 stripped 且有 debug_info

test@test-virtual-machine:~/ThirdParty/ffmpeg-7.0.1$ file ffplay
ffplay: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=482e5f5ac5c841cef2737b71aae261ce49403d74, for GNU/Linux 3.2.0, stripped

test@test-virtual-machine:~/ThirdParty/ffmpeg-7.0.1$ file ffplay_g 
ffplay_g: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=482e5f5ac5c841cef2737b71aae261ce49403d74, for GNU/Linux 3.2.0, with debug_info, not stripped

通过两个可执行文件的段表,也可以看到 ffplay_g 中也多了很多关于 debug 的段:

test@test-virtual-machine:~/ThirdParty/ffmpeg-7.0.1$ readelf -S ffplay
There are 30 section headers, starting at offset 0x141a290:

Section Headers:
  [Nr] Name              Type             Address           Offset    Size              EntSize          Flags  Link  Info  Align
  [ 0]                   NULL             0000000000000000  00000000  0000000000000000  0000000000000000           0     0     0
  [ 1] .interp           PROGBITS         0000000000000318  00000318  000000000000001c  0000000000000000   A       0     0     1
  [ 2] .note.gnu.pr[...] NOTE             0000000000000338  00000338  0000000000000030  0000000000000000   A       0     0     8
  [ 3] .note.gnu.bu[...] NOTE             0000000000000368  00000368  0000000000000024  0000000000000000   A       0     0     4
  [ 4] .note.ABI-tag     NOTE             000000000000038c  0000038c  0000000000000020  0000000000000000   A       0     0     4
  [ 5] .gnu.hash         GNU_HASH         00000000000003b0  000003b0  00000000000000b4  0000000000000000   A       6     0     8
  [ 6] .dynsym           DYNSYM           0000000000000468  00000468  0000000000002568  0000000000000018   A       7     1     8
  [ 7] .dynstr           STRTAB           00000000000029d0  000029d0  0000000000001456  0000000000000000   A       0     0     1
  [ 8] .gnu.version      VERSYM           0000000000003e26  00003e26  000000000000031e  0000000000000002   A       6     0     2
  [ 9] .gnu.version_r    VERNEED          0000000000004148  00004148  00000000000001a0  0000000000000000   A       7     4     8
  [10] .rela.dyn         RELA             00000000000042e8  000042e8  0000000000105738  0000000000000018   A       6     0     8
  [11] .rela.plt         RELA             0000000000109a20  00109a20  00000000000022b0  0000000000000018  AI       6    25     8
  [12] .init             PROGBITS         000000000010c000  0010c000  000000000000001b  0000000000000000  AX       0     0     4
  [13] .plt              PROGBITS         000000000010c020  0010c020  0000000000001730  0000000000000010  AX       0     0     16
  [14] .plt.got          PROGBITS         000000000010d750  0010d750  0000000000000130  0000000000000010  AX       0     0     16
  [15] .plt.sec          PROGBITS         000000000010d880  0010d880  0000000000001720  0000000000000010  AX       0     0     16
  [16] .text             PROGBITS         000000000010efa0  0010efa0  0000000000dddd4b  0000000000000000  AX       0     0     16
  [17] .fini             PROGBITS         0000000000eeccec  00eeccec  000000000000000d  0000000000000000  AX       0     0     4
  [18] .rodata           PROGBITS         0000000000eed000  00eed000  00000000002ee2e0  0000000000000000   A       0     0     32
  [19] .eh_frame_hdr     PROGBITS         00000000011db2e0  011db2e0  00000000000222ac  0000000000000000   A       0     0     4
  [20] .eh_frame         PROGBITS         00000000011fd590  011fd590  0000000000108080  0000000000000000   A       0     0     8
  [21] .init_array       INIT_ARRAY       0000000001306950  01305950  0000000000000008  0000000000000008  WA       0     0     8
  [22] .fini_array       FINI_ARRAY       0000000001306958  01305958  0000000000000008  0000000000000008  WA       0     0     8
  [23] .data.rel.ro      PROGBITS         0000000001306960  01305960  0000000000112580  0000000000000000  WA       0     0     32
  [24] .dynamic          DYNAMIC          0000000001418ee0  01417ee0  0000000000000290  0000000000000010  WA       7     0     8
  [25] .got              PROGBITS         0000000001419170  01418170  0000000000000e80  0000000000000008  WA       0     0     8
  [26] .data             PROGBITS         000000000141a000  01419000  0000000000001148  0000000000000000  WA       0     0     32
  [27] .bss              NOBITS           000000000141b160  0141a148  0000000001564c70  0000000000000000  WA       0     0     32
  [28] .comment          PROGBITS         0000000000000000  0141a148  000000000000002b  0000000000000001  MS       0     0     1
  [29] .shstrtab         STRTAB           0000000000000000  0141a173  0000000000000117  0000000000000000           0     0     1
Key to Flags:
  W (write), A (alloc), X (execute), M (merge), S (strings), I (info),
  L (link order), O (extra OS processing required), G (group), T (TLS),
  C (compressed), x (unknown), o (OS specific), E (exclude),
  D (mbind), l (large), p (processor specific)

test@test-virtual-machine:~/ThirdParty/ffmpeg-7.0.1$ readelf -S ffplay_g 
There are 40 section headers, starting at offset 0x61a6798:

Section Headers:
  [Nr] Name              Type             Address           Offset    Size              EntSize          Flags  Link  Info  Align
  [ 0]                   NULL             0000000000000000  00000000  0000000000000000  0000000000000000           0     0     0
  [ 1] .interp           PROGBITS         0000000000000318  00000318  000000000000001c  0000000000000000   A       0     0     1
  [ 2] .note.gnu.pr[...] NOTE             0000000000000338  00000338  0000000000000030  0000000000000000   A       0     0     8
  [ 3] .note.gnu.bu[...] NOTE             0000000000000368  00000368  0000000000000024  0000000000000000   A       0     0     4
  [ 4] .note.ABI-tag     NOTE             000000000000038c  0000038c  0000000000000020  0000000000000000   A       0     0     4
  [ 5] .gnu.hash         GNU_HASH         00000000000003b0  000003b0  00000000000000b4  0000000000000000   A       6     0     8
  [ 6] .dynsym           DYNSYM           0000000000000468  00000468  0000000000002568  0000000000000018   A       7     1     8
  [ 7] .dynstr           STRTAB           00000000000029d0  000029d0  0000000000001456  0000000000000000   A       0     0     1
  [ 8] .gnu.version      VERSYM           0000000000003e26  00003e26  000000000000031e  0000000000000002   A       6     0     2
  [ 9] .gnu.version_r    VERNEED          0000000000004148  00004148  00000000000001a0  0000000000000000   A       7     4     8
  [10] .rela.dyn         RELA             00000000000042e8  000042e8  0000000000105738  0000000000000018   A       6     0     8
  [11] .rela.plt         RELA             0000000000109a20  00109a20  00000000000022b0  0000000000000018  AI       6    25     8
  [12] .init             PROGBITS         000000000010c000  0010c000  000000000000001b  0000000000000000  AX       0     0     4
  [13] .plt              PROGBITS         000000000010c020  0010c020  0000000000001730  0000000000000010  AX       0     0     16
  [14] .plt.got          PROGBITS         000000000010d750  0010d750  0000000000000130  0000000000000010  AX       0     0     16
  [15] .plt.sec          PROGBITS         000000000010d880  0010d880  0000000000001720  0000000000000010  AX       0     0     16
  [16] .text             PROGBITS         000000000010efa0  0010efa0  0000000000dddd4b  0000000000000000  AX       0     0     16
  [17] .fini             PROGBITS         0000000000eeccec  00eeccec  000000000000000d  0000000000000000  AX       0     0     4
  [18] .rodata           PROGBITS         0000000000eed000  00eed000  00000000002ee2e0  0000000000000000   A       0     0     32
  [19] .eh_frame_hdr     PROGBITS         00000000011db2e0  011db2e0  00000000000222ac  0000000000000000   A       0     0     4
  [20] .eh_frame         PROGBITS         00000000011fd590  011fd590  0000000000108080  0000000000000000   A       0     0     8
  [21] .init_array       INIT_ARRAY       0000000001306950  01305950  0000000000000008  0000000000000008  WA       0     0     8
  [22] .fini_array       FINI_ARRAY       0000000001306958  01305958  0000000000000008  0000000000000008  WA       0     0     8
  [23] .data.rel.ro      PROGBITS         0000000001306960  01305960  0000000000112580  0000000000000000  WA       0     0     32
  [24] .dynamic          DYNAMIC          0000000001418ee0  01417ee0  0000000000000290  0000000000000010  WA       7     0     8
  [25] .got              PROGBITS         0000000001419170  01418170  0000000000000e80  0000000000000008  WA       0     0     8
  [26] .data             PROGBITS         000000000141a000  01419000  0000000000001148  0000000000000000  WA       0     0     32
  [27] .bss              NOBITS           000000000141b160  0141a148  0000000001564c70  0000000000000000  WA       0     0     32
  [28] .comment          PROGBITS         0000000000000000  0141a148  000000000000002b  0000000000000001  MS       0     0     1
  [29] .debug_aranges    PROGBITS         0000000000000000  0141a173  000000000001e330  0000000000000000           0     0     1
  [30] .debug_info       PROGBITS         0000000000000000  014384a3  0000000002393d74  0000000000000000           0     0     1
  [31] .debug_abbrev     PROGBITS         0000000000000000  037cc217  0000000000210b30  0000000000000000           0     0     1
  [32] .debug_line       PROGBITS         0000000000000000  039dcd47  0000000000c3e22a  0000000000000000           0     0     1
  [33] .debug_str        PROGBITS         0000000000000000  0461af71  00000000001024e4  0000000000000001  MS       0     0     1
  [34] .debug_line_str   PROGBITS         0000000000000000  0471d455  000000000000de2d  0000000000000001  MS       0     0     1
  [35] .debug_loclists   PROGBITS         0000000000000000  0472b282  000000000171aed3  0000000000000000           0     0     1
  [36] .debug_rnglists   PROGBITS         0000000000000000  05e46155  00000000002430b3  0000000000000000           0     0     1
  [37] .symtab           SYMTAB           0000000000000000  06089208  00000000000ac7d0  0000000000000018          38   22877     8
  [38] .strtab           STRTAB           0000000000000000  061359d8  0000000000070c28  0000000000000000           0     0     1
  [39] .shstrtab         STRTAB           0000000000000000  061a6600  0000000000000197  0000000000000000           0     0     1
Key to Flags:
  W (write), A (alloc), X (execute), M (merge), S (strings), I (info),
  L (link order), O (extra OS processing required), G (group), T (TLS),
  C (compressed), x (unknown), o (OS specific), E (exclude),
  D (mbind), l (large), p (processor specific)

参考:
ffmpeg源码编译环境搭建

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值