如何将x264 x265的动态库编译入Linux系统中的FFmpeg源码 - FFmpeg编译

0 前言

在Linux操作系统中实现x264库编译、x265库编译,并将他们编译入FFmpeg中。作为一个工作记录,方便后面操作。

1 下载ffmpeg

bash 复制代码
git clone https://git.ffmpeg.org/ffmpeg.git ffmpeg
bash 复制代码
cd ffmpeg
git checkout n4.3

2 编译ffmpeg

安装必要的依赖库

bash 复制代码
sudo apt update
sudo apt install -y libsdl2-dev  # ffplay 依赖的 SDL2 库
sudo apt install -y build-essential yasm cmake libtool libc6 libc6-dev unzip wget libfdk-aac-dev libopus-dev
bash 复制代码
./configure --prefix=/usr/local/ffmpeg --enable-debug=3 --disable-static --enable-shared --enable-sdl2 --enable-libfdk-aac --enable-libopus --enable-vaapi --enable-hwaccel=h264_vaapi --enable-hwaccel=hevc_vaapi --enable-gpl --enable-libx264 --enable-libx265 --enable-pthreads --enable-nonfree
make -j4
sudo make install

3 配置路径

bash 复制代码
sudo echo "export PATH=/usr/local/ffmpeg/bin:\$PATH" >> /etc/profile
source /etc/profile 
bash 复制代码
echo "/usr/local/ffmpeg/lib" | sudo tee /etc/ld.so.conf.d/ffmpeg.conf
sudo ldconfig

4 验证是否集成成功

4.1 验证 FFmpeg 是否识别 x264、x265

bash 复制代码
ffmpeg -encoders | grep -E "x264|x265"

若输出类似以下内容,说明集成成功:

bash 复制代码
ffmpeg version n4.3 Copyright (c) 2000-2020 the FFmpeg developers
  built with gcc 11 (Ubuntu 11.4.0-1ubuntu1~22.04.2)
  configuration: --prefix=/usr/local/ffmpeg --enable-debug=3 --disable-static --enable-shared --enable-sdl2 --enable-libfdk-aac --enable-libopus --enable-vaapi --enable-hwaccel=h264_vaapi --enable-hwaccel=hevc_vaapi --enable-gpl --enable-libx264 --enable-libx265 --enable-pthreads --enable-nonfree
  libavutil      56. 51.100 / 56. 51.100
  libavcodec     58. 91.100 / 58. 91.100
  libavformat    58. 45.100 / 58. 45.100
  libavdevice    58. 10.100 / 58. 10.100
  libavfilter     7. 85.100 /  7. 85.100
  libswscale      5.  7.100 /  5.  7.100
  libswresample   3.  7.100 /  3.  7.100
  libpostproc    55.  7.100 / 55.  7.100
 V..... libx264              libx264 H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10 (codec h264)
 V..... libx264rgb           libx264 H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10 RGB (codec h264)
 V..... libx265              libx265 H.265 / HEVC (codec hevc)

4.2 测试编码功能(可选,实际验证可用性)

bash 复制代码
# 使用x264编码视频(输出h264格式)
ffmpeg -i input.mp4 -c:v libx264 -crf 23 -preset medium output_h264.mp4

# 使用x265编码视频(输出h265格式,更高压缩比)
ffmpeg -i input.mp4 -c:v libx265 -crf 28 -preset medium output_h265.mp4
相关推荐
Tipriest_2 小时前
linux /etc/profile.d 目录介绍
linux·运维·服务器
NotStrandedYet2 小时前
CentOS停更后的新选择:图文详解安装6.x内核openEuler+GNOME图形桌面
linux·运维·信创·国产化·openeuler·国产操作系统
山上三树2 小时前
codedump
linux·服务器
boligongzhu2 小时前
ubuntu22.04 安装Docker Engine和Compose
linux·ubuntu·docker·容器
liuyunshengsir2 小时前
huggingface-cli download 断点续传
linux·hugging face·魔塔社区
小码吃趴菜2 小时前
信号与管道
linux
大聪明-PLUS2 小时前
使用 Shell 脚本生成配置文件的 6 种方法
linux·嵌入式·arm·smarc
脏脏a2 小时前
【Linux】Linux 初探:历史溯源与常用指令速览
linux·运维·服务器·基础指令
I · T · LUCKYBOOM2 小时前
2.1编译安装--单台服务器托管多网站
linux·运维·服务器·网络