1、前期准备

下载ffmpeg  

ffmpeg官方下载地址

下载libx264

libx264下载地址

下载jetson-ffmpeg补丁包

jetson-ffmpeg下载地址

2、编译安装libx264

1、解压
tar -zxvf x264.tar.gz 

2、配置
./configure --enable-shared

3、编译&安装
make -j8 && sudo make install

4、验证
x264 --version

看到输出版本号代表安装成功

(base) nvidia@xl:~$ x264 --version
x264 0.165.x
(libswscale 5.5.100)
(libavformat 58.29.100)
built on Apr 11 2025, gcc: 9.4.0
x264 configuration: --chroma-format=all
libx264 configuration: --chroma-format=all
x264 license: GPL version 2 or later
libswscale/libavformat license: GPL version 2 or later

3、编译安装ffmpeg

1、解压
tar -zxvf ffmpeg-4.4.tar.gz

2、配置
./configure --enable-shared --enable-swscale --enable-gpl --enable-nonfree --enable-pic --prefix=/home/nvidia/ffmpeg --enable-version3 --enable-postproc --enable-pthreads --enable-static --enable-libx264

3、编译&安装
make -j8 && sudo make install

4、配置环境变量
vim ~/.bashrc
#  将下面内容写入
export PATH=/home/nvidia/ffmpeg/bin:$PATH
export LD_LIBRARY_PATH=/home/nvidia/ffmpeg/lib/
vim ~/.bashrc

5、验证
ffmpeg --version

出现配置信息即安装成功

(py38) nvidia@xl:~$ ffmpeg
ffmpeg version 2ec7f8e Copyright (c) 2000-2025 the FFmpeg developers
  built with gcc 9 (Ubuntu 9.4.0-1ubuntu1~20.04.2)
  configuration: --enable-shared --enable-swscale --enable-gpl --enable-nonfree --enable-pic --prefix=/home/nvidia/ffmpeg --enable-version3 --enable-postproc --enable-pthreads --enable-static --enable-libx264
  libavutil      56. 70.100 / 56. 70.100
  libavcodec     58.134.100 / 58.134.100
  libavformat    58. 76.100 / 58. 76.100
  libavdevice    58. 13.100 / 58. 13.100
  libavfilter     7.110.100 /  7.110.100
  libswscale      5.  9.100 /  5.  9.100
  libswresample   3.  9.100 /  3.  9.100
  libpostproc    55.  9.100 / 55.  9.100
Hyper fast Audio and Video encoder
usage: ffmpeg [options] [[infile options] -i infile]... {[outfile options] outfile}...

Use -h to get full help or, even better, run 'man ffmpeg'

4、编译安装jetson-ffmpeg

1、编译与安装库
git clone https://github.com/Keylost/jetson-ffmpeg.git
cd jetson-ffmpeg
mkdir build
cd build
cmake ..
make
sudo make install
sudo ldconfig

2、打补丁并构建ffmpeg
git clone git://source.ffmpeg.org/ffmpeg.git -b release/4.4 --depth=1

3、获取与系统相匹配的补丁
wget -O ffmpeg_nvmpi.patch https://github.com/Keylost/jetson-ffmpeg/raw/master/ffmpeg_patches/ffmpeg4.4_nvmpi.patch

4、应用对应ffmpeg版本的补丁
git apply ffmpeg_nvmpi.patch

5、配置文件(添加nvmpi配置,此处配置需要再~/jetson-ffmpeg/build/ffmpeg目录下配置,包括下面的编译安装都在此目录下运行)
./configure --enable-shared --enable-swscale --enable-gpl --enable-nonfree --enable-pic --prefix=/home/nvidia/ffmpeg --enable-version3 --enable-postproc --enable-pthreads --enable-static --enable-libx264 --enable-nvmpi

6、编译及安装
make -j8 && sudo make install

7、验证
ffmpeg

查看配置中是否有nvmpi

(py38) nvidia@xl:~$ ffmpeg
ffmpeg version 2ec7f8e Copyright (c) 2000-2025 the FFmpeg developers
  built with gcc 9 (Ubuntu 9.4.0-1ubuntu1~20.04.2)
  configuration: --enable-shared --enable-swscale --enable-gpl --enable-nonfree --enable-pic --prefix=/home/nvidia/ffmpeg --enable-version3 --enable-postproc --enable-pthreads --enable-static --enable-libx264 --enable-nvmpi
  libavutil      56. 70.100 / 56. 70.100
  libavcodec     58.134.100 / 58.134.100
  libavformat    58. 76.100 / 58. 76.100
  libavdevice    58. 13.100 / 58. 13.100
  libavfilter     7.110.100 /  7.110.100
  libswscale      5.  9.100 /  5.  9.100
  libswresample   3.  9.100 /  3.  9.100
  libpostproc    55.  9.100 / 55.  9.100
Hyper fast Audio and Video encoder
usage: ffmpeg [options] [[infile options] -i infile]... {[outfile options] outfile}...

Use -h to get full help or, even better, run 'man ffmpeg'

至此就可以在jetson的ffmpeg中使用"h264_nvmpi"进行视频编解码了。

Logo

有“AI”的1024 = 2048,欢迎大家加入2048 AI社区

更多推荐